use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class MappingProject method buildComputerDescriptor.
protected void buildComputerDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
// SECTION: DESCRIPTOR
descriptor.setJavaClass(Computer.class);
descriptor.getInheritancePolicy().setParentClass(Hardware.class);
Vector vector = new Vector();
vector.addElement("MAP_COM");
descriptor.setTableNames(vector);
descriptor.addPrimaryKeyFieldName("MAP_COM.ID");
// SECTION: PROPERTIES
descriptor.getInheritancePolicy().setShouldReadSubclasses(false);
// SECTION: COPY POLICY
descriptor.createCopyPolicy("constructor");
// SECTION: INSTANTIATION POLICY
descriptor.createInstantiationPolicy("static method");
descriptor.getInstantiationPolicy().setMethodName("createNew");
// SECTION: DIRECTTOFIELDMAPPING
DirectToFieldMapping directtofieldmapping = new DirectToFieldMapping();
directtofieldmapping.setAttributeName("description");
directtofieldmapping.setIsReadOnly(false);
directtofieldmapping.setFieldName("MAP_COM.DESCRIP");
descriptor.addMapping(directtofieldmapping);
// SECTION: DIRECTTOFIELDMAPPING
DirectToFieldMapping directtofieldmapping1 = new DirectToFieldMapping();
directtofieldmapping1.setAttributeName("id");
directtofieldmapping1.setIsReadOnly(false);
directtofieldmapping1.setFieldName("MAP_COM.ID");
descriptor.addMapping(directtofieldmapping1);
// SECTION: DIRECTTOFIELDMAPPING
DirectToFieldMapping directtofieldmapping2 = new DirectToFieldMapping();
directtofieldmapping2.setAttributeName("serialNumber");
directtofieldmapping2.setIsReadOnly(false);
directtofieldmapping2.setGetMethodName("getSerialNumber");
directtofieldmapping2.setSetMethodName("setSerialNumber");
directtofieldmapping2.setFieldName("MAP_COM.SERL_NO");
descriptor.addMapping(directtofieldmapping2);
// SECTION: OBJECTTYPEMAPPING
DirectToFieldMapping objecttypemapping = new DirectToFieldMapping();
ObjectTypeConverter objecttypeconverter = new ObjectTypeConverter();
objecttypemapping.setAttributeName("isMacintosh");
objecttypemapping.setIsReadOnly(false);
objecttypemapping.setFieldName("MAP_COM.IS_MAC");
objecttypeconverter.addConversionValue("No", Boolean.FALSE);
objecttypeconverter.addConversionValue("Yes", Boolean.TRUE);
objecttypemapping.setNullValue(Boolean.FALSE);
objecttypemapping.setConverter(objecttypeconverter);
descriptor.addMapping(objecttypemapping);
// SECTION: ONETOONEMAPPING
OneToOneMapping onetoonemapping = new OneToOneMapping();
onetoonemapping.setAttributeName("monitor");
onetoonemapping.setIsReadOnly(false);
onetoonemapping.setUsesIndirection(false);
onetoonemapping.setGetMethodName("getMonitor");
onetoonemapping.setSetMethodName("setMonitor");
onetoonemapping.setReferenceClass(Monitor.class);
onetoonemapping.setIsPrivateOwned(true);
onetoonemapping.addForeignKeyFieldName("MAP_COM.MON_SER", "MAP_MON.SERL_NO");
descriptor.addMapping(onetoonemapping);
addDescriptor(descriptor);
}
use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class MappingProject method buildEmployeeDescriptor.
protected void buildEmployeeDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
// SECTION: DESCRIPTOR
descriptor.setJavaClass(Employee.class);
Vector vector = new Vector();
vector.addElement("MAP_EMP");
descriptor.setTableNames(vector);
descriptor.addPrimaryKeyFieldName("MAP_EMP.FNAME");
descriptor.addPrimaryKeyFieldName("MAP_EMP.LNAME");
descriptor.addPrimaryKeyFieldName("MAP_EMP.SEX");
// SECTION: COPY POLICY
descriptor.createCopyPolicy("constructor");
descriptor.useSoftIdentityMap();
// SECTION: INSTANTIATION POLICY
descriptor.createInstantiationPolicy("constructor");
// SECTION: DIRECTCOLLECTIONMAPPING
DirectCollectionMapping directcollectionmapping = new DirectCollectionMapping();
directcollectionmapping.setAttributeName("policies");
directcollectionmapping.setIsReadOnly(false);
directcollectionmapping.setUsesIndirection(true);
directcollectionmapping.setIsPrivateOwned(false);
directcollectionmapping.setDirectFieldName("MAP_POL.POLICY");
directcollectionmapping.setReferenceTableName("MAP_POL");
directcollectionmapping.addReferenceKeyFieldName("MAP_POL.LNAME", "MAP_EMP.LNAME");
directcollectionmapping.addReferenceKeyFieldName("MAP_POL.FNAME", "MAP_EMP.FNAME");
descriptor.addMapping(directcollectionmapping);
// SECTION: DIRECTTOFIELDMAPPING
DirectToFieldMapping directtofieldmapping = new DirectToFieldMapping();
directtofieldmapping.setAttributeName("firstName");
directtofieldmapping.setIsReadOnly(false);
directtofieldmapping.setFieldName("MAP_EMP.FNAME");
descriptor.addMapping(directtofieldmapping);
// SECTION: DIRECTTOFIELDMAPPING
DirectToFieldMapping directtofieldmapping1 = new DirectToFieldMapping();
directtofieldmapping1.setAttributeName("lastName");
directtofieldmapping1.setIsReadOnly(false);
directtofieldmapping1.setFieldName("MAP_EMP.LNAME");
descriptor.addMapping(directtofieldmapping1);
// SECTION: ONETOONEMAPPING
OneToOneMapping onetoonemapping1 = new OneToOneMapping();
onetoonemapping1.setAttributeName("cubicle");
onetoonemapping1.setIsReadOnly(false);
onetoonemapping1.setUsesIndirection(false);
onetoonemapping1.setReferenceClass(Cubicle.class);
onetoonemapping1.setIsPrivateOwned(true);
onetoonemapping1.addForeignKeyFieldName("MAP_EMP.C_ID", "MAP_CUB.C_ID");
descriptor.addMapping(onetoonemapping1);
// SECTION: MANYTOMANYMAPPING
ManyToManyMapping manytomanymapping = new ManyToManyMapping();
manytomanymapping.setAttributeName("phoneNumbers");
manytomanymapping.setIsReadOnly(false);
manytomanymapping.setUsesIndirection(true);
manytomanymapping.setReferenceClass(Phone.class);
manytomanymapping.setIsPrivateOwned(true);
manytomanymapping.setRelationTableName("MAP_EMPH");
manytomanymapping.addSourceRelationKeyFieldName("MAP_EMPH.LNAME", "MAP_EMP.LNAME");
manytomanymapping.addSourceRelationKeyFieldName("MAP_EMPH.FNAME", "MAP_EMP.FNAME");
manytomanymapping.addTargetRelationKeyFieldName("MAP_EMPH.P_ID", "MAP_PHO.P_ID");
descriptor.addMapping(manytomanymapping);
// SECTION: MANYTOMANYMAPPING
ManyToManyMapping manytomanymapping1 = new ManyToManyMapping();
manytomanymapping1.setAttributeName("shipments");
manytomanymapping1.setIsReadOnly(false);
manytomanymapping1.setUsesIndirection(false);
manytomanymapping1.setReferenceClass(Shipment.class);
manytomanymapping1.setIsPrivateOwned(false);
manytomanymapping1.setRelationTableName("MAP_EMSP");
manytomanymapping1.addSourceRelationKeyFieldName("MAP_EMSP.EMP_LNAME", "MAP_EMP.LNAME");
manytomanymapping1.addSourceRelationKeyFieldName("MAP_EMSP.EMP_FNAME", "MAP_EMP.FNAME");
manytomanymapping1.addTargetRelationKeyFieldName("MAP_EMSP.SP_TSMIL", "MAP_SHIP.SP_TSMIL");
manytomanymapping1.addTargetRelationKeyFieldName("MAP_EMSP.SP_TS", "MAP_SHIP.SP_TS");
descriptor.addMapping(manytomanymapping1);
// SECTION: OBJECTTYPEMAPPING
DirectToFieldMapping objecttypemapping = new DirectToFieldMapping();
ObjectTypeConverter objecttypeconverter = new ObjectTypeConverter();
objecttypemapping.setAttributeName("sex");
objecttypemapping.setIsReadOnly(false);
objecttypemapping.setFieldName("MAP_EMP.SEX");
objecttypeconverter.setDefaultAttributeValue("female");
objecttypeconverter.addConversionValue("F", "female");
objecttypeconverter.addConversionValue("M", "male");
objecttypemapping.setConverter(objecttypeconverter);
descriptor.addMapping(objecttypemapping);
// SECTION: ONETOMANYMAPPING
OneToManyMapping onetomanymapping = new OneToManyMapping();
onetomanymapping.setAttributeName("managedEmployees");
onetomanymapping.setIsReadOnly(false);
onetomanymapping.setUsesIndirection(false);
onetomanymapping.setGetMethodName("getManagedEmployeesForTOPLink");
onetomanymapping.setSetMethodName("setManagedEmployeesFromTOPLink");
onetomanymapping.setReferenceClass(Employee.class);
onetomanymapping.setIsPrivateOwned(false);
onetomanymapping.addTargetForeignKeyFieldName("MAP_EMP.M_LNAME", "MAP_EMP.LNAME");
onetomanymapping.addTargetForeignKeyFieldName("MAP_EMP.M_FNAME", "MAP_EMP.FNAME");
descriptor.addMapping(onetomanymapping);
// SECTION: ONETOONEMAPPING
OneToOneMapping onetoonemapping = new OneToOneMapping();
onetoonemapping.setAttributeName("computer");
onetoonemapping.setIsReadOnly(false);
onetoonemapping.setUsesIndirection(false);
onetoonemapping.setGetMethodName("getComputer");
onetoonemapping.setSetMethodName("setComputer");
onetoonemapping.setReferenceClass(Hardware.class);
onetoonemapping.setIsPrivateOwned(true);
onetoonemapping.addTargetForeignKeyFieldName("MAP_HRW.EMP_FNAME", "MAP_EMP.FNAME");
onetoonemapping.addTargetForeignKeyFieldName("MAP_HRW.EMP_LNAME", "MAP_EMP.LNAME");
descriptor.addMapping(onetoonemapping);
// SECTION: ONETOONEMAPPING
OneToOneMapping onetoonemapping2 = new OneToOneMapping();
onetoonemapping2.setAttributeName("manager");
onetoonemapping2.setIsReadOnly(false);
onetoonemapping2.setUsesIndirection(false);
onetoonemapping2.setGetMethodName("getManager");
onetoonemapping2.setSetMethodName("setManager");
onetoonemapping2.setReferenceClass(Employee.class);
onetoonemapping2.setIsPrivateOwned(false);
onetoonemapping2.addForeignKeyFieldName("MAP_EMP.M_FNAME", "MAP_EMP.FNAME");
onetoonemapping2.addForeignKeyFieldName("MAP_EMP.M_LNAME", "MAP_EMP.LNAME");
descriptor.addMapping(onetoonemapping2);
// SECTION: SERIALIZEDMAPPING
DirectToFieldMapping serializedmapping = new DirectToFieldMapping();
SerializedObjectConverter serializedconverter = new SerializedObjectConverter();
serializedmapping.setAttributeName("jobDescription");
serializedmapping.setIsReadOnly(false);
serializedmapping.setGetMethodName("getJobDescription");
serializedmapping.setSetMethodName("setJobDescription");
serializedmapping.setFieldName("MAP_EMP.JDESC");
serializedmapping.setConverter(serializedconverter);
descriptor.addMapping(serializedmapping);
// SECTION: TRANSFORMATIONMAPPING
TransformationMapping transformationmapping = new TransformationMapping();
transformationmapping.setAttributeName("dateAndTimeOfBirth");
transformationmapping.setIsReadOnly(false);
transformationmapping.setUsesIndirection(false);
transformationmapping.setAttributeTransformation("setDateAndTime");
transformationmapping.addFieldTransformation("MAP_EMP.BDAY", "getDate");
transformationmapping.addFieldTransformation("MAP_EMP.BTIME", "getTime");
descriptor.addMapping(transformationmapping);
// SECTION: TRANSFORMATIONMAPPING
TransformationMapping transformationmapping1 = new TransformationMapping();
transformationmapping1.setAttributeName("designation");
transformationmapping1.setIsReadOnly(false);
transformationmapping1.setUsesIndirection(true);
transformationmapping1.setGetMethodName("getDesignation");
transformationmapping1.setSetMethodName("setDesignation");
transformationmapping1.setAttributeTransformation("getRankFromRow");
transformationmapping1.addFieldTransformation("MAP_EMP.ERANK", "getRankFromObject");
descriptor.addMapping(transformationmapping1);
// SECTION: TYPECONVERSIONMAPPING
DirectToFieldMapping typeconversionmapping = new DirectToFieldMapping();
TypeConversionConverter typeconversionconverter = new TypeConversionConverter();
typeconversionmapping.setAttributeName("joiningDate");
typeconversionmapping.setIsReadOnly(false);
typeconversionmapping.setFieldName("MAP_EMP.JDAY");
typeconversionconverter.setObjectClass(java.util.Date.class);
typeconversionconverter.setDataClass(java.sql.Date.class);
typeconversionmapping.setConverter(typeconversionconverter);
descriptor.addMapping(typeconversionmapping);
addDescriptor(descriptor);
}
use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class IsolatedEmployeeProject method buildEmployeeDescriptor.
public RelationalDescriptor buildEmployeeDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(org.eclipse.persistence.testing.tests.isolatedsession.IsolatedEmployee.class);
descriptor.addTableName("ISOLATED_EMPLOYEE");
descriptor.addTableName("ISOLATED_SALARY");
descriptor.addPrimaryKeyFieldName("ISOLATED_EMPLOYEE.EMP_ID");
// Descriptor properties.
descriptor.setSequenceNumberFieldName("EMP_ID");
descriptor.setSequenceNumberName("EMP_SEQ");
VersionLockingPolicy lockingPolicy = new VersionLockingPolicy();
lockingPolicy.setWriteLockFieldName("VERSION");
descriptor.setOptimisticLockingPolicy(lockingPolicy);
descriptor.setCacheIsolation(CacheIsolationType.ISOLATED);
// Tests depend on uow merge.
descriptor.setUnitOfWorkCacheIsolationLevel(RelationalDescriptor.ISOLATE_NEW_DATA_AFTER_TRANSACTION);
// Query manager.
descriptor.getQueryManager().checkCacheForDoesExist();
// Event manager.
// Mappings.
DirectToFieldMapping firstNameMapping = new DirectToFieldMapping();
firstNameMapping.setAttributeName("firstName");
firstNameMapping.setFieldName("ISOLATED_EMPLOYEE.F_NAME");
firstNameMapping.setNullValue("");
descriptor.addMapping(firstNameMapping);
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("ISOLATED_EMPLOYEE.EMP_ID");
descriptor.addMapping(idMapping);
DirectToFieldMapping lastNameMapping = new DirectToFieldMapping();
lastNameMapping.setAttributeName("lastName");
lastNameMapping.setFieldName("ISOLATED_EMPLOYEE.L_NAME");
lastNameMapping.setNullValue("");
descriptor.addMapping(lastNameMapping);
DirectToFieldMapping salaryMapping = new DirectToFieldMapping();
salaryMapping.setAttributeName("salary");
salaryMapping.setFieldName("ISOLATED_SALARY.SALARY");
descriptor.addMapping(salaryMapping);
DirectToFieldMapping genderMapping = new DirectToFieldMapping();
ObjectTypeConverter genderConverter = new ObjectTypeConverter();
genderMapping.setAttributeName("gender");
genderMapping.setFieldName("ISOLATED_EMPLOYEE.GENDER");
genderConverter.addConversionValue("M", "Male");
genderConverter.addConversionValue("F", "Female");
genderMapping.setConverter(genderConverter);
descriptor.addMapping(genderMapping);
TransformationMapping normalHoursMapping = new TransformationMapping();
normalHoursMapping.setAttributeName("normalHours");
normalHoursMapping.setAttributeTransformation("buildNormalHours");
normalHoursMapping.addFieldTransformation("ISOLATED_EMPLOYEE.START_TIME", "getStartTime");
normalHoursMapping.addFieldTransformation("ISOLATED_EMPLOYEE.END_TIME", "getEndTime");
descriptor.addMapping(normalHoursMapping);
AggregateObjectMapping periodMapping = new AggregateObjectMapping();
periodMapping.setAttributeName("period");
periodMapping.setReferenceClass(org.eclipse.persistence.testing.tests.isolatedsession.IsolatedEmploymentPeriod.class);
periodMapping.setIsNullAllowed(true);
descriptor.addMapping(periodMapping);
DirectCollectionMapping responsibilitiesListMapping = new DirectCollectionMapping();
responsibilitiesListMapping.setAttributeName("responsibilitiesList");
responsibilitiesListMapping.useBasicIndirection();
responsibilitiesListMapping.setReferenceTableName("ISOLATED_RESPONS");
responsibilitiesListMapping.setDirectFieldName("ISOLATED_RESPONS.DESCRIP");
responsibilitiesListMapping.addReferenceKeyFieldName("ISOLATED_RESPONS.EMP_ID", "ISOLATED_EMPLOYEE.EMP_ID");
descriptor.addMapping(responsibilitiesListMapping);
OneToOneMapping addressMapping = new OneToOneMapping();
addressMapping.setAttributeName("address");
addressMapping.setReferenceClass(org.eclipse.persistence.testing.tests.isolatedsession.IsolatedAddress.class);
addressMapping.useBasicIndirection();
addressMapping.privateOwnedRelationship();
addressMapping.addForeignKeyFieldName("ISOLATED_EMPLOYEE.ADDR_ID", "ISOLATED_ADDRESS.ADDRESS_ID");
descriptor.addMapping(addressMapping);
OneToOneMapping managerMapping = new OneToOneMapping();
managerMapping.setAttributeName("manager");
managerMapping.setReferenceClass(IsolatedEmployee.class);
managerMapping.useBasicIndirection();
managerMapping.addForeignKeyFieldName("ISOLATED_EMPLOYEE.MANAGER_ID", "ISOLATED_EMPLOYEE.EMP_ID");
descriptor.addMapping(managerMapping);
OneToManyMapping managedEmployeesMapping = new OneToManyMapping();
managedEmployeesMapping.setAttributeName("managedEmployees");
managedEmployeesMapping.setReferenceClass(IsolatedEmployee.class);
managedEmployeesMapping.useBasicIndirection();
managedEmployeesMapping.addTargetForeignKeyFieldName("ISOLATED_EMPLOYEE.MANAGER_ID", "ISOLATED_EMPLOYEE.EMP_ID");
descriptor.addMapping(managedEmployeesMapping);
OneToManyMapping phoneNumbersMapping = new OneToManyMapping();
phoneNumbersMapping.setAttributeName("phoneNumbers");
phoneNumbersMapping.setReferenceClass(IsolatedPhoneNumber.class);
phoneNumbersMapping.useBasicIndirection();
phoneNumbersMapping.privateOwnedRelationship();
phoneNumbersMapping.addTargetForeignKeyFieldName("ISOLATED_PHONE.EMP_ID", "ISOLATED_EMPLOYEE.EMP_ID");
descriptor.addMapping(phoneNumbersMapping);
return descriptor;
}
use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testSexObjectTypeConverterDefaultValue.
/**
* Verifies a default object type value is set from metadata processing.
*/
public void testSexObjectTypeConverterDefaultValue() {
ServerSession session = JUnitTestCase.getServerSession(m_persistenceUnit);
ClassDescriptor employeeDescriptor = session.getDescriptor(Employee.class);
DirectToFieldMapping mapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("gender");
assertNotNull("Gender mapping from Employee not found.", mapping);
assertTrue("No object type converter found on the gender mapping.", ObjectTypeConverter.class.isAssignableFrom(mapping.getConverter().getClass()));
assertTrue("Default object value on the object type converter for gender was not set to Male.", ((ObjectTypeConverter) mapping.getConverter()).getDefaultAttributeValue().equals(Employee.Gender.Male.name()));
}
use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testSexObjectTypeConverterDefaultValue.
/**
* Verifies a default object type value is set from metadata processing.
*/
public void testSexObjectTypeConverterDefaultValue() {
DatabaseSessionImpl session = getDatabaseSession();
ClassDescriptor employeeDescriptor = session.getDescriptor(Employee.class);
DirectToFieldMapping mapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("gender");
assertNotNull("Gender mapping from Employee not found.", mapping);
assertTrue("No object type converter found on the gender mapping.", ObjectTypeConverter.class.isAssignableFrom(mapping.getConverter().getClass()));
assertTrue("Default object value on the object type converter for gender was not set to Male.", ((ObjectTypeConverter) mapping.getConverter()).getDefaultAttributeValue().equals(Employee.Gender.Male.name()));
}
Aggregations