boolean adjustQuantity)
throws Exception
{
BigDecimal nextId = null;
BigDecimal quantity = null;
DatabaseMap dbMap = tableMap.getDatabaseMap();
TableMap tMap = dbMap.getTable(tableName);
// Block on the table. Multiple tables are allowed to ask for
// ids simultaneously.
// synchronized(tMap) see comment in the getNextIds method
// {
if (adjustQuantity)
checkTiming(tableName);
DBConnection dbCon = null;
try
{
String databaseName = dbMap.getName();
// Get a connection to the db by starting a
// transaction.
if (transactionsSupported)
{
dbCon = BasePeer.beginTransaction(databaseName);
}
else
{
dbCon = TurbineDB.getConnection(databaseName);
}
Connection connection = dbCon.getConnection();
// Write the current value of quantity of keys to grab
// to the database, primarily to obtain a write lock
// on the table/row, but this value will also be used
// as the starting value when an IDBroker is
// instantiated.
quantity = getQuantity(tableName);
Criteria criteria = new Criteria(2)
.add( QUANTITY, quantity );
Criteria selectCriteria = new Criteria(2)
.add( TABLE_NAME, tableName );
criteria.setDbName(dbMap.getName());
selectCriteria.setDbName(dbMap.getName());
BasePeer.doUpdate( selectCriteria, criteria, dbCon );
// Read the next starting ID from the ID_TABLE.
BigDecimal[] results = selectRow(connection, tableName);
nextId = results[0]; // NEXT_ID column