Search in sources :

Example 11 with ObjectTypeConverter

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;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DatabaseType(org.eclipse.persistence.internal.helper.DatabaseType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) PLSQLargument(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLargument) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 12 with ObjectTypeConverter

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;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) VersionLockingPolicy(org.eclipse.persistence.descriptors.VersionLockingPolicy) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) AttributeChangeTrackingPolicy(org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy)

Example 13 with ObjectTypeConverter

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;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter)

Example 14 with ObjectTypeConverter

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;
}
Also used : XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter)

Example 15 with ObjectTypeConverter

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);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter)

Aggregations

ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)35 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)26 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)25 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)10 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)8 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)6 XMLField (org.eclipse.persistence.oxm.XMLField)5 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)5 ArrayList (java.util.ArrayList)4 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)4 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)4 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Vector (java.util.Vector)2 VersionLockingPolicy (org.eclipse.persistence.descriptors.VersionLockingPolicy)2 CacheIdentityMap (org.eclipse.persistence.internal.identitymaps.CacheIdentityMap)2 FullIdentityMap (org.eclipse.persistence.internal.identitymaps.FullIdentityMap)2