Search in sources :

Example 26 with CollectionMapping

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

the class AbstractPersistenceUnitResource method addMapping.

@SuppressWarnings("rawtypes")
private void addMapping(Descriptor descriptor, DatabaseMapping mapping) {
    String target = null;
    String collectionName = null;
    if (mapping.isCollectionMapping()) {
        if (mapping.isEISMapping()) {
            EISCompositeCollectionMapping collectionMapping = (EISCompositeCollectionMapping) mapping;
            Class collectionClass = collectionMapping.getContainerPolicy().getContainerClass();
            String collectionType = getSimplePublicCollectionTypeName(collectionClass);
            if (collectionType == null) {
                collectionType = collectionClass.getSimpleName();
            }
            if (collectionMapping.getReferenceClass() != null) {
                collectionName = collectionMapping.getReferenceClass().getSimpleName();
            }
            if ((collectionName == null) && (collectionMapping.getAttributeClassification() != null)) {
                collectionName = collectionMapping.getAttributeClassification().getSimpleName();
            }
            if (collectionMapping.getContainerPolicy().isMapPolicy()) {
                String mapKeyType = collectionMapping.getContainerPolicy().getKeyType().getClass().getSimpleName();
                target = collectionType + "<" + mapKeyType + ", " + collectionName + ">";
            } else {
                target = collectionType + "<" + collectionName + ">";
            }
        } else {
            CollectionMapping collectionMapping = (CollectionMapping) mapping;
            Class collectionClass = collectionMapping.getContainerPolicy().getContainerClass();
            String collectionType = getSimplePublicCollectionTypeName(collectionClass);
            if (collectionType == null) {
                collectionType = collectionClass.getSimpleName();
            }
            if (collectionMapping.getReferenceClass() != null) {
                collectionName = collectionMapping.getReferenceClass().getSimpleName();
            }
            if ((collectionName == null) && (collectionMapping.getAttributeClassification() != null)) {
                collectionName = collectionMapping.getAttributeClassification().getSimpleName();
            }
            if (collectionMapping.getContainerPolicy().isMapPolicy()) {
                String mapKeyType = collectionMapping.getContainerPolicy().getKeyType().getClass().getSimpleName();
                target = collectionType + "<" + mapKeyType + ", " + collectionName + ">";
            } else {
                target = collectionType + "<" + collectionName + ">";
            }
        }
    } else if (mapping.isForeignReferenceMapping()) {
        target = ((ForeignReferenceMapping) mapping).getReferenceClass().getSimpleName();
    } else {
        target = mapping.getAttributeClassification().getSimpleName();
    }
    descriptor.getAttributes().add(new Attribute(mapping.getAttributeName(), target));
}
Also used : EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping) Attribute(org.eclipse.persistence.internal.jpa.rs.metadata.model.Attribute) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping) EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping)

Example 27 with CollectionMapping

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

the class DirectCollectionAccessor method process.

/**
 * INTERNAL:
 */
protected void process(DatabaseMapping mapping) {
    // Add the mapping to the descriptor.
    setMapping(mapping);
    // Set the attribute name.
    mapping.setAttributeName(getAttributeName());
    // Will check for PROPERTY access
    setAccessorMethods(mapping);
    if (mapping instanceof CollectionMapping) {
        CollectionMapping collectionMapping = (CollectionMapping) mapping;
        // Set the reference class name.
        collectionMapping.setReferenceClassName(getReferenceClassName());
        // Process join fetch type.
        processJoinFetch(getJoinFetch(), collectionMapping);
        // Process the batch fetch if specified.
        processBatchFetch(collectionMapping);
        // Process the collection table.
        processCollectionTable(collectionMapping);
        // The spec. requires pessimistic lock to be extend-able to CollectionTable
        collectionMapping.setShouldExtendPessimisticLockScope(true);
        // Set the cascade on delete if specified.
        collectionMapping.setIsCascadeOnDeleteSetOnDatabase(isCascadeOnDelete());
    } else if (mapping instanceof AggregateMapping) {
        AggregateMapping aggregateMapping = (AggregateMapping) mapping;
        // Set the reference class name.
        aggregateMapping.setReferenceClassName(getReferenceClassName());
    }
    // Set the non cacheable if specified.
    mapping.setIsCacheable(!isNonCacheable());
    // Process a @ReturnInsert and @ReturnUpdate (to log a warning message)
    processReturnInsertAndUpdate();
    // Process any partitioning policies.
    processPartitioning();
}
Also used : DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping) AbstractCompositeDirectCollectionMapping(org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping) AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) AggregateMapping(org.eclipse.persistence.mappings.AggregateMapping)

Aggregations

CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)27 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)11 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)6 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)4 Expression (org.eclipse.persistence.expressions.Expression)3 AggregateCollectionMapping (org.eclipse.persistence.mappings.AggregateCollectionMapping)3 EntityManager (jakarta.persistence.EntityManager)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 EISCompositeCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping)2 EISOneToManyMapping (org.eclipse.persistence.eis.mappings.EISOneToManyMapping)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)2 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)2 MapContainerPolicy (org.eclipse.persistence.internal.queries.MapContainerPolicy)2 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)2 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)2