use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class EISOneToManyMappingHelper method mergeChangesIntoObjectWithoutOrder.
/**
* Merge changes from the source to the target object.
* Make the necessary removals and adds and map key modifications.
*/
private void mergeChangesIntoObjectWithoutOrder(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager, AbstractSession targetSession) {
EISCollectionChangeRecord sdkChangeRecord = (EISCollectionChangeRecord) changeRecord;
ContainerPolicy cp = this.getContainerPolicy();
AbstractSession session = mergeManager.getSession();
Object targetCollection = null;
if (sdkChangeRecord.getOwner().isNew()) {
targetCollection = cp.containerInstance(sdkChangeRecord.getAdds().size());
} else {
targetCollection = this.getRealCollectionAttributeValueFromObject(target, session);
}
List removes = sdkChangeRecord.getRemoves();
List adds = sdkChangeRecord.getAdds();
List changedMapKeys = sdkChangeRecord.getChangedMapKeys();
synchronized (targetCollection) {
for (Object removed : removes) {
Object removeElement = buildRemovedElementFromChangeSet(removed, mergeManager, targetSession);
Object targetElement = null;
for (Object iter = cp.iteratorFor(targetCollection); cp.hasNext(iter); ) {
targetElement = cp.next(iter, session);
if (this.compareElements(targetElement, removeElement, session)) {
// matching element found - skip the rest of them
break;
}
}
if (targetElement != null) {
// a matching element was found, remove it
cp.removeFrom(targetElement, targetCollection, session);
}
}
for (Object added : adds) {
Object addElement = buildAddedElementFromChangeSet(added, mergeManager, targetSession);
cp.addInto(addElement, targetCollection, session);
}
for (Object changed : changedMapKeys) {
Object changedMapKeyElement = buildAddedElementFromChangeSet(changed, mergeManager, targetSession);
Object originalElement = ((UnitOfWorkImpl) session).getOriginalVersionOfObject(changedMapKeyElement);
cp.removeFrom(originalElement, targetCollection, session);
cp.addInto(changedMapKeyElement, targetCollection, session);
}
}
// reset the attribute to allow for set method to re-morph changes if the collection is not being stored directly
setRealAttributeValueInObject(target, targetCollection);
}
use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class EISOneToManyMappingHelper method compareAttributeValuesWithoutOrder.
/**
* Compare the attributes. Return true if they are alike.
* Ignore the order of the elements.
*/
private boolean compareAttributeValuesWithoutOrder(Object collection1, Object collection2, AbstractSession session) {
ContainerPolicy cp = this.getContainerPolicy();
// "clone" it so we can clear out the slots
List vector2 = cp.vectorFor(collection2, session);
for (Object iter1 = cp.iteratorFor(collection1); cp.hasNext(iter1); ) {
Object element1 = cp.next(iter1, session);
boolean found = false;
for (int i = 0; i < vector2.size(); i++) {
if (this.compareElements(element1, vector2.get(i), session)) {
found = true;
// clear out the matching element
vector2.set(i, XXX);
// matching element found - skip the rest of them
break;
}
}
if (!found) {
return false;
}
}
// look for elements that were not in collection1
for (Object value : vector2) {
if (value != XXX) {
return false;
}
}
return true;
}
use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class EISOneToManyMappingHelper method compareForChange.
/**
* INTERNAL:
* Build and return the change record that results
* from comparing the two collection attributes.
*/
public ChangeRecord compareForChange(Object clone, Object backup, ObjectChangeSet owner, AbstractSession session) {
ContainerPolicy cp = this.getContainerPolicy();
Object cloneCollection = this.getRealCollectionAttributeValueFromObject(clone, session);
Object backupCollection = null;
if (owner.isNew()) {
backupCollection = cp.containerInstance(1);
} else {
backupCollection = this.getRealCollectionAttributeValueFromObject(backup, session);
}
if (cp.hasOrder()) {
return this.compareAttributeValuesForChangeWithOrder(cloneCollection, backupCollection, owner, session);
} else {
return this.compareAttributeValuesForChangeWithoutOrder(cloneCollection, backupCollection, owner, session);
}
}
use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class XMLBinaryDataCollectionMapping method writeFromObjectIntoRow.
@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) {
XMLRecord record = (XMLRecord) row;
Object attributeValue = getAttributeValueFromObject(object);
ContainerPolicy cp = this.getContainerPolicy();
Vector elements = new Vector(cp.sizeFor(attributeValue));
XMLField field = (XMLField) getField();
NamespaceResolver resolver = field.getNamespaceResolver();
boolean isAttribute = field.getLastXPathFragment().isAttribute();
String prefix = null;
XMLField includeField = null;
if (!isAttribute) {
if (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) {
field = (XMLField) getField();
// on the current element
if (resolver != null) {
prefix = resolver.resolveNamespaceURI(XMLConstants.XOP_URL);
}
if (prefix == null) {
// "xop";
prefix = XMLConstants.XOP_PREFIX;
resolver = new NamespaceResolver();
resolver.put(prefix, XMLConstants.XOP_URL);
}
includeField = new XMLField(prefix + XMLConstants.COLON + INCLUDE + "/@href");
includeField.setNamespaceResolver(resolver);
}
}
XMLField textField = new XMLField(field.getXPath() + '/' + XMLConstants.TEXT);
textField.setNamespaceResolver(field.getNamespaceResolver());
textField.setSchemaType(field.getSchemaType());
// field = textField;
boolean inline = false;
for (Object iter = cp.iteratorFor(attributeValue); cp.hasNext(iter); ) {
Object element = cp.next(iter, session);
element = getValueToWrite(element, object, record, field, includeField, session);
if (element == null) {
AbstractNullPolicy nullPolicy = getNullPolicy();
if (nullPolicy == null) {
elements.addElement(null);
} else {
if (nullPolicy.getMarshalNullRepresentation() == XMLNullRepresentationType.XSI_NIL) {
elements.addElement(XMLRecord.NIL);
} else if (nullPolicy.getMarshalNullRepresentation() == XMLNullRepresentationType.ABSENT_NODE) {
// Do nothing
} else {
elements.addElement(XMLConstants.EMPTY_STRING);
}
}
} else {
if (element.getClass() == ClassConstants.ABYTE) {
inline = true;
}
elements.addElement(element);
}
}
Object fieldValue = null;
if (!elements.isEmpty()) {
fieldValue = this.getDescriptor().buildFieldValueFromDirectValues(elements, elementDataTypeName, session);
}
if (inline) {
row.put(textField, fieldValue);
} else {
row.put(field, fieldValue);
}
}
use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class XMLAnyAttributeMapping method buildObjectValuesFromDOMRecord.
private Object buildObjectValuesFromDOMRecord(DOMRecord record, AbstractSession session, ObjectBuildingQuery query) {
// This DOMRecord represents the root node of the AnyType instance
// Grab ALL children to populate the collection.
ContainerPolicy cp = getContainerPolicy();
Object container = null;
if (reuseContainer) {
Object currentObject = record.getCurrentObject();
Object value = getAttributeAccessor().getAttributeValueFromObject(currentObject);
container = value != null ? value : cp.containerInstance();
} else {
container = cp.containerInstance();
}
org.w3c.dom.Element root = (Element) record.getDOM();
NamedNodeMap attributes = root.getAttributes();
Attr next;
String localName;
int numberOfAtts = attributes.getLength();
for (int i = 0; i < numberOfAtts; i++) {
next = (Attr) attributes.item(i);
localName = next.getLocalName();
if (null == localName) {
localName = next.getName();
}
String namespaceURI = next.getNamespaceURI();
boolean includeAttribute = true;
if (!isNamespaceDeclarationIncluded && javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) {
includeAttribute = false;
} else if (!isSchemaInstanceIncluded && javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(namespaceURI)) {
includeAttribute = false;
}
if (includeAttribute) {
String value = next.getValue();
QName key = new QName(namespaceURI, localName);
cp.addInto(key, value, container, session);
}
}
return container;
}
Aggregations