Search in sources :

Example 1 with RemoteSession

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

the class EntityManagerSetupImpl method updateRemote.

/**
 * Checks for partitioning properties.
 */
protected void updateRemote(Map m, ClassLoader loader) {
    String protocol = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_PROTOCOL, m, this.session);
    String serverName = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_SERVER_NAME, m, this.session);
    if (serverName == null) {
        // Configure as client.
        if (protocol != null) {
            RemoteConnection connection = null;
            if (protocol.equalsIgnoreCase(RemoteProtocol.RMI)) {
                String url = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_URL, m, this.session);
                if (url == null) {
                    throw EntityManagerSetupException.missingProperty(PersistenceUnitProperties.REMOTE_URL);
                }
                try {
                    connection = new RMIConnection(((RMIServerSessionManager) Naming.lookup(url)).createRemoteSessionController());
                } catch (Exception exception) {
                    throw ValidationException.invalidValueForProperty(url, PersistenceUnitProperties.REMOTE_URL, exception);
                }
            } else {
                try {
                    Class<? extends RemoteConnection> cls = findClassForProperty(protocol, PersistenceUnitProperties.REMOTE_PROTOCOL, loader);
                    Constructor<? extends RemoteConnection> constructor = cls.getConstructor();
                    connection = constructor.newInstance();
                } catch (Exception exception) {
                    throw ValidationException.invalidValueForProperty(protocol, PersistenceUnitProperties.REMOTE_PROTOCOL, exception);
                }
            }
            RemoteSession remoteSession = new RemoteSession();
            remoteSession.setIsMetadataRemote(false);
            remoteSession.setProject(this.session.getProject());
            remoteSession.setProfiler(this.session.getProfiler());
            remoteSession.setSessionLog(this.session.getSessionLog());
            remoteSession.setEventManager(this.session.getEventManager());
            remoteSession.setQueries(this.session.getQueries());
            remoteSession.setProperties(this.session.getProperties());
            remoteSession.setName(this.session.getName());
            remoteSession.setRemoteConnection(connection);
            this.session = remoteSession;
        }
    } else {
        // Configure as server.
        if (protocol.equalsIgnoreCase(RemoteProtocol.RMI)) {
            RMIServerSessionManager manager = null;
            // Make sure RMI registry is started.
            try {
                java.rmi.registry.LocateRegistry.createRegistry(1099);
            } catch (Exception exception) {
                System.out.println("Security violation " + exception.toString());
            }
            // Create local instance of the factory
            try {
                manager = new RMIServerSessionManagerDispatcher(session);
            } catch (RemoteException exception) {
                throw ValidationException.invalidValueForProperty(serverName, PersistenceUnitProperties.REMOTE_SERVER_NAME, exception);
            }
            // Put the local instance into the Registry
            try {
                Naming.unbind(serverName);
            } catch (Exception exception) {
            // Ignore.
            }
            // Put the local instance into the Registry
            try {
                Naming.rebind(serverName, manager);
            } catch (Exception exception) {
                throw ValidationException.invalidValueForProperty(serverName, PersistenceUnitProperties.REMOTE_SERVER_NAME, exception);
            }
        }
    }
}
Also used : RMIServerSessionManagerDispatcher(org.eclipse.persistence.sessions.remote.rmi.RMIServerSessionManagerDispatcher) RMIConnection(org.eclipse.persistence.sessions.remote.rmi.RMIConnection) RemoteSession(org.eclipse.persistence.sessions.remote.RemoteSession) RMIServerSessionManager(org.eclipse.persistence.sessions.remote.rmi.RMIServerSessionManager) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString) RemoteConnection(org.eclipse.persistence.internal.sessions.remote.RemoteConnection) RemoteException(java.rmi.RemoteException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) OptimisticLockException(jakarta.persistence.OptimisticLockException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) RemoteException(java.rmi.RemoteException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EntityManagerSetupException(org.eclipse.persistence.exceptions.EntityManagerSetupException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConversionException(org.eclipse.persistence.exceptions.ConversionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PersistenceException(jakarta.persistence.PersistenceException) MalformedURLException(java.net.MalformedURLException) PersistenceUnitLoadingException(org.eclipse.persistence.exceptions.PersistenceUnitLoadingException)

Example 2 with RemoteSession

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

the class ComplexMultipleUnitOfWorkTest method verify.

@Override
public void verify() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    Session sessionToVerifyDelete;
    if (getSession() instanceof RemoteSession) {
        sessionToVerifyDelete = RemoteModel.getServerSession();
    } else {
        sessionToVerifyDelete = getSession();
    }
    // Verify if object deleted in the uow was deleted
    if (!(((AbstractSession) sessionToVerifyDelete).verifyDelete(this.readInSession))) {
        throw new TestErrorException("The object '" + this.readInSession + "'deleted in the uow was not completely deleted from the database.");
    }
    // Verify if object deleted in the uow was deleted
    if (!(((AbstractSession) sessionToVerifyDelete).verifyDelete(this.readInUow))) {
        throw new TestErrorException("The object '" + this.readInUow + "'deleted in the nested uow was not completely deleted from the database.");
    }
    ReadObjectQuery query = new ReadObjectQuery();
    query.setSelectionObject(this.newEmployeeInUow);
    Employee objectFromDatabase = (Employee) getSession().executeQuery(query);
    if (!(((AbstractSession) getSession()).compareObjects(this.newEmployeeInUow, objectFromDatabase))) {
        throw new TestErrorException("The object read from the database, '" + this.newEmployeeInUow + "' does not match the originial, '" + objectFromDatabase + ".");
    }
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) RemoteSession(org.eclipse.persistence.sessions.remote.RemoteSession) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) RemoteSession(org.eclipse.persistence.sessions.remote.RemoteSession) Session(org.eclipse.persistence.sessions.Session) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 3 with RemoteSession

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

the class RemoteConnectionExceptionsTest method setRemoteConnection.

protected void setRemoteConnection(RemoteConnection remoteConnection) {
    Class<? extends RemoteConnection> cls = remoteConnection.getClass();
    if (!remoteConnectionClass.equals(cls)) {
        throw new TestProblemException("remoteConnection's type is different from the type used to create the test");
    }
    this.remoteConnection = remoteConnection;
    this.remoteConnection.setSession(new RemoteSession());
}
Also used : RemoteSession(org.eclipse.persistence.sessions.remote.RemoteSession)

Example 4 with RemoteSession

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

the class CommitAfterExecuteModifyQueryDuringTransTest method setup.

/**
 * Test makes modifications that is not wrapped in a transaction..
 */
@Override
public void setup() {
    if (getSession() instanceof RemoteSession) {
        throw new TestWarningException("test will not run on RemoteSession - it uses events");
    }
    // employee to be modified - needed for reset.
    cachedEmployee = (Employee) getSession().readObject(Employee.class);
    ClassDescriptor descriptor = getSession().getDescriptor(this.cachedEmployee);
    if (descriptor.isProtectedIsolation() && descriptor.shouldIsolateProtectedObjectsInUnitOfWork() && getSession() instanceof IsolatedClientSession) {
        // this will have read a version of the protected Entity into the Isolated Cache even though the test wants to isolated to UOW
        // replace with actual shared cache version
        this.cachedEmployee = (Employee) ((AbstractSession) getSession()).getParentIdentityMapSession(descriptor, false, true).getIdentityMapAccessor().getFromIdentityMap(this.cachedEmployee);
    }
    originalEmployee = (Employee) getSession().copy(cachedEmployee);
    employeesNewFirstName = "formerlyKnownAs";
    initialVersionField = getSession().getIdentityMapAccessor().getWriteLockValue(cachedEmployee);
    // query to be executed more than once
    dataModifyQuery = new DataModifyQuery("UPDATE EMPLOYEE SET F_NAME = #F_NAME, VERSION = #VERSION WHERE L_NAME = #L_NAME");
    dataModifyQuery.addArgument("F_NAME");
    dataModifyQuery.addArgument("VERSION");
    dataModifyQuery.addArgument("L_NAME");
}
Also used : IsolatedClientSession(org.eclipse.persistence.internal.sessions.IsolatedClientSession) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) RemoteSession(org.eclipse.persistence.sessions.remote.RemoteSession) DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Aggregations

RemoteSession (org.eclipse.persistence.sessions.remote.RemoteSession)4 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)2 OptimisticLockException (jakarta.persistence.OptimisticLockException)1 PersistenceException (jakarta.persistence.PersistenceException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 RemoteException (java.rmi.RemoteException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 ConversionException (org.eclipse.persistence.exceptions.ConversionException)1 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)1 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)1 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)1 EntityManagerSetupException (org.eclipse.persistence.exceptions.EntityManagerSetupException)1 IntegrityException (org.eclipse.persistence.exceptions.IntegrityException)1 PersistenceUnitLoadingException (org.eclipse.persistence.exceptions.PersistenceUnitLoadingException)1 ValidationException (org.eclipse.persistence.exceptions.ValidationException)1 EntityManagerFactoryProvider.getConfigPropertyAsString (org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString)1