#2655 - Remove JndiDataSourceLookup - app perform JNDI lookup if needed

This commit is contained in:
Rob Bygrave
2022-04-20 17:45:25 +12:00
parent 956ebf173e
commit f01e60094f
4 changed files with 9 additions and 89 deletions
@@ -340,11 +340,6 @@ public class DatabaseConfig {
*/
private ClassLoadConfig classLoadConfig = new ClassLoadConfig();
/**
* The data source JNDI name if using a JNDI DataSource.
*/
private String dataSourceJndiName;
/**
* The naming convention.
*/
@@ -392,12 +387,12 @@ public class DatabaseConfig {
* Note: It is possible that multiple servers are sharing the same state file as
* long as they are in the <b>same</b> JVM/ClassLoader scope. In this case it is
* recommended to use the same uuidNodeId configuration.
*
*
* If you have multiple servers in different JVMs, do <b>not</b> share the state
* files!
*/
private String uuidNodeId;
/**
* The clock used for setting the timestamps (e.g. @UpdatedTimestamp) on objects.
*/
@@ -1761,24 +1756,6 @@ public class DatabaseConfig {
this.readOnlyDataSourceConfig = readOnlyDataSourceConfig;
}
/**
* Return the JNDI name of the DataSource to use.
*/
public String getDataSourceJndiName() {
return dataSourceJndiName;
}
/**
* Set the JNDI name of the DataSource to use.
* <p>
* By default a prefix of "java:comp/env/jdbc/" is used to lookup the
* DataSource. This prefix is not used if dataSourceJndiName starts with
* "java:".
*/
public void setDataSourceJndiName(String dataSourceJndiName) {
this.dataSourceJndiName = dataSourceJndiName;
}
/**
* Return a value used to represent TRUE in the database.
* <p>
@@ -2061,14 +2038,14 @@ public class DatabaseConfig {
public void setUuidStateFile(String uuidStateFile) {
this.uuidStateFile = uuidStateFile;
}
/**
* Returns the V1-UUID-NodeId
* Returns the V1-UUID-NodeId
*/
public String getUuidNodeId() {
return uuidNodeId;
}
/**
* Sets the V1-UUID-NodeId.
*/
@@ -2937,7 +2914,6 @@ public class DatabaseConfig {
asOfViewSuffix = p.get("asOfViewSuffix", asOfViewSuffix);
asOfSysPeriod = p.get("asOfSysPeriod", asOfSysPeriod);
historyTableSuffix = p.get("historyTableSuffix", historyTableSuffix);
dataSourceJndiName = p.get("dataSourceJndiName", dataSourceJndiName);
jdbcFetchSizeFindEach = p.getInt("jdbcFetchSizeFindEach", jdbcFetchSizeFindEach);
jdbcFetchSizeFindList = p.getInt("jdbcFetchSizeFindList", jdbcFetchSizeFindList);
databasePlatformName = p.get("databasePlatformName", databasePlatformName);
@@ -14,7 +14,6 @@ import javax.sql.DataSource;
*/
final class InitDataSource {
private final JndiDataSourceLookup jndiDataSourceFactory = new JndiDataSourceLookup();
private final DatabaseConfig config;
/**
@@ -41,21 +40,9 @@ final class InitDataSource {
* Initialise the "main" read write DataSource from configuration.
*/
private DataSource initDataSource() {
final String jndiName = config.getDataSourceJndiName();
if (jndiName != null) {
return jndiDataSource(jndiName);
}
return createFromConfig(config.getDataSourceConfig(), false);
}
private DataSource jndiDataSource(String jndiName) {
DataSource ds = jndiDataSourceFactory.lookup(jndiName);
if (ds == null) {
throw new PersistenceException("JNDI lookup for DataSource " + jndiName + " returned null.");
}
return ds;
}
/**
* Initialise the "read only" DataSource from configuration.
*/
@@ -1,33 +0,0 @@
package io.ebeaninternal.server.core;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.PersistenceException;
import javax.sql.DataSource;
/**
* Helper to lookup a DataSource from JNDI.
*/
class JndiDataSourceLookup {
/**
* Return the DataSource by JNDI lookup.
* <p>
* If name is null the 'default' dataSource is returned.
* </p>
*/
public DataSource lookup(String jndiName) {
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiName);
if (ds == null) {
throw new PersistenceException("JNDI DataSource [" + jndiName + "] not found?");
}
return ds;
} catch (NamingException ex) {
throw new PersistenceException(ex);
}
}
}
@@ -27,7 +27,7 @@ public final class JtaTransactionManager implements ExternalTransactionManager {
private TransactionScopeManager scope;
/**
* Instantiates a new spring aware transaction scope manager.
* Instantiates a new JTA transaction manager.
*/
public JtaTransactionManager() {
}
@@ -37,10 +37,8 @@ public final class JtaTransactionManager implements ExternalTransactionManager {
*/
@Override
public void setTransactionManager(Object txnMgr) {
// RB: At this stage not exposing TransactionManager to
// the public API and hence the Object type and casting here
this.transactionManager = (TransactionManager) txnMgr;
this.scope = transactionManager.scope();
}
@@ -72,16 +70,13 @@ public final class JtaTransactionManager implements ExternalTransactionManager {
}
/**
* Looks for a current Spring managed transaction and wraps/returns that as a Ebean transaction.
* Looks for a current JTA managed transaction and wraps/returns that as an Ebean transaction.
* <p>
* Returns null if there is no current spring transaction (lazy loading outside a spring txn etc).
* </p>
*/
@Override
public Object getCurrentTransaction() {
TransactionSynchronizationRegistry syncRegistry = getSyncRegistry();
SpiTransaction t = (SpiTransaction) syncRegistry.getResource(EBEAN_TXN_RESOURCE);
if (t != null) {
// we have already seen this transaction
@@ -122,14 +117,10 @@ public final class JtaTransactionManager implements ExternalTransactionManager {
return newTrans;
}
/**
* Create a listener to register with JTA to enable Ebean to be
* notified when transactions commit and rollback.
* Create a listener to register with JTA to enable Ebean to be notified when transactions commit and rollback.
* <p>
* This is used by Ebean to notify it's appropriate listeners and maintain it's server
* cache etc.
* </p>
* This is used by Ebean to notify its appropriate listeners and maintain its server cache etc.
*/
private JtaTxnListener createJtaTxnListener(SpiTransaction t) {
return new JtaTxnListener(transactionManager, t);
@@ -169,7 +160,6 @@ public final class JtaTransactionManager implements ExternalTransactionManager {
* <p>
* When Ebean is notified (of the commit/rollback) it can then manage its
* cache, notify BeanPersistListeners etc.
* </p>
*/
private static class JtaTxnListener implements Synchronization {