Search in sources :

Example 11 with AbstractDirectMapping

use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.

the class ObjectAccessor method processMapsId.

/**
 * INTERNAL:
 * Process the mapping keys from the maps id value.
 */
protected void processMapsId(OneToOneMapping oneToOneMapping) {
    EmbeddedIdAccessor embeddedIdAccessor = getDescriptor().getEmbeddedIdAccessor();
    if (embeddedIdAccessor == null) {
        // Case #4: a simple id association
        MappingAccessor idAccessor = getDescriptor().getMappingAccessor(getDescriptor().getIdAttributeName());
        DatabaseMapping idMapping = idAccessor.getMapping();
        // Grab the foreign key field and set it as the descriptor's id field.
        DatabaseField foreignKeyField = oneToOneMapping.getForeignKeyFields().elementAt(0);
        updatePrimaryKeyField(idAccessor, foreignKeyField);
        // Update the field on the mapping.
        ((AbstractDirectMapping) idMapping).setField(foreignKeyField);
        // Set the primary key mapping as read only.
        idMapping.setIsReadOnly(true);
        // Set the maps id mapping.
        oneToOneMapping.setDerivedIdMapping(idMapping);
    } else {
        if (embeddedIdAccessor.getReferenceClassName().equals(getReferenceDescriptor().getPKClassName())) {
            // Case #5: Parent's id class is the same as dependent's embedded id class
            // Case #6: Both parent and dependent use same embedded id class.
            processMapsIdFields(oneToOneMapping, embeddedIdAccessor, embeddedIdAccessor);
        } else {
            if (m_mapsId.equals("")) {
                // User didn't specify a mapsId value. By default the attribute name from this object accessor is used.
                m_mapsId = getAttributeName();
            }
            // Set the maps id value on the mapping.
            oneToOneMapping.setMapsIdValue(m_mapsId);
            MappingAccessor mappingAccessor = embeddedIdAccessor.getReferenceDescriptor().getMappingAccessor(m_mapsId);
            if (mappingAccessor == null) {
                throw ValidationException.invalidMappedByIdValue(m_mapsId, getAnnotatedElementName(), embeddedIdAccessor.getReferenceClass());
            } else {
                // Case #1: Dependent's embedded id maps a basic mapping to parent entity.
                // Case #2: Dependent's embedded id maps the parent's id class
                // Case #3: Dependent's embedded if maps the parent's embedded id class
                processMapsIdFields(oneToOneMapping, embeddedIdAccessor, mappingAccessor);
            }
        }
        // Set the maps id mapping.
        oneToOneMapping.setDerivedIdMapping(embeddedIdAccessor.getMapping());
    }
}
Also used : AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 12 with AbstractDirectMapping

use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.

the class AbstractEntityResource method checkIdempotenceOnRelationships.

/**
 * This method maintains idempotence on PUT by disallowing sequencing in relationships.
 *
 * @param descriptor    descriptor of the entity passed in 'entity' parameter.
 * @param entity        entity to process.
 * @return true if check is passed (no sequencing)
 */
private boolean checkIdempotenceOnRelationships(ClassDescriptor descriptor, Object entity) {
    final List<DatabaseMapping> mappings = descriptor.getMappings();
    if ((mappings != null) && (!mappings.isEmpty())) {
        for (DatabaseMapping mapping : mappings) {
            if (mapping instanceof ForeignReferenceMapping) {
                final ForeignReferenceMapping fkMapping = (ForeignReferenceMapping) mapping;
                if ((fkMapping.isCascadePersist()) || (fkMapping.isCascadeMerge())) {
                    final ClassDescriptor referenceDescriptor = fkMapping.getReferenceDescriptor();
                    if (referenceDescriptor != null) {
                        if (referenceDescriptor instanceof RelationalDescriptor) {
                            final RelationalDescriptor relDesc = (RelationalDescriptor) referenceDescriptor;
                            final AbstractDirectMapping relSequenceMapping = relDesc.getObjectBuilder().getSequenceMapping();
                            if (relSequenceMapping != null) {
                                final Object value = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
                                if (value != null) {
                                    if (value instanceof ValueHolder) {
                                        final ValueHolder<?> holder = (ValueHolder<?>) value;
                                        if (holder.getValue() != null) {
                                            return false;
                                        }
                                    } else if (value instanceof Collection) {
                                        if (!(((Collection<?>) value).isEmpty())) {
                                            return false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Collection(java.util.Collection) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) ValueHolder(org.eclipse.persistence.indirection.ValueHolder)

Example 13 with AbstractDirectMapping

use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.

the class DynamicTypeBuilder method addEnum.

public DynamicEnumBuilder addEnum(String fieldName, String className, String columnName, DynamicClassLoader dcl) {
    dcl.addEnum(className, (Object) null);
    AbstractDirectMapping adm = addDirectMappingForEnum(fieldName, className, columnName);
    return new DynamicEnumBuilder(className, adm, dcl);
}
Also used : AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping)

Example 14 with AbstractDirectMapping

use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.

the class ClassDescriptor method addDirectMapping.

/**
 * PUBLIC:
 * Add a direct to field mapping to the receiver. The new mapping specifies that
 * an instance variable of the class of objects which the receiver describes maps in
 * the default manner for its type to the indicated database field.
 *
 * @param attributeName is the name of an instance variable of the
 * class which the receiver describes.
 * @param fieldName is the name of the database column which corresponds
 * with the designated instance variable.
 * @return The newly created DatabaseMapping is returned.
 */
public DatabaseMapping addDirectMapping(String attributeName, String fieldName) {
    AbstractDirectMapping mapping = newDirectMapping();
    mapping.setAttributeName(attributeName);
    mapping.setField(new DatabaseField(fieldName));
    return addMapping(mapping);
}
Also used : AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField)

Example 15 with AbstractDirectMapping

use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.

the class MappedKeyMapContainerPolicy method setKeyField.

/**
 * INTERNAL:
 * Set the DatabaseField that will represent the key in a DirectMapMapping.
 */
public void setKeyField(DatabaseField keyField, ClassDescriptor descriptor) {
    if (keyMapping == null) {
        AbstractDirectMapping newKeyMapping = new DirectToFieldMapping();
        newKeyMapping.setField(keyField);
        newKeyMapping.setDescriptor(descriptor);
        setKeyMapping(newKeyMapping);
    }
    if (((DatabaseMapping) keyMapping).isDirectToFieldMapping()) {
        ((AbstractDirectMapping) keyMapping).setField(keyField);
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Aggregations

AbstractDirectMapping (org.eclipse.persistence.mappings.foundation.AbstractDirectMapping)20 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)6 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)6 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)3 Converter (org.eclipse.persistence.mappings.converters.Converter)3 Iterator (java.util.Iterator)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)2 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)2 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)2 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)2 SerializedObjectConverter (org.eclipse.persistence.mappings.converters.SerializedObjectConverter)2 TypeConversionConverter (org.eclipse.persistence.mappings.converters.TypeConversionConverter)2 XMLField (org.eclipse.persistence.oxm.XMLField)2 IOException (java.io.IOException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Vector (java.util.Vector)1