Package com.ibatis.sqlmap.engine.scope

Examples of com.ibatis.sqlmap.engine.scope.ErrorContext


   * @throws SQLException - if the query fails
   */
  public void executeQuery(RequestScope request, Connection conn, String sql, Object[] parameters,
                           int skipResults, int maxResults, RowHandlerCallback callback)
      throws SQLException {
    ErrorContext errorContext = request.getErrorContext();
    errorContext.setActivity("executing query");
    errorContext.setObjectId(sql);

    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");

      Integer rsType = request.getStatement().getResultSetType();
      if (rsType != null) {
        ps = conn.prepareStatement(sql, rsType.intValue(), ResultSet.CONCUR_READ_ONLY);
      } else {
        ps = conn.prepareStatement(sql);
      }

      Integer fetchSize = request.getStatement().getFetchSize();
      if (fetchSize != null) {
        ps.setFetchSize(fetchSize.intValue());
      }

      errorContext.setMoreInfo("Check the parameters (set parameters failed).");
      request.getParameterMap().setParameters(request, ps, parameters);

      errorContext.setMoreInfo("Check the statement (query failed).");

      ps.execute();
      rs = ps.getResultSet();

      errorContext.setMoreInfo("Check the results (failed to retrieve results).");
      handleResults(request, rs, skipResults, maxResults, callback);

      // clear out remaining results
      while (ps.getMoreResults());

View Full Code Here


   *
   * @throws SQLException - if the procedure fails
   */
  public int executeUpdateProcedure(RequestScope request, Connection conn, String sql, Object[] parameters)
      throws SQLException {
    ErrorContext errorContext = request.getErrorContext();
    errorContext.setActivity("executing update procedure");
    errorContext.setObjectId(sql);

    CallableStatement cs = null;
    int rows = 0;

    try {
      errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
      cs = conn.prepareCall(sql);

      ParameterMap parameterMap = request.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(request, 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(cs, mappings, parameters);
    } finally {
      closeStatement(cs);
    }

View Full Code Here

   * @throws SQLException - if the procedure fails
   */
  public void executeQueryProcedure(RequestScope request, Connection conn, String sql, Object[] parameters,
                                    int skipResults, int maxResults, RowHandlerCallback callback)
      throws SQLException {
    ErrorContext errorContext = request.getErrorContext();
    errorContext.setActivity("executing query procedure");
    errorContext.setObjectId(sql);

    CallableStatement cs = null;
    ResultSet rs = null;

    try {
      errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
      cs = conn.prepareCall(sql);

      ParameterMap parameterMap = request.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(request, cs, parameters);

      errorContext.setMoreInfo("Check the statement (update procedure failed).");

      cs.execute();
      rs = cs.getResultSet();

      errorContext.setMoreInfo("Check the results (failed to retrieve results).");
      handleResults(request, rs, skipResults, maxResults, callback);

      // consume additional results
      while (cs.getMoreResults());

      errorContext.setMoreInfo("Check the output parameters (retrieval of output parameters failed).");
      retrieveOutputParameters(cs, mappings, parameters);

    } finally {
      try {
        closeResultSet(rs);
View Full Code Here

     * @return - the number of records changed
     * @throws SQLException
     *             - if the update fails
     */
    public int executeUpdate(StatementScope statementScope, Connection conn, String sql, Object[] parameters) throws SQLException {
        ErrorContext errorContext = statementScope.getErrorContext();
        errorContext.setActivity("executing update");
        errorContext.setObjectId(sql);
        PreparedStatement ps = null;
        setupResultObjectFactory(statementScope);
        int rows = 0;
        try {
            errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
            ps = prepareStatement(statementScope.getSession(), conn, sql);
            setStatementTimeout(statementScope.getStatement(), ps);
            errorContext.setMoreInfo("Check the parameters (set parameters failed).");
            statementScope.getParameterMap().setParameters(statementScope, ps, parameters);
            errorContext.setMoreInfo("Check the statement (update failed).");
            ps.execute();
            rows = ps.getUpdateCount();
        } finally {
            closeStatement(statementScope.getSession(), ps);
            // conn.commit();
View Full Code Here

     * @throws SQLException
     *             - if the query fails
     */
    public void executeQuery(StatementScope statementScope, Connection conn, String sql, Object[] parameters, int skipResults,
            int maxResults, RowHandlerCallback callback) throws SQLException {
        ErrorContext errorContext = statementScope.getErrorContext();
        errorContext.setActivity("executing query");
        errorContext.setObjectId(sql);
        PreparedStatement ps = null;
        ResultSet rs = null;
        setupResultObjectFactory(statementScope);
        try {
            errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
            Integer rsType = statementScope.getStatement().getResultSetType();
            if (rsType != null) {
                ps = prepareStatement(statementScope.getSession(), conn, sql, rsType);
            } else {
                ps = prepareStatement(statementScope.getSession(), conn, sql);
            }
            setStatementTimeout(statementScope.getStatement(), ps);
            Integer fetchSize = statementScope.getStatement().getFetchSize();
            if (fetchSize != null) {
                ps.setFetchSize(fetchSize.intValue());
            }
            errorContext.setMoreInfo("Check the parameters (set parameters failed).");
            statementScope.getParameterMap().setParameters(statementScope, ps, parameters);
            errorContext.setMoreInfo("Check the statement (query failed).");
            ps.execute();
            errorContext.setMoreInfo("Check the results (failed to retrieve results).");

            // Begin ResultSet Handling
            rs = handleMultipleResults(ps, statementScope, skipResults, maxResults, callback);
            // End ResultSet Handling
        } finally {
View Full Code Here

     * @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;
View Full Code Here

     * @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);
View Full Code Here

    public Object setData(StatementScope statementScope, ResultMap resultMap, Object resultObject, Object[] values) {
        if (resultPlan != null) {
            Object object = resultObject;

            ErrorContext errorContext = statementScope.getErrorContext();

            if (object == null) {
                errorContext.setMoreInfo("The error occured while instantiating the result object");
                try {
                    object = ResultObjectFactoryUtil.createObjectThroughFactory(resultMap.getResultClass());
                } catch (Exception e) {
                    throw new RuntimeException("JavaBeansDataExchange could not instantiate result class.  Cause: " + e, e);
                }
            }
            errorContext.setMoreInfo("The error happened while setting a property on the result object.");
            resultPlan.setProperties(object, values);
            return object;
        } else {
            return null;
        }
View Full Code Here

            DEBUG.P(1);

            DEBUG.P("this.getId()=" + this.getId());
            DEBUG.P("this.getResource()=" + this.getResource());

            ErrorContext errorContext = statementScope.getErrorContext();
            errorContext.setActivity("preparing the mapped statement for execution");
            errorContext.setObjectId(this.getId()); //sql语句id
            errorContext.setResource(this.getResource()); //对应表的sqlMap文件名

            try {
                parameterObject = validateParameter(parameterObject);

                Sql sql = getSql();

                errorContext.setMoreInfo("Check the parameter map.");
                ParameterMap parameterMap = sql.getParameterMap(statementScope, parameterObject);

                errorContext.setMoreInfo("Check the result map.");
                ResultMap resultMap = sql.getResultMap(statementScope, parameterObject);

                statementScope.setResultMap(resultMap);
                statementScope.setParameterMap(parameterMap);

                errorContext.setMoreInfo("Check the parameter map.");
                Object[] parameters = parameterMap.getParameterObjectValues(statementScope, parameterObject);

                DEBUG.PA("parameters", parameters);

                errorContext.setMoreInfo("Check the SQL statement.");
                String sqlString = sql.getSql(statementScope, parameterObject);

                DEBUG.P("sqlString=" + sqlString);

                errorContext.setActivity("executing mapped statement");
                errorContext.setMoreInfo("Check the SQL statement or the result map.");
                RowHandlerCallback callback = new RowHandlerCallback(resultMap, resultObject, rowHandler);
                sqlExecuteQuery(statementScope, conn, sqlString, parameters, skipResults, maxResults, callback);

                errorContext.setMoreInfo("Check the output parameters.");
                if (parameterObject != null) {
                    //是个空的实现
                    postProcessParameterObject(statementScope, parameterObject, parameters);
                }

                errorContext.reset();
                sql.cleanup(statementScope);
                notifyListeners();
            } catch (SQLException e) {
                errorContext.setCause(e);
                throw new NestedSQLException(errorContext.toString(), e.getSQLState(), e.getErrorCode(), e);
            } catch (Exception e) {
                errorContext.setCause(e);
                throw new NestedSQLException(errorContext.toString(), e);
            }

        } finally {//我加上的
            DEBUG.P(0, this, "executeQueryWithCallback(...)");
        }
View Full Code Here

     * @return row read as an array of column values.
     *
     * @throws java.sql.SQLException
     */
    public Object[] getResults(StatementScope statementScope, ResultSet rs) throws SQLException {
        ErrorContext errorContext = statementScope.getErrorContext();
        errorContext.setActivity("applying a result map");
        errorContext.setObjectId(this.getId());
        errorContext.setResource(this.getResource());
        errorContext.setMoreInfo("Check the result map.");

        boolean foundData = false;
        Object[] columnValues = new Object[getResultMappings().length];
        for (int i = 0; i < getResultMappings().length; i++) {
            ResultMapping mapping = (ResultMapping) getResultMappings()[i];
            errorContext.setMoreInfo(mapping.getErrorString());
            if (mapping.getStatementName() != null) {
                if (resultClass == null) {
                    throw new SqlMapException("The result class was null when trying to get results for ResultMap named "
                            + getId() + ".");
                } else if (Map.class.isAssignableFrom(resultClass)) {
View Full Code Here

TOP

Related Classes of com.ibatis.sqlmap.engine.scope.ErrorContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.