}
try
{
ManagedConnection mconn = storeMgr.getConnection(om);
SQLController sqlControl = storeMgr.getSQLController();
try
{
PreparedStatement ps = sqlControl.getStatementForQuery(mconn, stmt[useUpdateLock ? 1 : 0]);
try
{
// Provide the primary key field(s)
if (sm.getInternalObjectId() instanceof OID)
{
table.getDataStoreObjectIdMapping().setObject(om, ps,
mappingStatementIndex.getDatastoreId().getParameterIndex(), sm.getInternalObjectId());
}
else
{
sm.provideFields(consumer.getPrimaryKeyFieldsToBeProvided(),
new ParameterSetter(sm, ps, mappingStatementIndex.getFields(), false));
}
ResultSet rs = sqlControl.executeStatementQuery(mconn, stmt[useUpdateLock ? 1 : 0], ps);
try
{
if (!rs.next())
{
JPOXLogger.DATASTORE_RETRIEVE.warn(LOCALISER.msg("050018",
sm.getInternalObjectId()));
throw new JPOXObjectNotFoundException("No such database row", sm.getInternalObjectId());
}
sm.replaceFields(consumer.getNumbersOfFieldsToBeFetched(),
new ResultSetGetter(sm, rs, mappingStatementIndex.getFields()));
if (sm.getTransactionalVersion(sm.getObject()) == null)
{
// Object has no version set so update it from this fetch
Object datastoreVersion = null;
if (fetchingSurrogateVersion)
{
// Surrogate version column - get from the result set using the version mapping
datastoreVersion = table.getVersionMapping(true).getObject(om, rs,
mappingStatementIndex.getVersion().getExpressionIndex());
}
else if (versionFieldName != null)
{
// Version field - already populated in the field in the object
AbstractClassMetaData cmd = (AbstractClassMetaData)versionMetaData.getParent();
datastoreVersion = sm.provideField(cmd.getAbsolutePositionOfMember(versionFieldName));
}
sm.setVersion(datastoreVersion);
}
}
finally
{
rs.close();
}
}
finally
{
sqlControl.closeStatement(mconn, ps);
}
}
finally
{
mconn.release();