Search in sources :

Example 6 with EmbeddedElementPCMapping

use of org.datanucleus.store.rdbms.mapping.java.EmbeddedElementPCMapping in project datanucleus-rdbms by datanucleus.

the class AbstractCollectionStore method updateEmbeddedElement.

/**
 * Method to update a field of an embedded element.
 * @param op ObjectProvider of the owner
 * @param element The element to update
 * @param fieldNumber The number of the field to update
 * @param value The value
 * @return true if the datastore was updated
 */
public boolean updateEmbeddedElement(ObjectProvider op, E element, int fieldNumber, Object value) {
    boolean modified = false;
    if (elementMapping != null && elementMapping instanceof EmbeddedElementPCMapping) {
        String fieldName = elementCmd.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 = ((EmbeddedElementPCMapping) elementMapping).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 = updateEmbeddedElement(op, element, fieldNumber, value, fieldMapping);
    }
    return modified;
}
Also used : JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) EmbeddedElementPCMapping(org.datanucleus.store.rdbms.mapping.java.EmbeddedElementPCMapping)

Example 7 with EmbeddedElementPCMapping

use of org.datanucleus.store.rdbms.mapping.java.EmbeddedElementPCMapping in project datanucleus-rdbms by datanucleus.

the class AbstractCollectionStore method getUpdateEmbeddedElementStmt.

/**
 * Generate statement for update the field of an embedded element.
 * <PRE>
 * UPDATE SETTABLE
 * SET EMBEDDEDFIELD1 = ?
 * WHERE OWNERCOL=?
 * AND ELEMENTCOL = ?
 * </PRE>
 *
 * @param fieldMapping The mapping for the field within the embedded object to be updated
 * @return Statement for updating an embedded element in the Set
 */
protected String getUpdateEmbeddedElementStmt(JavaTypeMapping fieldMapping) {
    JavaTypeMapping ownerMapping = getOwnerMapping();
    StringBuilder stmt = new StringBuilder("UPDATE ").append(containerTable.toString()).append(" SET ");
    for (int i = 0; i < fieldMapping.getNumberOfDatastoreMappings(); i++) {
        if (i > 0) {
            stmt.append(",");
        }
        stmt.append(fieldMapping.getDatastoreMapping(i).getColumn().getIdentifier().toString());
        stmt.append(" = ");
        stmt.append(fieldMapping.getDatastoreMapping(i).getUpdateInputParameter());
    }
    stmt.append(" WHERE ");
    BackingStoreHelper.appendWhereClauseForMapping(stmt, ownerMapping, null, true);
    EmbeddedElementPCMapping embeddedMapping = (EmbeddedElementPCMapping) elementMapping;
    for (int i = 0; i < embeddedMapping.getNumberOfJavaTypeMappings(); i++) {
        JavaTypeMapping m = embeddedMapping.getJavaTypeMapping(i);
        if (m != null) {
            for (int j = 0; j < m.getNumberOfDatastoreMappings(); j++) {
                stmt.append(" AND ");
                stmt.append(m.getDatastoreMapping(j).getColumn().getIdentifier().toString());
                stmt.append(" = ");
                stmt.append(m.getDatastoreMapping(j).getUpdateInputParameter());
            }
        }
    }
    return stmt.toString();
}
Also used : JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) EmbeddedElementPCMapping(org.datanucleus.store.rdbms.mapping.java.EmbeddedElementPCMapping)

Aggregations

EmbeddedElementPCMapping (org.datanucleus.store.rdbms.mapping.java.EmbeddedElementPCMapping)7 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)6 ArrayList (java.util.ArrayList)2 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)2 PersistableMapping (org.datanucleus.store.rdbms.mapping.java.PersistableMapping)2 ReferenceMapping (org.datanucleus.store.rdbms.mapping.java.ReferenceMapping)2 SerialisedPCMapping (org.datanucleus.store.rdbms.mapping.java.SerialisedPCMapping)2 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ExecutionContext (org.datanucleus.ExecutionContext)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 ElementMetaData (org.datanucleus.metadata.ElementMetaData)1 IndexMetaData (org.datanucleus.metadata.IndexMetaData)1 UniqueMetaData (org.datanucleus.metadata.UniqueMetaData)1 ObjectProvider (org.datanucleus.state.ObjectProvider)1 NoTableManagedException (org.datanucleus.store.rdbms.exceptions.NoTableManagedException)1 ParameterSetter (org.datanucleus.store.rdbms.fieldmanager.ParameterSetter)1