Search in sources :

Example 6 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLObjectBuilder method createRecordFor.

public AbstractRecord createRecordFor(Object object, DocumentPreservationPolicy docPresPolicy) {
    Element cachedNode = null;
    XMLRecord record = null;
    if (docPresPolicy != null) {
        cachedNode = (Element) docPresPolicy.getNodeForObject(object);
    }
    if (cachedNode == null) {
        record = new DOMRecord(getDescriptor().getTableName(), getNamespaceResolver());
        docPresPolicy.addObjectToCache(object, record.getDOM());
    } else {
        record = new DOMRecord(cachedNode);
    }
    record.setDocPresPolicy(docPresPolicy);
    return record;
}
Also used : DOMRecord(org.eclipse.persistence.oxm.record.DOMRecord) Element(org.w3c.dom.Element) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 7 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLObjectBuilder method createRecord.

/**
 * Create a new row/record for the object builder with the given name. This
 * allows subclasses to define different record types.
 */
public AbstractMarshalRecord createRecord(String rootName, Node parent, AbstractSession session) {
    NamespaceResolver namespaceResolver = getNamespaceResolver();
    XMLRecord xmlRec = new DOMRecord(rootName, namespaceResolver, parent);
    xmlRec.setSession(session);
    return xmlRec;
}
Also used : DOMRecord(org.eclipse.persistence.oxm.record.DOMRecord) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 8 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLObjectBuilder method buildRow.

/**
 * Build the nested row into the parent dom.
 */
public AbstractRecord buildRow(Object object, AbstractSession session, DatabaseField xmlField, XMLRecord parentRecord) {
    if (isXmlDescriptor() && ((Descriptor) getDescriptor()).shouldPreserveDocument()) {
        Object pk = extractPrimaryKeyFromObject(object, session);
        if ((pk == null) || (pk instanceof CacheId) && (((CacheId) pk).getPrimaryKey().length == 0)) {
            pk = new CacheId(new Object[] { new WeakObjectWrapper(object) });
        }
        CacheKey cacheKey = session.getIdentityMapAccessorInstance().getCacheKeyForObject(pk, getDescriptor().getJavaClass(), getDescriptor(), false);
        if ((cacheKey != null) && (cacheKey.getRecord() != null)) {
            XMLRecord nestedRecord = (XMLRecord) cacheKey.getRecord();
            nestedRecord.setMarshaller(parentRecord.getMarshaller());
            nestedRecord.setLeafElementType(parentRecord.getLeafElementType());
            parentRecord.setLeafElementType((XPathQName) null);
            return buildIntoNestedRow(nestedRecord, object, session);
        }
    }
    Element newNode = XPathEngine.getInstance().createUnownedElement(parentRecord.getDOM(), (Field) xmlField);
    XMLRecord nestedRecord = new DOMRecord(newNode);
    nestedRecord.setNamespaceResolver(parentRecord.getNamespaceResolver());
    nestedRecord.setMarshaller(parentRecord.getMarshaller());
    nestedRecord.setLeafElementType(parentRecord.getLeafElementType());
    parentRecord.setLeafElementType((XPathQName) null);
    return buildIntoNestedRow(nestedRecord, object, session);
}
Also used : CacheId(org.eclipse.persistence.internal.identitymaps.CacheId) DOMRecord(org.eclipse.persistence.oxm.record.DOMRecord) Element(org.w3c.dom.Element) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) CacheKey(org.eclipse.persistence.internal.identitymaps.CacheKey)

Example 9 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLObjectBuilder method buildIntoNestedRow.

public AbstractRecord buildIntoNestedRow(AbstractRecord row, Object originalObject, Object object, AbstractSession session, Descriptor refDesc, Field xmlField, boolean wasXMLRoot) {
    // PERF: Avoid synchronized enumerator as is concurrency bottleneck.
    XMLRecord record = (XMLRecord) row;
    record.setSession(session);
    XMLMarshaller marshaller = record.getMarshaller();
    if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
        marshaller.getMarshalListener().beforeMarshal(object);
    }
    List extraNamespaces = null;
    if (isXmlDescriptor()) {
        Descriptor xmlDescriptor = (Descriptor) getDescriptor();
        extraNamespaces = addExtraNamespacesToNamespaceResolver(xmlDescriptor, record, session, false, false);
        writeExtraNamespaces(extraNamespaces, record);
        record.addXsiTypeAndClassIndicatorIfRequired(xmlDescriptor, refDesc, xmlField, originalObject, object, wasXMLRoot, false);
    }
    writeOutMappings(record, object, session);
    // If this descriptor is involved in inheritance add the class type.
    if (isXmlDescriptor()) {
        record.removeExtraNamespacesFromNamespaceResolver(extraNamespaces, session);
    }
    // the non default tables.
    if (!getDescriptor().isAggregateDescriptor()) {
        addPrimaryKeyForNonDefaultTable(row);
    }
    if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
        marshaller.getMarshalListener().afterMarshal(object);
    }
    return row;
}
Also used : XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 10 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class QNameInheritancePolicy method addClassIndicatorFieldToRow.

/**
 * INTERNAL:
 * Add abstract class indicator information to the database row.  This is
 * required when building a row for an insert or an update of a concrete child
 * descriptor.
 */
@Override
public void addClassIndicatorFieldToRow(AbstractRecord databaseRow) {
    if (hasClassExtractor()) {
        return;
    }
    CoreField field = getClassIndicatorField();
    Object value = getClassIndicatorValue();
    if (usesXsiType) {
        boolean namespaceAware = ((XMLRecord) databaseRow).isNamespaceAware() || ((XMLRecord) databaseRow).hasCustomNamespaceMapper();
        if (value instanceof String) {
            if (namespaceAware) {
                if (((XMLRecord) databaseRow).getNamespaceSeparator() != Constants.COLON) {
                    value = ((String) value).replace(Constants.COLON, ((XMLRecord) databaseRow).getNamespaceSeparator());
                }
            } else {
                int colonIndex = ((String) value).indexOf(Constants.COLON);
                if (colonIndex > -1) {
                    value = ((String) value).substring(colonIndex + 1);
                }
            }
        }
    }
    databaseRow.put(field, value);
}
Also used : CoreField(org.eclipse.persistence.internal.core.helper.CoreField) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Aggregations

XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)50 XMLField (org.eclipse.persistence.oxm.XMLField)19 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)16 DOMRecord (org.eclipse.persistence.oxm.record.DOMRecord)14 Element (org.w3c.dom.Element)11 Vector (java.util.Vector)10 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)10 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)8 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)7 XMLObjectBuilder (org.eclipse.persistence.internal.oxm.XMLObjectBuilder)7 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)6 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)6 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)6 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)6 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)6 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)6 MapValueAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor)6 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)6 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)6 Field (org.eclipse.persistence.internal.oxm.mappings.Field)5