Search in sources :

Example 1 with SQLBatchUpdateHelper

use of com.dexels.navajo.adapter.sqlmap.SQLBatchUpdateHelper in project navajo by Dexels.

the class SQLMap method getDBResultSet.

/**
 * NOTE: DO NOT USE THIS METHOD ON LARGE RESULTSETS WITHOUT SETTING
 * ENDINDEX.
 */
@Override
public final ResultSet getDBResultSet(boolean updateOnly) throws SQLException, UserException {
    createConnection();
    if (con == null) {
        AuditLog.log("SQLMap", "Could not connect to database: " + datasource + ", check your connection", Level.SEVERE, (myAccess != null ? myAccess.accessID : "unknown access"));
        throw new UserException(-1, "in SQLMap. Could not open database connection [driver = " + driver + ", url = " + url + ", username = '" + username + "', password = '" + password + "']");
    }
    if (debug) {
        Access.writeToConsole(myAccess, "SQLMAP, GOT CONNECTION, STARTING QUERY\n");
    }
    // batch mode?
    this.batchMode = updateOnly && ((this.query == null) || (this.query.length() == 0)) && (this.update != null) && (this.update.indexOf(SQLBatchUpdateHelper.DELIMITER) > 0);
    if (this.batchMode) {
        if (this.debug) {
            Access.writeToConsole(myAccess, this.getClass() + ": detected batch mode, trying a batch update\n");
        }
        this.helper = new SQLBatchUpdateHelper(this.update, this.con, this.parameters, this.myAccess, this.getDbIdentifier(), this, this.isLegacyMode, this.debug, updateOnly);
        this.updateCount = this.helper.getUpdateCount();
        // this.batchMode = false;
        return (this.helper.getResultSet());
    }
    if (debug) {
        Access.writeToConsole(myAccess, "BEFORE PREPARESTATEMENT()\n");
    }
    // Check for open statement.
    if (this.statement != null) {
        try {
            this.statement.close();
        } catch (Exception e) {
        }
        this.statement = null;
    }
    if (query != null) {
        this.statement = con.prepareStatement(query);
    } else {
        this.statement = con.prepareStatement(update);
    }
    openResultSets++;
    if (debug) {
        Access.writeToConsole(myAccess, "AFTER PREPARESTATEMENT(), SETTING MAXROWS...\n");
    }
    this.statement.setMaxRows(this.endIndex);
    if (debug) {
        Access.writeToConsole(myAccess, "SET MAXROWS DONE..SETTING STATEMENT PARAMETERS\n");
    }
    setStatementParameters(statement);
    ResultSet rs = null;
    if (updateOnly) {
        this.statement.executeUpdate();
    } else {
        try {
            if (debug) {
                Access.writeToConsole(myAccess, "CALLING EXECUTEQUERY()\n");
            }
            rs = this.statement.executeQuery();
            if (debug) {
                Access.writeToConsole(myAccess, "GOT RESULTSET!!!!!\n");
            }
        } catch (SQLException e) {
            // using executeQuery() if query does not return a resultset.
            if (e.getMessage().indexOf("JZ0R2") == -1) {
                throw e;
            }
        }
    }
    this.updateCount = this.statement.getUpdateCount();
    // dump any SQL warnings
    if (debug) {
        SQLWarning warning = this.statement.getWarnings();
        while (warning != null) {
            Access.writeToConsole(myAccess, "SQL warning: " + warning.getMessage() + "\n");
            warning = warning.getNextWarning();
        }
    }
    return rs;
}
Also used : SQLWarning(java.sql.SQLWarning) SQLBatchUpdateHelper(com.dexels.navajo.adapter.sqlmap.SQLBatchUpdateHelper) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) UserException(com.dexels.navajo.script.api.UserException) NavajoException(com.dexels.navajo.document.NavajoException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) SQLException(java.sql.SQLException)

Example 2 with SQLBatchUpdateHelper

use of com.dexels.navajo.adapter.sqlmap.SQLBatchUpdateHelper in project navajo by Dexels.

the class JDBCMap method getDBResultSet.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.dexels.navajo.adapter.JDBCMappable#getDBResultSet(boolean)
	 */
@Override
public final ResultSet getDBResultSet(boolean updateOnly) throws SQLException, UserException {
    createConnection();
    if (con == null) {
        AuditLog.log("SQLMap", "Could not connect to database: " + datasource + ", check your connection", Level.SEVERE, (myAccess != null ? myAccess.accessID : "unknown access"));
        throw new UserException(-1, "in SQLMap. Could not open database connection']");
    }
    if (debug) {
        Access.writeToConsole(myAccess, "SQLMAP, GOT CONNECTION, STARTING QUERY\n");
    }
    if (updateOnly && ((this.query == null) || (this.query.length() == 0)) && (this.update != null) && (this.update.indexOf(SQLBatchUpdateHelper.DELIMITER) >= 0)) {
        if (this.debug) {
            Access.writeToConsole(myAccess, this.getClass() + ": detected batch mode, trying a batch update\n");
        }
        SQLBatchUpdateHelper helper = new SQLBatchUpdateHelper(this.update, this.con, this.parameters, this.myAccess, this.dbIdentifier, this, this.isLegacyMode, this.debug, updateOnly);
        this.updateCount = helper.getUpdateCount();
        return (helper.getResultSet());
    }
    if (debug) {
        Access.writeToConsole(myAccess, "BEFORE PREPARESTATEMENT()\n");
    }
    // Check for open statement.
    if (this.statement != null) {
        try {
            this.statement.close();
        } catch (Exception e) {
        }
        this.statement = null;
    }
    if (query != null) {
        this.statement = con.prepareStatement(query);
    } else {
        this.statement = con.prepareStatement(update);
    }
    if (debug) {
        Access.writeToConsole(myAccess, "AFTER PREPARESTATEMENT(), SETTING MAXROWS...\n");
    }
    if (debug) {
        Access.writeToConsole(myAccess, "SET MAXROWS DONE..SETTING STATEMENT PARAMETERS\n");
    }
    setStatementParameters(statement);
    ResultSet rs = null;
    if (updateOnly) {
        this.statement.executeUpdate();
    } else {
        if (debug) {
            Access.writeToConsole(myAccess, "CALLING EXECUTEQUERY()\n");
        }
        rs = this.statement.executeQuery();
        if (debug) {
            Access.writeToConsole(myAccess, "GOT RESULTSET!!!!!\n");
        }
    }
    this.updateCount = this.statement.getUpdateCount();
    // dump any SQL warnings
    if (debug) {
        SQLWarning warning = this.statement.getWarnings();
        while (warning != null) {
            Access.writeToConsole(myAccess, "SQL warning: " + warning.getMessage() + "\n");
            warning = warning.getNextWarning();
        }
    }
    return rs;
}
Also used : SQLWarning(java.sql.SQLWarning) SQLBatchUpdateHelper(com.dexels.navajo.adapter.sqlmap.SQLBatchUpdateHelper) ResultSet(java.sql.ResultSet) UserException(com.dexels.navajo.script.api.UserException) UserException(com.dexels.navajo.script.api.UserException) SQLException(java.sql.SQLException) MappableException(com.dexels.navajo.script.api.MappableException) IOException(java.io.IOException)

Aggregations

SQLBatchUpdateHelper (com.dexels.navajo.adapter.sqlmap.SQLBatchUpdateHelper)2 MappableException (com.dexels.navajo.script.api.MappableException)2 UserException (com.dexels.navajo.script.api.UserException)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 SQLWarning (java.sql.SQLWarning)2 NavajoException (com.dexels.navajo.document.NavajoException)1 IOException (java.io.IOException)1