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);
}
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;
}
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");
}
}
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;
}
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;
}
Aggregations