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