use of org.datanucleus.store.rdbms.mapping.java.EmbeddedValuePCMapping in project datanucleus-rdbms by datanucleus.
the class AbstractMapStore method updateEmbeddedValue.
/**
* Method to update a field of an embedded key.
* @param op ObjectProvider of the owner
* @param value The value to update
* @param fieldNumber The number of the field to update
* @param newValue The new value
*/
public boolean updateEmbeddedValue(ObjectProvider op, Object value, int fieldNumber, Object newValue) {
boolean modified = false;
if (valueMapping != null && valueMapping instanceof EmbeddedValuePCMapping) {
String fieldName = valueCmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber).getName();
if (fieldName == null) {
// We have no mapping for this field so presumably is the owner field or a PK field
return false;
}
JavaTypeMapping fieldMapping = ((EmbeddedValuePCMapping) valueMapping).getJavaTypeMapping(fieldName);
if (fieldMapping == null) {
// We have no mapping for this field so presumably is the owner field or a PK field
return false;
}
modified = updateEmbeddedValue(op, value, fieldNumber, newValue, fieldMapping);
}
return modified;
}
use of org.datanucleus.store.rdbms.mapping.java.EmbeddedValuePCMapping in project datanucleus-rdbms by datanucleus.
the class BackingStoreHelper method populateEmbeddedValueFieldsInStatement.
/**
* Convenience method to populate the passed PreparedStatement with the field values from
* the embedded map value starting at the specified jdbc position.
* @param op ObjectProvider of the owning container
* @param value The embedded value
* @param ps The PreparedStatement
* @param jdbcPosition JDBC position in the statement to start at
* @param joinTable The Join table where the values are embedded
* @param mapStore The map store
* @return The next JDBC position
*/
public static int populateEmbeddedValueFieldsInStatement(ObjectProvider op, Object value, PreparedStatement ps, int jdbcPosition, JoinTable joinTable, AbstractMapStore mapStore) {
AbstractClassMetaData vmd = mapStore.getValueClassMetaData();
EmbeddedValuePCMapping embeddedMapping = (EmbeddedValuePCMapping) mapStore.getValueMapping();
StatementClassMapping mappingDefinition = new StatementClassMapping();
int[] elementFieldNumbers = new int[embeddedMapping.getNumberOfJavaTypeMappings()];
for (int i = 0; i < embeddedMapping.getNumberOfJavaTypeMappings(); i++) {
JavaTypeMapping fieldMapping = embeddedMapping.getJavaTypeMapping(i);
int absFieldNum = vmd.getAbsolutePositionOfMember(fieldMapping.getMemberMetaData().getName());
elementFieldNumbers[i] = absFieldNum;
StatementMappingIndex stmtMapping = new StatementMappingIndex(fieldMapping);
int[] jdbcParamPositions = new int[fieldMapping.getNumberOfDatastoreMappings()];
for (int j = 0; j < fieldMapping.getNumberOfDatastoreMappings(); j++) {
jdbcParamPositions[j] = jdbcPosition++;
}
stmtMapping.addParameterOccurrence(jdbcParamPositions);
mappingDefinition.addMappingForMember(absFieldNum, stmtMapping);
}
ObjectProvider elementOP = mapStore.getObjectProviderForEmbeddedPCObject(op, value, joinTable.getOwnerMemberMetaData(), ObjectProvider.EMBEDDED_MAP_VALUE_PC);
elementOP.provideFields(elementFieldNumbers, new ParameterSetter(elementOP, ps, mappingDefinition));
return jdbcPosition;
}
Aggregations