/** * Get the value from the wrapped value holder, instantiating it * if necessary, and clone it. */ protected Object instantiate() { UnitOfWorkImpl unitOfWork; if (isSerializedRemoteUnitOfWorkValueHolder()) { unitOfWork = getRemoteUnitOfWork(); } else { unitOfWork = getUnitOfWork(); } if (unitOfWork == null){ throw ValidationException.instantiatingValueholderWithNullSession(); } Object originalAttributeValue; Object cloneAttributeValue; // the wrapped value holder is transient, so it will be null for a remote UOW if (isSerializedRemoteUnitOfWorkValueHolder()) { originalAttributeValue = getValueFromServerObject(); cloneAttributeValue = buildCloneFor(originalAttributeValue); } else { cloneAttributeValue = instantiateImpl(); } // Set the value in the backup clone also. // In some cases we may want to force instantiation before the backup is built if (getBackupValueHolder() != null) { getBackupValueHolder().setValue(buildBackupCloneFor(cloneAttributeValue)); } return cloneAttributeValue; }
/** * This is used for a remote unit of work. * If the value holder is sent back to the server uninstantiated and * it needs to be instantiated, then we must find the original * object and get the appropriate attribute from it. */ protected Object getValueFromServerObject() { setSession(getRemoteUnitOfWork()); Object primaryKey = getSession().getId(getSourceObject()); Object originalObject = getUnitOfWork().getParent().getIdentityMapAccessor().getFromIdentityMap(primaryKey, getSourceObject().getClass()); if (originalObject == null) { originalObject = getUnitOfWork().getParent().readObject(getSourceObject()); } ClassDescriptor descriptor = getSession().getDescriptor(originalObject); DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(getSourceAttributeName()); setMapping(mapping); return getMapping().getRealAttributeValueFromObject(originalObject, getSession()); }
/** * Used to determine if this is a remote uow value holder that was serialized to the server. * It has no reference to its wrapper value holder, so must find its original object to be able to instantiate. */ public boolean isSerializedRemoteUnitOfWorkValueHolder() { return (getRemoteUnitOfWork() != null) && (getRemoteUnitOfWork().getParent() != null) && (getWrappedValueHolder() == null); }
/** * INTERNAL: * Answers if this valueholder is easy to instantiate. * @return true if getValue() won't trigger a database read. */ public boolean isEasilyInstantiated() { return isInstantiated() || ((getWrappedValueHolder() != null) && (getWrappedValueHolder() instanceof DatabaseValueHolder) && ((DatabaseValueHolder)getWrappedValueHolder()).isEasilyInstantiated()); }
/** * Get the value from the wrapped value holder, instantiating it * if necessary, and clone it. */ protected Object instantiate() { Object originalAttributeValue; Object cloneAttributeValue; if (isSerializedRemoteUnitOfWorkValueHolder()) { originalAttributeValue = getValueFromServerObject(); cloneAttributeValue = buildCloneFor(originalAttributeValue); } else { if (getUnitOfWork() == null) { throw ValidationException.instantiatingValueholderWithNullSession(); } cloneAttributeValue = instantiateImpl(); } // Set the value in the backup clone also. // In some cases we may want to force instantiation before the backup is built if (this.backupValueHolder != null) { this.backupValueHolder.setValue(buildBackupCloneFor(cloneAttributeValue)); } return cloneAttributeValue; }
/** * INTERNAL: * Return the original indirection object for a unit of work indirection object. */ public Object getOriginalIndirectionObject(Object unitOfWorkIndirectionObject, AbstractSession session) { if (unitOfWorkIndirectionObject instanceof UnitOfWorkValueHolder) { ValueHolderInterface valueHolder = ((UnitOfWorkValueHolder)unitOfWorkIndirectionObject).getWrappedValueHolder(); if ((valueHolder == null) && session.isRemoteUnitOfWork()) { RemoteSessionController controller = ((RemoteUnitOfWork)session).getParentSessionController(); valueHolder = (ValueHolderInterface)controller.getRemoteValueHolders().get(((UnitOfWorkValueHolder)unitOfWorkIndirectionObject).getWrappedValueHolderRemoteID()); } return valueHolder; } else { if (unitOfWorkIndirectionObject == null) { System.out.println("Debug line"); } return unitOfWorkIndirectionObject; } }
public Object getOriginalValueHolder(Object unitOfWorkIndirectionObject, AbstractSession session) { if ((unitOfWorkIndirectionObject instanceof UnitOfWorkValueHolder) && (((UnitOfWorkValueHolder)unitOfWorkIndirectionObject).getRemoteUnitOfWork() != null)) { ValueHolderInterface valueHolder = ((UnitOfWorkValueHolder) unitOfWorkIndirectionObject).getWrappedValueHolder(); if (valueHolder == null) { RemoteUnitOfWork remoteUnitOfWork = (RemoteUnitOfWork)((UnitOfWorkValueHolder)unitOfWorkIndirectionObject).getRemoteUnitOfWork(); RemoteSessionController controller = remoteUnitOfWork.getParentSessionController(); ObjID id = ((UnitOfWorkValueHolder) unitOfWorkIndirectionObject).getWrappedValueHolderRemoteID(); if (id != null) { Object object = ((UnitOfWorkValueHolder) unitOfWorkIndirectionObject).getSourceObject(); AbstractRecord row = this.mapping.getDescriptor().getObjectBuilder().buildRow(object, session, WriteType.UNDEFINED); ReadObjectQuery query = new ReadObjectQuery();
if (getWrappedValueHolder() instanceof DatabaseValueHolder) { synchronized(getWrappedValueHolder()){ DatabaseValueHolder wrapped = (DatabaseValueHolder)getWrappedValueHolder(); UnitOfWorkImpl unitOfWork = getUnitOfWork(); if (!wrapped.isEasilyInstantiated()) { if (wrapped.isPessimisticLockingValueHolder()) { Object originalAttributeValue = getWrappedValueHolder().getValue(); return buildCloneFor(originalAttributeValue);
/** * Triggers UnitOfWork valueholders directly without triggering the wrapped * valueholder (this). * <p> * When in transaction and/or for pessimistic locking the * UnitOfWorkValueHolder needs to be triggered directly without triggering * the wrapped valueholder. However only the wrapped valueholder knows how * to trigger the indirection, i.e. it may be a batchValueHolder, and it * stores all the info like the row and the query. Note: This method is not * thread-safe. It must be used in a synchronized manner */ public Object instantiateForUnitOfWorkValueHolder(UnitOfWorkValueHolder unitOfWorkValueHolder) { return instantiate(unitOfWorkValueHolder.getUnitOfWork()); }
ValueHolderInterface valueHolder = ((UnitOfWorkValueHolder) unitOfWorkIndirectionObject).getWrappedValueHolder(); if ((valueHolder == null) && session.isRemoteUnitOfWork()) { Object id = ((UnitOfWorkValueHolder) unitOfWorkIndirectionObject).getWrappedValueHolderRemoteID(); if (id == null) { Object object = ((UnitOfWorkValueHolder) unitOfWorkIndirectionObject).getSourceObject(); AbstractRecord row = getMapping().getDescriptor().getObjectBuilder().buildRow(object, session); ReadObjectQuery query = new ReadObjectQuery();
UnitOfWorkImpl unitOfWork = getUnitOfWork(); if (!wrapped.isEasilyInstantiated()) { if (wrapped.isPessimisticLockingValueHolder()) { return buildCloneFor(this.wrappedValueHolder.getValue());
/** * INTERNAL: * Returns whether the mapping has listOrderField. */ protected boolean usesListOrderField() { if(this.valueHolder instanceof UnitOfWorkValueHolder) { return ((CollectionMapping)((UnitOfWorkValueHolder)this.valueHolder).getMapping()).getListOrderField() != null; } else { return false; } }
/** * INTERNAL: * Answers if this valueholder is a pessimistic locking one. Such valueholders * are special in that they can be triggered multiple times by different * UnitsOfWork. Each time a lock query will be issued. Hence even if * instantiated it may have to be instantiated again, and once instantatiated * all fields can not be reset. */ public boolean isPessimisticLockingValueHolder() { // This abstract method needs to be implemented but is not meaningfull for // this subclass. return ((getWrappedValueHolder() != null) && (getWrappedValueHolder() instanceof DatabaseValueHolder) && ((DatabaseValueHolder)getWrappedValueHolder()).isPessimisticLockingValueHolder()); }
/** * Triggers UnitOfWork valueholders directly without triggering the wrapped * valueholder (this). * <p> * When in transaction and/or for pessimistic locking the UnitOfWorkValueHolder * needs to be triggered directly without triggering the wrapped valueholder. * However only the wrapped valueholder knows how to trigger the indirection, * i.e. it may be a batchValueHolder, and it stores all the info like the row * and the query. * Note: This method is not thread-safe. It must be used in a synchronizaed manner */ public Object instantiateForUnitOfWorkValueHolder(UnitOfWorkValueHolder unitOfWorkValueHolder) { if ((getWrappedServerValueHolder() != null) && (getWrappedServerValueHolder() instanceof DatabaseValueHolder)) { DatabaseValueHolder wrapped = (DatabaseValueHolder)getWrappedServerValueHolder(); return wrapped.instantiateForUnitOfWorkValueHolder(unitOfWorkValueHolder); } // The scenario of triggering a valueholder in transaction when // the RemoteUnitOfWork is on the client side may be impossible. return unitOfWorkValueHolder.buildCloneFor(getValue()); }
protected UnitOfWorkImpl getUnitOfWork() { return (UnitOfWorkImpl)getSession(); }
/** * Get the value from the wrapped value holder, instantiating it * if necessary, and clone it. */ protected Object instantiate() { Object originalAttributeValue; Object cloneAttributeValue; if (isSerializedRemoteUnitOfWorkValueHolder()) { originalAttributeValue = getValueFromServerObject(); cloneAttributeValue = buildCloneFor(originalAttributeValue); } else { if (getUnitOfWork() == null) { throw ValidationException.instantiatingValueholderWithNullSession(); } cloneAttributeValue = instantiateImpl(); } // Set the value in the backup clone also. // In some cases we may want to force instantiation before the backup is built if (this.backupValueHolder != null) { this.backupValueHolder.setValue(buildBackupCloneFor(cloneAttributeValue)); } return cloneAttributeValue; }
/** * INTERNAL: * Return the original indirection object for a unit of work indirection object. */ public Object getOriginalIndirectionObject(Object unitOfWorkIndirectionObject, AbstractSession session) { if (unitOfWorkIndirectionObject instanceof UnitOfWorkValueHolder) { ValueHolderInterface valueHolder = ((UnitOfWorkValueHolder)unitOfWorkIndirectionObject).getWrappedValueHolder(); if ((valueHolder == null) && session.isRemoteUnitOfWork()) { RemoteSessionController controller = ((RemoteUnitOfWork)session).getParentSessionController(); valueHolder = controller.getRemoteValueHolders().get(((UnitOfWorkValueHolder)unitOfWorkIndirectionObject).getWrappedValueHolderRemoteID()); } return valueHolder; } else { return unitOfWorkIndirectionObject; } }
public Object getOriginalValueHolder(Object unitOfWorkIndirectionObject, AbstractSession session) { if ((unitOfWorkIndirectionObject instanceof UnitOfWorkValueHolder) && (((UnitOfWorkValueHolder)unitOfWorkIndirectionObject).getRemoteUnitOfWork() != null)) { ValueHolderInterface valueHolder = ((UnitOfWorkValueHolder) unitOfWorkIndirectionObject).getWrappedValueHolder(); if (valueHolder == null) { RemoteUnitOfWork remoteUnitOfWork = (RemoteUnitOfWork)((UnitOfWorkValueHolder)unitOfWorkIndirectionObject).getRemoteUnitOfWork(); RemoteSessionController controller = remoteUnitOfWork.getParentSessionController(); ObjID id = ((UnitOfWorkValueHolder) unitOfWorkIndirectionObject).getWrappedValueHolderRemoteID(); if (id != null) { Object object = ((UnitOfWorkValueHolder) unitOfWorkIndirectionObject).getSourceObject(); AbstractRecord row = this.mapping.getDescriptor().getObjectBuilder().buildRow(object, session, WriteType.UNDEFINED); ReadObjectQuery query = new ReadObjectQuery();
/** * Triggers UnitOfWork valueholders directly without triggering the wrapped * valueholder (this). * <p> * When in transaction and/or for pessimistic locking the * UnitOfWorkValueHolder needs to be triggered directly without triggering * the wrapped valueholder. However only the wrapped valueholder knows how * to trigger the indirection, i.e. it may be a batchValueHolder, and it * stores all the info like the row and the query. Note: This method is not * thread-safe. It must be used in a synchronized manner */ public Object instantiateForUnitOfWorkValueHolder(UnitOfWorkValueHolder unitOfWorkValueHolder) { return instantiate(unitOfWorkValueHolder.getUnitOfWork()); }
UnitOfWorkImpl unitOfWork = getUnitOfWork(); if (!wrapped.isEasilyInstantiated()) { if (wrapped.isPessimisticLockingValueHolder()) { return buildCloneFor(this.wrappedValueHolder.getValue());