}
if (versionMetaData != null && versionMetaData.getFieldName() == null)
{
// SELECT clause - set the surrogate version column to the new version
StatementMappingIndex mapIdx = stmtMappingDefinition.getVersion();
for (int i=0;i<mapIdx.getNumberOfParameterOccurrences();i++)
{
table.getVersionMapping(false).setObject(ec, ps,
mapIdx.getParameterPositionsForOccurrence(i), nextVersion);
}
}
// WHERE clause - primary key fields
if (table.getIdentityType() == IdentityType.DATASTORE)
{
// a). datastore identity
StatementMappingIndex mapIdx = stmtMappingDefinition.getDatastoreId();
for (int i=0;i<mapIdx.getNumberOfParameterOccurrences();i++)
{
table.getDatastoreObjectIdMapping().setObject(ec, ps,
mapIdx.getParameterPositionsForOccurrence(i), sm.getInternalObjectId());
}
}
else if (table.getIdentityType() == IdentityType.APPLICATION)
{
// b). application identity
StatementClassMapping mappingDefinition = new StatementClassMapping();
StatementMappingIndex[] idxs = stmtMappingDefinition.getPrimaryKeys();
for (int i=0;i<idxs.length;i++)
{
if (idxs[i] != null)
{
mappingDefinition.addMappingForMember(i, idxs[i]);
}
}
sm.provideFields(pkFieldNumbers,
storeMgr.getFieldManagerForStatementGeneration(sm, ps, mappingDefinition, true));
}
if (optimisticChecks)
{
if (currentVersion == null)
{
// Somehow the version is not set on this object (not read in ?) so report the bug
String msg = LOCALISER.msg("052201",
sm.getInternalObjectId(), table);
NucleusLogger.PERSISTENCE.error(msg);
throw new NucleusException(msg);
}
// WHERE clause - current version discriminator
StatementMappingIndex mapIdx = stmtMappingDefinition.getVersion2();
for (int i=0;i<mapIdx.getNumberOfParameterOccurrences();i++)
{
mapIdx.getMapping().setObject(ec, ps,
mapIdx.getParameterPositionsForOccurrence(i), currentVersion);
}
}
int[] rcs = sqlControl.executeStatementUpdate(mconn, stmt, ps, !batch);
if (rcs[0] == 0 && optimisticChecks)