mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
#2379 - Refactor tidy internals only - method names and tidy for internal BatchPstmt and related
This commit is contained in:
1 parent
ad0befe90a
commit
a7a056f041
10 files changed
+37
-64
No files matched your search
@@ -101,7 +101,6 @@ public final class BatchControl {
|
||||
* Note that UpdateSql and CallableSql will ALWAYS flush first. This is due to
|
||||
* it already having been bound to a PreparedStatement where as the Beans go
|
||||
* through a 2 step process when they are flushed (delayed binding).
|
||||
* </p>
|
||||
*/
|
||||
public void setBatchFlushOnMixed(boolean flushBatchOnMixed) {
|
||||
this.batchFlushOnMixed = flushBatchOnMixed;
|
||||
@@ -111,7 +110,6 @@ public final class BatchControl {
|
||||
* Set the size of batch execution.
|
||||
* <p>
|
||||
* The user can set this via the Transaction.
|
||||
* </p>
|
||||
*/
|
||||
public void setBatchSize(int batchSize) {
|
||||
if (batchSize > 1) {
|
||||
@@ -123,7 +121,6 @@ public final class BatchControl {
|
||||
* Set whether or not to use getGeneratedKeys for this batch execution.
|
||||
* <p>
|
||||
* The user can set this via the transaction
|
||||
* </p>
|
||||
*/
|
||||
public void setGetGeneratedKeys(Boolean getGeneratedKeys) {
|
||||
if (getGeneratedKeys != null) {
|
||||
@@ -147,7 +144,7 @@ public final class BatchControl {
|
||||
// execute the request immediately without batching
|
||||
return request.executeNow();
|
||||
}
|
||||
if (!addBatch && pstmtHolder.getMaxSize() >= batchSize) {
|
||||
if (!addBatch && pstmtHolder.maxSize() >= batchSize) {
|
||||
flush();
|
||||
}
|
||||
// for OrmUpdate, SqlUpdate, CallableSql there is no queue...
|
||||
@@ -188,10 +185,8 @@ public final class BatchControl {
|
||||
// as the bean gets changed from dirty to loaded earlier)
|
||||
return false;
|
||||
}
|
||||
|
||||
BatchedBeanHolder beanHolder = getBeanHolder(request);
|
||||
BatchedBeanHolder beanHolder = beanHolder(request);
|
||||
int bufferSize = beanHolder.append(request);
|
||||
|
||||
bufferMax = Math.max(bufferMax, bufferSize);
|
||||
// flush if any buffer hits 10 times batch size
|
||||
return (bufferMax >= batchSize * 10);
|
||||
@@ -200,7 +195,7 @@ public final class BatchControl {
|
||||
/**
|
||||
* Return the actual batch of PreparedStatements.
|
||||
*/
|
||||
public BatchedPstmtHolder getPstmtHolder() {
|
||||
public BatchedPstmtHolder pstmtHolder() {
|
||||
return pstmtHolder;
|
||||
}
|
||||
|
||||
@@ -315,7 +310,7 @@ public final class BatchControl {
|
||||
private void executeAll() throws BatchedSqlException {
|
||||
do {
|
||||
// convert entry map to array for sorting
|
||||
BatchedBeanHolder[] bsArray = getBeanHolderArray();
|
||||
BatchedBeanHolder[] bsArray = beanHolderArray();
|
||||
Arrays.sort(bsArray, depthComparator);
|
||||
if (transaction.isLogSummary()) {
|
||||
transaction.logSummary("BatchControl flush " + Arrays.toString(bsArray));
|
||||
@@ -342,13 +337,11 @@ public final class BatchControl {
|
||||
* Return an entry for the given type description. The type description is
|
||||
* typically the bean class name (or table name for MapBeans).
|
||||
*/
|
||||
private BatchedBeanHolder getBeanHolder(PersistRequestBean<?> request) {
|
||||
|
||||
private BatchedBeanHolder beanHolder(PersistRequestBean<?> request) {
|
||||
int depth = transaction.depth();
|
||||
BeanDescriptor<?> desc = request.descriptor();
|
||||
// batching by bean type AND depth
|
||||
String key = desc.rootName() + ":" + depth;
|
||||
|
||||
BatchedBeanHolder batchBeanHolder = beanHoldMap.get(key);
|
||||
if (batchBeanHolder == null) {
|
||||
int ordering = depthOrder.orderingFor(depth);
|
||||
@@ -368,7 +361,7 @@ public final class BatchControl {
|
||||
/**
|
||||
* Return the BatchedBeanHolder's ready for sorting and executing.
|
||||
*/
|
||||
private BatchedBeanHolder[] getBeanHolderArray() {
|
||||
private BatchedBeanHolder[] beanHolderArray() {
|
||||
return beanHoldMap.values().toArray(new BatchedBeanHolder[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ final class BatchDepthComparator implements Comparator<BatchedBeanHolder>, Seria
|
||||
|
||||
@Override
|
||||
public int compare(BatchedBeanHolder b1, BatchedBeanHolder b2) {
|
||||
|
||||
return Integer.compare(b1.getOrder(), b2.getOrder());
|
||||
return Integer.compare(b1.order(), b2.order());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -64,7 +64,7 @@ final class BatchedBeanHolder {
|
||||
/**
|
||||
* Return the depth.
|
||||
*/
|
||||
public int getOrder() {
|
||||
public int order() {
|
||||
return order;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,16 +38,11 @@ public final class BatchedPstmt implements SpiProfileTransactionEvent {
|
||||
* The list of BatchPostExecute used to perform post processing.
|
||||
*/
|
||||
private final List<BatchPostExecute> list = new ArrayList<>();
|
||||
|
||||
private final String sql;
|
||||
|
||||
private final SpiTransaction transaction;
|
||||
|
||||
private long profileStart;
|
||||
private long timedStart;
|
||||
|
||||
private int[] results;
|
||||
|
||||
private List<InputStream> inputStreams;
|
||||
|
||||
/**
|
||||
@@ -75,14 +70,14 @@ public final class BatchedPstmt implements SpiProfileTransactionEvent {
|
||||
/**
|
||||
* Return the sql
|
||||
*/
|
||||
public String getSql() {
|
||||
public String sql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the statement adding the postExecute task.
|
||||
*/
|
||||
public PreparedStatement getStatement(BatchPostExecute postExecute) throws SQLException {
|
||||
public PreparedStatement statement(BatchPostExecute postExecute) throws SQLException {
|
||||
if (postExecute.isFlushQueue() && list.size() >= 20) {
|
||||
flushStatementBatch();
|
||||
}
|
||||
@@ -191,7 +186,7 @@ public final class BatchedPstmt implements SpiProfileTransactionEvent {
|
||||
/**
|
||||
* Return the execution results (row counts).
|
||||
*/
|
||||
public int[] getResults() {
|
||||
public int[] results() {
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,15 +35,15 @@ public final class BatchedPstmtHolder {
|
||||
* Return the PreparedStatement if it has already been used in this Batch.
|
||||
* This will return null if no matching PreparedStatement is found.
|
||||
*/
|
||||
PreparedStatement getStmt(String stmtKey, BatchPostExecute postExecute) throws SQLException {
|
||||
BatchedPstmt batchedPstmt = getBatchedPstmt(stmtKey);
|
||||
return (batchedPstmt == null) ? null : batchedPstmt.getStatement(postExecute);
|
||||
PreparedStatement stmt(String stmtKey, BatchPostExecute postExecute) throws SQLException {
|
||||
BatchedPstmt batchedPstmt = batchedPstmt(stmtKey);
|
||||
return (batchedPstmt == null) ? null : batchedPstmt.statement(postExecute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BatchedPstmt that holds the batched statement.
|
||||
*/
|
||||
public BatchedPstmt getBatchedPstmt(String stmtKey) {
|
||||
public BatchedPstmt batchedPstmt(String stmtKey) {
|
||||
BatchedPstmt bs = stmtMap.get(stmtKey);
|
||||
if (bs == null) {
|
||||
return null;
|
||||
@@ -61,7 +61,7 @@ public final class BatchedPstmtHolder {
|
||||
* Return the size of the biggest batched statement.
|
||||
* Used to determine when to flush the batch.
|
||||
*/
|
||||
int getMaxSize() {
|
||||
int maxSize() {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public final class BatchedPstmtHolder {
|
||||
*/
|
||||
public void addStmt(BatchedPstmt bs, BatchPostExecute postExecute) {
|
||||
bs.add(postExecute);
|
||||
stmtMap.put(bs.getSql(), bs);
|
||||
stmtMap.put(bs.sql(), bs);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +97,7 @@ public final class BatchedPstmtHolder {
|
||||
throw new PersistenceException("No batched statement found for key " + key);
|
||||
}
|
||||
batchedPstmt.executeBatch(getGeneratedKeys);
|
||||
return batchedPstmt.getResults();
|
||||
return batchedPstmt.results();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,7 +138,7 @@ public final class BatchedPstmtHolder {
|
||||
try {
|
||||
bs.executeBatch(getGeneratedKeys);
|
||||
} catch (SQLException ex) {
|
||||
throw new BatchedSqlException("Error when batch flush on sql: " + bs.getSql(), ex);
|
||||
throw new BatchedSqlException("Error when batch flush on sql: " + bs.sql(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,18 +68,16 @@ final class ExeCallableSql {
|
||||
|
||||
CallableStatement cstmt;
|
||||
if (batchThisRequest) {
|
||||
cstmt = pstmtFactory.getCstmtBatch(t, logSql, sql, request);
|
||||
cstmt = pstmtFactory.cstmtBatch(t, logSql, sql, request);
|
||||
} else {
|
||||
if (logSql) {
|
||||
t.logSql(TrimLogSql.trim(sql));
|
||||
}
|
||||
cstmt = pstmtFactory.getCstmt(t, sql);
|
||||
cstmt = pstmtFactory.cstmt(t, sql);
|
||||
}
|
||||
|
||||
if (callableSql.getTimeout() > 0) {
|
||||
cstmt.setQueryTimeout(callableSql.getTimeout());
|
||||
}
|
||||
|
||||
String bindLog = null;
|
||||
if (!bindParams.isEmpty()) {
|
||||
bindLog = binder.bind(bindParams, cstmt, t.getInternalConnection());
|
||||
|
||||
@@ -72,33 +72,27 @@ final class ExeOrmUpdate {
|
||||
SpiTransaction t = request.transaction();
|
||||
|
||||
String sql = ormUpdate.getUpdateStatement();
|
||||
|
||||
// convert bean and property names to table and
|
||||
// column names if required
|
||||
sql = translate(request, sql);
|
||||
|
||||
BindParams bindParams = ormUpdate.getBindParams();
|
||||
|
||||
// process named parameters if required
|
||||
sql = BindParamsParser.parse(bindParams, sql);
|
||||
|
||||
ormUpdate.setGeneratedSql(sql);
|
||||
|
||||
PreparedStatement pstmt;
|
||||
if (batchThisRequest) {
|
||||
pstmt = pstmtFactory.getPstmtBatch(t, sql, request);
|
||||
pstmt = pstmtFactory.pstmtBatch(t, sql, request);
|
||||
} else {
|
||||
if (t.isLogSql()) {
|
||||
t.logSql(sql);
|
||||
}
|
||||
pstmt = pstmtFactory.getPstmt(t, sql, false);
|
||||
pstmt = pstmtFactory.pstmt(t, sql, false);
|
||||
}
|
||||
|
||||
String bindLog = null;
|
||||
if (!bindParams.isEmpty()) {
|
||||
bindLog = binder.bind(bindParams, pstmt, t.getInternalConnection());
|
||||
}
|
||||
|
||||
request.setBindLog(bindLog);
|
||||
return pstmt;
|
||||
}
|
||||
|
||||
@@ -86,23 +86,19 @@ final class ExeUpdateSql {
|
||||
|
||||
PreparedStatement pstmt;
|
||||
if (batchThisRequest) {
|
||||
pstmt = pstmtFactory.getPstmtBatch(t, sql, request);
|
||||
pstmt = pstmtFactory.pstmtBatch(t, sql, request);
|
||||
} else {
|
||||
pstmt = pstmtFactory.getPstmt(t, sql, request.isGetGeneratedKeys());
|
||||
pstmt = pstmtFactory.pstmt(t, sql, request.isGetGeneratedKeys());
|
||||
}
|
||||
|
||||
if (updateSql.getTimeout() > 0) {
|
||||
pstmt.setQueryTimeout(updateSql.getTimeout());
|
||||
}
|
||||
|
||||
String bindLog = null;
|
||||
if (!bindParams.isEmpty()) {
|
||||
bindLog = binder.bind(bindParams, pstmt, t.getInternalConnection());
|
||||
}
|
||||
|
||||
request.setBindLog(bindLog);
|
||||
updateSql.setGeneratedSql(sql);
|
||||
|
||||
if (batchThisRequest) {
|
||||
request.logSqlBatchBind();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ final class PstmtFactory {
|
||||
/**
|
||||
* Get a callable statement without any batching.
|
||||
*/
|
||||
CallableStatement getCstmt(SpiTransaction t, String sql) throws SQLException {
|
||||
CallableStatement cstmt(SpiTransaction t, String sql) throws SQLException {
|
||||
Connection conn = t.getInternalConnection();
|
||||
return conn.prepareCall(sql);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ final class PstmtFactory {
|
||||
/**
|
||||
* Get a prepared statement without any batching.
|
||||
*/
|
||||
PreparedStatement getPstmt(SpiTransaction t, String sql, boolean getGeneratedKeys) throws SQLException {
|
||||
PreparedStatement pstmt(SpiTransaction t, String sql, boolean getGeneratedKeys) throws SQLException {
|
||||
Connection conn = t.getInternalConnection();
|
||||
if (getGeneratedKeys) {
|
||||
return conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
@@ -40,16 +40,15 @@ final class PstmtFactory {
|
||||
/**
|
||||
* Return a prepared statement taking into account batch requirements.
|
||||
*/
|
||||
PreparedStatement getPstmtBatch(SpiTransaction t, String sql, BatchPostExecute batchExe) throws SQLException {
|
||||
BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder();
|
||||
BatchedPstmt existingStmt = batch.getBatchedPstmt(sql);
|
||||
PreparedStatement pstmtBatch(SpiTransaction t, String sql, BatchPostExecute batchExe) throws SQLException {
|
||||
BatchedPstmtHolder batch = t.getBatchControl().pstmtHolder();
|
||||
BatchedPstmt existingStmt = batch.batchedPstmt(sql);
|
||||
if (existingStmt != null) {
|
||||
if (existingStmt.isEmpty() && t.isLogSql()) {
|
||||
t.logSql(TrimLogSql.trim(sql));
|
||||
}
|
||||
return existingStmt.getStatement(batchExe);
|
||||
return existingStmt.statement(batchExe);
|
||||
}
|
||||
|
||||
if (t.isLogSql()) {
|
||||
t.logSql(TrimLogSql.trim(sql));
|
||||
}
|
||||
@@ -63,13 +62,12 @@ final class PstmtFactory {
|
||||
/**
|
||||
* Return a callable statement taking into account batch requirements.
|
||||
*/
|
||||
CallableStatement getCstmtBatch(SpiTransaction t, boolean logSql, String sql, BatchPostExecute batchExe) throws SQLException {
|
||||
BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder();
|
||||
CallableStatement stmt = (CallableStatement) batch.getStmt(sql, batchExe);
|
||||
CallableStatement cstmtBatch(SpiTransaction t, boolean logSql, String sql, BatchPostExecute batchExe) throws SQLException {
|
||||
BatchedPstmtHolder batch = t.getBatchControl().pstmtHolder();
|
||||
CallableStatement stmt = (CallableStatement) batch.stmt(sql, batchExe);
|
||||
if (stmt != null) {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
if (logSql) {
|
||||
t.logSql(sql);
|
||||
}
|
||||
|
||||
@@ -249,11 +249,11 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
* Return a prepared statement taking into account batch requirements.
|
||||
*/
|
||||
PreparedStatement getPstmtBatch(SpiTransaction t, String sql, PersistRequestBean<?> request, boolean genKeys) throws SQLException {
|
||||
BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder();
|
||||
batchedPstmt = batch.getBatchedPstmt(sql);
|
||||
BatchedPstmtHolder batch = t.getBatchControl().pstmtHolder();
|
||||
batchedPstmt = batch.batchedPstmt(sql);
|
||||
if (batchedPstmt != null) {
|
||||
batchedStatus = batchedPstmt.isEmpty() ? BATCHED_FIRST : BATCHED;
|
||||
return batchedPstmt.getStatement(request);
|
||||
return batchedPstmt.statement(request);
|
||||
}
|
||||
batchedStatus = BATCHED_FIRST;
|
||||
PreparedStatement stmt = getPstmt(t, sql, genKeys);
|
||||
|
||||
Reference in new issue
Block a user