/** * INTERNAL: * Builds a shallow original object. Only direct attributes and primary * keys are populated. In this way the minimum original required for * instantiating a working copy clone can be built without placing it in * the shared cache (no concern over cycles). * @param original later the input to buildCloneFromRow */ @Override public void buildShallowOriginalFromRow(AbstractRecord record, Object original, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) { // In this case we know it is a primary key mapping, so hope that it // is essentially a direct mapping. If it is a 1-1 with a // no-indirection pointer back to original, then will get a stack // overflow. // Only solution to this is to trigger the transformation using the root // session. UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)query.getSession(); query.setSession(unitOfWork.getParent()); try { readFromRowIntoObject(record, joinManager, original, null, query, executionSession, false); } finally { query.setSession(unitOfWork); } }
/** * INTERNAL: * Extracts value from return row and set the attribute to the value in the object. * Return row is merged into object after execution of insert or update call * accordiing to ReturningPolicy. */ public Object readFromReturnRowIntoObject(AbstractRecord row, Object object, ReadObjectQuery query, Collection handledMappings) throws DatabaseException { AbstractRecord transformationRow = new DatabaseRecord(getFields().size()); for (int i = 0; i < getFields().size(); i++) { DatabaseField field = getFields().elementAt(i); Object value; if (row.containsKey(field)) { value = row.get(field); } else { value = valueFromObject(object, field, query.getSession()); } transformationRow.add(field, value); } Object attributeValue = readFromRowIntoObject(transformationRow, null, object, query, query.getSession()); if (handledMappings != null) { handledMappings.add(this); } return attributeValue; }
/** * INTERNAL: * Builds a shallow original object. Only direct attributes and primary * keys are populated. In this way the minimum original required for * instantiating a working copy clone can be built without placing it in * the shared cache (no concern over cycles). * @parameter original later the input to buildCloneFromRow */ public void buildShallowOriginalFromRow(AbstractRecord record, Object original, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) { // In this case we know it is a primary key mapping, so hope that it // is essentially a direct mapping. If it is a 1-1 with a // no-indirection pointer back to original, then will get a stack // overflow. // Only solution to this is to trigger the transformation using the root // session. UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)query.getSession(); query.setSession(unitOfWork.getParent()); try { readFromRowIntoObject(record, joinManager, original, query, executionSession); } finally { query.setSession(unitOfWork); } }
/** * INTERNAL: * Builds a shallow original object. Only direct attributes and primary * keys are populated. In this way the minimum original required for * instantiating a working copy clone can be built without placing it in * the shared cache (no concern over cycles). * @param original later the input to buildCloneFromRow */ @Override public void buildShallowOriginalFromRow(AbstractRecord record, Object original, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) { // In this case we know it is a primary key mapping, so hope that it // is essentially a direct mapping. If it is a 1-1 with a // no-indirection pointer back to original, then will get a stack // overflow. // Only solution to this is to trigger the transformation using the root // session. UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)query.getSession(); query.setSession(unitOfWork.getParent()); try { readFromRowIntoObject(record, joinManager, original, null, query, executionSession, false); } finally { query.setSession(unitOfWork); } }
/** * INTERNAL: * Extract value from the row and set the attribute to this value in the * working copy clone. * In order to bypass the shared cache when in transaction a UnitOfWork must * be able to populate working copies directly from the row. */ public void buildCloneFromRow(AbstractRecord record, JoinedAttributeManager joinManager, Object clone, ObjectBuildingQuery sourceQuery, UnitOfWorkImpl unitOfWork, AbstractSession executionSession) { // If mapping is a no-attribute transformation mapping, do nothing if (isWriteOnly()) { return; } // This will set the value in the clone automatically. Object attributeValue = readFromRowIntoObject(record, joinManager, clone, sourceQuery, executionSession); Object clonedAttributeValue; // If the mapping is read-only, a direct pass through of the value will be performed. // This is done because the method invocation is not possible as the row will be // empty and we have no way to clone the value. // Since the value cannot change anyway we just pass it through. if (isReadOnly() || !isMutable()) { clonedAttributeValue = attributeValue; } else { clonedAttributeValue = getIndirectionPolicy().cloneAttribute(attributeValue, null,// no original clone, unitOfWork, true);// build clone directly from row. } setAttributeValueInObject(clone, clonedAttributeValue); }
/** * INTERNAL: * Extract value from the row and set the attribute to this value in the * working copy clone. * In order to bypass the shared cache when in transaction a UnitOfWork must * be able to populate working copies directly from the row. */ @Override public void buildCloneFromRow(AbstractRecord record, JoinedAttributeManager joinManager, Object clone, CacheKey sharedCacheKey, ObjectBuildingQuery sourceQuery, UnitOfWorkImpl unitOfWork, AbstractSession executionSession) { // If mapping is a no-attribute transformation mapping, do nothing if (isWriteOnly()) { return; } // This will set the value in the clone automatically. Object attributeValue = readFromRowIntoObject(record, joinManager, clone, sharedCacheKey, sourceQuery, executionSession, true); if (usesIndirection()) { boolean wasCacheUsed = this.isCacheable && sharedCacheKey != null && this.descriptor.getCachePolicy().isProtectedIsolation() && sharedCacheKey.getObject() != null; //it would be better if wasCacheUsed could be calculated within readFromRowIntoObject but that would require changing the signature of all mappings just for //transformation mapping. if (!wasCacheUsed){ //if the cache was used then the attribute has already been cloned by readFromRowIntoObject attributeValue = this.indirectionPolicy.cloneAttribute(attributeValue, null,// no original null, clone, null, unitOfWork, true);// build clone directly from row. } setAttributeValueInObject(clone, attributeValue); } }
/** * INTERNAL: * Extract value from the row and set the attribute to this value in the * working copy clone. * In order to bypass the shared cache when in transaction a UnitOfWork must * be able to populate working copies directly from the row. */ @Override public void buildCloneFromRow(AbstractRecord record, JoinedAttributeManager joinManager, Object clone, CacheKey sharedCacheKey, ObjectBuildingQuery sourceQuery, UnitOfWorkImpl unitOfWork, AbstractSession executionSession) { // If mapping is a no-attribute transformation mapping, do nothing if (isWriteOnly()) { return; } // This will set the value in the clone automatically. Object attributeValue = readFromRowIntoObject(record, joinManager, clone, sharedCacheKey, sourceQuery, executionSession, true); if (usesIndirection()) { boolean wasCacheUsed = this.isCacheable && sharedCacheKey != null && this.descriptor.getCachePolicy().isProtectedIsolation() && sharedCacheKey.getObject() != null; //it would be better if wasCacheUsed could be calculated within readFromRowIntoObject but that would require changing the signature of all mappings just for //transformation mapping. if (!wasCacheUsed){ //if the cache was used then the attribute has already been cloned by readFromRowIntoObject attributeValue = this.indirectionPolicy.cloneAttribute(attributeValue, null,// no original null, clone, null, unitOfWork, true);// build clone directly from row. } setAttributeValueInObject(clone, attributeValue); } }
Object attributeValue = readFromRowIntoObject(transformationRow, null, object, null, query, query.getSession(), true); if (handledMappings != null) { handledMappings.add(this);
for (int x = 0, transformationMappingsSize = transformationMappings.size(); x < transformationMappingsSize; x++) { AbstractTransformationMapping transformationMapping = (AbstractTransformationMapping)transformationMappings.get(x); transformationMapping.readFromRowIntoObject(transformationRecord, null, currentObject, query, session);
Object attributeValue = readFromRowIntoObject(transformationRow, null, object, null, query, query.getSession(), true); if (handledMappings != null) { handledMappings.add(this);