import org.eclipse.persistence.config.DescriptorCustomizer; import org.eclipse.persistence.descriptors.ClassDescriptor; import org.eclipse.persistence.mappings.DatabaseMapping; import org.eclipse.persistence.oxm.mappings.XMLDirectMapping; import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType; public class AddressCustomizer implements DescriptorCustomizer { @Override public void customize(ClassDescriptor descriptor) throws Exception { for(DatabaseMapping mapping : descriptor.getMappings()) { if(mapping.isAbstractDirectMapping()) { XMLDirectMapping xmlDirectMapping = (XMLDirectMapping) mapping; xmlDirectMapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE); xmlDirectMapping.getNullPolicy().setNullRepresentedByEmptyNode(true); } } } }
import org.eclipse.persistence.descriptors.ClassDescriptor; import org.eclipse.persistence.mappings.DatabaseMapping; import org.eclipse.persistence.oxm.mappings.XMLDirectMapping; import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType; import org.eclipse.persistence.sessions.*; public class NullPolicySessionEventListener extends SessionEventAdapter { @Override public void preLogin(SessionEvent event) { Project project = event.getSession().getProject(); for(ClassDescriptor descriptor : project.getOrderedDescriptors()) { for(DatabaseMapping mapping : descriptor.getMappings()) { if(mapping.isAbstractDirectMapping()) { XMLDirectMapping xmlDirectMapping = (XMLDirectMapping) mapping; xmlDirectMapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE); xmlDirectMapping.getNullPolicy().setNullRepresentedByEmptyNode(true); } } } } }
/** * INTERNAL: * Return whether a map key this container policy represents is an attribute * By default this method will return false since only subclasses actually represent maps. */ @Override public boolean isMapKeyAttribute() { return ((DatabaseMapping)keyMapping).isAbstractDirectMapping(); }
/** * INTERNAL: * Return whether a map key this container policy represents is an attribute * By default this method will return false since only subclasses actually represent maps. */ @Override public boolean isMapKeyAttribute() { return ((DatabaseMapping)keyMapping).isAbstractDirectMapping(); }
/** * INTERNAL: * Return whether a map key this container policy represents is an attribute * By default this method will return false since only subclasses actually represent maps. * @return */ public boolean isMapKeyAttribute(){ return ((DatabaseMapping)keyMapping).isAbstractDirectMapping(); }
private List<String> getEnumeration(DatabaseMapping textMapping) { JAXBEnumTypeConverter converter = null; if(textMapping.isAbstractDirectMapping()) { converter = (JAXBEnumTypeConverter) ((DirectMapping)textMapping).getConverter(); } else if(textMapping.isAbstractCompositeDirectCollectionMapping()) { converter = (JAXBEnumTypeConverter) ((DirectCollectionMapping)textMapping).getValueConverter(); } if(converter == null) { return null; } List<String> enumeration = new ArrayList<String>(); for(Object nextValue: converter.getAttributeToFieldValues().values()) { enumeration.add(nextValue.toString()); } return enumeration; }
private List<String> getEnumeration(DatabaseMapping textMapping) { JAXBEnumTypeConverter converter = null; if(textMapping.isAbstractDirectMapping()) { converter = (JAXBEnumTypeConverter) ((DirectMapping)textMapping).getConverter(); } else if(textMapping.isAbstractCompositeDirectCollectionMapping()) { converter = (JAXBEnumTypeConverter) ((DirectCollectionMapping)textMapping).getValueConverter(); } if(converter == null) { return null; } List<String> enumeration = new ArrayList<String>(); for(Object nextValue: converter.getAttributeToFieldValues().values()) { enumeration.add(nextValue.toString()); } return enumeration; }
public Converter getConverter(XMLField field) { if(null != this.fieldsToConverters) { Converter converter = fieldsToConverters.get(field); if(null != converter) { return converter; } if(null != this.choiceElementMappings) { DatabaseMapping mapping = (DatabaseMapping) this.choiceElementMappings.get(field); if(null == mapping) { return null; } if(mapping.isAbstractCompositeDirectCollectionMapping()) { return ((XMLCompositeDirectCollectionMapping)mapping).getValueConverter(); } else if(mapping.isAbstractDirectMapping()) { return ((XMLDirectMapping)mapping).getConverter(); } } } return null; }
public Converter getConverter(XMLField field) { if(null != this.fieldsToConverters) { Converter converter = fieldsToConverters.get(field); if(null != converter) { return converter; } if(null != this.choiceElementMappings) { DatabaseMapping mapping = (DatabaseMapping) this.choiceElementMappings.get(field); if(null == mapping) { return null; } if(mapping.isAbstractCompositeDirectCollectionMapping()) { return ((XMLCompositeDirectCollectionMapping)mapping).getValueConverter(); } else if(mapping.isAbstractDirectMapping()) { return ((XMLDirectMapping)mapping).getConverter(); } } } return null; }
public Converter getConverter(XMLField field) { if(null != this.fieldsToConverters) { Converter converter = fieldsToConverters.get(field); if(null != converter) { return converter; } if(null != this.choiceElementMappings) { DatabaseMapping mapping = (DatabaseMapping) this.choiceElementMappings.get(field); if(null == mapping) { return null; } if(mapping.isAbstractCompositeDirectCollectionMapping()) { return ((XMLCompositeDirectCollectionMapping)mapping).getValueConverter(); } else if(mapping.isAbstractDirectMapping()) { return ((XMLDirectMapping)mapping).getConverter(); } } } return null; }
public Converter getConverter(XMLField field) { if(null != this.fieldsToConverters) { Converter converter = fieldsToConverters.get(field); if(null != converter) { return converter; } if(null != this.choiceElementMappings) { DatabaseMapping mapping = (DatabaseMapping) this.choiceElementMappings.get(field); if(null == mapping) { return null; } if(mapping.isAbstractCompositeDirectCollectionMapping()) { return ((XMLCompositeDirectCollectionMapping)mapping).getValueConverter(); } else if(mapping.isAbstractDirectMapping()) { return ((XMLDirectMapping)mapping).getConverter(); } } } return null; }
public Converter getConverter(XMLField field) { if(null != this.fieldsToConverters) { Converter converter = fieldsToConverters.get(field); if(null != converter) { return converter; } if(null != this.choiceElementMappings) { DatabaseMapping mapping = (DatabaseMapping) this.choiceElementMappings.get(field); if(null == mapping) { return null; } if(mapping.isAbstractCompositeDirectCollectionMapping()) { return ((XMLCompositeDirectCollectionMapping)mapping).getValueConverter(); } else if(mapping.isAbstractDirectMapping()) { return ((XMLDirectMapping)mapping).getConverter(); } } } return null; }
public Converter getConverter(XMLField field) { if(null != this.fieldsToConverters) { Converter converter = fieldsToConverters.get(field); if(null != converter) { return converter; } if(null != this.choiceElementMappings) { DatabaseMapping mapping = (DatabaseMapping) this.choiceElementMappings.get(field); if(null == mapping) { return null; } if(mapping.isAbstractCompositeDirectCollectionMapping()) { return ((XMLCompositeDirectCollectionMapping)mapping).getValueConverter(); } else if(mapping.isAbstractDirectMapping()) { return ((XMLDirectMapping)mapping).getConverter(); } } } return null; }
/** * INTERNAL: * Return the DatabaseField that represents the key in a DirectMapMapping. MapContainerPolicy gets it fields from the reference descriptor * of the provided mappings. It uses its keyName to lookup the appropriate mapping and returns the field from * that mapping. */ @Override public DatabaseField getDirectKeyField(CollectionMapping baseMapping){ if (baseMapping == null){ return null; } ClassDescriptor descriptor = baseMapping.getReferenceDescriptor(); DatabaseMapping mapping = descriptor.getMappingForAttributeName(Helper.getAttributeNameFromMethodName(keyName)); if (mapping.isAbstractDirectMapping()){ return ((AbstractDirectMapping)mapping).getField(); } return null; }
/** * INTERNAL: * Return the DatabaseField that represents the key in a DirectMapMapping. MapContainerPolicy gets it fields from the reference descriptor * of the provided mappings. It uses its keyName to lookup the appropriate mapping and returns the field from * that mapping. */ @Override public DatabaseField getDirectKeyField(CollectionMapping baseMapping){ if (baseMapping == null){ return null; } ClassDescriptor descriptor = baseMapping.getReferenceDescriptor(); DatabaseMapping mapping = descriptor.getMappingForAttributeName(Helper.getAttributeNameFromMethodName(keyName)); if (mapping.isAbstractDirectMapping()){ return ((AbstractDirectMapping)mapping).getField(); } return null; }
/** * INTERNAL: * Return the DatabaseField that represents the key in a DirectMapMapping. MapContainerPolicy gets it fields from the reference descriptor * of the provided mappings. It uses its keyName to lookup the appropriate mapping and returns the field from * that mapping * @return */ public DatabaseField getDirectKeyField(CollectionMapping baseMapping){ if (baseMapping == null){ return null; } ClassDescriptor descriptor = baseMapping.getReferenceDescriptor(); DatabaseMapping mapping = descriptor.getMappingForAttributeName(Helper.getAttributeNameFromMethodName(keyName)); if (mapping.isAbstractDirectMapping()){ return ((AbstractDirectMapping)mapping).getField(); } return null; }
/** * INTERNAL: */ public void process(DatabaseMapping mapping, MappingAccessor accessor, MetadataClass referenceClass, boolean isForMapKey) { if (mapping.isAbstractDirectMapping()) { AbstractDirectMapping directMapping = ((AbstractDirectMapping) mapping); directMapping.setFieldType(Types.STRUCT); directMapping.setConverter(null); directMapping.setConverterClassName(null); } else if (!(mapping.isDirectCollectionMapping() || mapping.isDirectMapMapping())){ throw ValidationException.invalidMappingForStructConverter(getName(), mapping); } }
public Object convertDataValueToObjectValue(Object dataValue, Session session) { XMLRoot root = new XMLRoot(); root.setLocalName(this.rootFragment.getLocalName()); root.setNamespaceURI(this.rootFragment.getNamespaceURI()); if(mapping.isAbstractDirectMapping()){ if ((dataValue == null) || (dataValue.getClass() != mapping.getAttributeClassification())) { try { dataValue = session.getDatasourcePlatform().convertObject(dataValue, mapping.getAttributeClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, mapping.getDescriptor(), e); } } } root.setObject(dataValue); return root; }
public Object convertDataValueToObjectValue(Object dataValue, Session session) { XMLRoot root = new XMLRoot(); root.setLocalName(this.rootFragment.getLocalName()); root.setNamespaceURI(this.rootFragment.getNamespaceURI()); if(mapping.isAbstractDirectMapping()){ if ((dataValue == null) || (dataValue.getClass() != mapping.getAttributeClassification())) { try { dataValue = session.getDatasourcePlatform().convertObject(dataValue, mapping.getAttributeClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, mapping.getDescriptor(), e); } } } root.setObject(dataValue); return root; }
public Object convertDataValueToObjectValue(Object dataValue, Session session) { XMLRoot root = new XMLRoot(); root.setLocalName(this.rootFragment.getLocalName()); root.setNamespaceURI(this.rootFragment.getNamespaceURI()); if(mapping.isAbstractDirectMapping()){ if ((dataValue == null) || (dataValue.getClass() != mapping.getAttributeClassification())) { try { dataValue = session.getDatasourcePlatform().convertObject(dataValue, mapping.getAttributeClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, mapping.getDescriptor(), e); } } } root.setObject(dataValue); return root; }