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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations