/** * INTERNAL: * Copy of the attribute of the object. * This is NOT used for unit of work but for templatizing an object. */ public void buildCopy(Object copy, Object original, ObjectCopyingPolicy policy) { // If mapping is a no-attribute transformation mapping, do nothing if (isWriteOnly()) { return; } Object attributeValue = getAttributeValueFromObject(original); 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 { AbstractRecord row = this.buildPhantomRowFrom(original, policy.getSession()); clonedAttributeValue = invokeAttributeTransformer(row, copy, policy.getSession()); } setAttributeValueInObject(copy, clonedAttributeValue); }
@Override public void initialize(AbstractTransformationMapping mapping) { transformationMapping = mapping; namespaceResolver = ((XMLDescriptor)mapping.getDescriptor()).getNamespaceResolver(); }
/** * PUBLIC: * Add the name of field and the name of the method * that returns the value to be placed in said field * when the object is written to the database. * The method may take zero arguments, or it may * take a single argument of type * <code>org.eclipse.persistence.sessions.Session</code>. */ public void addFieldTransformation(String fieldName, String methodName) { addFieldTransformation(new DatabaseField(fieldName), methodName); }
/** * INTERNAL: * Will be used by Gromit. For details see usesIndirection(). * @see #useBasicIndirection() * @see #dontUseIndirection() */ public void setUsesIndirection(boolean usesIndirection) { if (usesIndirection) { useBasicIndirection(); } else { dontUseIndirection(); } }
/** * INTERNAL: * Require for cloning, the part must be cloned. * Ignore the attribute value, go right to the object itself. */ public Object buildCloneForPartObject(Object attributeValue, Object original, CacheKey cacheKey, Object clone, AbstractSession cloningSession, Integer refreshCascade, boolean isExisting, boolean isFromSharedCache) { if (isReadOnly() || !isMutable()) { return attributeValue; } AbstractRecord row = buildPhantomRowFrom(original, cloningSession); return invokeAttributeTransformer(row, clone, cloningSession); }
/** * INTERNAL: * Used during building the backup shallow copy to copy the vector without re-registering the target objects. * For 1-1 or ref the reference is from the clone so it is already registered. */ public Object buildBackupCloneForPartObject(Object attributeValue, Object clone, Object backup, UnitOfWorkImpl unitOfWork) { if (!isMutable()) { return attributeValue; } AbstractRecord row = this.buildPhantomRowFrom(clone, unitOfWork); return this.invokeAttributeTransformer(row, backup, unitOfWork); }
if (isWriteOnly()) { return; if (mergeManager.shouldRefreshRemoteObject() && usesIndirection()) { getIndirectionPolicy().mergeRemoteValueHolder(target, source, mergeManager); return; if (!areObjectsToBeProcessedInstantiated(target)) { } else if (!areObjectsToBeProcessedInstantiated(source)) { if (mergeManager.shouldMergeWorkingCopyIntoOriginal() && (!areObjectsToBeProcessedInstantiated(source))) { setAttributeValueInObject(target, getIndirectionPolicy().getOriginalIndirectionObject(getAttributeValueFromObject(source), mergeManager.getSession())); return; if (isReadOnly()) { setRealAttributeValueInObject(target, getRealAttributeValueFromObject(source, mergeManager.getSession())); return; if (!isMutable()) { Object attribute = getRealAttributeValueFromObject(source, mergeManager.getSession()); if (this.descriptor.getObjectChangePolicy().isObjectChangeTrackingPolicy()) { Object targetAttribute = getRealAttributeValueFromObject(target, mergeManager.getSession()); if ((mergeManager.shouldMergeCloneIntoWorkingCopy() || mergeManager.shouldMergeCloneWithReferencesIntoWorkingCopy()) && (((targetAttribute == null) && (attribute != null)) || ((targetAttribute != null) && (!targetAttribute.equals(attribute))))) { this.descriptor.getObjectChangePolicy().raiseInternalPropertyChangeEvent(target, getAttributeName(), targetAttribute, attribute);
/** * INTERNAL: * Copy of the attribute of the object. * This is NOT used for unit of work but for templatizing an object. */ @Override public void buildCopy(Object copy, Object original, CopyGroup group) { // If mapping is a no-attribute transformation mapping, do nothing if (isWriteOnly()) { return; } 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 = getRealAttributeValueFromObject(original, group.getSession()); } else { AbstractRecord row = buildPhantomRowFrom(original, group.getSession()); clonedAttributeValue = invokeAttributeTransformer(row, copy, group.getSession()); } this.indirectionPolicy.reset(copy); setRealAttributeValueInObject(copy, clonedAttributeValue); }
/** * INTERNAL: * Clone the attribute from the original and assign it to the clone. */ public void buildClone(Object original, Object clone, UnitOfWorkImpl unitOfWork) { // If mapping is a no-attribute transformation mapping, do nothing if (isWriteOnly()) { return; } Object attributeValue = getAttributeValueFromObject(original); 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, original, clone, unitOfWork, false);// building clone from an original not a row. } setAttributeValueInObject(clone, clonedAttributeValue); }
if (isReadOnly() || isWriteOnly()) { return null; Object cloneAttribute = getAttributeValueFromObject(clone); Object backUpAttribute = null; if ((cloneAttribute != null) && (!getIndirectionPolicy().objectIsInstantiated(cloneAttribute))) { return null; } else { if (backUp != null) { backUpAttribute = getAttributeValueFromObject(backUp); boolean backUpIsInstantiated = ((backUpAttribute == null) || (getIndirectionPolicy().objectIsInstantiated(backUpAttribute))); for (Enumeration stream = getFieldToTransformers().elements(); stream.hasMoreElements();) { Object[] pair = (Object[])stream.nextElement(); Object backUpFieldValue = null; if (clone != null) { cloneFieldValue = invokeFieldTransformer(field, transformer, clone, session); backUpFieldValue = invokeFieldTransformer(field, transformer, backUp, session); return buildChangeRecord(clone, owner, session);
if (isReadOnly() || isWriteOnly()) { return null; Object cloneAttribute = getAttributeValueFromObject(clone); Object backUpAttribute = null; if ((cloneAttribute != null) && (!this.indirectionPolicy.objectIsInstantiated(cloneAttribute))) { } else { if (backUp != null) { backUpAttribute = getAttributeValueFromObject(backUp); backupValue = this.indirectionPolicy.getRealAttributeValueFromObject(backUp, backUpAttribute); Object backUpFieldValue = null; if (clone != null) { cloneFieldValue = invokeFieldTransformer(field, transformer, clone, session); backUpFieldValue = invokeFieldTransformer(field, transformer, backUp, session); return internalBuildChangeRecord(clone, backupValue, owner, session);
/** * INTERNAL: * Clone the attribute from the clone and assign it to the backup. */ @Override public void buildBackupClone(Object clone, Object backup, UnitOfWorkImpl unitOfWork) { // If mapping is a no-attribute transformation mapping, do nothing if (isWriteOnly()) { return; } Object attributeValue = getAttributeValueFromObject(clone); Object clonedAttributeValue = this.indirectionPolicy.backupCloneAttribute(attributeValue, clone, backup, unitOfWork); setAttributeValueInObject(backup, clonedAttributeValue); }
/** * INTERNAL: * The mapping is initialized with the given session. */ @Override public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); initializeAttributeTransformer(session); initializeFieldToTransformers(session); setFields(collectFields()); this.indirectionPolicy.initialize(); if (usesIndirection()) { for (DatabaseField field : this.fields) { field.setKeepInRow(true); } } }
/** * INTERNAL: * Either create a new change record or update the change record with the new value. * This is used by attribute change tracking. */ @Override public void updateChangeRecord(Object clone, Object newValue, Object oldValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { TransformationMappingChangeRecord changeRecord = (TransformationMappingChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); Object updatedObject = descriptor.getInstantiationPolicy().buildNewInstance(); this.setAttributeValueInObject(updatedObject, newValue); if (!isWriteOnly()) { if (changeRecord == null) { objectChangeSet.addChange(internalBuildChangeRecord(updatedObject, oldValue, objectChangeSet, uow)); } else { changeRecord.setRow(this.buildPhantomRowFrom(updatedObject, uow)); } } }
/** * INTERNAL: * The mapping is initialized with the given session. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); initializeAttributeTransformer(session); initializeFieldToTransformers(session); setFields(collectFields()); getIndirectionPolicy().initialize(); }
/** * INTERNAL: * Trigger the instantiation of the attribute if lazy. */ @Override public void instantiateAttribute(Object object, AbstractSession session) { this.indirectionPolicy.instantiateObject(object, getAttributeValueFromObject(object)); }
/** * INTERNAL: * Get a value from the object and set that in the respective field of the row. * But before that check if the reference object is instantiated or not. */ @Override public void writeFromObjectIntoRowForUpdate(WriteObjectQuery query, AbstractRecord record) { if (!areObjectsToBeProcessedInstantiated(query.getObject())) { return; } if (query.getSession().isUnitOfWork()) { if (compareObjects(query.getBackupClone(), query.getObject(), query.getSession())) { return; } } writeFromObjectIntoRow(query.getObject(), record, query.getSession(), WriteType.UPDATE); }
value = row.get(field); } else { value = valueFromObject(object, field, query.getSession()); record.setAttribute(attributeName); record.setMapping(this); record.setOldValue(getAttributeValueFromObject(object)); changeSet.addChange(record); Object attributeValue = readFromRowIntoObject(transformationRow, null, object, null, query, query.getSession(), true); if (handledMappings != null) { handledMappings.add(this);
/** * INTERNAL: * Trigger the instantiation of the attribute if lazy. */ public void instantiateAttribute(Object object, AbstractSession session) { getIndirectionPolicy().instantiateObject(object, getAttributeValueFromObject(object)); }
final Class javaClass = this.mapping.getDescriptor().getJavaClass(); try { attributeTransformationMethod = Helper.getDeclaredMethod(javaClass, methodName, parameterTypes); } catch (NoSuchMethodException ex3) { throw DescriptorException.noSuchMethodOnInitializingAttributeMethod(this.mapping.getAttributeMethodName(), mapping, ex3); } catch (SecurityException se) { throw DescriptorException.securityOnInitializingAttributeMethod(this.mapping.getAttributeMethodName(), mapping, se); throw DescriptorException.securityOnInitializingAttributeMethod(this.mapping.getAttributeMethodName(), mapping, se); throw DescriptorException.securityOnInitializingAttributeMethod(this.mapping.getAttributeMethodName(), mapping, se);