Debug.logWarning("[SequenceUtil.SequenceBank.fillBank]: Unable to esablish a connection with the database... Error was: " + e.toString(), module);
throw e;
}
if (connection == null) {
throw new GenericEntityException("[SequenceUtil.SequenceBank.fillBank]: Unable to esablish a connection with the database, connection was null...");
}
String sql = null;
try {
// we shouldn't need this, and some TX managers complain about it, so not including it: connection.setAutoCommit(false);
stmt = connection.createStatement();
sql = "SELECT " + parentUtil.idColName + " FROM " + parentUtil.tableName + " WHERE " + parentUtil.nameColName + "='" + this.seqName + "'";
rs = stmt.executeQuery(sql);
boolean gotVal1 = false;
if (rs.next()) {
val1 = rs.getLong(parentUtil.idColName);
gotVal1 = true;
}
rs.close();
if (!gotVal1) {
Debug.logWarning("[SequenceUtil.SequenceBank.fillBank] first select failed: will try to add new row, result set was empty for sequence [" + seqName + "] \nUsed SQL: " + sql + " \n Thread Name is: " + Thread.currentThread().getName() + ":" + Thread.currentThread().toString(), module);
sql = "INSERT INTO " + parentUtil.tableName + " (" + parentUtil.nameColName + ", " + parentUtil.idColName + ") VALUES ('" + this.seqName + "', " + startSeqId + ")";
if (stmt.executeUpdate(sql) <= 0) {
throw new GenericEntityException("No rows changed when trying insert new sequence row with this SQL: " + sql);
}
continue;
}
sql = "UPDATE " + parentUtil.tableName + " SET " + parentUtil.idColName + "=" + parentUtil.idColName + "+" + bankSize + " WHERE " + parentUtil.nameColName + "='" + this.seqName + "'";
if (stmt.executeUpdate(sql) <= 0) {
throw new GenericEntityException("[SequenceUtil.SequenceBank.fillBank] update failed, no rows changes for seqName: " + seqName);
}
sql = "SELECT " + parentUtil.idColName + " FROM " + parentUtil.tableName + " WHERE " + parentUtil.nameColName + "='" + this.seqName + "'";
rs = stmt.executeQuery(sql);
boolean gotVal2 = false;
if (rs.next()) {
val2 = rs.getLong(parentUtil.idColName);
gotVal2 = true;
}
rs.close();
if (!gotVal2) {
throw new GenericEntityException("[SequenceUtil.SequenceBank.fillBank] second select failed: aborting, result set was empty for sequence: " + seqName);
}
// got val1 and val2 at this point, if we don't have the right difference between them, force a rollback (with
//setRollbackOnly and NOT with an exception because we don't want to break from the loop, just err out and
//continue), then flow out to allow the wait and loop thing to happen