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;
}
use of org.eclipse.persistence.sessions.JNDIConnector in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testGenerateSessionNameFromConnectionProperties.
public void testGenerateSessionNameFromConnectionProperties() {
// the test requires passing properties to createEMF or createContainerEMF method.
if (isOnServer()) {
return;
}
String errorMsg = "";
EntityManagerFactory emf;
Map properties;
String puName = "default";
String customizer = "org.eclipse.persistence.testing.tests.jpa.advanced.EntityManagerJUnitTestSuite$SessionNameCustomizer";
String myJtaDS = "myJtaDS";
String myNonJtaDS = "myNonJtaDS";
String myUrl = "myUrl";
String myUser = "myUser";
String myDriver = "myDriver";
String myPassword = "myPassword";
ServerSession originalSession = JUnitTestCase.getServerSession();
String loggingLevel = originalSession.getSessionLog().getLevelString();
SessionNameCustomizer.ss = null;
// 0: The session name specified in persistence.xml is NOT overridden -> the existing session is used by emf.
// If persistence.xml no longer specifies session name then comment out this part of the test.
properties = new HashMap();
// required by the test
properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, customizer);
// log on the same level as original session
properties.put(PersistenceUnitProperties.LOGGING_LEVEL, loggingLevel);
properties.put(PersistenceUnitProperties.TRANSACTION_TYPE, "RESOURCE_LOCAL");
// to override data source if one is specified in persistence.xml
properties.put(PersistenceUnitProperties.JTA_DATASOURCE, "");
// to override data source if one is specified in persistence.xml
properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, "");
properties.put(PersistenceUnitProperties.JDBC_URL, myUrl);
properties.put(PersistenceUnitProperties.JDBC_USER, myUser);
properties.put(PersistenceUnitProperties.JDBC_DRIVER, myDriver);
properties.put(PersistenceUnitProperties.JDBC_PASSWORD, myPassword);
emf = Persistence.createEntityManagerFactory(puName, properties);
try {
emf.createEntityManager();
} catch (Exception ex) {
// Ignore exception that probably caused by attempt to connect the session with invalid connection data provided in the properties.
} finally {
emf.close();
if (SessionNameCustomizer.ss != null && SessionNameCustomizer.ss != originalSession) {
errorMsg += "0: Session name NOT overridden by an empty string - original session expected; ";
}
// clear for the next test
SessionNameCustomizer.ss = null;
}
// 1: New session with DefaultConnector with myUrl, myDriver, myUser, myPassword
properties = new HashMap();
// required by the test
properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, customizer);
// log on the same level as original session
properties.put(PersistenceUnitProperties.LOGGING_LEVEL, loggingLevel);
// to override SESSION_NAME if one is specified in persistence.xml
properties.put(PersistenceUnitProperties.SESSION_NAME, "");
properties.put(PersistenceUnitProperties.TRANSACTION_TYPE, "RESOURCE_LOCAL");
// to override data source if one is specified in persistence.xml
properties.put(PersistenceUnitProperties.JTA_DATASOURCE, "");
// to override data source if one is specified in persistence.xml
properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, "");
properties.put(PersistenceUnitProperties.JDBC_URL, myUrl);
properties.put(PersistenceUnitProperties.JDBC_USER, myUser);
properties.put(PersistenceUnitProperties.JDBC_DRIVER, myDriver);
properties.put(PersistenceUnitProperties.JDBC_PASSWORD, myPassword);
emf = Persistence.createEntityManagerFactory(puName, properties);
try {
emf.createEntityManager();
} catch (Exception ex) {
// Ignore exception that probably caused by attempt to connect the session with invalid connection data provided in the properties.
} finally {
emf.close();
if (SessionNameCustomizer.ss == null && SessionNameCustomizer.ss == originalSession) {
errorMsg += "1: New session expected; ";
} else {
if (SessionNameCustomizer.ss.getLogin().shouldUseExternalConnectionPooling()) {
errorMsg += "1: internal connection pooling expected; ";
}
if (SessionNameCustomizer.ss.getLogin().shouldUseExternalTransactionController()) {
errorMsg += "1: no externalTransactionController expected; ";
}
if (!myUser.equals(SessionNameCustomizer.ss.getLogin().getUserName())) {
errorMsg += "1: myUser expected; ";
}
Connector connector = SessionNameCustomizer.ss.getLogin().getConnector();
if (connector instanceof DefaultConnector) {
if (!myUrl.equals(((DefaultConnector) connector).getDatabaseURL())) {
errorMsg += "1: myUrl expected; ";
}
if (!myDriver.equals(((DefaultConnector) connector).getDriverClassName())) {
errorMsg += "1: myDriver expected; ";
}
} else {
errorMsg += "1: DefaultConnector expected; ";
}
}
// clear for the next test
SessionNameCustomizer.ss = null;
}
// 2: New session with JNDIConnector with myJtaDs, myNonJtaDs
properties = new HashMap();
// required by the test
properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, customizer);
// log on the same level as original session
properties.put(PersistenceUnitProperties.LOGGING_LEVEL, loggingLevel);
// to override SESSION_NAME if one is specified in persistence.xml
properties.put(PersistenceUnitProperties.SESSION_NAME, "");
properties.put(PersistenceUnitProperties.TRANSACTION_TYPE, "JTA");
properties.put(PersistenceUnitProperties.JTA_DATASOURCE, myJtaDS);
properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, myNonJtaDS);
// to override user if one is specified in persistence.xml
properties.put(PersistenceUnitProperties.JDBC_USER, "");
// note that there is no need to override JDBC_URL, JDBC_DRIVER, JDBC_PASSWORD with an empty string, they will be ignored.
// JDBC_URL, JDBC_DRIVER - because data source(s) are specified; JDBC_PASSWORD - because JDBC_USER is not specified
emf = Persistence.createEntityManagerFactory(puName, properties);
try {
emf.createEntityManager();
} catch (Exception ex) {
// Ignore exception that probably caused by attempt to connect the session with invalid connection data provided in the properties.
} finally {
emf.close();
if (SessionNameCustomizer.ss == null && SessionNameCustomizer.ss == originalSession) {
errorMsg += "2: New session expected; ";
} else {
if (!SessionNameCustomizer.ss.getLogin().shouldUseExternalConnectionPooling()) {
errorMsg += "2: external connection pooling expected; ";
}
if (!SessionNameCustomizer.ss.getLogin().shouldUseExternalTransactionController()) {
errorMsg += "2: externalTransactionController expected; ";
}
if (SessionNameCustomizer.ss.getLogin().getUserName().length() > 0) {
errorMsg += "2: empty string user expected; ";
}
Connector connector = SessionNameCustomizer.ss.getLogin().getConnector();
if (connector instanceof JNDIConnector) {
if (!myJtaDS.equals(((JNDIConnector) connector).getName())) {
errorMsg += "2: myJtaDS expected; ";
}
} else {
errorMsg += "2: JNDIConnector expected; ";
}
if (!SessionNameCustomizer.ss.getReadConnectionPool().getLogin().shouldUseExternalConnectionPooling()) {
errorMsg += "2: resding: external connection pooling expected; ";
}
if (SessionNameCustomizer.ss.getReadConnectionPool().getLogin().shouldUseExternalTransactionController()) {
errorMsg += "2: reading no externalTransactionController expected; ";
}
if (SessionNameCustomizer.ss.getReadConnectionPool().getLogin().getUserName().length() > 0) {
errorMsg += "2: reading: empty string user expected; ";
}
Connector readConnector = ((DatasourceLogin) SessionNameCustomizer.ss.getReadConnectionPool().getLogin()).getConnector();
if (readConnector instanceof JNDIConnector) {
if (!myNonJtaDS.equals(((JNDIConnector) readConnector).getName())) {
errorMsg += "2: reading: myNonJtaDS expected; ";
}
} else {
errorMsg += "2: reading: JNDIConnector expected; ";
}
}
// clear for the next test
SessionNameCustomizer.ss = null;
}
if (errorMsg.length() > 0) {
fail(errorMsg);
}
}
use of org.eclipse.persistence.sessions.JNDIConnector in project eclipselink by eclipse-ee4j.
the class UCPCallbackUnitOfWorkTests method buildServerSession.
@Override
public Server buildServerSession() {
try {
PoolDataSource dataSource = PoolDataSourceFactory.getPoolDataSource();
// dataSource.setONSConfiguration("nodes=adcdbc01-r.us.oracle.com:6200");
dataSource.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
dataSource.setURL(getSession().getLogin().getConnectionString());
dataSource.setUser(getSession().getLogin().getUserName());
dataSource.setPassword(getSession().getLogin().getPassword());
dataSource.setInitialPoolSize(5);
dataSource.setMinPoolSize(5);
dataSource.setMaxPoolSize(10);
dataSource.setFastConnectionFailoverEnabled(true);
Project project = getSession().getProject().clone();
project.setLogin(project.getLogin().clone());
project.getLogin().setConnector(new JNDIConnector(dataSource));
project.getLogin().setUsesExternalConnectionPooling(true);
project.getLogin().setPartitioningCallback(new UCPDataPartitioningCallback());
Server server = project.createServerSession();
server.setPartitioningPolicy(new RoundRobinPartitioningPolicy("node1", "node2"));
server.setSessionLog(getSession().getSessionLog());
server.login();
return server;
} catch (SQLException error) {
throw new TestErrorException("UCP failed to initialize.", error);
}
}
use of org.eclipse.persistence.sessions.JNDIConnector in project eclipselink by eclipse-ee4j.
the class ProxyTestHelper method setProxyConnectorIntoLogin.
public void setProxyConnectorIntoLogin(DatabaseLogin login, Session session) throws SQLException {
if (oracleDataSource != null) {
return;
}
JNDIConnector connector = createProxyConnector(session);
connector.setDataSource(oracleDataSource);
login.setConnector(connector);
login.setUsesExternalConnectionPooling(true);
}
use of org.eclipse.persistence.sessions.JNDIConnector in project eclipselink by eclipse-ee4j.
the class UnwrapConnectionCustomSQLTestModel method setup.
@Override
public void setup() {
if (!getSession().getPlatform().isOracle()) {
throw new TestWarningException("WARNING: This model is not supposed to be run on databases other than Oracle.");
}
DatabaseSession session = (DatabaseSession) getSession();
session.logout();
// save the connector to restore later
originalConnector = session.getLogin().getConnector();
DataSource dataSource = new TestOracleDataSource(session.getLogin().getDriverClassName(), session.getLogin().getConnectionString(), (Properties) session.getLogin().getProperties().clone());
session.getLogin().setConnector(new JNDIConnector(dataSource));
originalServerPlatform = session.getServerPlatform();
session.setServerPlatform(new TestServerPlatform(session));
originalShouldUseExternalConnectionPooling = session.getLogin().shouldUseExternalConnectionPooling();
session.getLogin().useExternalConnectionPooling();
session.login();
super.setup();
}
Aggregations