* Override the default login creation method.
* If persistenceInfo is available, use the information from it to setup the login
* and possibly to set readConnectionPool.
*/
protected void updateLogins(Map m){
DatasourceLogin login = (DatasourceLogin)this.session.getDatasourceLogin();
String eclipselinkPlatform = PropertiesHandler.getPropertyValueLogDebug(PersistenceUnitProperties.TARGET_DATABASE, m, this.session);
if (eclipselinkPlatform != null) {
login.setPlatformClassName(eclipselinkPlatform, this.persistenceUnitInfo.getClassLoader());
}
// Check for EIS platform, need to use an EIS login.
boolean isEIS = false;
if (login.getDatasourcePlatform() instanceof EISPlatform) {
isEIS = true;
EISLogin newLogin = new EISLogin();
newLogin.setDatasourcePlatform(login.getDatasourcePlatform());
this.session.setDatasourceLogin(newLogin);
if (this.session.isServerSession()) {
for (ConnectionPool pool : ((ServerSession)this.session).getConnectionPools().values()) {
pool.setLogin(newLogin);
}
}
login = newLogin;
}
// Check for EIS or custom (JDBC) Connector class.
Object connectorValue = getConfigPropertyLogDebug(PersistenceUnitProperties.NOSQL_CONNECTION_SPEC, m, this.session);
String connectorProperty = PersistenceUnitProperties.NOSQL_CONNECTION_SPEC;
if (connectorValue == null) {
connectorValue = getConfigPropertyLogDebug(PersistenceUnitProperties.JDBC_CONNECTOR, m, this.session);
connectorProperty = PersistenceUnitProperties.JDBC_CONNECTOR;
}
if (connectorValue instanceof Connector) {
login.setConnector((Connector)connectorValue);
} else if (connectorValue instanceof String) {
Class cls = null;
// Try both class loaders.
try {
cls = findClassForProperty((String)connectorValue, connectorProperty, this.persistenceUnitInfo.getClassLoader());
} catch (Throwable failed) {
cls = findClassForProperty((String)connectorValue, connectorProperty, getClass().getClassLoader());
}
Connector connector = null;
try {
Constructor constructor = cls.getConstructor();
connector = (Connector)constructor.newInstance();
} catch (Exception exception) {
throw EntityManagerSetupException.failedToInstantiateProperty((String)connectorValue, connectorProperty, exception);
}
if (connector != null) {
login.setConnector(connector);
}
} else if (connectorValue != null) {
// Assume JCA connection spec.
((EISConnectionSpec)login.getConnector()).setConnectionSpecObject(connectorValue);
}
// Check for EIS ConnectionFactory.
Object factoryValue = getConfigPropertyLogDebug(PersistenceUnitProperties.NOSQL_CONNECTION_FACTORY, m, this.session);
if (factoryValue instanceof String) {
// JNDI name.
((EISConnectionSpec)login.getConnector()).setName((String)factoryValue);
} else if (factoryValue != null) {
((EISConnectionSpec)login.getConnector()).setConnectionFactoryObject(factoryValue);
}
// Process EIS or JDBC connection properties.
Map propertiesMap = PropertiesHandler.getPrefixValuesLogDebug(PersistenceUnitProperties.NOSQL_PROPERTY, m, session);
if (propertiesMap.isEmpty()) {
propertiesMap = PropertiesHandler.getPrefixValuesLogDebug(PersistenceUnitProperties.JDBC_PROPERTY, m, session);
}
for (Iterator iterator = propertiesMap.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry entry = (Map.Entry)iterator.next();
String property = (String)entry.getKey();
Object value = entry.getValue();
login.setProperty(property, value);
}
// Note: This call does not checked the stored persistenceUnitInfo or extended properties because
// the map passed into this method should represent the full set of properties we expect to process
String user = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_USER, m, this.session);
String password = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_PASSWORD, m, this.session);
if(user != null) {
login.setUserName(user);
}
if (password != null) {
login.setPassword(this.securableObjectHolder.getSecurableObject().decryptPassword(password));
}
PersistenceUnitTransactionType transactionType = this.persistenceUnitInfo.getTransactionType();
//bug 5867753: find and override the transaction type using properties
String transTypeString = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.TRANSACTION_TYPE, m, this.session);
if (transTypeString != null && transTypeString.length() > 0) {
transactionType = PersistenceUnitTransactionType.valueOf(transTypeString);
}
//find the jta datasource
javax.sql.DataSource jtaDatasource = getDatasourceFromProperties(m, PersistenceUnitProperties.JTA_DATASOURCE, this.persistenceUnitInfo.getJtaDataSource());
//find the non jta datasource
javax.sql.DataSource nonjtaDatasource = getDatasourceFromProperties(m, PersistenceUnitProperties.NON_JTA_DATASOURCE, this.persistenceUnitInfo.getNonJtaDataSource());
if (isValidationOnly(m, false) && transactionType == PersistenceUnitTransactionType.JTA && jtaDatasource == null) {
updateLoginDefaultConnector(login, m);
return;
}
login.setUsesExternalTransactionController(transactionType == PersistenceUnitTransactionType.JTA);
// Avoid processing data-source if EIS, as container may pass in a default one.
if (isEIS) {
return;
}
javax.sql.DataSource mainDatasource = null;
javax.sql.DataSource readDatasource = null;
if (login.shouldUseExternalTransactionController()) {
// JtaDataSource is guaranteed to be non null - otherwise exception would've been thrown earlier
mainDatasource = jtaDatasource;
// only define readDatasource if there is jta mainDatasource
readDatasource = nonjtaDatasource;
} else {
// JtaDataSource will be ignored because transactionType is RESOURCE_LOCAL
if (jtaDatasource != null) {
session.log(SessionLog.WARNING, SessionLog.TRANSACTION, "resource_local_persistence_init_info_ignores_jta_data_source", this.persistenceUnitInfo.getPersistenceUnitName());
}
if (nonjtaDatasource != null) {
mainDatasource = nonjtaDatasource;
} else {
updateLoginDefaultConnector(login, m);
return;
}
}
// mainDatasource is guaranteed to be non null - TODO: No it is not, if they did not set one it is null, should raise error, not null-pointer.
if (!(login.getConnector() instanceof JNDIConnector)) {
JNDIConnector jndiConnector;
if (mainDatasource instanceof DataSourceImpl) {
//Bug5209363 Pass in the datasource name instead of the dummy datasource
jndiConnector = new JNDIConnector(((DataSourceImpl)mainDatasource).getName());
} else {
jndiConnector = new JNDIConnector(mainDatasource);
}
login.setConnector(jndiConnector);
String useInternalConnectionPool = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.CONNECTION_POOL_INTERNALLY_POOL_DATASOURCE, m, this.session);
if (!"true".equalsIgnoreCase(useInternalConnectionPool)){
login.setUsesExternalConnectionPooling(true);
}
}
if (this.session.isServerSession()) {
// set readLogin
if (readDatasource != null) {
DatasourceLogin readLogin = login.clone();
readLogin.dontUseExternalTransactionController();
JNDIConnector jndiConnector;
if (readDatasource instanceof DataSourceImpl) {
//Bug5209363 Pass in the datasource name instead of the dummy datasource
jndiConnector = new JNDIConnector(((DataSourceImpl)readDatasource).getName());
} else {
jndiConnector = new JNDIConnector(readDatasource);
}
readLogin.setConnector(jndiConnector);
((ServerSession)this.session).setReadConnectionPool(readLogin);
}
}
}