#1918 - Ebean 12.1.9 breaks Guice in Stage.PRODUCTION mode for multi tenant apps

This commit is contained in:
rob bygrave
2020-01-28 12:07:07 +13:00
parent df63eeaa8c
commit acff330b37
5 changed files with 20 additions and 16 deletions
@@ -4,6 +4,8 @@ import io.ebean.TxScope;
import io.ebeaninternal.server.transaction.TransactionScopeManager;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
/**
* Service provider interface for the transaction manager.
@@ -55,4 +57,9 @@ public interface SpiTransactionManager {
*/
void notifyOfQueryOnly(SpiTransaction transaction);
/**
* Return a connection used for query plan collection.
*/
Connection getQueryPlanConnection() throws SQLException;
}
@@ -239,9 +239,6 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
*/
private final int lazyLoadBatchSize;
/**
* The query batch size
*/
private final int queryBatchSize;
private final boolean updateAllPropertiesInBatch;
@@ -275,16 +272,13 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
beanDescriptorManager.setEbeanServer(this);
this.updateAllPropertiesInBatch = serverConfig.isUpdateAllPropertiesInBatch();
this.callStackFactory = initCallStackFactory(serverConfig);
this.persister = config.createPersister(this);
this.queryEngine = config.createOrmQueryEngine();
this.relationalQueryEngine = config.createRelationalQueryEngine();
this.dtoQueryEngine = config.createDtoQueryEngine();
this.autoTuneService = config.createAutoTuneService(this);
this.readAuditPrepare = config.getReadAuditPrepare();
this.readAuditLogger = config.getReadAuditLogger();
this.beanLoader = new DefaultBeanLoader(this);
this.jsonContext = config.createJsonContext(this);
this.dataTimeZone = config.getDataTimeZone();
@@ -293,15 +287,13 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
DocStoreIntegration docStoreComponents = config.createDocStoreIntegration(this);
this.transactionManager = config.createTransactionManager(docStoreComponents.updateProcessor());
this.documentStore = docStoreComponents.documentStore();
this.queryPlanManager = config.initQueryPlanManager(transactionManager.getDataSource());
this.queryPlanManager = config.initQueryPlanManager(transactionManager);
this.metaInfoManager = new DefaultMetaInfoManager(this);
this.serverPlugins = config.getPlugins();
this.ddlGenerator = new DdlGenerator(this, serverConfig);
this.scriptRunner = new DScriptRunner(this);
configureServerPlugins();
// Register with the JVM Shutdown hook
ShutdownManager.registerEbeanServer(this);
}
@@ -651,12 +651,12 @@ public class InternalConfiguration {
return new DefaultServerCacheManager(builder);
}
public QueryPlanManager initQueryPlanManager(DataSource dataSource) {
public QueryPlanManager initQueryPlanManager(TransactionManager transactionManager) {
if (!serverConfig.isCollectQueryPlans()) {
return QueryPlanManager.NOOP;
}
long threshold = serverConfig.getCollectQueryPlanThresholdMicros();
return new CQueryPlanManager(dataSource, threshold, queryPlanLogger(databasePlatform.getPlatform()), extraMetrics);
return new CQueryPlanManager(transactionManager, threshold, queryPlanLogger(databasePlatform.getPlatform()), extraMetrics);
}
/**
@@ -8,11 +8,11 @@ import io.ebeaninternal.api.QueryPlanManager;
import io.ebeaninternal.api.SpiDbQueryPlan;
import io.ebeaninternal.api.SpiQueryBindCapture;
import io.ebeaninternal.api.SpiQueryPlan;
import io.ebeaninternal.server.transaction.TransactionManager;
import io.ebeaninternal.server.type.bindcapture.BindCapture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
@@ -28,7 +28,7 @@ public class CQueryPlanManager implements QueryPlanManager {
private final ConcurrentHashMap<CQueryBindCapture, Object> plans = new ConcurrentHashMap<>();
private final DataSource dataSource;
private final TransactionManager transactionManager;
private final long defaultThreshold;
@@ -38,8 +38,8 @@ public class CQueryPlanManager implements QueryPlanManager {
private final TimedMetric timeBindCapture;
public CQueryPlanManager(DataSource dataSource, long defaultThreshold, QueryPlanLogger planLogger, ExtraMetrics extraMetrics) {
this.dataSource = dataSource;
public CQueryPlanManager(TransactionManager transactionManager, long defaultThreshold, QueryPlanLogger planLogger, ExtraMetrics extraMetrics) {
this.transactionManager = transactionManager;
this.defaultThreshold = defaultThreshold;
this.planLogger = planLogger;
this.timeCollection = extraMetrics.getPlanCollect();
@@ -65,7 +65,7 @@ public class CQueryPlanManager implements QueryPlanManager {
}
private List<MetaQueryPlan> collectPlans(QueryPlanRequest request) {
try (Connection connection = dataSource.getConnection()) {
try (Connection connection = transactionManager.getQueryPlanConnection()) {
CQueryPlanRequest req = new CQueryPlanRequest(connection, request, plans.keySet().iterator());
while (req.hasNext()) {
req.nextCapture();
@@ -312,6 +312,11 @@ public class TransactionManager implements SpiTransactionManager {
return serverName;
}
@Override
public Connection getQueryPlanConnection() throws SQLException {
return dataSourceSupplier.getConnection(null);
}
@Override
public DataSource getDataSource() {
return dataSourceSupplier.getDataSource();