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);
}
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;
}
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);
}
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());
}
}
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);
}
Aggregations