Search in sources :

Example 16 with AggregateObjectMapping

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

the class MapCollectionsProject method buildAggregateEntity1MMapHolderDescriptor.

protected void buildAggregateEntity1MMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(AggregateEntity1MMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("AGG_ENT_1M_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("AGG_ENT_1M_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("AGG_ENT_1M_MAP_HOLDER_ID");
    descriptor.setSequenceNumberFieldName("ID");
    // SECTION: DIRECTTOFIELDMAPPING
    org.eclipse.persistence.mappings.DirectToFieldMapping directtofieldmapping = new org.eclipse.persistence.mappings.DirectToFieldMapping();
    directtofieldmapping.setAttributeName("id");
    directtofieldmapping.setIsReadOnly(false);
    directtofieldmapping.setGetMethodName("getId");
    directtofieldmapping.setSetMethodName("setId");
    directtofieldmapping.setFieldName("AGG_ENT_1M_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    OneToManyMapping mapMapping = new OneToManyMapping();
    mapMapping.setAttributeName("aggregateToEntityMap");
    mapMapping.setReferenceClass(AEOTMMapValue.class);
    mapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    mapMapping.setGetMethodName("getAggregateToEntityMap");
    mapMapping.setSetMethodName("setAggregateToEntityMap");
    mapMapping.addTargetForeignKeyFieldName("AE_OM_ENT_MAP_VALUE.HOLDER_ID", "AGG_ENT_1M_MAP_HOLDER.ID");
    AggregateObjectMapping keyMapping = new AggregateObjectMapping();
    keyMapping.setReferenceClass(AggregateMapKey.class);
    keyMapping.addFieldNameTranslation("AE_OM_ENT_MAP_VALUE.MAP_KEY", "key->DIRECT");
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(mapMapping);
    mapMapping.setContainerPolicy(policy);
    descriptor.addMapping(mapMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) UnidirectionalOneToManyMapping(org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)

Example 17 with AggregateObjectMapping

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

the class MapCollectionsProject method buildAggregateAggregateMapHolderDescriptor.

protected void buildAggregateAggregateMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(AggregateAggregateMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("AGG_AGG_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("AGG_AGG_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("AGG_AGG_MAP_HOLDER_ID");
    descriptor.setSequenceNumberFieldName("ID");
    // SECTION: DIRECTTOFIELDMAPPING
    org.eclipse.persistence.mappings.DirectToFieldMapping directtofieldmapping = new org.eclipse.persistence.mappings.DirectToFieldMapping();
    directtofieldmapping.setAttributeName("id");
    directtofieldmapping.setIsReadOnly(false);
    directtofieldmapping.setGetMethodName("getId");
    directtofieldmapping.setSetMethodName("setId");
    directtofieldmapping.setFieldName("AGG_AGG_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    // SECTION: AGGREGATECOLLECTIONMAPPING
    org.eclipse.persistence.mappings.AggregateCollectionMapping aggregatecollectionmapping = new org.eclipse.persistence.mappings.AggregateCollectionMapping();
    aggregatecollectionmapping.setAttributeName("aggregateToAggregateMap");
    aggregatecollectionmapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    aggregatecollectionmapping.setGetMethodName("getAggregateToAggregateMap");
    aggregatecollectionmapping.setSetMethodName("setAggregateToAggregateMap");
    aggregatecollectionmapping.setReferenceClass(AggregateMapKey.class);
    aggregatecollectionmapping.addTargetForeignKeyFieldName("AGG_AGG_MAP_REL.HOLDER_ID", "AGG_AGG_MAP_HOLDER.ID");
    aggregatecollectionmapping.addFieldNameTranslation("AGG_AGG_MAP_REL.MAP_VALUE", "key->DIRECT");
    AggregateObjectMapping keyMapping = new AggregateObjectMapping();
    keyMapping.setReferenceClass(AggregateMapKey.class);
    keyMapping.addFieldNameTranslation("AGG_AGG_MAP_REL.MAP_KEY", "key->DIRECT");
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(aggregatecollectionmapping);
    aggregatecollectionmapping.setContainerPolicy(policy);
    descriptor.addMapping(aggregatecollectionmapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)

Example 18 with AggregateObjectMapping

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

the class MapCollectionsProject method buildAggregateEntityU1MMapHolderDescriptor.

protected void buildAggregateEntityU1MMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(AggregateEntityU1MMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("AGG_ENT_U1M_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("AGG_ENT_U1M_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("AGG_ENT_U1M_MAP_HOLDER_ID");
    descriptor.setSequenceNumberFieldName("ID");
    // SECTION: DIRECTTOFIELDMAPPING
    org.eclipse.persistence.mappings.DirectToFieldMapping directtofieldmapping = new org.eclipse.persistence.mappings.DirectToFieldMapping();
    directtofieldmapping.setAttributeName("id");
    directtofieldmapping.setIsReadOnly(false);
    directtofieldmapping.setGetMethodName("getId");
    directtofieldmapping.setSetMethodName("setId");
    directtofieldmapping.setFieldName("AGG_ENT_U1M_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    UnidirectionalOneToManyMapping mapMapping = new UnidirectionalOneToManyMapping();
    mapMapping.setAttributeName("aggregateToEntityMap");
    mapMapping.setReferenceClass(EntityMapValue.class);
    mapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    mapMapping.setGetMethodName("getAggregateToEntityMap");
    mapMapping.setSetMethodName("setAggregateToEntityMap");
    mapMapping.addTargetForeignKeyFieldName("ENT_MAP_VALUE.HOLDER_ID", "AGG_ENT_U1M_MAP_HOLDER.ID");
    AggregateObjectMapping keyMapping = new AggregateObjectMapping();
    keyMapping.setReferenceClass(AggregateMapKey.class);
    keyMapping.addFieldNameTranslation("ENT_MAP_VALUE.MAP_KEY_1", "key->DIRECT");
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(mapMapping);
    mapMapping.setContainerPolicy(policy);
    descriptor.addMapping(mapMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy) UnidirectionalOneToManyMapping(org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)

Example 19 with AggregateObjectMapping

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

the class MapCollectionsProject method buildAggregateEntityMapHolderDescriptor.

protected void buildAggregateEntityMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(AggregateEntityMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("AGG_ENT_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("AGG_ENT_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("AGG_ENT_MAP_HOLDER_ID");
    descriptor.setSequenceNumberFieldName("ID");
    // SECTION: DIRECTTOFIELDMAPPING
    org.eclipse.persistence.mappings.DirectToFieldMapping directtofieldmapping = new org.eclipse.persistence.mappings.DirectToFieldMapping();
    directtofieldmapping.setAttributeName("id");
    directtofieldmapping.setIsReadOnly(false);
    directtofieldmapping.setGetMethodName("getId");
    directtofieldmapping.setSetMethodName("setId");
    directtofieldmapping.setFieldName("AGG_ENT_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    ManyToManyMapping mapMapping = new ManyToManyMapping();
    mapMapping.setAttributeName("aggregateToEntityMap");
    mapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    mapMapping.setReferenceClass(EntityMapValue.class);
    mapMapping.setRelationTableName("AGG_ENT_MAP_REL");
    mapMapping.setGetMethodName("getAggregateToEntityMap");
    mapMapping.setSetMethodName("setAggregateToEntityMap");
    mapMapping.addSourceRelationKeyFieldName("AGG_ENT_MAP_REL.HOLDER_ID", "AGG_ENT_MAP_HOLDER.ID");
    mapMapping.addTargetRelationKeyFieldName("AGG_ENT_MAP_REL.VALUE_ID", "ENT_MAP_VALUE.ID");
    AggregateObjectMapping keyMapping = new AggregateObjectMapping();
    keyMapping.setReferenceClass(AggregateMapKey.class);
    keyMapping.addFieldNameTranslation("AGG_ENT_MAP_REL.MAP_KEY", "key->DIRECT");
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(mapMapping);
    mapMapping.setContainerPolicy(policy);
    descriptor.addMapping(mapMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)

Example 20 with AggregateObjectMapping

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

the class ObjectPersistenceRuntimeXMLProject method buildAggregateObjectMappingDescriptor.

protected ClassDescriptor buildAggregateObjectMappingDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(AggregateObjectMapping.class);
    descriptor.getInheritancePolicy().setParentClass(AggregateMapping.class);
    XMLDirectMapping isNullAllowedMapping = new XMLDirectMapping();
    isNullAllowedMapping.setAttributeName("isNullAllowed");
    isNullAllowedMapping.setGetMethodName("isNullAllowed");
    isNullAllowedMapping.setSetMethodName("setIsNullAllowed");
    isNullAllowedMapping.setXPath(getPrimaryNamespaceXPath() + "allow-null/text()");
    isNullAllowedMapping.setNullValue(Boolean.TRUE);
    descriptor.addMapping(isNullAllowedMapping);
    XMLCompositeCollectionMapping aggregateToSourceFieldNameAssociationsMapping = new XMLCompositeCollectionMapping();
    aggregateToSourceFieldNameAssociationsMapping.setReferenceClass(FieldTranslation.class);
    // Handle translation of fields associations string to field.
    aggregateToSourceFieldNameAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            /*bug 322233: AttributeOverrides and AssociationOverride
                 * changed getAggregateToSourceFieldAssociations to hold String->DatabaseField associations
                 */
            AggregateObjectMapping mapping = (AggregateObjectMapping) object;
            List<Association> associations = mapping.getAggregateToSourceFieldAssociations();
            Vector<FieldTranslation> translations = new Vector<>(associations.size());
            for (int index = 0; index < associations.size(); index++) {
                Association association = associations.get(index);
                FieldTranslation translation = new FieldTranslation();
                translation.setKey(new DatabaseField((String) association.getKey()));
                translation.setValue(association.getValue());
                translations.add(translation);
            }
            return translations;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            AggregateObjectMapping mapping = (AggregateObjectMapping) object;
            @SuppressWarnings({ "unchecked" }) Vector<Association> associations = (Vector<Association>) value;
            for (int index = 0; index < associations.size(); index++) {
                Association association = associations.get(index);
                association.setKey(((DatabaseField) association.getKey()).getQualifiedName());
            }
            mapping.setAggregateToSourceFieldAssociations(associations);
        }
    });
    aggregateToSourceFieldNameAssociationsMapping.setAttributeName("aggregateToSourceFieldNameAssociationsMapping");
    aggregateToSourceFieldNameAssociationsMapping.setXPath(getPrimaryNamespaceXPath() + "field-translations/" + getPrimaryNamespaceXPath() + "field-translation");
    descriptor.addMapping(aggregateToSourceFieldNameAssociationsMapping);
    return descriptor;
}
Also used : AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) Association(org.eclipse.persistence.mappings.Association) PropertyAssociation(org.eclipse.persistence.mappings.PropertyAssociation) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) FieldTranslation(org.eclipse.persistence.internal.descriptors.FieldTranslation) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) ArrayList(java.util.ArrayList) List(java.util.List) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) Vector(java.util.Vector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector)

Aggregations

AggregateObjectMapping (org.eclipse.persistence.mappings.AggregateObjectMapping)21 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)10 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)8 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)5 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)5 MappedKeyMapContainerPolicy (org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)5 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)5 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)4 ArrayList (java.util.ArrayList)3 Vector (java.util.Vector)3 VersionLockingPolicy (org.eclipse.persistence.descriptors.VersionLockingPolicy)2 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)2 Association (org.eclipse.persistence.mappings.Association)2 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)2 UnidirectionalOneToManyMapping (org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)2 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)2 Test (org.junit.Test)2 EmbeddedParameters (com.haulmont.cuba.core.entity.annotation.EmbeddedParameters)1 EmbeddedParameters (io.jmix.core.entity.annotation.EmbeddedParameters)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1