#379 - Add MySql support for @History

This commit is contained in:
Robin Bygrave committed 2015-08-18 06:13:59 +12:00
1 parent 98ec00a2d6
commit 9d83017374
7 files changed
+78 -6

No files matched your search

@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.core;
import javax.sql.DataSource;
import com.avaje.ebean.config.dbplatform.DbHistorySupport;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedPropertyFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -106,7 +107,6 @@ public class InternalConfiguration {
this.expressionFactory = new DefaultExpressionFactory(serverConfig.isExpressionEqualsWithNullAsNoop());
this.typeManager = new DefaultTypeManager(serverConfig, bootupClasses);
this.binder = new Binder(typeManager);
this.resourceManager = ResourceManagerFactory.createResourceManager(serverConfig);
this.deployOrmXml = new DeployOrmXml(resourceManager.getResourceSource());
@@ -120,7 +120,10 @@ public class InternalConfiguration {
this.transactionManager = createTransactionManager();
this.cQueryEngine = new CQueryEngine(serverConfig.getDatabasePlatform(), binder, asOfTableMapping, serverConfig.getAsOfSysPeriod());
DatabasePlatform databasePlatform = serverConfig.getDatabasePlatform();
this.binder = new Binder(typeManager, getAsOfBindCount(databasePlatform));
this.cQueryEngine = new CQueryEngine(databasePlatform, binder, asOfTableMapping, serverConfig.getAsOfSysPeriod());
ExternalTransactionManager externalTransactionManager = serverConfig.getExternalTransactionManager();
if (externalTransactionManager == null && serverConfig.isUseJtaTransactionManager()) {
@@ -135,7 +138,15 @@ public class InternalConfiguration {
}
}
/**
* For 'As Of' queries return the number of bind variables per predicate.
*/
private int getAsOfBindCount(DatabasePlatform databasePlatform) {
DbHistorySupport historySupport = databasePlatform.getHistorySupport();
return historySupport == null ? 0 : historySupport.getBindCount();
}
/**
* Create the TransactionManager taking into account autoCommit mode.
*/
@@ -26,11 +26,21 @@ public class Binder {
private final TypeManager typeManager;
private final int asOfBindCount;
/**
* Set the PreparedStatement with which to bind variables to.
*/
public Binder(TypeManager typeManager) {
public Binder(TypeManager typeManager, int asOfBindCount) {
this.typeManager = typeManager;
this.asOfBindCount = asOfBindCount;
}
/**
* Return the bind count per predicate for 'As Of' query predicates.
*/
public int getAsOfBindCount() {
return asOfBindCount;
}
/**
@@ -172,7 +172,7 @@ public class CQueryPredicates {
// there is one effective date predicate per table alias
Timestamp asOf = query.getAsOf();
bindLog.append(" asOf ").append(asOf);
for (int i = 0; i < historyTableAlias.size(); i++) {
for (int i = 0; i < historyTableAlias.size() * binder.getAsOfBindCount(); i++) {
binder.bindObject(dataBind, asOf);
}
}