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();
if (clustered) {
sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'" + " FOR UPDATE";
} else {
sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'";
}
rs = stmt.executeQuery(sql);
boolean gotVal1 = false;
if (rs.next()) {
val1 = rs.getLong(SequenceUtil.this.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 " + SequenceUtil.this.tableName + " (" + SequenceUtil.this.nameColName + ", " + SequenceUtil.this.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 " + SequenceUtil.this.tableName + " SET " + SequenceUtil.this.idColName + "=" + SequenceUtil.this.idColName + "+" + bankSize + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'";
if (stmt.executeUpdate(sql) <= 0) {
throw new GenericEntityException("[SequenceUtil.SequenceBank.fillBank] update failed, no rows changes for seqName: " + seqName);
}
if (clustered) {
sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'" + " FOR UPDATE";
} else {
sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'";
}
rs = stmt.executeQuery(sql);
boolean gotVal2 = false;
if (rs.next()) {
val2 = rs.getLong(SequenceUtil.this.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