use of org.eclipse.persistence.mappings.OneToManyMapping in project eclipselink by eclipse-ee4j.
the class AttributeAndMappingWithTransparentIndirectionMismatchTest method test.
@Override
public void test() {
TransparentIndirectionPolicy policy = new TransparentIndirectionPolicy();
OneToManyMapping mapping = new OneToManyMapping();
mapping.setAttributeName("manager");
mapping.setReferenceClass(org.eclipse.persistence.testing.models.employee.domain.Employee.class);
mapping.addTargetForeignKeyFieldName("EMPLOYEE.MANAGER_ID", "EMPLOYEE.EMP_ID");
policy.setMapping(mapping);
try {
policy.validateDeclaredAttributeType(AttributeAndMappingWithTransparentIndirectionMismatchTest.class, getSession().getIntegrityChecker());
} catch (EclipseLinkException exception) {
caughtException = exception;
}
}
use of org.eclipse.persistence.mappings.OneToManyMapping in project eclipselink by eclipse-ee4j.
the class MapCollectionsProject method buildEntityEntity1MMapHolderDescriptor.
protected void buildEntityEntity1MMapHolderDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
// SECTION: DESCRIPTOR
descriptor.setJavaClass(EntityEntity1MMapHolder.class);
Vector vector = new Vector();
vector.addElement("ENT_ENT_1M_MAP_HOLDER");
descriptor.setTableNames(vector);
descriptor.addPrimaryKeyFieldName("ENT_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("ENT_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("ENT_ENT_1M_MAP_HOLDER.ID");
descriptor.addMapping(directtofieldmapping);
OneToManyMapping mapMapping = new OneToManyMapping();
mapMapping.setAttributeName("entityToEntityMap");
mapMapping.setReferenceClass(EEOTMMapValue.class);
mapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
mapMapping.setGetMethodName("getEntityToEntityMap");
mapMapping.setSetMethodName("setEntityToEntityMap");
mapMapping.addTargetForeignKeyFieldName("EE_OM_ENT_MAP_VALUE.HOLDER_ID", "ENT_ENT_1M_MAP_HOLDER.ID");
org.eclipse.persistence.mappings.OneToOneMapping keyMapping = new org.eclipse.persistence.mappings.OneToOneMapping();
keyMapping.setReferenceClass(EntityMapKey.class);
keyMapping.dontUseIndirection();
keyMapping.addForeignKeyFieldName("EE_OM_ENT_MAP_VALUE.KEY_ID", "ENT_MAP_KEY.ID");
keyMapping.setDescriptor(descriptor);
MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
policy.setKeyMapping(keyMapping);
policy.setValueMapping(mapMapping);
mapMapping.setContainerPolicy(policy);
descriptor.addMapping(mapMapping);
addDescriptor(descriptor);
}
use of org.eclipse.persistence.mappings.OneToManyMapping 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);
}
use of org.eclipse.persistence.mappings.OneToManyMapping in project eclipselink by eclipse-ee4j.
the class MapCollectionsProject method buildDirectEntity1MMapHolderDescriptor.
protected void buildDirectEntity1MMapHolderDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
// SECTION: DESCRIPTOR
descriptor.setJavaClass(DirectEntity1MMapHolder.class);
Vector vector = new Vector();
vector.addElement("DIR_ENT_1M_MAP_HOLDER");
descriptor.setTableNames(vector);
descriptor.addPrimaryKeyFieldName("DIR_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("DIR_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("DIR_ENT_1M_MAP_HOLDER.ID");
descriptor.addMapping(directtofieldmapping);
OneToManyMapping mapMapping = new OneToManyMapping();
mapMapping.setAttributeName("directToEntityMap");
mapMapping.setReferenceClass(DEOTMMapValue.class);
mapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
mapMapping.setGetMethodName("getDirectToEntityMap");
mapMapping.setSetMethodName("setDirectToEntityMap");
mapMapping.addTargetForeignKeyFieldName("DE_OM_ENT_MAP_VALUE.HOLDER_ID", "DIR_ENT_1M_MAP_HOLDER.ID");
org.eclipse.persistence.mappings.DirectToFieldMapping keyMapping = new org.eclipse.persistence.mappings.DirectToFieldMapping();
keyMapping.setFieldName("DE_OM_ENT_MAP_VALUE.MAP_KEY");
keyMapping.setAttributeClassification(Integer.class);
keyMapping.setDescriptor(descriptor);
MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
policy.setKeyMapping(keyMapping);
policy.setValueMapping(mapMapping);
mapMapping.setContainerPolicy(policy);
descriptor.addMapping(mapMapping);
addDescriptor(descriptor);
}
use of org.eclipse.persistence.mappings.OneToManyMapping in project eclipselink by eclipse-ee4j.
the class Person method descriptor.
public static RelationalDescriptor descriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
OneToManyMapping oneToMany = new OneToManyMapping();
/* First define the class, table and descriptor properties. */
descriptor.setJavaClass(Person.class);
descriptor.setTableName("U_EMP");
descriptor.setPrimaryKeyFieldName("ID");
descriptor.setSequenceNumberName("SEQ");
descriptor.setSequenceNumberFieldName("ID");
/* Next define the attribute mappings. */
descriptor.addDirectMapping("id", "ID");
descriptor.addDirectMapping("name", "NAME");
oneToMany.setAttributeName("contacts");
oneToMany.setReferenceClass(Contact.class);
oneToMany.addTargetForeignKeyFieldName("EMP_ID", "ID");
oneToMany.dontUseIndirection();
descriptor.addMapping(oneToMany);
TransformationMapping trans = new TransformationMapping();
trans.setIsReadOnly(true);
trans.dontUseIndirection();
trans.setAttributeName("luckyNumber");
trans.setAttributeTransformation("calculateLuckyNumber");
descriptor.addMapping(trans);
return descriptor;
}
Aggregations