use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildPLSQLargumentDescriptor.
protected ClassDescriptor buildPLSQLargumentDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(PLSQLargument.class);
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setXPath(getPrimaryNamespaceXPath() + "name/text()");
descriptor.addMapping(nameMapping);
XMLDirectMapping indexMapping = new XMLDirectMapping();
indexMapping.setAttributeName("originalIndex");
indexMapping.setXPath(getPrimaryNamespaceXPath() + "index/text()");
indexMapping.setNullValue(-1);
descriptor.addMapping(indexMapping);
XMLDirectMapping directionMapping = new XMLDirectMapping();
directionMapping.setAttributeName("direction");
directionMapping.setXPath(getPrimaryNamespaceXPath() + "direction/text()");
ObjectTypeConverter directionConverter = new ObjectTypeConverter();
directionConverter.addConversionValue("IN", IN);
directionConverter.addConversionValue("INOUT", INOUT);
directionConverter.addConversionValue("OUT", OUT);
directionMapping.setConverter(directionConverter);
directionMapping.setNullValue(IN);
descriptor.addMapping(directionMapping);
XMLDirectMapping lengthMapping = new XMLDirectMapping();
lengthMapping.setAttributeName("length");
lengthMapping.setXPath(getPrimaryNamespaceXPath() + "length/text()");
lengthMapping.setNullValue(255);
descriptor.addMapping(lengthMapping);
XMLDirectMapping precisionMapping = new XMLDirectMapping();
precisionMapping.setAttributeName("precision");
precisionMapping.setXPath(getPrimaryNamespaceXPath() + "precision/text()");
precisionMapping.setNullValue(MIN_VALUE);
descriptor.addMapping(precisionMapping);
XMLDirectMapping scaleMapping = new XMLDirectMapping();
scaleMapping.setAttributeName("scale");
scaleMapping.setXPath(getPrimaryNamespaceXPath() + "scale/text()");
scaleMapping.setNullValue(MIN_VALUE);
descriptor.addMapping(scaleMapping);
XMLDirectMapping cursorOutputMapping = new XMLDirectMapping();
cursorOutputMapping.setAttributeName("cursorOutput");
cursorOutputMapping.setXPath("@cursorOutput");
cursorOutputMapping.setNullValue(Boolean.FALSE);
descriptor.addMapping(cursorOutputMapping);
XMLCompositeObjectMapping databaseTypeMapping = new XMLCompositeObjectMapping();
databaseTypeMapping.setAttributeName("databaseTypeWrapper");
databaseTypeMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
PLSQLargument argument = (PLSQLargument) object;
DatabaseType type = argument.databaseType;
return wrapType(type);
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
PLSQLargument argument = (PLSQLargument) object;
DatabaseTypeWrapper type = (DatabaseTypeWrapper) value;
argument.databaseType = type.getWrappedType();
}
});
databaseTypeMapping.setReferenceClass(DatabaseTypeWrapper.class);
databaseTypeMapping.setXPath(".");
descriptor.addMapping(databaseTypeMapping);
return descriptor;
}
use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class ALCTEmployeeProject method buildEmployeeDescriptor.
public ClassDescriptor buildEmployeeDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(ALCTEmployee.class);
descriptor.addTableName("ALCTEMPLOYEE");
descriptor.addPrimaryKeyFieldName("ALCTEMPLOYEE.EMP_ID");
// Descriptor Properties.
descriptor.useSoftCacheWeakIdentityMap();
descriptor.setIdentityMapSize(100);
descriptor.useRemoteSoftCacheWeakIdentityMap();
descriptor.setRemoteIdentityMapSize(100);
descriptor.setSequenceNumberFieldName("ALCTEMPLOYEE.EMP_ID");
descriptor.setSequenceNumberName("EMP_SEQ");
VersionLockingPolicy lockingPolicy = new VersionLockingPolicy();
lockingPolicy.setWriteLockFieldName("ALCTEMPLOYEE.VERSION");
descriptor.setOptimisticLockingPolicy(lockingPolicy);
descriptor.setAlias("ALCTEmployee");
// Change Tracking
descriptor.setObjectChangePolicy(new AttributeChangeTrackingPolicy());
// Cache Invalidation Policy
// Query Manager.
descriptor.getQueryManager().checkCacheForDoesExist();
descriptor.getQueryManager().setQueryTimeout(0);
// Named Queries.
// Event Manager.
// Mappings.
DirectToFieldMapping firstNameMapping = new DirectToFieldMapping();
firstNameMapping.setAttributeName("firstName");
firstNameMapping.setFieldName("ALCTEMPLOYEE.F_NAME");
firstNameMapping.setNullValue("");
descriptor.addMapping(firstNameMapping);
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("ALCTEMPLOYEE.EMP_ID");
descriptor.addMapping(idMapping);
DirectToFieldMapping lastNameMapping = new DirectToFieldMapping();
lastNameMapping.setAttributeName("lastName");
lastNameMapping.setFieldName("ALCTEMPLOYEE.L_NAME");
lastNameMapping.setNullValue("");
descriptor.addMapping(lastNameMapping);
DirectToFieldMapping genderMapping = new DirectToFieldMapping();
genderMapping.setAttributeName("gender");
genderMapping.setFieldName("ALCTEMPLOYEE.GENDER");
ObjectTypeConverter genderMappingConverter = new ObjectTypeConverter();
genderMappingConverter.addConversionValue("F", "Female");
genderMappingConverter.addConversionValue("M", "Male");
genderMapping.setConverter(genderMappingConverter);
descriptor.addMapping(genderMapping);
AggregateObjectMapping periodMapping = new AggregateObjectMapping();
periodMapping.setAttributeName("period");
periodMapping.setReferenceClass(ALCTEmploymentPeriod.class);
periodMapping.setIsNullAllowed(true);
periodMapping.addFieldNameTranslation("ALCTEMPLOYEE.END_DATE", "endDate->DIRECT");
periodMapping.addFieldNameTranslation("ALCTEMPLOYEE.START_DATE", "startDate->DIRECT");
descriptor.addMapping(periodMapping);
return descriptor;
}
use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class NoAttributeValueConversionToFieldValueProvidedTest method descriptor.
public RelationalDescriptor descriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems.class);
descriptor.addTableName("EMPLOYEE");
descriptor.addPrimaryKeyFieldName("EMPLOYEE.EMP_ID");
// Descriptor properties.
descriptor.useFullIdentityMap();
descriptor.setIdentityMapSize(100);
descriptor.useRemoteFullIdentityMap();
descriptor.setRemoteIdentityMapSize(100);
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("EMPLOYEE.EMP_ID");
descriptor.addMapping(idMapping);
DirectToFieldMapping genderMapping = new DirectToFieldMapping();
genderMapping.setAttributeName("gender");
genderMapping.setFieldName("EMPLOYEE.GENDER");
ObjectTypeConverter genderConverter = new ObjectTypeConverter();
genderConverter.addConversionValue("M", "Male");
genderConverter.addConversionValue("F", "Female");
genderMapping.setConverter(genderConverter);
descriptor.addMapping(genderMapping);
return descriptor;
}
use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class ConverterProject method getEmployeeDescriptor.
public ClassDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setDefaultRootElement("employee");
descriptor.setJavaClass(Employee.class);
XMLDirectMapping firstNameMapping = new XMLDirectMapping();
firstNameMapping.setAttributeName("firstName");
firstNameMapping.setXPath("first-name/text()");
descriptor.addMapping(firstNameMapping);
XMLDirectMapping lastNameMapping = new XMLDirectMapping();
lastNameMapping.setAttributeName("lastName");
lastNameMapping.setXPath("last-name/text()");
descriptor.addMapping(lastNameMapping);
XMLDirectMapping genderMapping = new XMLDirectMapping();
genderMapping.setAttributeName("gender");
genderMapping.setXPath("gender/text()");
ObjectTypeConverter converter = new ObjectTypeConverter(genderMapping);
converter.addConversionValue("M", "Male");
converter.addConversionValue("F", "Female");
genderMapping.setConverter(converter);
descriptor.addMapping(genderMapping);
return descriptor;
}
use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.
the class MappingProject method buildPeripheralDescriptor.
public void buildPeripheralDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(Peripheral.class);
descriptor.addTableName("MAP_PERIPHERAL");
descriptor.addPrimaryKeyFieldName("MAP_PERIPHERAL.ID");
// ClassDescriptor Properties.
descriptor.setAlias("Peripheral");
descriptor.setAmendmentClass(Peripheral.class);
descriptor.setAmendmentMethodName("addToDescriptor");
// Query Manager.
descriptor.getQueryManager().checkCacheForDoesExist();
// Mappings.
DirectToFieldMapping validMapping = new DirectToFieldMapping();
validMapping.setAttributeName("valid");
validMapping.setFieldName("MAP_PERIPHERAL.VALID");
ObjectTypeConverter validMappingConverter = new ObjectTypeConverter();
validMappingConverter.addConversionValue('N', Boolean.valueOf("false"));
validMappingConverter.addConversionValue('Y', Boolean.valueOf("true"));
validMapping.setConverter(validMappingConverter);
descriptor.addMapping(validMapping);
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("MAP_PERIPHERAL.ID");
descriptor.addMapping(idMapping);
DirectToFieldMapping nameMapping = new DirectToFieldMapping();
nameMapping.setAttributeName("name");
nameMapping.setFieldName("MAP_PERIPHERAL.NAME");
descriptor.addMapping(nameMapping);
descriptor.applyAmendmentMethod();
addDescriptor(descriptor);
}
Aggregations