}
}
catch (NotYetFlushedException e)
{
setObjectAsNull(ec, ps, param);
throw new NotYetFlushedException(value);
}
}
if (valueSM != null)
{
valueSM.setStoringPC();
}
// If the field doesn't map to any datastore fields (e.g remote FK), omit the set process
if (getNumberOfDatastoreMappings() > 0)
{
if (id instanceof OID)
{
OID oid = (OID)id;
try
{
// Try as a Long
getDatastoreMapping(0).setObject(ps, param[0], oid.getKeyValue());
}
catch (Exception e)
{
// Must be a String
getDatastoreMapping(0).setObject(ps, param[0], oid.getKeyValue().toString());
}
}
else
{
boolean fieldsSet = false;
if (api.isSingleFieldIdentity(id) && javaTypeMappings.length > 1)
{
Object key = api.getTargetKeyForSingleFieldIdentity(id);
AbstractClassMetaData keyCmd = ec.getMetaDataManager().getMetaDataForClass(key.getClass(), clr);
if (keyCmd != null && keyCmd.getIdentityType() == IdentityType.NONDURABLE)
{
// Embedded ID - Make sure these are called starting at lowest first, in order
// We cannot just call OP.provideFields with all fields since that does last first
ObjectProvider keyOP = ec.findObjectProvider(key);
int[] fieldNums = keyCmd.getAllMemberPositions();
FieldManager fm = new AppIDObjectIdFieldManager(param, ec, ps, javaTypeMappings);
for (int i=0;i<fieldNums.length;i++)
{
keyOP.provideFields(new int[] {fieldNums[i]}, fm);
}
fieldsSet = true;
}
}
if (!fieldsSet)
{
// TODO Factor out this PersistenceCapable reference
((PersistenceCapable)value).jdoCopyKeyFieldsFromObjectId(
new AppIDObjectIdFieldManager(param, ec, ps, javaTypeMappings), id);
}
}
}
}
else
{
if (valueSM != null)
{
valueSM.setStoringPC();
}
if (getNumberOfDatastoreMappings() > 0)
{
// Object is in the process of being inserted so we cant use its id currently and we need to store
// a foreign key to it (which we cant yet do). Just put "null" in and throw "NotYetFlushedException",
// to be caught by ParameterSetter and will signal to the PC object being inserted that it needs
// to inform this object when it is inserted.
setObjectAsNull(ec, ps, param);
throw new NotYetFlushedException(value);
}
}
}
finally
{