Search in sources :

Example 1 with RemoteUnitOfWork

use of org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork in project eclipselink by eclipse-ee4j.

the class BasicIndirectionPolicy method getOriginalValueHolder.

/**
 * INTERNAL: Return the original valueHolder object. Access to the
 * underlying valueholder may be required when serializing the valueholder
 * or converting the valueHolder to another type.
 */
@Override
public Object getOriginalValueHolder(Object unitOfWorkIndirectionObject, AbstractSession session) {
    if ((unitOfWorkIndirectionObject instanceof UnitOfWorkValueHolder) && (((UnitOfWorkValueHolder<?>) unitOfWorkIndirectionObject).getRemoteUnitOfWork() != null)) {
        ValueHolderInterface<?> valueHolder = ((UnitOfWorkValueHolder<?>) unitOfWorkIndirectionObject).getWrappedValueHolder();
        if (valueHolder == null) {
            // For remote session the original value holder is transient,
            // so the value must be found in the registry or created.
            RemoteUnitOfWork remoteUnitOfWork = (RemoteUnitOfWork) ((UnitOfWorkValueHolder<?>) unitOfWorkIndirectionObject).getRemoteUnitOfWork();
            RemoteSessionController controller = remoteUnitOfWork.getParentSessionController();
            ObjID id = ((UnitOfWorkValueHolder<?>) unitOfWorkIndirectionObject).getWrappedValueHolderRemoteID();
            if (id != null) {
                // on the client, the id should be enough to create a new remote value holder.
                if (controller != null) {
                    valueHolder = controller.getRemoteValueHolders().get(id);
                } else if (session.isRemoteSession()) {
                    valueHolder = new RemoteValueHolder<>(id);
                    ((RemoteValueHolder<?>) valueHolder).setSession(session);
                }
            }
            if (valueHolder == null) {
                // Must build a new value holder.
                Object object = ((UnitOfWorkValueHolder<?>) unitOfWorkIndirectionObject).getSourceObject();
                AbstractRecord row = this.mapping.getDescriptor().getObjectBuilder().buildRow(object, session, WriteType.UNDEFINED);
                ReadObjectQuery query = new ReadObjectQuery();
                query.setSession(session);
                valueHolder = (ValueHolderInterface<?>) this.mapping.valueFromRow(row, null, query, true);
            }
            return valueHolder;
        }
    }
    if (unitOfWorkIndirectionObject instanceof WrappingValueHolder) {
        ValueHolderInterface<?> valueHolder = ((WrappingValueHolder<?>) unitOfWorkIndirectionObject).getWrappedValueHolder();
        if (!session.isProtectedSession()) {
            while (valueHolder instanceof WrappingValueHolder && ((WrappingValueHolder<?>) valueHolder).getWrappedValueHolder() != null) {
                valueHolder = ((WrappingValueHolder<?>) valueHolder).getWrappedValueHolder();
            }
        }
        if (valueHolder instanceof DatabaseValueHolder) {
            ((DatabaseValueHolder<?>) valueHolder).releaseWrappedValueHolder(session);
        }
        return valueHolder;
    } else {
        return unitOfWorkIndirectionObject;
    }
}
Also used : RemoteUnitOfWork(org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork) RemoteSessionController(org.eclipse.persistence.internal.sessions.remote.RemoteSessionController) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) ObjID(java.rmi.server.ObjID) RemoteValueHolder(org.eclipse.persistence.internal.sessions.remote.RemoteValueHolder) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord)

Example 2 with RemoteUnitOfWork

use of org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork in project eclipselink by eclipse-ee4j.

the class ContainerIndirectionPolicy method getOriginalIndirectionObject.

/**
 * INTERNAL:
 *    Return the original indirection object for a unit of work indirection object.
 */
@Override
public Object getOriginalIndirectionObject(Object unitOfWorkIndirectionObject, AbstractSession session) {
    IndirectContainer container = (IndirectContainer) unitOfWorkIndirectionObject;
    if (container.getValueHolder() instanceof UnitOfWorkValueHolder) {
        ValueHolderInterface<?> valueHolder = ((UnitOfWorkValueHolder<?>) container.getValueHolder()).getWrappedValueHolder();
        if ((valueHolder == null) && session.isRemoteUnitOfWork()) {
            RemoteSessionController controller = ((RemoteUnitOfWork) session).getParentSessionController();
            valueHolder = controller.getRemoteValueHolders().get(((UnitOfWorkValueHolder<?>) container.getValueHolder()).getWrappedValueHolderRemoteID());
        }
        return buildContainer(valueHolder);
    } else {
        return container;
    }
}
Also used : RemoteUnitOfWork(org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork) RemoteSessionController(org.eclipse.persistence.internal.sessions.remote.RemoteSessionController) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer)

Example 3 with RemoteUnitOfWork

use of org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork in project eclipselink by eclipse-ee4j.

the class RMIConnection method commitRootUnitOfWork.

/**
 * INTERNAL:
 * Commit root unit of work from the client side to the server side.
 */
@Override
public RemoteUnitOfWork commitRootUnitOfWork(RemoteUnitOfWork theRemoteUnitOfWork) {
    try {
        Transporter transporter = new Transporter();
        transporter.setObject(theRemoteUnitOfWork);
        transporter.prepare(this.session);
        transporter = getRemoteSessionController().commitRootUnitOfWork(transporter);
        transporter.expand(this.session);
        if (!transporter.wasOperationSuccessful()) {
            throw transporter.getException();
        } else {
            return (RemoteUnitOfWork) transporter.getObject();
        }
    } catch (RemoteException exception) {
        throw CommunicationException.errorInInvocation(exception);
    }
}
Also used : RemoteUnitOfWork(org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork) RemoteException(java.rmi.RemoteException) Transporter(org.eclipse.persistence.internal.sessions.remote.Transporter)

Example 4 with RemoteUnitOfWork

use of org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork in project eclipselink by eclipse-ee4j.

the class RMIConnection method commitRootUnitOfWork.

/**
 * INTERNAL:
 * Commit root unit of work from the client side to the server side.
 */
@Override
public RemoteUnitOfWork commitRootUnitOfWork(RemoteUnitOfWork theRemoteUnitOfWork) {
    try {
        Transporter transporter = new Transporter();
        transporter.setObject(theRemoteUnitOfWork);
        transporter.prepare(this.session);
        transporter = getRemoteSessionController().commitRootUnitOfWork(transporter);
        transporter.expand(this.session);
        if (!transporter.wasOperationSuccessful()) {
            throw transporter.getException();
        } else {
            return (RemoteUnitOfWork) transporter.getObject();
        }
    } catch (RemoteException exception) {
        throw CommunicationException.errorInInvocation(exception);
    }
}
Also used : RemoteUnitOfWork(org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork) RemoteException(java.rmi.RemoteException) Transporter(org.eclipse.persistence.internal.sessions.remote.Transporter)

Example 5 with RemoteUnitOfWork

use of org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork in project eclipselink by eclipse-ee4j.

the class ProxyIndirectionPolicy method getOriginalIndirectionObject.

/**
 * INTERNAL:
 * Return the original indirection object for a unit of work indirection object.
 */
@Override
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;
    }
}
Also used : RemoteUnitOfWork(org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork) RemoteSessionController(org.eclipse.persistence.internal.sessions.remote.RemoteSessionController)

Aggregations

RemoteUnitOfWork (org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork)5 RemoteSessionController (org.eclipse.persistence.internal.sessions.remote.RemoteSessionController)3 RemoteException (java.rmi.RemoteException)2 Transporter (org.eclipse.persistence.internal.sessions.remote.Transporter)2 ObjID (java.rmi.server.ObjID)1 IndirectContainer (org.eclipse.persistence.indirection.IndirectContainer)1 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)1 RemoteValueHolder (org.eclipse.persistence.internal.sessions.remote.RemoteValueHolder)1 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)1