示例#1
0
 /**
  * Execute a stored procedure that updates data
  *
  * @param statementScope - the request scope
  * @param conn - the database connection
  * @param sql - the SQL to call the procedure
  * @param parameters - the parameters for the procedure
  * @return - the rows impacted by the procedure
  * @throws SQLException - if the procedure fails
  */
 public int executeUpdateProcedure(
     StatementScope statementScope, Connection conn, String sql, Object[] parameters)
     throws SQLException {
   ErrorContext errorContext = statementScope.getErrorContext();
   errorContext.setActivity("executing update procedure");
   errorContext.setObjectId(sql);
   CallableStatement cs = null;
   setupResultObjectFactory(statementScope);
   int rows = 0;
   try {
     errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
     cs = prepareCall(statementScope.getSession(), conn, sql);
     setStatementTimeout(statementScope.getStatement(), cs);
     ParameterMap parameterMap = statementScope.getParameterMap();
     ParameterMapping[] mappings = parameterMap.getParameterMappings();
     errorContext.setMoreInfo("Check the output parameters (register output parameters failed).");
     registerOutputParameters(cs, mappings);
     errorContext.setMoreInfo("Check the parameters (set parameters failed).");
     parameterMap.setParameters(statementScope, cs, parameters);
     errorContext.setMoreInfo("Check the statement (update procedure failed).");
     cs.execute();
     rows = cs.getUpdateCount();
     errorContext.setMoreInfo(
         "Check the output parameters (retrieval of output parameters failed).");
     retrieveOutputParameters(statementScope, cs, mappings, parameters, null);
   } finally {
     closeStatement(statementScope.getSession(), cs);
   }
   return rows;
 }
示例#2
0
  /**
   * Execute a stored procedure
   *
   * @param statementScope - the request scope
   * @param conn - the database connection
   * @param sql - the sql to call the procedure
   * @param parameters - the parameters for the procedure
   * @param skipResults - the number of results to skip
   * @param maxResults - the maximum number of results to return
   * @param callback - a row handler for processing the results
   * @throws SQLException - if the procedure fails
   */
  public void executeQueryProcedure(
      StatementScope statementScope,
      Connection conn,
      String sql,
      Object[] parameters,
      int skipResults,
      int maxResults,
      RowHandlerCallback callback)
      throws SQLException {
    ErrorContext errorContext = statementScope.getErrorContext();
    errorContext.setActivity("executing query procedure");
    errorContext.setObjectId(sql);
    CallableStatement cs = null;
    ResultSet rs = null;
    setupResultObjectFactory(statementScope);
    try {
      errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
      Integer rsType = statementScope.getStatement().getResultSetType();
      if (rsType != null) {
        cs = prepareCall(statementScope.getSession(), conn, sql, rsType);
      } else {
        cs = prepareCall(statementScope.getSession(), conn, sql);
      }
      setStatementTimeout(statementScope.getStatement(), cs);
      Integer fetchSize = statementScope.getStatement().getFetchSize();
      if (fetchSize != null) {
        cs.setFetchSize(fetchSize.intValue());
      }
      ParameterMap parameterMap = statementScope.getParameterMap();
      ParameterMapping[] mappings = parameterMap.getParameterMappings();
      errorContext.setMoreInfo("Check the output parameters (register output parameters failed).");
      registerOutputParameters(cs, mappings);
      errorContext.setMoreInfo("Check the parameters (set parameters failed).");
      parameterMap.setParameters(statementScope, cs, parameters);
      errorContext.setMoreInfo("Check the statement (update procedure failed).");
      cs.execute();
      errorContext.setMoreInfo("Check the results (failed to retrieve results).");

      // Begin ResultSet Handling
      rs = handleMultipleResults(cs, statementScope, skipResults, maxResults, callback);
      // End ResultSet Handling
      errorContext.setMoreInfo(
          "Check the output parameters (retrieval of output parameters failed).");
      retrieveOutputParameters(statementScope, cs, mappings, parameters, callback);

    } finally {
      try {
        closeResultSet(rs);
      } finally {
        closeStatement(statementScope.getSession(), cs);
      }
    }
  }
示例#3
0
  public Object setData(
      StatementScope statementScope,
      ParameterMap parameterMap,
      Object parameterObject,
      Object[] values) {
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
    List data = new ArrayList();
    for (int i = 0; i < mappings.length; i++) {
      if (mappings[i].isOutputAllowed()) {
        String propName = mappings[i].getPropertyName();
        int index = Integer.parseInt((propName.substring(1, propName.length() - 1)));
        data.set(index, values[i]);
      }
    }

    return data;
  }
示例#4
0
  public Object[] getData(
      StatementScope statementScope, ParameterMap parameterMap, Object parameterObject) {
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
    Object[] data = new Object[mappings.length];
    for (int i = 0; i < mappings.length; i++) {
      String propName = mappings[i].getPropertyName();

      // parse on the '.' notation and get nested properties
      String[] propertyArray = propName.split("\\.");

      if (propertyArray.length > 0) {
        // iterate list of properties to discover values

        Object tempData = parameterObject;

        for (int x = 0; x < propertyArray.length; x++) {

          // is property an array reference
          int arrayStartIndex = propertyArray[x].indexOf('[');

          if (arrayStartIndex == -1) {

            // is a normal property
            tempData = ProbeFactory.getProbe().getObject(tempData, propertyArray[x]);

          } else {

            int index =
                Integer.parseInt(
                    propertyArray[x].substring(arrayStartIndex + 1, propertyArray[x].length() - 1));
            tempData = ((List) tempData).get(index);
          }
        }

        data[i] = tempData;

      } else {

        int index =
            Integer.parseInt(
                (propName.substring(propName.indexOf('[') + 1, propName.length() - 1)));
        data[i] = ((List) parameterObject).get(index);
      }
    }
    return data;
  }