Search in sources :

Example 1 with TypeConversionConverter

use of org.eclipse.persistence.mappings.converters.TypeConversionConverter in project eclipselink by eclipse-ee4j.

the class TypeConverterMetadata method process.

/**
 * INTERNAL:
 */
@Override
public void process(DatabaseMapping mapping, MappingAccessor accessor, MetadataClass referenceClass, boolean isForMapKey) {
    TypeConversionConverter converter = new TypeConversionConverter(mapping);
    // Process the data type and set the data class name.
    converter.setDataClassName(getDataType(accessor, referenceClass).getName());
    // Process the object type and set the object class name.
    converter.setObjectClassName(getObjectType(accessor, referenceClass).getName());
    // Set the converter on the mapping.
    setConverter(mapping, converter, isForMapKey);
    // Set the field classification.
    setFieldClassification(mapping, m_dataType, isForMapKey);
}
Also used : TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter)

Example 2 with TypeConversionConverter

use of org.eclipse.persistence.mappings.converters.TypeConversionConverter in project eclipselink by eclipse-ee4j.

the class LoadAndSavePurchaseOrderWithAnnotations method defineTypes.

@Override
protected List defineTypes() {
    List types = super.defineTypes();
    SDOType itemType = (SDOType) typeHelper.getType(null, "ItemSDO");
    SDOType binaryType = (SDOType) typeHelper.getType(null, "myBinaryHandlerType");
    SDOProperty binaryDataProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryData");
    SDOProperty binaryDataHandlerProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataHandler");
    SDOProperty binaryDataManyProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataMany");
    SDOProperty binaryDataHandlerManyProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataHandlerMany");
    SDOProperty binaryDataHandlerNoMimeProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataHandlerNoMime");
    SDOProperty binaryDataHandlerManyNoMimeProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataHandlerManyNoMime");
    assertTrue(binaryDataProp.getType().equals(SDOConstants.SDO_BYTES));
    assertTrue(binaryDataHandlerProp.getType().equals(binaryType));
    assertTrue(binaryDataManyProp.isMany());
    assertTrue(binaryDataHandlerManyProp.isMany());
    assertTrue(binaryDataHandlerManyNoMimeProp.isMany());
    assertTrue(binaryDataProp.getXmlMapping() instanceof XMLBinaryDataMapping);
    assertTrue(binaryDataHandlerProp.getXmlMapping() instanceof XMLBinaryDataMapping);
    assertTrue(binaryDataManyProp.getXmlMapping() instanceof XMLBinaryDataCollectionMapping);
    assertTrue(binaryDataHandlerManyProp.getXmlMapping() instanceof XMLBinaryDataCollectionMapping);
    assertTrue(binaryDataHandlerNoMimeProp.getXmlMapping() instanceof XMLBinaryDataMapping);
    assertTrue(binaryDataHandlerManyNoMimeProp.getXmlMapping() instanceof XMLBinaryDataCollectionMapping);
    assertTrue(((XMLBinaryDataMapping) binaryDataProp.getXmlMapping()).getConverter() == null);
    assertTrue(((XMLBinaryDataMapping) binaryDataHandlerProp.getXmlMapping()).getConverter() == null);
    assertTrue(((XMLBinaryDataMapping) binaryDataHandlerNoMimeProp.getXmlMapping()).getConverter() == null);
    assertTrue(((XMLBinaryDataCollectionMapping) binaryDataManyProp.getXmlMapping()).getValueConverter() instanceof TypeConversionConverter);
    assertTrue(((XMLBinaryDataCollectionMapping) binaryDataHandlerManyProp.getXmlMapping()).getValueConverter() == null);
    assertTrue(((XMLBinaryDataCollectionMapping) binaryDataHandlerManyNoMimeProp.getXmlMapping()).getValueConverter() == null);
    return types;
}
Also used : XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) SDOType(org.eclipse.persistence.sdo.SDOType) ArrayList(java.util.ArrayList) List(java.util.List) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 3 with TypeConversionConverter

use of org.eclipse.persistence.mappings.converters.TypeConversionConverter in project eclipselink by eclipse-ee4j.

the class MappingProject method buildCubicleDescriptor.

protected void buildCubicleDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(Cubicle.class);
    Vector vector = new Vector();
    vector.addElement("MAP_CUB");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("MAP_CUB.C_ID");
    // SECTION: PROPERTIES
    descriptor.setSequenceNumberName("SEQ_ID");
    descriptor.setSequenceNumberFieldName("C_ID");
    // SECTION: COPY POLICY
    descriptor.createCopyPolicy("constructor");
    // SECTION: INSTANTIATION POLICY
    descriptor.createInstantiationPolicy("constructor");
    // SECTION: DIRECTTOFIELDMAPPING
    DirectToFieldMapping typeConversionMapping = new DirectToFieldMapping();
    TypeConversionConverter typeConversionConverter = new TypeConversionConverter();
    typeConversionMapping.setAttributeName("id");
    typeConversionMapping.setIsReadOnly(false);
    typeConversionMapping.setFieldName("MAP_CUB.C_ID");
    typeConversionConverter.setObjectClass(java.math.BigDecimal.class);
    typeConversionConverter.setDataClass(String.class);
    typeConversionMapping.setConverter(typeConversionConverter);
    descriptor.addMapping(typeConversionMapping);
    // SECTION: DIRECTTOFIELDMAPPING
    DirectToFieldMapping directtofieldmapping1 = new DirectToFieldMapping();
    directtofieldmapping1.setAttributeName("location");
    directtofieldmapping1.setIsReadOnly(false);
    directtofieldmapping1.setFieldName("MAP_CUB.LOCATION");
    descriptor.addMapping(directtofieldmapping1);
    // SECTION: MANYTOMANYMAPPING
    ManyToManyMapping manytomanymapping = new ManyToManyMapping();
    manytomanymapping.setAttributeName("emergencyExits");
    manytomanymapping.setIsReadOnly(false);
    manytomanymapping.setUsesIndirection(false);
    manytomanymapping.setReferenceClass(EmergencyExit.class);
    manytomanymapping.setIsPrivateOwned(false);
    manytomanymapping.setRelationTableName("CUBICLE_EMERGENCYEXIT");
    manytomanymapping.addSourceRelationKeyFieldName("CUBICLE_EMERGENCYEXIT.CUBICLE_LOCATION", "MAP_CUB.LOCATION");
    manytomanymapping.addTargetRelationKeyFieldName("CUBICLE_EMERGENCYEXIT.EXIT_ID", "MAP_EMERGENCYEXIT.EXIT_ID");
    descriptor.addMapping(manytomanymapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) Vector(java.util.Vector)

Example 4 with TypeConversionConverter

use of org.eclipse.persistence.mappings.converters.TypeConversionConverter in project eclipselink by eclipse-ee4j.

the class EISCompositeDirectCollectionMapping method initialize.

/**
 * INTERNAL:
 * Initialize the mapping.
 */
@Override
public void initialize(AbstractSession session) throws DescriptorException {
    super.initialize(session);
    if (this.getField() instanceof XMLField && getValueConverter() instanceof TypeConversionConverter) {
        TypeConversionConverter converter = (TypeConversionConverter) getValueConverter();
        this.getField().setType(converter.getObjectClass());
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter)

Example 5 with TypeConversionConverter

use of org.eclipse.persistence.mappings.converters.TypeConversionConverter in project eclipselink by eclipse-ee4j.

the class DirectMapMapping method setKeyClass.

/**
 * PUBLIC:
 * This is a helper method to set the key converter to a TypeConversionConverter.
 * This ensures that the key value from the database is converted to the correct
 * Java type.  The converter can also be set directly.
 * Note that setting the converter to another converter will overwrite this setting.
 */
public void setKeyClass(Class<?> keyClass) {
    TypeConversionConverter converter = new TypeConversionConverter(this);
    converter.setObjectClass(keyClass);
    setKeyConverter(converter);
}
Also used : TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter)

Aggregations

TypeConversionConverter (org.eclipse.persistence.mappings.converters.TypeConversionConverter)12 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)3 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)3 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)3 SerializedObjectConverter (org.eclipse.persistence.mappings.converters.SerializedObjectConverter)3 XMLField (org.eclipse.persistence.oxm.XMLField)3 Vector (java.util.Vector)2 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)2 XMLBinaryDataCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)2 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)2 java.util (java.util)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 oracle.sql (oracle.sql)1 CollectionContainerPolicy (org.eclipse.persistence.internal.queries.CollectionContainerPolicy)1 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)1 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)1 RelationTableMechanism (org.eclipse.persistence.mappings.RelationTableMechanism)1