use of org.datanucleus.store.rdbms.mapping.java.EmbeddedPCMapping in project datanucleus-rdbms by datanucleus.
the class ParameterSetter method storeObjectField.
public void storeObjectField(int fieldNumber, Object value) {
StatementMappingIndex mapIdx = stmtMappings.getMappingForMemberPosition(fieldNumber);
if (value == null && mapIdx.getMapping().getMemberMetaData().getNullValue() == NullValue.EXCEPTION) {
throw new NucleusUserException(Localiser.msg("052400", mapIdx.getMapping().getMemberMetaData().getFullFieldName()));
}
try {
JavaTypeMapping mapping = mapIdx.getMapping();
boolean provideOwner = false;
if (mapping instanceof EmbeddedPCMapping || mapping instanceof SerialisedPCMapping || mapping instanceof SerialisedReferenceMapping || mapping instanceof PersistableMapping || mapping instanceof InterfaceMapping) {
// Pass in the owner ObjectProvider/field for any mappings that have relations
provideOwner = true;
}
if (mapIdx.getNumberOfParameterOccurrences() > 0) {
for (int i = 0; i < mapIdx.getNumberOfParameterOccurrences(); i++) {
// Set this value for all occurrences of this parameter
if (provideOwner) {
mapping.setObject(ec, statement, mapIdx.getParameterPositionsForOccurrence(i), value, op, fieldNumber);
} else {
mapping.setObject(ec, statement, mapIdx.getParameterPositionsForOccurrence(i), value);
}
}
} else {
// Important : call setObject even if the paramIndices is null (reachability)
if (provideOwner) {
mapping.setObject(ec, statement, null, value, op, fieldNumber);
} else {
mapping.setObject(ec, statement, null, value);
}
}
AbstractMemberMetaData mmd = op.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
RelationType relationType = mmd.getRelationType(ec.getClassLoaderResolver());
if (op.getClassMetaData().getSCOMutableMemberFlags()[fieldNumber]) {
SCOUtils.wrapSCOField(op, fieldNumber, value, true);
} else if (RelationType.isRelationSingleValued(relationType) && (mmd.getEmbeddedMetaData() != null && mmd.getEmbeddedMetaData().getOwnerMember() != null)) {
// Embedded PC, so make sure the field is wrapped where appropriate TODO This should be part of ManagedRelationships
op.updateOwnerFieldInEmbeddedField(fieldNumber, value);
}
} catch (NotYetFlushedException e) {
if (op.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber).getNullValue() == NullValue.EXCEPTION) {
throw e;
}
op.updateFieldAfterInsert(e.getPersistable(), fieldNumber);
}
}
use of org.datanucleus.store.rdbms.mapping.java.EmbeddedPCMapping in project datanucleus-rdbms by datanucleus.
the class ResultSetGetter method fetchObjectField.
public Object fetchObjectField(int fieldNumber) {
StatementMappingIndex mapIdx = resultMappings.getMappingForMemberPosition(fieldNumber);
JavaTypeMapping mapping = mapIdx.getMapping();
AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
RelationType relationType = mmd.getRelationType(ec.getClassLoaderResolver());
Object value;
if (mapping instanceof EmbeddedPCMapping || mapping instanceof SerialisedPCMapping || mapping instanceof SerialisedReferenceMapping) {
value = mapping.getObject(ec, rs, mapIdx.getColumnPositions(), op, fieldNumber);
} else {
if (mmd.isSingleCollection()) {
StatementClassMapping relationMappings = resultMappings.getMappingDefinitionForMemberPosition(fieldNumber);
if (relationMappings != null) {
Class type = ec.getClassLoaderResolver().classForName(mmd.getCollection().getElementType());
value = processSubObjectFields(mapping, type, relationMappings);
ElementContainerHandler containerHandler = ec.getTypeManager().getContainerHandler(mmd.getType());
value = containerHandler.newContainer(mmd, value);
} else {
value = mapping.getObject(ec, rs, mapIdx.getColumnPositions());
}
} else if (RelationType.isRelationSingleValued(relationType)) {
// Process fields of sub-object if available in this result set
StatementClassMapping relationMappings = resultMappings.getMappingDefinitionForMemberPosition(fieldNumber);
if (relationMappings != null) {
value = processSubObjectFields(mapping, mmd.getType(), relationMappings);
} else {
value = mapping.getObject(ec, rs, mapIdx.getColumnPositions());
}
} else {
value = mapping.getObject(ec, rs, mapIdx.getColumnPositions());
}
}
if (op != null) {
if (cmd.getSCOMutableMemberFlags()[fieldNumber]) {
// Wrap any SCO mutable fields
return SCOUtils.wrapSCOField(op, fieldNumber, value, false);
} else if (RelationType.isRelationSingleValued(relationType) && (mmd.getEmbeddedMetaData() != null && mmd.getEmbeddedMetaData().getOwnerMember() != null)) {
// Embedded PC, so make sure the field is wrapped where appropriate TODO This should be part of ManagedRelationships
op.updateOwnerFieldInEmbeddedField(fieldNumber, value);
return value;
}
}
return value;
}
Aggregations