use of org.eclipse.persistence.internal.identitymaps.CacheId in project eclipselink by eclipse-ee4j.
the class RelationTableMechanism method extractKeyFromTargetRow.
/**
* INTERNAL:
* Extract the source primary key value from the relation row.
* Used for batch reading, most following same order and fields as in the mapping.
*/
protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) {
int size = getSourceRelationKeyFields().size();
Object[] key = new Object[size];
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField relationField = this.sourceRelationKeyFields.get(index);
DatabaseField sourceField = this.sourceKeyFields.get(index);
Object value = row.get(relationField);
// Must ensure the classification gets a cache hit.
value = conversionManager.convertObject(value, sourceField.getType());
key[index] = value;
}
return new CacheId(key);
}
use of org.eclipse.persistence.internal.identitymaps.CacheId in project eclipselink by eclipse-ee4j.
the class XMLObjectBuilder method buildObject.
/**
* INTERNAL: Override the parent's buildObject to allow for the caching of
* aggregate objects in OX. By caching aggregates along with XML Nodes that
* they were created from, we are able to preserve the structure and
* unmapped content of the document that was used to create these objects.
*/
@Override
public Object buildObject(ObjectBuildingQuery query, AbstractRecord databaseRow, JoinedAttributeManager joinManager) throws DatabaseException, QueryException {
XMLRecord row = (XMLRecord) databaseRow;
row.setSession(query.getSession());
XMLUnmarshaller unmarshaller = row.getUnmarshaller();
Object parent = row.getOwningObject();
if (!(isXmlDescriptor() || getDescriptor().isDescriptorTypeAggregate())) {
return super.buildObject(query, databaseRow, joinManager);
}
query.getSession().startOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL);
ClassDescriptor concreteDescriptor = getDescriptor();
Object domainObject = null;
// in the mapping
if (concreteDescriptor.hasInheritance() && (parent == null)) {
// look for an xsi:type attribute in the xml document
InheritancePolicy inheritancePolicy = concreteDescriptor.getInheritancePolicy();
Class<?> classValue = inheritancePolicy.classFromRow(databaseRow, query.getSession());
if ((classValue == null) && isXmlDescriptor()) {
// no xsi:type attribute - look for type indicator on the
// default root element
QName leafElementType = ((Descriptor) concreteDescriptor).getDefaultRootElementType();
// inheritance policy
if (leafElementType != null) {
XPathQName xpathQName = new XPathQName(leafElementType, row.isNamespaceAware());
Object indicator = inheritancePolicy.getClassIndicatorMapping().get(xpathQName);
if (indicator != null) {
classValue = (Class) indicator;
}
}
}
// class, if non-abstract
if (classValue != null) {
concreteDescriptor = query.getSession().getDescriptor(classValue);
if ((concreteDescriptor == null) && query.hasPartialAttributeExpressions()) {
concreteDescriptor = getDescriptor();
}
if (concreteDescriptor == null) {
throw QueryException.noDescriptorForClassFromInheritancePolicy(query, classValue);
}
} else {
// make sure the class is non-abstract
if (Modifier.isAbstract(concreteDescriptor.getJavaClass().getModifiers())) {
// throw an exception
throw DescriptorException.missingClassIndicatorField(databaseRow, inheritancePolicy.getDescriptor());
}
}
}
domainObject = concreteDescriptor.getObjectBuilder().buildNewInstance();
row.setCurrentObject(domainObject);
if ((unmarshaller != null) && (unmarshaller.getUnmarshalListener() != null)) {
unmarshaller.getUnmarshalListener().beforeUnmarshal(domainObject, parent);
}
concreteDescriptor.getObjectBuilder().buildAttributesIntoObject(domainObject, null, databaseRow, query, joinManager, null, false, query.getSession());
if (isXmlDescriptor() && ((Descriptor) concreteDescriptor).getPrimaryKeyFieldNames().size() > 0) {
Object pk = extractPrimaryKeyFromRow(databaseRow, query.getSession());
if ((pk != null) && (((CacheId) pk).getPrimaryKey().length > 0)) {
DOMRecord domRecord = (DOMRecord) databaseRow;
domRecord.getReferenceResolver().putValue(concreteDescriptor.getJavaClass(), pk, domainObject);
}
}
DocumentPreservationPolicy docPresPolicy = row.getDocPresPolicy();
if (docPresPolicy != null) {
// EIS XML Cases won't have a doc pres policy set
row.getDocPresPolicy().addObjectToCache(domainObject, row.getDOM());
}
query.getSession().endOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL);
if ((unmarshaller != null) && (unmarshaller.getUnmarshalListener() != null)) {
unmarshaller.getUnmarshalListener().afterUnmarshal(domainObject, parent);
}
return domainObject;
}
use of org.eclipse.persistence.internal.identitymaps.CacheId in project eclipselink by eclipse-ee4j.
the class DirectCollectionMapping method extractKeyFromTargetRow.
/**
* INTERNAL:
* Extract the source primary key value from the reference direct row.
* Used for batch reading, most following same order and fields as in the mapping.
*/
@Override
protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) {
int size = this.referenceKeyFields.size();
Object[] key = new Object[size];
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField relationField = this.referenceKeyFields.get(index);
DatabaseField sourceField = this.sourceKeyFields.get(index);
Object value = row.get(relationField);
// Must ensure the classification gets a cache hit.
try {
value = conversionManager.convertObject(value, sourceField.getType());
} catch (ConversionException e) {
throw ConversionException.couldNotBeConverted(this, getDescriptor(), e);
}
key[index] = value;
}
return new CacheId(key);
}
use of org.eclipse.persistence.internal.identitymaps.CacheId in project eclipselink by eclipse-ee4j.
the class DirectCollectionMapping method extractBatchKeyFromRow.
/**
* INTERNAL:
* Extract the primary key value from the source row.
* Used for batch reading, most following same order and fields as in the mapping.
*/
@Override
protected Object extractBatchKeyFromRow(AbstractRecord row, AbstractSession session) {
int size = this.sourceKeyFields.size();
Object[] key = new Object[size];
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField field = this.sourceKeyFields.get(index);
Object value = row.get(field);
// Must ensure the classification to get a cache hit.
try {
value = conversionManager.convertObject(value, field.getType());
} catch (ConversionException exception) {
throw ConversionException.couldNotBeConverted(this, this.descriptor, exception);
}
key[index] = value;
}
return new CacheId(key);
}
use of org.eclipse.persistence.internal.identitymaps.CacheId in project eclipselink by eclipse-ee4j.
the class OneToManyMapping method extractBatchKeyFromRow.
/**
* Extract the key field values from the specified row.
* Used for batch reading. Keep the fields in the same order
* as in the targetForeignKeysToSourceKeys map.
*/
@Override
protected Object extractBatchKeyFromRow(AbstractRecord row, AbstractSession session) {
int size = this.sourceKeyFields.size();
Object[] key = new Object[size];
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField sourceField = this.sourceKeyFields.get(index);
Object value = row.get(sourceField);
// Must ensure the classification to get a cache hit.
try {
value = conversionManager.convertObject(value, sourceField.getType());
} catch (ConversionException exception) {
throw ConversionException.couldNotBeConverted(this, this.descriptor, exception);
}
key[index] = value;
}
return new CacheId(key);
}
Aggregations