Search in sources :

Example 11 with DirectMapMapping

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

the class DirectMapMergeTest method getNewProject.

@Override
protected Project getNewProject() {
    Project p = new DirectMapMappingsProject();
    DirectMapMapping mapping = (DirectMapMapping) p.getDescriptor(DirectMapMappings.class).getMappingForAttributeName("directMap");
    mapping.setKeyClass(Integer.class);
    return p;
}
Also used : Project(org.eclipse.persistence.sessions.Project) DirectMapMappingsProject(org.eclipse.persistence.testing.models.directmap.DirectMapMappingsProject) DirectMapMappingsProject(org.eclipse.persistence.testing.models.directmap.DirectMapMappingsProject) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 12 with DirectMapMapping

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

the class TestUpdateEntityDirectMapMapping method setup.

@Override
public void setup() {
    DirectMapMapping mapping = (DirectMapMapping) getSession().getProject().getDescriptor(EntityDirectMapHolder.class).getMappingForAttributeName("entityToDirectMap");
    keyMapping = (ForeignReferenceMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
    oldKeyPrivateOwnedValue = keyMapping.isPrivateOwned();
    keyMapping.setIsPrivateOwned(usePrivateOwned);
    super.setup();
}
Also used : MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 13 with DirectMapMapping

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

the class DirectMapMappingsProject method buildDescriptors.

public RelationalDescriptor buildDescriptors() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(org.eclipse.persistence.testing.models.directmap.DirectMapMappings.class);
    descriptor.addTableName("DIRECTMAPMAPPINGS");
    descriptor.addPrimaryKeyFieldName("DIRECTMAPMAPPINGS.ID");
    // RelationalDescriptor properties.
    descriptor.useSoftCacheWeakIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("DIRECTMAPMAPPINGS.ID");
    descriptor.setSequenceNumberName("dmmappings_seq");
    descriptor.setAlias("DirectMapMappings");
    // Query manager.
    descriptor.getQueryManager().checkCacheForDoesExist();
    // Mappings.
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("DIRECTMAPMAPPINGS.ID");
    descriptor.addMapping(idMapping);
    DirectMapMapping directMapMapping = new DirectMapMapping();
    directMapMapping.setAttributeName("directMap");
    directMapMapping.setReferenceTableName("DIRECTMAP1");
    directMapMapping.setDirectFieldName("DIRECTMAP1.VAL");
    // "KEY" is a reserved keyword for SyBase, it can't be used as a field name
    directMapMapping.setDirectKeyFieldName("DIRECTMAP1.KEY_FIELD");
    directMapMapping.addReferenceKeyFieldName("DIRECTMAP1.ID", "DIRECTMAPMAPPINGS.ID");
    directMapMapping.setReferenceClass(Hashtable.class);
    directMapMapping.setUsesIndirection(false);
    directMapMapping.useMapClass(Hashtable.class);
    directMapMapping.setKeyClass(Integer.class);
    directMapMapping.setValueClass(String.class);
    descriptor.addMapping(directMapMapping);
    // direct map batch reading mapping
    DirectMapMapping directMapBatchMapping = new DirectMapMapping();
    directMapBatchMapping.setAttributeName("directMapForBatchRead");
    directMapBatchMapping.setReferenceTableName("DIRECTMAP2");
    directMapBatchMapping.setDirectFieldName("DIRECTMAP2.VAL");
    directMapBatchMapping.setDirectKeyFieldName("DIRECTMAP2.KEY_FIELD");
    directMapBatchMapping.addReferenceKeyFieldName("DIRECTMAP2.ID", "DIRECTMAPMAPPINGS.ID");
    directMapBatchMapping.setReferenceClass(Hashtable.class);
    directMapBatchMapping.setUsesIndirection(false);
    directMapBatchMapping.useMapClass(Hashtable.class);
    directMapBatchMapping.setKeyClass(Integer.class);
    directMapBatchMapping.setValueClass(String.class);
    directMapBatchMapping.useBatchReading();
    descriptor.addMapping(directMapBatchMapping);
    DirectMapMapping indirectionDirectMapMapping = new DirectMapMapping();
    indirectionDirectMapMapping.setAttributeName("indirectionDirectMap");
    indirectionDirectMapMapping.setReferenceTableName("DIRECTMAP3");
    indirectionDirectMapMapping.setDirectFieldName("DIRECTMAP3.VAL");
    indirectionDirectMapMapping.setDirectKeyFieldName("DIRECTMAP3.KEY_FIELD");
    indirectionDirectMapMapping.addReferenceKeyFieldName("DIRECTMAP3.ID", "DIRECTMAPMAPPINGS.ID");
    indirectionDirectMapMapping.setReferenceClass(Hashtable.class);
    indirectionDirectMapMapping.useTransparentMap();
    indirectionDirectMapMapping.useMapClass(IndirectMapSubclass.class);
    indirectionDirectMapMapping.setKeyClass(Integer.class);
    indirectionDirectMapMapping.setValueClass(String.class);
    descriptor.addMapping(indirectionDirectMapMapping);
    DirectMapMapping directMapBlobMapping = new DirectMapMapping();
    directMapBlobMapping.setAttributeName("blobDirectMap");
    directMapBlobMapping.setReferenceTableName("DIRECTMAPBLOB");
    directMapBlobMapping.setDirectFieldName("DIRECTMAPBLOB.VAL");
    directMapBlobMapping.setDirectKeyFieldName("DIRECTMAPBLOB.KEY_FIELD");
    directMapBlobMapping.addReferenceKeyFieldName("DIRECTMAPBLOB.ID", "DIRECTMAPMAPPINGS.ID");
    directMapBlobMapping.setReferenceClass(Hashtable.class);
    directMapBlobMapping.setUsesIndirection(false);
    directMapBlobMapping.useMapClass(Hashtable.class);
    directMapBlobMapping.setKeyClass(Integer.class);
    directMapBlobMapping.setValueClass(Object.class);
    directMapBlobMapping.setValueConverter(new SerializedObjectConverter(directMapBlobMapping));
    descriptor.addMapping(directMapBlobMapping);
    DirectMapMapping directHashMapMapping = new DirectMapMapping();
    directHashMapMapping.setAttributeName("directHashMap");
    directHashMapMapping.setReferenceTableName("DIRECTMAP4");
    directHashMapMapping.setDirectFieldName("DIRECTMAP4.VAL");
    directHashMapMapping.setDirectKeyFieldName("DIRECTMAP4.KEY_FIELD");
    directHashMapMapping.addReferenceKeyFieldName("DIRECTMAP4.ID", "DIRECTMAPMAPPINGS.ID");
    directHashMapMapping.setReferenceClass(HashMap.class);
    directHashMapMapping.setUsesIndirection(false);
    directHashMapMapping.useMapClass(HashMap.class);
    directHashMapMapping.setKeyClass(Integer.class);
    directHashMapMapping.setValueClass(String.class);
    descriptor.addMapping(directHashMapMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 14 with DirectMapMapping

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

the class TypeResolver method visit.

@Override
public void visit(ValueExpression expression) {
    IdentificationVariable identificationVariable = (IdentificationVariable) expression.getExpression();
    Declaration declaration = queryContext.findDeclaration(identificationVariable.getVariableName());
    DatabaseMapping mapping = declaration.getMapping();
    if (mapping.isDirectMapMapping()) {
        DirectMapMapping mapMapping = (DirectMapMapping) mapping;
        type = mapMapping.getValueClass();
        if (type == null) {
            type = mapMapping.getDirectField().getType();
        }
    } else {
        type = calculateMappingType(declaration.getMapping());
    }
}
Also used : DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 15 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 JPA21_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 JPA21_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)

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