Search in sources :

Example 11 with JNDIConnector

use of org.eclipse.persistence.sessions.JNDIConnector in project gdmatrix by gdmatrix.

the class EclipseLinkSessionCustomizer method customize.

@Override
public void customize(Session session) throws Exception {
    JNDIConnector connector = (JNDIConnector) session.getLogin().getConnector();
    connector.setLookupType(JNDIConnector.STRING_LOOKUP);
}
Also used : JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector)

Example 12 with JNDIConnector

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

the class SimpleSpatialTestCase method getSession.

public static DatabaseSession getSession() throws Exception {
    DatabaseSession spatialSession = null;
    if (isJunit) {
        // look up the session from sessions.xml
        spatialSession = (DatabaseSession) SessionManager.getManager().getSession(SPATIAL_SESSION_NAME, SPATIAL_SESSIONS_XML_NAME);
    } else {
        // do not use sessions.xml to look up the session.  Build it from the test browser's session
        spatialSession = (DatabaseSession) SessionManager.getManager().getSessions().get(SPATIAL_SESSION_NAME);
        if (spatialSession == null) {
            Project project = new JGeometryProject();
            Session configSession = SimpleJGeometryTestModel.getConfigSession();
            project.setLogin((DatabaseLogin) configSession.getLogin().clone());
            spatialSession = new org.eclipse.persistence.internal.sessions.DatabaseSessionImpl(project);
            spatialSession.setServerPlatform(configSession.getServerPlatform());
            spatialSession.getPlatform().addStructConverter(new JGeometryConverter());
            // make the MyGeometryConverter type point at a user defined type for the current user
            // Bug5837254, in case test running on the server, the user name should extract from the metadata
            // of the datasource.
            Connector connector = spatialSession.getLogin().getConnector();
            String userName = "";
            if (connector instanceof DefaultConnector) {
                userName = spatialSession.getLogin().getUserName();
            } else if (connector instanceof JNDIConnector) {
                userName = ((JNDIConnector) spatialSession.getLogin().getConnector()).getDataSource().getConnection().getMetaData().getUserName();
            }
            MyGeometryConverter.MY_GEOMETRY_TYPE = userName + "." + MyGeometryConverter.MY_GEOMETRY_TYPE_NAME;
            MyGeometryConverter.MY_GEOMETRY_TYPE = MyGeometryConverter.MY_GEOMETRY_TYPE.toUpperCase();
            spatialSession.getPlatform().addStructConverter(new MyGeometryConverter());
            (spatialSession).login();
            SessionManager.getManager().addSession(SPATIAL_SESSION_NAME, spatialSession);
        }
        spatialSession.setSessionLog(SimpleJGeometryTestModel.getConfigSession().getSessionLog());
        spatialSession.setLogLevel(SimpleJGeometryTestModel.getConfigSession().getLogLevel());
    }
    return spatialSession;
}
Also used : JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector) Connector(org.eclipse.persistence.sessions.Connector) DefaultConnector(org.eclipse.persistence.sessions.DefaultConnector) MyGeometryConverter(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.MyGeometryConverter) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) Project(org.eclipse.persistence.sessions.Project) JGeometryProject(org.eclipse.persistence.testing.models.spatial.jgeometry.JGeometryProject) JGeometryProject(org.eclipse.persistence.testing.models.spatial.jgeometry.JGeometryProject) JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector) JGeometryConverter(org.eclipse.persistence.platform.database.oracle.converters.JGeometryConverter) DefaultConnector(org.eclipse.persistence.sessions.DefaultConnector) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) Session(org.eclipse.persistence.sessions.Session)

Example 13 with JNDIConnector

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

the class ProxyAuthenticationServerTestSuite method testJtaDataSource.

public void testJtaDataSource() throws Exception {
    if (!shouldRunPureJdbcTests) {
        System.out.println("Currently only WLS 10.3.4 and later is known to fully support Oracle Proxy Authentication in both JTA and Non Jta cases.");
        return;
    }
    if (!serverSession.getLogin().shouldUseExternalTransactionController()) {
        throw new RuntimeException("Test problem: jta data source is required");
    }
    System.out.println("====testJtaDataSource begin");
    // Context context = new InitialContext();
    // TransactionManager mngr = (TransactionManager)context.lookup("weblogic.transaction.TransactionManager");
    // Eclipselink session is used only to obtain TransactionManager from the application server.
    TransactionManager mngr = ((JTATransactionController) serverSession.getExternalTransactionController()).getTransactionManager();
    // DataSource jtaDs = (DataSource)context.lookup("jdbc/EclipseLinkDS");
    // Eclipselink session is used only to obtain jta data source from the application server.
    DataSource jtaDs = ((JNDIConnector) serverSession.getLogin().getConnector()).getDataSource();
    Properties props = new Properties();
    props.setProperty(OracleConnection.PROXY_USER_NAME, ProxyAuthenticationUsersAndProperties.proxyUser);
    props.setProperty(OracleConnection.PROXY_USER_PASSWORD, ProxyAuthenticationUsersAndProperties.proxyUserPassword);
    mngr.begin();
    Connection conn = jtaDs.getConnection();
    OracleConnection oracleConn;
    if (conn instanceof OracleConnection) {
        oracleConn = (OracleConnection) conn;
    } else {
        oracleConn = (OracleConnection) serverSession.getServerPlatform().unwrapConnection(conn);
    }
    oracleConn.openProxySession(OracleConnection.PROXYTYPE_USER_NAME, props);
    // 12c driver will default to an autoCommit setting of true on calling openProxySession
    oracleConn.setAutoCommit(false);
    System.out.println("====testJtaDataSource openProxySession ok");
    mngr.rollback();
    mngr.begin();
    conn = jtaDs.getConnection();
    if (conn instanceof OracleConnection) {
        oracleConn = (OracleConnection) conn;
    } else {
        oracleConn = (OracleConnection) serverSession.getServerPlatform().unwrapConnection(conn);
    }
    try {
        if (oracleConn.isProxySession()) {
            // close proxy session
            oracleConn.close(OracleConnection.PROXY_SESSION);
            fail("Connection has been released into connection pool with the proxy session still open");
        }
        System.out.println("====testJtaDataSource not a proxy session");
    } finally {
        try {
            conn.close();
        } catch (SQLException ex) {
        // Ignore
        }
        mngr.rollback();
        System.out.println("====testJtaDataSource end");
    }
}
Also used : SQLException(java.sql.SQLException) TransactionManager(jakarta.transaction.TransactionManager) JTATransactionController(org.eclipse.persistence.transaction.JTATransactionController) Connection(java.sql.Connection) OracleConnection(oracle.jdbc.OracleConnection) JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector) ProxyAuthenticationUsersAndProperties(org.eclipse.persistence.testing.tests.proxyauthentication.thin.ProxyAuthenticationUsersAndProperties) PersistenceUnitProperties(org.eclipse.persistence.config.PersistenceUnitProperties) Properties(java.util.Properties) OracleConnection(oracle.jdbc.OracleConnection) DataSource(javax.sql.DataSource)

Example 14 with JNDIConnector

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

the class SessionsFactory method buildDatabaseLoginConfig.

/**
 * INTERNAL:
 * Build a DatabaseLogin for the given Session
 * Wrapped by the getLogin() call, therefore, config can't be null at this
 * point.
 */
protected Login buildDatabaseLoginConfig(DatabaseLoginConfig databaseLoginConfig) {
    DatabaseLogin databaseLogin = new DatabaseLogin();
    // Driver class
    String driverClassName = databaseLoginConfig.getDriverClass();
    if (driverClassName != null) {
        try {
            Class<?> driverClass = m_classLoader.loadClass(driverClassName);
            databaseLogin.setDriverClass(driverClass);
        } catch (Exception exception) {
            throw SessionLoaderException.failedToLoadTag("driver-class", driverClassName, exception);
        }
    }
    // Connection URL
    String connectionString = databaseLoginConfig.getConnectionURL();
    if (connectionString != null) {
        databaseLogin.setConnectionString(connectionString);
    }
    // Datasource
    String datasourceName = databaseLoginConfig.getDatasource();
    if (datasourceName != null) {
        try {
            JNDIConnector jndiConnector = new JNDIConnector(new javax.naming.InitialContext(), datasourceName);
            jndiConnector.setLookupType(databaseLoginConfig.getLookupType());
            databaseLogin.setConnector(jndiConnector);
        } catch (Exception exception) {
            throw SessionLoaderException.failedToLoadTag("datasource", datasourceName, exception);
        }
    }
    // Bind all parameters - XML Schema default is false
    databaseLogin.setShouldBindAllParameters(databaseLoginConfig.getBindAllParameters());
    // Cache all statements - XML Schema default is false
    databaseLogin.setShouldCacheAllStatements(databaseLoginConfig.getCacheAllStatements());
    // Byte array binding - XML Schema default is true
    databaseLogin.setUsesByteArrayBinding(databaseLoginConfig.getByteArrayBinding());
    // String binding - XML Schema default is false
    databaseLogin.setUsesStringBinding(databaseLoginConfig.getStringBinding());
    // Stream binding - XML Schema default is false
    databaseLogin.setUsesStreamsForBinding(databaseLoginConfig.getStreamsForBinding());
    // Force field to uppper case - XML Schema default is false
    databaseLogin.setShouldForceFieldNamesToUpperCase(databaseLoginConfig.getForceFieldNamesToUppercase());
    // Optimize data conversion - XML Schema default is true
    databaseLogin.setShouldOptimizeDataConversion(databaseLoginConfig.getOptimizeDataConversion());
    // Trim strings - XML Schema default is true
    databaseLogin.setShouldTrimStrings(databaseLoginConfig.getTrimStrings());
    // Batch writing - XML Schema default is false
    databaseLogin.setUsesBatchWriting(databaseLoginConfig.getBatchWriting());
    // JDBC 2.0 batch writing - XML Schema default is true
    databaseLogin.setUsesJDBCBatchWriting(databaseLoginConfig.getJdbcBatchWriting());
    // Max batch writing size - XML Schema default is 32000
    Integer maxBatchWritingSize = databaseLoginConfig.getMaxBatchWritingSize();
    if (maxBatchWritingSize != null) {
        databaseLogin.setMaxBatchWritingSize(maxBatchWritingSize);
    }
    // Native SQL - XML Schema default is false
    databaseLogin.setUsesNativeSQL(databaseLoginConfig.getNativeSQL());
    // Process the common elements in LoginConfig
    processLoginConfig(databaseLoginConfig, databaseLogin);
    processStructConverterConfig(databaseLoginConfig.getStructConverterConfig(), databaseLogin);
    if (databaseLoginConfig.isConnectionHealthValidatedOnError() != null) {
        databaseLogin.setConnectionHealthValidatedOnError(databaseLoginConfig.isConnectionHealthValidatedOnError());
    }
    if (databaseLoginConfig.getQueryRetryAttemptCount() != null) {
        databaseLogin.setQueryRetryAttemptCount(databaseLoginConfig.getQueryRetryAttemptCount());
    }
    if (databaseLoginConfig.getDelayBetweenConnectionAttempts() != null) {
        databaseLogin.setDelayBetweenConnectionAttempts(databaseLoginConfig.getDelayBetweenConnectionAttempts());
    }
    if (databaseLoginConfig.getPingSQL() != null) {
        databaseLogin.setPingSQL(databaseLoginConfig.getPingSQL());
    }
    // Finally, return the newly created DatabaseLogin
    return databaseLogin;
}
Also used : DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Example 15 with JNDIConnector

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

the class SessionExchanger method cloneAndSetDataSource.

DatabaseLogin cloneAndSetDataSource(DatabaseLogin login, boolean useExternalConnectionPooling, int minConnections, int maxConnections) {
    DatabaseLogin cloneLogin = (DatabaseLogin) login.clone();
    if (useExternalConnectionPooling) {
        createDataSource(login.getConnectionString(), minConnections, maxConnections);
        cloneLogin.setConnector(new JNDIConnector(dataSource));
        cloneLogin.setUsesExternalConnectionPooling(true);
    }
    return cloneLogin;
}
Also used : DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector)

Aggregations

JNDIConnector (org.eclipse.persistence.sessions.JNDIConnector)23 HashMap (java.util.HashMap)7 Connector (org.eclipse.persistence.sessions.Connector)7 DefaultConnector (org.eclipse.persistence.sessions.DefaultConnector)6 EntityManager (jakarta.persistence.EntityManager)5 DataSource (javax.sql.DataSource)5 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)5 JpaEntityManagerFactory (org.eclipse.persistence.jpa.JpaEntityManagerFactory)5 DatasourceLogin (org.eclipse.persistence.sessions.DatasourceLogin)5 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)5 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)4 SQLException (java.sql.SQLException)4 Map (java.util.Map)4 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)4 ConnectionPolicy (org.eclipse.persistence.sessions.server.ConnectionPolicy)4 PersistenceException (jakarta.persistence.PersistenceException)3 ValidationException (org.eclipse.persistence.exceptions.ValidationException)3 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)3 Project (org.eclipse.persistence.sessions.Project)3 OptimisticLockException (jakarta.persistence.OptimisticLockException)2