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;
}
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;
}
Aggregations