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); }
public ClassDescriptor buildEmployeeDescriptor() { RelationalDescriptor descriptor = new RelationalDescriptor(); descriptor.setJavaClass(Employee.class); descriptor.addTableName("EMPLOYEE"); descriptor.addPrimaryKeyFieldName("EMPLOYEE.EMP_ID"); // Descriptor Properties. descriptor.useSoftCacheWeakIdentityMap(); descriptor.setIdentityMapSize(100); descriptor.setSequenceNumberFieldName("EMPLOYEE.EMP_ID"); descriptor.setSequenceNumberName("EMP_SEQ"); VersionLockingPolicy lockingPolicy = new VersionLockingPolicy(); lockingPolicy.setWriteLockFieldName("EMPLOYEE.VERSION"); lockingPolicy.storeInObject(); descriptor.setOptimisticLockingPolicy(lockingPolicy); descriptor.setAlias("Employee"); // Mappings. DirectToFieldMapping firstNameMapping = new DirectToFieldMapping(); firstNameMapping.setAttributeName("firstName"); firstNameMapping.setFieldName("EMPLOYEE.F_NAME"); firstNameMapping.setNullValue(""); descriptor.addMapping(firstNameMapping); DirectToFieldMapping idMapping = new DirectToFieldMapping(); idMapping.setAttributeName("id"); idMapping.setFieldName("EMPLOYEE.EMP_ID"); descriptor.addMapping(idMapping); DirectToFieldMapping versionMapping = new DirectToFieldMapping(); versionMapping.setAttributeName("version"); versionMapping.setFieldName("EMPLOYEE.VERSION"); descriptor.addMapping(versionMapping); DirectToFieldMapping lastNameMapping = new DirectToFieldMapping(); lastNameMapping.setAttributeName("lastName"); lastNameMapping.setFieldName("EMPLOYEE.L_NAME"); lastNameMapping.setNullValue(""); descriptor.addMapping(lastNameMapping); DirectToFieldMapping salaryMapping = new DirectToFieldMapping(); salaryMapping.setAttributeName("salary"); salaryMapping.setFieldName("EMPLOYEE.SALARY"); descriptor.addMapping(salaryMapping); DirectToFieldMapping genderMapping = new DirectToFieldMapping(); genderMapping.setAttributeName("gender"); genderMapping.setFieldName("EMPLOYEE.GENDER"); descriptor.addMapping(genderMapping); AggregateObjectMapping periodMapping = new AggregateObjectMapping(); periodMapping.setAttributeName("period"); periodMapping.setReferenceClass( org.eclipse.persistence.testing.models.performance.EmploymentPeriod.class); periodMapping.setIsNullAllowed(true); periodMapping.addFieldNameTranslation("EMPLOYEE.END_DATE", "endDate->DIRECT"); periodMapping.addFieldNameTranslation("EMPLOYEE.START_DATE", "startDate->DIRECT"); descriptor.addMapping(periodMapping); OneToOneMapping addressMapping = new OneToOneMapping(); addressMapping.setAttributeName("address"); addressMapping.setGetMethodName("getAddressHolder"); addressMapping.setSetMethodName("setAddressHolder"); addressMapping.setReferenceClass( org.eclipse.persistence.testing.models.performance.Address.class); addressMapping.useBasicIndirection(); addressMapping.privateOwnedRelationship(); addressMapping.addForeignKeyFieldName("EMPLOYEE.ADDR_ID", "ADDRESS.ADDRESS_ID"); descriptor.addMapping(addressMapping); OneToOneMapping managerMapping = new OneToOneMapping(); managerMapping.setAttributeName("manager"); managerMapping.setGetMethodName("getManagerHolder"); managerMapping.setSetMethodName("setManagerHolder"); managerMapping.setReferenceClass(Employee.class); managerMapping.useBasicIndirection(); managerMapping.addForeignKeyFieldName("EMPLOYEE.MANAGER_ID", "EMPLOYEE.EMP_ID"); descriptor.addMapping(managerMapping); OneToManyMapping managedEmployeesMapping = new OneToManyMapping(); managedEmployeesMapping.setAttributeName("managedEmployees"); managedEmployeesMapping.setReferenceClass(Employee.class); managedEmployeesMapping.useTransparentSet(); managedEmployeesMapping.addTargetForeignKeyFieldName("EMPLOYEE.MANAGER_ID", "EMPLOYEE.EMP_ID"); descriptor.addMapping(managedEmployeesMapping); OneToManyMapping phoneNumbersMapping = new OneToManyMapping(); phoneNumbersMapping.setAttributeName("phoneNumbers"); phoneNumbersMapping.setReferenceClass(PhoneNumber.class); phoneNumbersMapping.useTransparentSet(); phoneNumbersMapping.privateOwnedRelationship(); phoneNumbersMapping.addTargetForeignKeyFieldName("PHONE.EMP_ID", "EMPLOYEE.EMP_ID"); descriptor.addMapping(phoneNumbersMapping); ManyToManyMapping projectsMapping = new ManyToManyMapping(); projectsMapping.setAttributeName("projects"); projectsMapping.setReferenceClass(Project.class); projectsMapping.useTransparentSet(); projectsMapping.setRelationTableName("PROJ_EMP"); projectsMapping.addSourceRelationKeyFieldName("PROJ_EMP.EMP_ID", "EMPLOYEE.EMP_ID"); projectsMapping.addTargetRelationKeyFieldName("PROJ_EMP.PROJ_ID", "PROJECT.PROJ_ID"); descriptor.addMapping(projectsMapping); return descriptor; }