Search in sources :

Example 1 with ExternalConnectionPool

use of org.eclipse.persistence.sessions.server.ExternalConnectionPool in project eclipselink by eclipse-ee4j.

the class SequencingManager method createConnectionHandler.

protected void createConnectionHandler() {
    boolean isServerSession = getOwnerSession().isServerSession();
    if (getLogin() == null) {
        Login login;
        if (isServerSession) {
            login = ((ServerSession) getOwnerSession()).getReadConnectionPool().getLogin();
        } else {
            login = getOwnerSession().getDatasourceLogin();
        }
        setLogin(login);
    }
    if (getLogin() != null) {
        if (getLogin().shouldUseExternalTransactionController()) {
            throw ValidationException.invalidSequencingLogin();
        }
    }
    if (isServerSession) {
        ConnectionPool pool = null;
        if (this.connectionPool == null) {
            if (getLogin().shouldUseExternalConnectionPooling()) {
                pool = new ExternalConnectionPool("sequencing", getLogin(), (ServerSession) getOwnerSession());
            } else {
                if (getMinPoolSize() == -1) {
                    setMinPoolSize(2);
                }
                if (getMaxPoolSize() == -1) {
                    setMinPoolSize(2);
                }
                if (getInitialPoolSize() == -1) {
                    setInitialPoolSize(1);
                }
                pool = new ConnectionPool("sequencing", getLogin(), getInitialPoolSize(), getMinPoolSize(), getMaxPoolSize(), (ServerSession) getOwnerSession());
            }
        } else {
            pool = this.connectionPool;
        }
        setConnectionHandler(new ServerSessionConnectionHandler(pool));
    } else {
        setConnectionHandler(new DatabaseSessionConnectionHandler(getOwnerSession(), getLogin()));
    }
}
Also used : ExternalConnectionPool(org.eclipse.persistence.sessions.server.ExternalConnectionPool) ConnectionPool(org.eclipse.persistence.sessions.server.ConnectionPool) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) ExternalConnectionPool(org.eclipse.persistence.sessions.server.ExternalConnectionPool) Login(org.eclipse.persistence.sessions.Login)

Example 2 with ExternalConnectionPool

use of org.eclipse.persistence.sessions.server.ExternalConnectionPool in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method updateConnectionSettings.

/**
 * Process all properties under "eclipselink.connection-pool.".
 * This allows for named connection pools.
 * It also processes "read", "write", "default"  and "sequence" connection pools.
 */
protected void updateConnectionSettings(ServerSession serverSession, Map properties) {
    Map<String, Object> connectionsMap = PropertiesHandler.getPrefixValuesLogDebug(PersistenceUnitProperties.CONNECTION_POOL, properties, serverSession);
    if (connectionsMap.isEmpty()) {
        return;
    }
    for (Map.Entry<String, Object> entry : connectionsMap.entrySet()) {
        String poolName = "default";
        String attribute = null;
        try {
            int dotIdx = entry.getKey().indexOf('.');
            if (dotIdx == -1) {
                attribute = entry.getKey();
            } else {
                String key = entry.getKey();
                poolName = key.substring(0, dotIdx);
                attribute = key.substring(dotIdx + 1);
            }
            ConnectionPool pool = null;
            if (poolName.equals("write")) {
                poolName = "default";
            }
            if (poolName.equals("read")) {
                pool = serverSession.getReadConnectionPool();
                // By default there is no connection pool, so if the default, create a new one.
                if ((pool == null) || (pool == serverSession.getDefaultConnectionPool())) {
                    if (this.session.getDatasourceLogin().shouldUseExternalConnectionPooling()) {
                        pool = new ExternalConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
                    } else {
                        pool = new ConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
                    }
                    serverSession.setReadConnectionPool(pool);
                }
            } else if (poolName.equals("sequence")) {
                pool = getDatabaseSession().getSequencingControl().getConnectionPool();
                if (pool == null) {
                    if (this.session.getDatasourceLogin().shouldUseExternalConnectionPooling()) {
                        pool = new ExternalConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
                    } else {
                        pool = new ConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
                    }
                    getDatabaseSession().getSequencingControl().setConnectionPool(pool);
                }
            } else {
                pool = serverSession.getConnectionPool(poolName);
                if (pool == null) {
                    if (this.session.getDatasourceLogin().shouldUseExternalConnectionPooling()) {
                        pool = new ExternalConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
                    } else {
                        pool = new ConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
                    }
                    serverSession.addConnectionPool(pool);
                }
            }
            if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_INITIAL)) {
                pool.setInitialNumberOfConnections(Integer.parseInt((String) entry.getValue()));
            } else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_MIN)) {
                pool.setMinNumberOfConnections(Integer.parseInt((String) entry.getValue()));
            } else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_MAX)) {
                pool.setMaxNumberOfConnections(Integer.parseInt((String) entry.getValue()));
            } else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_URL)) {
                pool.setLogin(pool.getLogin().clone());
                ((DatabaseLogin) pool.getLogin()).setURL((String) entry.getValue());
            } else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_NON_JTA_DATA_SOURCE)) {
                pool.setLogin(pool.getLogin().clone());
                ((DatabaseLogin) pool.getLogin()).useDataSource((String) entry.getValue());
            } else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_JTA_DATA_SOURCE)) {
                pool.setLogin(pool.getLogin().clone());
                ((DatabaseLogin) pool.getLogin()).useDataSource((String) entry.getValue());
            } else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_USER)) {
                pool.setLogin(pool.getLogin().clone());
                pool.getLogin().setUserName((String) entry.getValue());
            } else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_PASSWORD)) {
                pool.setLogin(pool.getLogin().clone());
                pool.getLogin().setPassword((String) entry.getValue());
            } else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_WAIT)) {
                pool.setWaitTimeout(Integer.parseInt((String) entry.getValue()));
            } else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_FAILOVER)) {
                String failoverPools = (String) entry.getValue();
                if ((failoverPools.indexOf(',') != -1) || (failoverPools.indexOf(' ') != -1)) {
                    StringTokenizer tokenizer = new StringTokenizer(failoverPools, " ,");
                    while (tokenizer.hasMoreTokens()) {
                        pool.addFailoverConnectionPool(tokenizer.nextToken());
                    }
                } else {
                    pool.addFailoverConnectionPool((String) entry.getValue());
                }
            } else if (poolName.equals("read") && attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_SHARED)) {
                boolean shared = Boolean.parseBoolean((String) entry.getValue());
                if (shared) {
                    ReadConnectionPool readPool = new ReadConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
                    readPool.setInitialNumberOfConnections(pool.getInitialNumberOfConnections());
                    readPool.setMinNumberOfConnections(pool.getMinNumberOfConnections());
                    readPool.setMaxNumberOfConnections(pool.getMaxNumberOfConnections());
                    readPool.setWaitTimeout(pool.getWaitTimeout());
                    readPool.setLogin(pool.getLogin());
                    serverSession.setReadConnectionPool(readPool);
                }
            }
        } catch (RuntimeException exception) {
            this.session.handleException(ValidationException.invalidValueForProperty(entry.getValue(), entry.getKey(), exception));
        }
    }
}
Also used : ExternalConnectionPool(org.eclipse.persistence.sessions.server.ExternalConnectionPool) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) ConnectionPool(org.eclipse.persistence.sessions.server.ConnectionPool) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) StringTokenizer(java.util.StringTokenizer) ExternalConnectionPool(org.eclipse.persistence.sessions.server.ExternalConnectionPool) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) IdentityMap(org.eclipse.persistence.internal.identitymaps.IdentityMap) HashMap(java.util.HashMap)

Aggregations

ConnectionPool (org.eclipse.persistence.sessions.server.ConnectionPool)2 ExternalConnectionPool (org.eclipse.persistence.sessions.server.ExternalConnectionPool)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 IdentityMap (org.eclipse.persistence.internal.identitymaps.IdentityMap)1 EntityManagerFactoryProvider.getConfigPropertyAsString (org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString)1 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)1 Login (org.eclipse.persistence.sessions.Login)1 ReadConnectionPool (org.eclipse.persistence.sessions.server.ReadConnectionPool)1 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)1