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

This commit is contained in:
Rob Bygrave committed 2022-04-20 17:45:25 +12:00
1 parent 956ebf173e
commit f01e60094f
4 files changed
+4 -84

No files matched your search

@@ -340,11 +340,6 @@ public class DatabaseConfig {
*/ */
private ClassLoadConfig classLoadConfig = new ClassLoadConfig(); private ClassLoadConfig classLoadConfig = new ClassLoadConfig();
/**
* The data source JNDI name if using a JNDI DataSource.
*/
private String dataSourceJndiName;
/** /**
* The naming convention. * The naming convention.
*/ */
@@ -1761,24 +1756,6 @@ public class DatabaseConfig {
this.readOnlyDataSourceConfig = readOnlyDataSourceConfig; 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. * Return a value used to represent TRUE in the database.
* <p> * <p>
@@ -2937,7 +2914,6 @@ public class DatabaseConfig {
asOfViewSuffix = p.get("asOfViewSuffix", asOfViewSuffix); asOfViewSuffix = p.get("asOfViewSuffix", asOfViewSuffix);
asOfSysPeriod = p.get("asOfSysPeriod", asOfSysPeriod); asOfSysPeriod = p.get("asOfSysPeriod", asOfSysPeriod);
historyTableSuffix = p.get("historyTableSuffix", historyTableSuffix); historyTableSuffix = p.get("historyTableSuffix", historyTableSuffix);
dataSourceJndiName = p.get("dataSourceJndiName", dataSourceJndiName);
jdbcFetchSizeFindEach = p.getInt("jdbcFetchSizeFindEach", jdbcFetchSizeFindEach); jdbcFetchSizeFindEach = p.getInt("jdbcFetchSizeFindEach", jdbcFetchSizeFindEach);
jdbcFetchSizeFindList = p.getInt("jdbcFetchSizeFindList", jdbcFetchSizeFindList); jdbcFetchSizeFindList = p.getInt("jdbcFetchSizeFindList", jdbcFetchSizeFindList);
databasePlatformName = p.get("databasePlatformName", databasePlatformName); databasePlatformName = p.get("databasePlatformName", databasePlatformName);
@@ -14,7 +14,6 @@ import javax.sql.DataSource;
*/ */
final class InitDataSource { final class InitDataSource {
private final JndiDataSourceLookup jndiDataSourceFactory = new JndiDataSourceLookup();
private final DatabaseConfig config; private final DatabaseConfig config;
/** /**
@@ -41,21 +40,9 @@ final class InitDataSource {
* Initialise the "main" read write DataSource from configuration. * Initialise the "main" read write DataSource from configuration.
*/ */
private DataSource initDataSource() { private DataSource initDataSource() {
final String jndiName = config.getDataSourceJndiName();
if (jndiName != null) {
return jndiDataSource(jndiName);
}
return createFromConfig(config.getDataSourceConfig(), false); 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. * 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; private TransactionScopeManager scope;
/** /**
* Instantiates a new spring aware transaction scope manager. * Instantiates a new JTA transaction manager.
*/ */
public JtaTransactionManager() { public JtaTransactionManager() {
} }
@@ -37,10 +37,8 @@ public final class JtaTransactionManager implements ExternalTransactionManager {
*/ */
@Override @Override
public void setTransactionManager(Object txnMgr) { public void setTransactionManager(Object txnMgr) {
// RB: At this stage not exposing TransactionManager to // RB: At this stage not exposing TransactionManager to
// the public API and hence the Object type and casting here // the public API and hence the Object type and casting here
this.transactionManager = (TransactionManager) txnMgr; this.transactionManager = (TransactionManager) txnMgr;
this.scope = transactionManager.scope(); 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> * <p>
* Returns null if there is no current spring transaction (lazy loading outside a spring txn etc). * Returns null if there is no current spring transaction (lazy loading outside a spring txn etc).
* </p>
*/ */
@Override @Override
public Object getCurrentTransaction() { public Object getCurrentTransaction() {
TransactionSynchronizationRegistry syncRegistry = getSyncRegistry(); TransactionSynchronizationRegistry syncRegistry = getSyncRegistry();
SpiTransaction t = (SpiTransaction) syncRegistry.getResource(EBEAN_TXN_RESOURCE); SpiTransaction t = (SpiTransaction) syncRegistry.getResource(EBEAN_TXN_RESOURCE);
if (t != null) { if (t != null) {
// we have already seen this transaction // we have already seen this transaction
@@ -122,14 +117,10 @@ public final class JtaTransactionManager implements ExternalTransactionManager {
return newTrans; return newTrans;
} }
/** /**
* Create a listener to register with JTA to enable Ebean to be * Create a listener to register with JTA to enable Ebean to be notified when transactions commit and rollback.
* notified when transactions commit and rollback.
* <p> * <p>
* This is used by Ebean to notify it's appropriate listeners and maintain it's server * This is used by Ebean to notify its appropriate listeners and maintain its server cache etc.
* cache etc.
* </p>
*/ */
private JtaTxnListener createJtaTxnListener(SpiTransaction t) { private JtaTxnListener createJtaTxnListener(SpiTransaction t) {
return new JtaTxnListener(transactionManager, t); return new JtaTxnListener(transactionManager, t);
@@ -169,7 +160,6 @@ public final class JtaTransactionManager implements ExternalTransactionManager {
* <p> * <p>
* When Ebean is notified (of the commit/rollback) it can then manage its * When Ebean is notified (of the commit/rollback) it can then manage its
* cache, notify BeanPersistListeners etc. * cache, notify BeanPersistListeners etc.
* </p>
*/ */
private static class JtaTxnListener implements Synchronization { private static class JtaTxnListener implements Synchronization {