DatabaseMap dbMap = Torque.getDatabaseMap(criteria.getDbName());
TableMap tableMap = dbMap.getTable(tableName);
Object keyInfo = tableMap.getPrimaryKeyMethodInfo();
IdGenerator keyGen = tableMap.getIdGenerator();
ColumnMap pk = getPrimaryKey(criteria);
// pk will be null if there is no primary key defined for the table
// we're inserting into.
if (pk != null && !criteria.containsKey(pk.getFullyQualifiedName()))
{
if (keyGen == null)
{
throw new TorqueException(
"IdGenerator for table '" + tableName + "' is null");
}
// If the keyMethod is SEQUENCE or IDBROKERTABLE, get the id
// before the insert.
if (keyGen.isPriorToInsert())
{
try
{
if (pk.getType() instanceof Number)
{
id = new NumberKey(
keyGen.getIdAsBigDecimal(con, keyInfo));
}
else
{
id = new StringKey(keyGen.getIdAsString(con, keyInfo));
}
}
catch (Exception e)
{
throwTorqueException(e);
}
criteria.add(pk.getFullyQualifiedName(), id);
}
}
// Use Village to perform the insert.
TableDataSet tds = null;
try
{
tds = new TableDataSet(con, tableName);
Record rec = tds.addRecord();
BasePeer.insertOrUpdateRecord(rec, tableName, criteria);
}
catch (Exception e)
{
throwTorqueException(e);
}
finally
{
if (tds != null)
{
try
{
tds.close();
}
catch (Exception e)
{
throwTorqueException(e);
}
}
}
// If the primary key column is auto-incremented, get the id
// now.
if (pk != null && keyGen != null && keyGen.isPostInsert())
{
try
{
if (pk.getType() instanceof Number)
{
id = new NumberKey(keyGen.getIdAsBigDecimal(con, keyInfo));
}
else
{