Search in sources :

Example 6 with DirectMapMapping

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

the class MapCollectionsProject method buildEntityDirectMapHolderDescriptor.

protected void buildEntityDirectMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(EntityDirectMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("ENT_DIR_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("ENT_DIR_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("ENT_DIR_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("ENT_DIR_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    DirectMapMapping directMapMapping = new DirectMapMapping();
    directMapMapping.setAttributeName("entityToDirectMap");
    directMapMapping.setGetMethodName("getEntityToDirectMap");
    directMapMapping.setSetMethodName("setEntityToDirectMap");
    directMapMapping.setReferenceTableName("ENT_DIR_MAP_REL");
    directMapMapping.setDirectFieldName("ENT_DIR_MAP_REL.MAP_VALUE");
    directMapMapping.addReferenceKeyFieldName("ENT_DIR_MAP_REL.HOLDER_ID", "ENT_DIR_MAP_HOLDER.ID");
    directMapMapping.setDirectFieldClassification(Integer.class);
    directMapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    org.eclipse.persistence.mappings.OneToOneMapping keyMapping = new org.eclipse.persistence.mappings.OneToOneMapping();
    keyMapping.setReferenceClass(EntityMapKey.class);
    keyMapping.addForeignKeyFieldName("ENT_DIR_MAP_REL.KEY_ID", "ENT_MAP_KEY.ID");
    keyMapping.dontUseIndirection();
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(directMapMapping);
    directMapMapping.setContainerPolicy(policy);
    descriptor.addMapping(directMapMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 7 with DirectMapMapping

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

the class MapCollectionsProject method buildDirectDirectMapHolderDescriptor.

protected void buildDirectDirectMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(DirectDirectMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("DIR_DIR_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("DIR_DIR_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("DIR_DIR_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("DIR_DIR_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    DirectMapMapping directMapMapping = new DirectMapMapping();
    directMapMapping.setAttributeName("directToDirectMap");
    directMapMapping.setReferenceTableName("DIR_DIR_MAP_REL");
    directMapMapping.setDirectFieldName("DIR_DIR_MAP_REL.MAP_VALUE");
    directMapMapping.addReferenceKeyFieldName("DIR_DIR_MAP_REL.HOLDER_ID", "DIR_DIR_MAP_HOLDER.ID");
    directMapMapping.setDirectFieldClassification(Integer.class);
    directMapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    org.eclipse.persistence.mappings.DirectToFieldMapping keyMapping = new org.eclipse.persistence.mappings.DirectToFieldMapping();
    keyMapping.setFieldName("DIR_DIR_MAP_REL.MAP_KEY");
    keyMapping.setAttributeClassification(Integer.class);
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(directMapMapping);
    directMapMapping.setContainerPolicy(policy);
    descriptor.addMapping(directMapMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) 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) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 8 with DirectMapMapping

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

the class XMLForeignKeyTestSuite method testElementCollectionForeignKeys.

/**
 * Tests an element collection foreign key settings.
 */
public void testElementCollectionForeignKeys() {
    ClassDescriptor runnerDescriptor = getPersistenceUnitServerSession().getDescriptor(Runner.class);
    DirectMapMapping mapping = (DirectMapMapping) runnerDescriptor.getMappingForAttributeName("endorsements");
    OneToOneMapping keyMapping = (OneToOneMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
    DatabaseTable table = mapping.getReferenceTable();
    assertForeignKeyConstraint("FK_JPA22_XMLEndorsements", "FOREIGN KEY (ATHLETE_ID) REFERENCES JPA22_XML_DDL_RUNNER (ID)", table);
    table = keyMapping.getForeignKeyFields().get(0).getTable();
    assertForeignKeyConstraint("FK_JPA22_XMLEndorsements_Key", "FOREIGN KEY (ENDORSER_ID) REFERENCES JPA22_XML_DDL_ENDORSER (ID)", table);
    mapping = (DirectMapMapping) runnerDescriptor.getMappingForAttributeName("accomplishments");
    table = mapping.getReferenceTable();
    assertForeignKeyConstraint("FK_JPA22_XMLAccomplishments", "FOREIGN KEY (ATHLETE_ID) REFERENCES JPA22_XML_DDL_RUNNER (ID)", table);
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 9 with DirectMapMapping

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

the class ForeignKeyTestSuite method testElementCollectionForeignKeys.

/**
 * Tests an element collection foreign key settings.
 */
public void testElementCollectionForeignKeys() {
    ClassDescriptor runnerDescriptor = getPersistenceUnitServerSession().getDescriptor(Runner.class);
    DirectMapMapping mapping = (DirectMapMapping) runnerDescriptor.getMappingForAttributeName("endorsements");
    OneToOneMapping keyMapping = (OneToOneMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
    DatabaseTable table = mapping.getReferenceTable();
    assertForeignKeyConstraint("Endorsements_Foreign_Key", "FOREIGN KEY (ATHLETE_ID) REFERENCES JPA22_DDL_RUNNER (ID)", table);
    table = keyMapping.getForeignKeyFields().get(0).getTable();
    assertForeignKeyConstraint("Endorsements_Key_Foreign_Key", "FOREIGN KEY (ENDORSER_ID) REFERENCES JPA_DDL_ENDORSER (ID)", table);
    mapping = (DirectMapMapping) runnerDescriptor.getMappingForAttributeName("accomplishments");
    table = mapping.getReferenceTable();
    assertForeignKeyConstraint("Accomplistments_Foreign_Key", "FOREIGN KEY (ATHLETE_ID) REFERENCES JPA22_DDL_RUNNER (ID)", table);
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 10 with DirectMapMapping

use of org.eclipse.persistence.mappings.DirectMapMapping in project blaze-persistence by Blazebit.

the class EclipseLinkJpaProvider method getJoinTable.

@Override
public JoinTable getJoinTable(EntityType<?> ownerType, String attributeName) {
    DatabaseMapping mapping = getAttribute(ownerType, attributeName).getMapping();
    if (mapping instanceof OneToOneMapping) {
        OneToOneMapping oneToOneMapping = (OneToOneMapping) mapping;
        if (oneToOneMapping.hasRelationTable()) {
            Map<String, String> idColumnMapping = new LinkedHashMap<>();
            Map<String, String> keyMapping = null;
            Map<String, String> keyColumnTypes = null;
            Map<String, String> targetIdColumnMapping = new LinkedHashMap<>();
            return new JoinTable(oneToOneMapping.getRelationTable().getName(), null, idColumnMapping, keyMapping, keyColumnTypes, null, targetIdColumnMapping);
        }
    } else if (mapping instanceof CollectionMapping) {
        CollectionMapping collectionMapping = (CollectionMapping) mapping;
        if (collectionMapping instanceof ManyToManyMapping) {
            ManyToManyMapping manyToManyMapping = (ManyToManyMapping) collectionMapping;
            Vector<DatabaseField> sourceKeyFields = manyToManyMapping.getSourceKeyFields();
            Vector<DatabaseField> sourceRelationKeyFields = manyToManyMapping.getSourceRelationKeyFields();
            Vector<DatabaseField> targetKeyFields = manyToManyMapping.getTargetKeyFields();
            Vector<DatabaseField> targetRelationKeyFields = manyToManyMapping.getTargetRelationKeyFields();
            Map<String, String> idColumnMapping = new LinkedHashMap<>(sourceKeyFields.size());
            Map<String, String> targetIdColumnMapping = new LinkedHashMap<>(targetKeyFields.size());
            for (int i = 0; i < sourceKeyFields.size(); i++) {
                idColumnMapping.put(sourceKeyFields.get(i).getName(), sourceRelationKeyFields.get(i).getName());
            }
            for (int i = 0; i < targetKeyFields.size(); i++) {
                targetIdColumnMapping.put(targetKeyFields.get(i).getName(), targetRelationKeyFields.get(i).getName());
            }
            return new JoinTable(manyToManyMapping.getRelationTable().getName(), null, idColumnMapping, keyMapping(manyToManyMapping.getContainerPolicy().getIdentityFieldsForMapKey()), null, null, targetIdColumnMapping);
        } else if (collectionMapping instanceof DirectCollectionMapping) {
            DirectCollectionMapping directCollectionMapping = (DirectCollectionMapping) collectionMapping;
            Vector<DatabaseField> sourceKeyFields = directCollectionMapping.getSourceKeyFields();
            Vector<DatabaseField> referenceKeyFields = directCollectionMapping.getReferenceKeyFields();
            Map<String, String> idColumnMapping = new LinkedHashMap<>(sourceKeyFields.size());
            Map<String, String> targetIdColumnMapping = Collections.emptyMap();
            for (int i = 0; i < sourceKeyFields.size(); i++) {
                idColumnMapping.put(sourceKeyFields.get(i).getName(), referenceKeyFields.get(i).getName());
            }
            return new JoinTable(directCollectionMapping.getReferenceTableName(), null, idColumnMapping, keyMapping(directCollectionMapping.getContainerPolicy().getIdentityFieldsForMapKey()), null, null, targetIdColumnMapping);
        } else if (collectionMapping instanceof DirectMapMapping) {
            DirectMapMapping directMapMapping = (DirectMapMapping) collectionMapping;
            Vector<DatabaseField> sourceKeyFields = directMapMapping.getSourceKeyFields();
            Vector<DatabaseField> referenceKeyFields = directMapMapping.getReferenceKeyFields();
            Map<String, String> idColumnMapping = new LinkedHashMap<>(sourceKeyFields.size());
            Map<String, String> targetIdColumnMapping = Collections.emptyMap();
            for (int i = 0; i < sourceKeyFields.size(); i++) {
                idColumnMapping.put(sourceKeyFields.get(i).getName(), referenceKeyFields.get(i).getName());
            }
            return new JoinTable(directMapMapping.getReferenceTableName(), null, idColumnMapping, keyMapping(directMapMapping.getContainerPolicy().getIdentityFieldsForMapKey()), null, null, targetIdColumnMapping);
        } else if (collectionMapping instanceof AggregateCollectionMapping) {
            AggregateCollectionMapping aggregateCollectionMapping = (AggregateCollectionMapping) collectionMapping;
            Vector<DatabaseField> sourceKeyFields = aggregateCollectionMapping.getSourceKeyFields();
            Vector<DatabaseField> targetForeignKeyFields = aggregateCollectionMapping.getTargetForeignKeyFields();
            Map<String, String> idColumnMapping = new LinkedHashMap<>(sourceKeyFields.size());
            Map<String, String> targetIdColumnMapping = Collections.emptyMap();
            String tableName = null;
            for (int i = 0; i < sourceKeyFields.size(); i++) {
                tableName = targetForeignKeyFields.get(i).getTableName();
                idColumnMapping.put(sourceKeyFields.get(i).getName(), targetForeignKeyFields.get(i).getName());
            }
            return new JoinTable(tableName, null, idColumnMapping, keyMapping(aggregateCollectionMapping.getContainerPolicy().getIdentityFieldsForMapKey()), null, null, targetIdColumnMapping);
        }
    }
    return null;
}
Also used : ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) LinkedHashMap(java.util.LinkedHashMap) DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping) AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping) AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) Vector(java.util.Vector) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JoinTable(com.blazebit.persistence.spi.JoinTable)

Aggregations

DirectMapMapping (org.eclipse.persistence.mappings.DirectMapMapping)16 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)6 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)5 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)4 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)4 MappedKeyMapContainerPolicy (org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)4 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)3 AggregateCollectionMapping (org.eclipse.persistence.mappings.AggregateCollectionMapping)2 CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)2 JoinTable (com.blazebit.persistence.spi.JoinTable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Vector (java.util.Vector)1