Search in sources :

Example 1 with RemoteConnection

use of org.eclipse.persistence.internal.sessions.remote.RemoteConnection 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)

Aggregations

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 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 RemoteConnection (org.eclipse.persistence.internal.sessions.remote.RemoteConnection)1 RemoteSession (org.eclipse.persistence.sessions.remote.RemoteSession)1 RMIConnection (org.eclipse.persistence.sessions.remote.rmi.RMIConnection)1