mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#373 - Internals for Oracle - Remove the oracle proprietary jdbc batch handling in favour of standard jdbc batch api
This commit is contained in:
1 parent
9e170b40f6
commit
1eabb7fdb4
14 files changed
+125
-207
No files matched your search
@@ -5,8 +5,6 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
|
||||
/**
|
||||
* A batched statement that is held in BatchedPstmtHolder. It has a list of
|
||||
* BatchPostExecute which it will process after the statement is executed.
|
||||
@@ -33,23 +31,13 @@ public class BatchedPstmt {
|
||||
|
||||
private final String sql;
|
||||
|
||||
private final PstmtBatch pstmtBatch;
|
||||
|
||||
private final boolean occCheck;
|
||||
|
||||
|
||||
/**
|
||||
* Create with a given statement.
|
||||
*
|
||||
* @param isGenKeys true if an insert that uses generatedKeys
|
||||
*/
|
||||
public BatchedPstmt(PreparedStatement pstmt, boolean isGenKeys, String sql, PstmtBatch pstmtBatch, boolean occCheck) {
|
||||
|
||||
public BatchedPstmt(PreparedStatement pstmt, boolean isGenKeys, String sql) {
|
||||
this.pstmt = pstmt;
|
||||
this.isGenKeys = isGenKeys;
|
||||
this.sql = sql;
|
||||
this.pstmtBatch = pstmtBatch;
|
||||
this.occCheck = occCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,21 +100,7 @@ public class BatchedPstmt {
|
||||
|
||||
private void executeAndCheckRowCounts() throws SQLException {
|
||||
|
||||
if (pstmtBatch != null) {
|
||||
// oracle specific JDBC batch processing
|
||||
int rc = pstmtBatch.executeBatch(pstmt, list.size(), sql, occCheck);
|
||||
if (list.size() == 1) {
|
||||
list.get(0).checkRowCount(rc);
|
||||
}
|
||||
// the optimistic concurrency row count check
|
||||
// has already been done by pstmtBatch so just return
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// normal JDBC batch processing
|
||||
int[] results = pstmt.executeBatch();
|
||||
|
||||
if (results.length != list.size()) {
|
||||
String s = "results array error " + results.length + " " + list.size();
|
||||
throw new SQLException(s);
|
||||
|
||||
@@ -27,11 +27,11 @@ public final class DefaultPersistExecute implements PersistExecute {
|
||||
/**
|
||||
* Construct this DmlPersistExecute.
|
||||
*/
|
||||
public DefaultPersistExecute(Binder binder, PstmtBatch pstmtBatch, int defaultBatchSize) {
|
||||
public DefaultPersistExecute(Binder binder, int defaultBatchSize) {
|
||||
|
||||
this.exeOrmUpdate = new ExeOrmUpdate(binder, pstmtBatch);
|
||||
this.exeUpdateSql = new ExeUpdateSql(binder, pstmtBatch);
|
||||
this.exeCallableSql = new ExeCallableSql(binder, pstmtBatch);
|
||||
this.exeOrmUpdate = new ExeOrmUpdate(binder);
|
||||
this.exeUpdateSql = new ExeUpdateSql(binder);
|
||||
this.exeCallableSql = new ExeCallableSql(binder);
|
||||
this.defaultBatchSize = defaultBatchSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.persist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.avaje.ebean.CallableSql;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.SqlUpdate;
|
||||
@@ -26,13 +15,12 @@ import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.api.SpiUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.Message;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequest;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequest.Type;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestCallableSql;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestOrmUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestUpdateSql;
|
||||
import com.avaje.ebeaninternal.server.core.Persister;
|
||||
import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequest.Type;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanCollectionUtil;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
@@ -42,6 +30,15 @@ import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
|
||||
import com.avaje.ebeaninternal.server.deploy.ManyType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Persister implementation using DML.
|
||||
@@ -74,12 +71,11 @@ public final class DefaultPersister implements Persister {
|
||||
|
||||
private final boolean updatesDeleteMissingChildren;
|
||||
|
||||
public DefaultPersister(SpiEbeanServer server, Binder binder, BeanDescriptorManager descMgr, PstmtBatch pstmtBatch) {
|
||||
|
||||
public DefaultPersister(SpiEbeanServer server, Binder binder, BeanDescriptorManager descMgr) {
|
||||
this.server = server;
|
||||
this.updatesDeleteMissingChildren = server.getServerConfig().isUpdatesDeleteMissingChildren();
|
||||
this.beanDescriptorManager = descMgr;
|
||||
this.persistExecute = new DefaultPersistExecute(binder, pstmtBatch, server.getServerConfig().getPersistBatchSize());
|
||||
this.persistExecute = new DefaultPersistExecute(binder, server.getServerConfig().getPersistBatchSize());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package com.avaje.ebeaninternal.server.persist;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.api.SpiCallableSql;
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestCallableSql;
|
||||
import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.util.BindParamsParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Handles the execution of CallableSql requests.
|
||||
*/
|
||||
@@ -26,10 +24,9 @@ public class ExeCallableSql {
|
||||
|
||||
private final PstmtFactory pstmtFactory;
|
||||
|
||||
public ExeCallableSql(Binder binder, PstmtBatch pstmtBatch) {
|
||||
public ExeCallableSql(Binder binder) {
|
||||
this.binder = binder;
|
||||
// no batch support for CallableStatement in Oracle anyway
|
||||
this.pstmtFactory = new PstmtFactory(null);
|
||||
this.pstmtFactory = new PstmtFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
package com.avaje.ebeaninternal.server.persist;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.api.SpiUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestOrmUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.util.BindParamsParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Executes the UpdateSql requests.
|
||||
*/
|
||||
@@ -30,8 +28,8 @@ public class ExeOrmUpdate {
|
||||
/**
|
||||
* Create with a given binder.
|
||||
*/
|
||||
public ExeOrmUpdate(Binder binder, PstmtBatch pstmtBatch) {
|
||||
this.pstmtFactory = new PstmtFactory(pstmtBatch);
|
||||
public ExeOrmUpdate(Binder binder) {
|
||||
this.pstmtFactory = new PstmtFactory();
|
||||
this.binder = binder;
|
||||
}
|
||||
|
||||
@@ -46,12 +44,7 @@ public class ExeOrmUpdate {
|
||||
try {
|
||||
pstmt = bindStmt(request, batchThisRequest);
|
||||
if (batchThisRequest) {
|
||||
PstmtBatch pstmtBatch = request.getPstmtBatch();
|
||||
if (pstmtBatch != null) {
|
||||
pstmtBatch.addBatch(pstmt);
|
||||
} else {
|
||||
pstmt.addBatch();
|
||||
}
|
||||
pstmt.addBatch();
|
||||
// return -1 to indicate batch mode
|
||||
return -1;
|
||||
} else {
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.avaje.ebeaninternal.api.SpiSqlUpdate;
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestUpdateSql;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestUpdateSql.SqlType;
|
||||
import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.util.BindParamsParser;
|
||||
import org.slf4j.Logger;
|
||||
@@ -22,21 +21,16 @@ public class ExeUpdateSql {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExeUpdateSql.class);
|
||||
|
||||
private static final int defaultBatchSize = 20;
|
||||
|
||||
private final Binder binder;
|
||||
|
||||
private final PstmtFactory pstmtFactory;
|
||||
|
||||
private final PstmtBatch pstmtBatch;
|
||||
|
||||
/**
|
||||
* Create with a given binder.
|
||||
*/
|
||||
public ExeUpdateSql(Binder binder, PstmtBatch pstmtBatch) {
|
||||
public ExeUpdateSql(Binder binder) {
|
||||
this.binder = binder;
|
||||
this.pstmtBatch = pstmtBatch;
|
||||
this.pstmtFactory = new PstmtFactory(pstmtBatch);
|
||||
this.pstmtFactory = new PstmtFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,11 +46,7 @@ public class ExeUpdateSql {
|
||||
pstmt = bindStmt(request, batchThisRequest);
|
||||
|
||||
if (batchThisRequest) {
|
||||
if (pstmtBatch != null) {
|
||||
pstmtBatch.addBatch(pstmt);
|
||||
} else {
|
||||
pstmt.addBatch();
|
||||
}
|
||||
pstmt.addBatch();
|
||||
// return -1 to indicate batch mode
|
||||
return -1;
|
||||
} else {
|
||||
@@ -97,14 +87,6 @@ public class ExeUpdateSql {
|
||||
PreparedStatement pstmt;
|
||||
if (batchThisRequest) {
|
||||
pstmt = pstmtFactory.getPstmt(t, logSql, sql, request);
|
||||
if (pstmtBatch != null) {
|
||||
// oracle specific JDBC setting batch size ahead of time
|
||||
int batchSize = t.getBatchSize();
|
||||
if (batchSize < 1) {
|
||||
batchSize = defaultBatchSize;
|
||||
}
|
||||
pstmtBatch.setBatchSize(pstmt, batchSize);
|
||||
}
|
||||
} else {
|
||||
if (logSql) {
|
||||
t.logSql(sql);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.persist;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
|
||||
/**
|
||||
* Factory for creating Statements.
|
||||
* <p>
|
||||
@@ -17,11 +16,7 @@ import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
*/
|
||||
public class PstmtFactory {
|
||||
|
||||
|
||||
private final PstmtBatch pstmtBatch;
|
||||
|
||||
public PstmtFactory(PstmtBatch pstmtBatch) {
|
||||
this.pstmtBatch = pstmtBatch;
|
||||
public PstmtFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,11 +55,7 @@ public class PstmtFactory {
|
||||
Connection conn = t.getInternalConnection();
|
||||
stmt = conn.prepareStatement(sql);
|
||||
|
||||
if (pstmtBatch != null) {
|
||||
pstmtBatch.setBatchSize(stmt, t.getBatchControl().getBatchSize());
|
||||
}
|
||||
|
||||
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, pstmtBatch, false);
|
||||
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql);
|
||||
batch.addStmt(bs, batchExe);
|
||||
return stmt;
|
||||
}
|
||||
@@ -89,7 +80,7 @@ public class PstmtFactory {
|
||||
Connection conn = t.getInternalConnection();
|
||||
stmt = conn.prepareCall(sql);
|
||||
|
||||
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, pstmtBatch, false);
|
||||
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql);
|
||||
batch.addStmt(bs, batchExe);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dml;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.persistence.OptimisticLockException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
|
||||
import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.lib.util.Str;
|
||||
import com.avaje.ebeaninternal.server.persist.BatchedPstmt;
|
||||
@@ -21,6 +10,14 @@ import com.avaje.ebeaninternal.server.persist.BatchedPstmtHolder;
|
||||
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionManager;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Base class for Handler implementations.
|
||||
@@ -100,12 +97,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
*/
|
||||
@Override
|
||||
public void addBatch() throws SQLException {
|
||||
PstmtBatch pstmtBatch = persistRequest.getPstmtBatch();
|
||||
if (pstmtBatch != null) {
|
||||
pstmtBatch.addBatch(dataBind.getPstmt());
|
||||
} else {
|
||||
dataBind.getPstmt().addBatch();
|
||||
}
|
||||
dataBind.getPstmt().addBatch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,12 +269,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
|
||||
stmt = getPstmt(t, sql, genKeys);
|
||||
|
||||
PstmtBatch pstmtBatch = request.getPstmtBatch();
|
||||
if (pstmtBatch != null) {
|
||||
pstmtBatch.setBatchSize(stmt, t.getBatchControl().getBatchSize());
|
||||
}
|
||||
|
||||
BatchedPstmt bs = new BatchedPstmt(stmt, genKeys, sql, request.getPstmtBatch(), true);
|
||||
BatchedPstmt bs = new BatchedPstmt(stmt, genKeys, sql);
|
||||
batch.addStmt(bs, request);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user