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); } } } } }
@Override protected void initialize(ClassDescriptor descriptor) { int descriptorMappingsSize = descriptor.getMappings().size(); this.mappingsByField = new HashMap(descriptorMappingsSize); this.fieldsMap = new HashMap(descriptorMappingsSize); this.cloningMappings = new ArrayList(descriptorMappingsSize); }
/** * Build the row representation of the object that contains only the fields nullified by shallow insert, with all values set to null. */ public AbstractRecord buildRowForUpdateBeforeShallowDelete(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseTable table) { for (DatabaseMapping mapping : this.descriptor.getMappings()) { mapping.writeFromObjectIntoRowForUpdateBeforeShallowDelete(object, databaseRow, session, table); } return databaseRow; }
protected DatabaseMapping getMappingOfFirstPrimaryKey(ClassDescriptor descriptor) { if (descriptor != null) { for (Iterator i = descriptor.getMappings().iterator(); i.hasNext(); ) { DatabaseMapping m = (DatabaseMapping)i.next(); if (m.isPrimaryKeyMapping()) { return m; } } } return null; }
/** * Build the row representation of the object that contains only the fields nullified by shallow insert. */ public AbstractRecord buildRowForUpdateAfterShallowInsert(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseTable table) { for (DatabaseMapping mapping : this.descriptor.getMappings()) { mapping.writeFromObjectIntoRowForUpdateAfterShallowInsert(object, databaseRow, session, table); } return databaseRow; }
/** * ADVANCED: * Removes the locally defined mapping associated with a given attribute name. * This can be used in a amendment method before the descriptor has been initialized. */ public DatabaseMapping removeMappingForAttributeName(String attributeName) { DatabaseMapping mapping = getMappingForAttributeName(attributeName); getMappings().remove(mapping); return mapping; }
/** * Build the row representation of the object that contains only the fields nullified by shallow insert, with all values set to null. */ public AbstractRecord buildRowForUpdateBeforeShallowDelete(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseTable table) { for (DatabaseMapping mapping : this.descriptor.getMappings()) { mapping.writeFromObjectIntoRowForUpdateBeforeShallowDelete(object, databaseRow, session, table); } return databaseRow; }
/** * ADVANCED: * Removes the locally defined mapping associated with a given attribute name. * This can be used in a amendment method before the descriptor has been initialized. */ public DatabaseMapping removeMappingForAttributeName(String attributeName) { DatabaseMapping mapping = getMappingForAttributeName(attributeName); getMappings().remove(mapping); return mapping; }
/** * INTERNAL: * Checks if the class has any private owned parts or other dependencies, (i.e. M:M join table). */ public boolean hasDependencyOnParts() { for (DatabaseMapping mapping : getMappings()) { if (mapping.hasDependency()) { return true; } } return false; }
/** * Build the row representation of the object that contains only the fields nullified by shallow insert. */ public AbstractRecord buildRowForUpdateAfterShallowInsert(AbstractRecord databaseRow, Object object, AbstractSession session, DatabaseTable table) { for (DatabaseMapping mapping : this.descriptor.getMappings()) { mapping.writeFromObjectIntoRowForUpdateAfterShallowInsert(object, databaseRow, session, table); } return databaseRow; }
/** * INTERNAL: * Validate the entire pre-initialization descriptor. */ protected void validateBeforeInitialization(AbstractSession session) { selfValidationBeforeInitialization(session); for (Enumeration mappings = getMappings().elements(); mappings.hasMoreElements();) { ((DatabaseMapping)mappings.nextElement()).validateBeforeInitialization(session); } }
public void writeOutMappings(XMLRecord row, Object object, AbstractSession session) { List<DatabaseMapping> mappings = getDescriptor().getMappings(); for (int index = 0; index < mappings.size(); index++) { DatabaseMapping mapping = mappings.get(index); mapping.writeFromObjectIntoRow(object, row, session, WriteType.UNDEFINED); } } public void addNamespaceDeclarations(Document document) {
public void writeOutMappings(XMLRecord row, Object object, AbstractSession session) { Vector mappings = getDescriptor().getMappings(); for (int index = 0; index < mappings.size(); index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); mapping.writeFromObjectIntoRow(object, row, session); } } public void addNamespaceDeclarations(Document document) {
public List<String> getPropertyNames() { List<String> propertyNames = new ArrayList<String>(); if (type != null && type.getDescriptor() != null) { for (DatabaseMapping dm : type.getDescriptor().getMappings()) { propertyNames.add(dm.getAttributeName()); } } return propertyNames; }
/** * INTERNAL: * Validate the entire pre-initialization descriptor. */ protected void validateBeforeInitialization(AbstractSession session) { selfValidationBeforeInitialization(session); for (DatabaseMapping mapping : getMappings()) { mapping.validateBeforeInitialization(session); } }
/** * INTERNAL: * Validate the entire pre-initialization descriptor. */ protected void validateBeforeInitialization(AbstractSession session) { selfValidationBeforeInitialization(session); for (DatabaseMapping mapping : getMappings()) { mapping.validateBeforeInitialization(session); } }
public List<String> getPropertyNames() { List<String> propertyNames = new ArrayList<String>(); if (type != null && type.getDescriptor() != null) { for (DatabaseMapping dm : type.getDescriptor().getMappings()) { propertyNames.add(dm.getAttributeName()); } } return propertyNames; }
public boolean contains(String propertyName) { boolean contains = false; if (type != null && type.getDescriptor() != null) { for (DatabaseMapping dm : type.getDescriptor().getMappings()) { if (dm.getAttributeName().equals(propertyName)) { contains = true; break; } } } return contains; }
/** * INTERNAL: * This method is used to store the FK fields that can be cached that correspond to noncacheable mappings * the FK field values will be used to re-issue the query when cloning the shared cache entity */ @Override public void collectQueryParameters(Set<DatabaseField> record){ for (DatabaseMapping mapping : getReferenceDescriptor().getMappings()){ if ((mapping.isForeignReferenceMapping() && !mapping.isCacheable()) || (mapping.isAggregateObjectMapping() && mapping.getReferenceDescriptor().hasNoncacheableMappings())){ ((ForeignReferenceMapping) mapping).collectQueryParameters(record); } } }