Search in sources :

Example 6 with EmbeddedValuePCMapping

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;
}
Also used : JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) EmbeddedValuePCMapping(org.datanucleus.store.rdbms.mapping.java.EmbeddedValuePCMapping)

Example 7 with EmbeddedValuePCMapping

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;
}
Also used : JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ObjectProvider(org.datanucleus.state.ObjectProvider) EmbeddedValuePCMapping(org.datanucleus.store.rdbms.mapping.java.EmbeddedValuePCMapping) StatementMappingIndex(org.datanucleus.store.rdbms.query.StatementMappingIndex) ParameterSetter(org.datanucleus.store.rdbms.fieldmanager.ParameterSetter) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) StatementClassMapping(org.datanucleus.store.rdbms.query.StatementClassMapping)

Aggregations

EmbeddedValuePCMapping (org.datanucleus.store.rdbms.mapping.java.EmbeddedValuePCMapping)7 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)6 EmbeddedKeyPCMapping (org.datanucleus.store.rdbms.mapping.java.EmbeddedKeyPCMapping)4 ForeignKeyMetaData (org.datanucleus.metadata.ForeignKeyMetaData)3 PersistableMapping (org.datanucleus.store.rdbms.mapping.java.PersistableMapping)3 ArrayList (java.util.ArrayList)2 KeyMetaData (org.datanucleus.metadata.KeyMetaData)2 PrimaryKeyMetaData (org.datanucleus.metadata.PrimaryKeyMetaData)2 ValueMetaData (org.datanucleus.metadata.ValueMetaData)2 ReferenceMapping (org.datanucleus.store.rdbms.mapping.java.ReferenceMapping)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)1 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)1 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)1 IndexMetaData (org.datanucleus.metadata.IndexMetaData)1 MapMetaData (org.datanucleus.metadata.MapMetaData)1