mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#759 - Use default value of 100 for JDBC buffer fetchSize for findEach() / findEachWhile() - Add global defaults ServerConfig jdbcFetchSizeFindEach, jdbcFetchSizeFindList
This commit is contained in:
@@ -163,6 +163,17 @@ public class ServerConfig {
|
||||
*/
|
||||
private int databaseSequenceBatchSize = 20;
|
||||
|
||||
/**
|
||||
* JDBC fetchSize hint when using findList. Defaults to 0 leaving it up to the JDBC driver.
|
||||
*/
|
||||
private int jdbcFetchSizeFindList;
|
||||
|
||||
/**
|
||||
* JDBC fetchSize hint when using findEach/findEachWhile. Defaults to 100. Note that this does
|
||||
* not apply to MySql as that gets special treatment (forward only etc).
|
||||
*/
|
||||
private int jdbcFetchSizeFindEach = 100;
|
||||
|
||||
/**
|
||||
* Suffix appended to the base table to derive the view that contains the union
|
||||
* of the base table and the history table in order to support asOf queries.
|
||||
@@ -719,6 +730,34 @@ public class ServerConfig {
|
||||
this.databaseSequenceBatchSize = databaseSequenceBatchSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default JDBC fetchSize hint for findList queries.
|
||||
*/
|
||||
public int getJdbcFetchSizeFindList() {
|
||||
return jdbcFetchSizeFindList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default JDBC fetchSize hint for findList queries.
|
||||
*/
|
||||
public void setJdbcFetchSizeFindList(int jdbcFetchSizeFindList) {
|
||||
this.jdbcFetchSizeFindList = jdbcFetchSizeFindList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default JDBC fetchSize hint for findEach/findEachWhile queries.
|
||||
*/
|
||||
public int getJdbcFetchSizeFindEach() {
|
||||
return jdbcFetchSizeFindEach;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default JDBC fetchSize hint for findEach/findEachWhile queries.
|
||||
*/
|
||||
public void setJdbcFetchSizeFindEach(int jdbcFetchSizeFindEach) {
|
||||
this.jdbcFetchSizeFindEach = jdbcFetchSizeFindEach;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ChangeLogPrepare.
|
||||
* <p>
|
||||
@@ -2405,6 +2444,8 @@ public class ServerConfig {
|
||||
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);
|
||||
databaseSequenceBatchSize = p.getInt("databaseSequenceBatchSize", databaseSequenceBatchSize);
|
||||
databaseBooleanTrue = p.get("databaseBooleanTrue", databaseBooleanTrue);
|
||||
databaseBooleanFalse = p.get("databaseBooleanFalse", databaseBooleanFalse);
|
||||
|
||||
@@ -625,6 +625,11 @@ public interface SpiQuery<T> extends Query<T> {
|
||||
*/
|
||||
void setGeneratedSql(String generatedSql);
|
||||
|
||||
/**
|
||||
* Set the JDBC fetchSize buffer hint if not explicitly set.
|
||||
*/
|
||||
void setDefaultFetchBuffer(int fetchSize);
|
||||
|
||||
/**
|
||||
* Return the hint for Statement.setFetchSize().
|
||||
*/
|
||||
|
||||
@@ -137,7 +137,7 @@ public class InternalConfiguration {
|
||||
|
||||
this.dataTimeZone = initDataTimeZone();
|
||||
this.binder = getBinder(typeManager, databasePlatform, dataTimeZone);
|
||||
this.cQueryEngine = new CQueryEngine(databasePlatform, binder, asOfTableMapping, serverConfig.getAsOfSysPeriod(), draftTableMap);
|
||||
this.cQueryEngine = new CQueryEngine(serverConfig, databasePlatform, binder, asOfTableMapping, draftTableMap);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -520,4 +520,11 @@ public final class OrmQueryRequest<T> extends BeanRequest implements BeanQueryRe
|
||||
public String getBaseTableAlias() {
|
||||
return query.getAlias() == null ? beanDescriptor.getBaseTableAlias() : query.getAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the JDBC buffer fetchSize hint if not set explicitly.
|
||||
*/
|
||||
public void setDefaultFetchBuffer(int fetchSize) {
|
||||
query.setDefaultFetchBuffer(fetchSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.query;
|
||||
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebeaninternal.server.core.QueryIterator;
|
||||
import com.avaje.ebean.ValuePair;
|
||||
import com.avaje.ebean.Version;
|
||||
@@ -35,15 +36,22 @@ public class CQueryEngine {
|
||||
|
||||
private static final String T0 = "t0";
|
||||
|
||||
private final int defaultFetchSizeFindList;
|
||||
|
||||
private final int defaultFetchSizeFindEach;
|
||||
|
||||
private final boolean forwardOnlyHintOnFindIterate;
|
||||
|
||||
private final CQueryBuilder queryBuilder;
|
||||
|
||||
private final CQueryHistorySupport historySupport;
|
||||
|
||||
public CQueryEngine(DatabasePlatform dbPlatform, Binder binder, Map<String, String> asOfTableMapping, String asOfSysPeriod, Map<String, String> draftTableMap) {
|
||||
public CQueryEngine(ServerConfig serverConfig, DatabasePlatform dbPlatform, Binder binder, Map<String, String> asOfTableMapping, Map<String, String> draftTableMap) {
|
||||
this.defaultFetchSizeFindEach = serverConfig.getJdbcFetchSizeFindEach();
|
||||
this.defaultFetchSizeFindList = serverConfig.getJdbcFetchSizeFindList();
|
||||
this.forwardOnlyHintOnFindIterate = dbPlatform.isForwardOnlyHintOnFindIterate();
|
||||
this.historySupport = new CQueryHistorySupport(dbPlatform.getHistorySupport(), asOfTableMapping, asOfSysPeriod);
|
||||
|
||||
this.historySupport = new CQueryHistorySupport(dbPlatform.getHistorySupport(), asOfTableMapping, serverConfig.getAsOfSysPeriod());
|
||||
this.queryBuilder = new CQueryBuilder(dbPlatform, binder, historySupport, new CQueryDraftSupport(draftTableMap));
|
||||
}
|
||||
|
||||
@@ -91,11 +99,7 @@ public class CQueryEngine {
|
||||
BeanIdList list = rcQuery.findIds();
|
||||
|
||||
if (request.isLogSql()) {
|
||||
String logSql = rcQuery.getGeneratedSql();
|
||||
if (TransactionManager.SQL_LOGGER.isTraceEnabled()) {
|
||||
logSql = Str.add(logSql, "; --bind(", rcQuery.getBindLog(), ")");
|
||||
}
|
||||
request.logSql(logSql);
|
||||
logGeneratedSql(request, rcQuery.getGeneratedSql(), rcQuery.getBindLog());
|
||||
}
|
||||
|
||||
if (request.isLogSummary()) {
|
||||
@@ -115,6 +119,14 @@ public class CQueryEngine {
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void logGeneratedSql(OrmQueryRequest<T> request, String sql, String bindLog) {
|
||||
String logSql = sql;
|
||||
if (TransactionManager.SQL_LOGGER.isTraceEnabled()) {
|
||||
logSql = Str.add(logSql, "; --bind(", bindLog, ")");
|
||||
}
|
||||
request.logSql(logSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and execute the row count query.
|
||||
*/
|
||||
@@ -126,11 +138,7 @@ public class CQueryEngine {
|
||||
int rowCount = rcQuery.findRowCount();
|
||||
|
||||
if (request.isLogSql()) {
|
||||
String logSql = rcQuery.getGeneratedSql();
|
||||
if (TransactionManager.SQL_LOGGER.isTraceEnabled()) {
|
||||
logSql = Str.add(logSql, "; --bind(", rcQuery.getBindLog(), ")");
|
||||
}
|
||||
request.logSql(logSql);
|
||||
logGeneratedSql(request, rcQuery.getGeneratedSql(), rcQuery.getBindLog());
|
||||
}
|
||||
|
||||
if (request.isLogSummary()) {
|
||||
@@ -138,7 +146,6 @@ public class CQueryEngine {
|
||||
}
|
||||
|
||||
if (request.getQuery().isFutureFetch()) {
|
||||
logger.debug("Future findRowCount completed!");
|
||||
request.getTransaction().end();
|
||||
}
|
||||
|
||||
@@ -159,7 +166,9 @@ public class CQueryEngine {
|
||||
request.setCancelableQuery(cquery);
|
||||
|
||||
try {
|
||||
|
||||
if (defaultFetchSizeFindEach > 0) {
|
||||
request.setDefaultFetchBuffer(defaultFetchSizeFindEach);
|
||||
}
|
||||
if (!cquery.prepareBindExecuteQueryForwardOnly(forwardOnlyHintOnFindIterate)) {
|
||||
// query has been cancelled already
|
||||
logger.trace("Future fetch already cancelled");
|
||||
@@ -301,6 +310,9 @@ public class CQueryEngine {
|
||||
request.setCancelableQuery(cquery);
|
||||
|
||||
try {
|
||||
if (defaultFetchSizeFindList > 0) {
|
||||
request.setDefaultFetchBuffer(defaultFetchSizeFindList);
|
||||
}
|
||||
if (!cquery.prepareBindExecuteQuery()) {
|
||||
// query has been cancelled already
|
||||
logger.trace("Future fetch already cancelled");
|
||||
|
||||
@@ -1366,6 +1366,13 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
this.generatedSql = generatedSql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultFetchBuffer(int fetchSize) {
|
||||
if (bufferFetchSizeHint == 0) {
|
||||
bufferFetchSizeHint = fetchSize;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> setBufferFetchSizeHint(int bufferFetchSizeHint) {
|
||||
this.bufferFetchSizeHint = bufferFetchSizeHint;
|
||||
|
||||
Reference in New Issue
Block a user