mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#220 - Refactor Persist batch, add effectively add PersistBatch.INSERT (to ALL and NONE) and allow batching per request (save(), insert(), update(), delete())
This commit is contained in:
1 parent
bb6571f426
commit
6bb38f2674
31 files changed
+1731
-973
No files matched your search
@@ -28,20 +28,16 @@ public class DeleteHandler extends DmlHandler {
|
||||
public void bind() throws SQLException {
|
||||
|
||||
sql = meta.getSql(persistRequest);
|
||||
|
||||
SpiTransaction t = persistRequest.getTransaction();
|
||||
boolean isBatch = t.isBatchThisRequest();
|
||||
|
||||
PreparedStatement pstmt;
|
||||
if (isBatch) {
|
||||
if (persistRequest.isBatched()) {
|
||||
pstmt = getPstmt(t, sql, persistRequest, false);
|
||||
} else {
|
||||
pstmt = getPstmt(t, sql, false);
|
||||
}
|
||||
dataBind = new DataBind(pstmt);
|
||||
|
||||
meta.bind(persistRequest, this);
|
||||
|
||||
logSql(sql);
|
||||
}
|
||||
|
||||
@@ -51,9 +47,6 @@ public class DeleteHandler extends DmlHandler {
|
||||
public void execute() throws SQLException, OptimisticLockException {
|
||||
int rowCount = dataBind.executeUpdate();
|
||||
checkRowCount(rowCount);
|
||||
|
||||
// Deletes the bean from the PersistenceContext
|
||||
persistRequest.postDelete();
|
||||
}
|
||||
|
||||
public void registerDerivedRelationship(DerivedRelationshipData assocBean) {
|
||||
|
||||
@@ -69,35 +69,28 @@ public final class DmlBeanPersister implements BeanPersister {
|
||||
/**
|
||||
* execute request taking batching into account.
|
||||
*/
|
||||
private void execute(PersistRequest request, PersistHandler handler) {
|
||||
|
||||
SpiTransaction trans = request.getTransaction();
|
||||
boolean batchThisRequest = trans.isBatchThisRequest();
|
||||
private void execute(PersistRequestBean<?> request, PersistHandler handler) {
|
||||
|
||||
boolean batched = request.isBatched();
|
||||
try {
|
||||
|
||||
handler.bind();
|
||||
|
||||
if (batchThisRequest) {
|
||||
if (batched) {
|
||||
handler.addBatch();
|
||||
|
||||
} else {
|
||||
// immediate insert
|
||||
handler.execute();
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
// log the error to the transaction log
|
||||
String errMsg = StringHelper.replaceStringMulti(e.getMessage(), new String[]{"\r","\n"}, "\\n ");
|
||||
String msg = "ERROR executing DML bindLog["+handler.getBindLog()+"] error["+errMsg+"]";
|
||||
if (request.getTransaction().isLogSummary()) {
|
||||
request.getTransaction().logSummary(msg);
|
||||
}
|
||||
|
||||
// log the error to the transaction log
|
||||
String errMsg = StringHelper.replaceStringMulti(e.getMessage(), new String[]{"\r","\n"}, "\\n ");
|
||||
String msg = "ERROR executing DML bindLog["+handler.getBindLog()+"] error["+errMsg+"]";
|
||||
if (request.getTransaction().isLogSummary()) {
|
||||
request.getTransaction().logSummary(msg);
|
||||
}
|
||||
throw new PersistenceException(msg, e);
|
||||
|
||||
} finally {
|
||||
if (!batchThisRequest && handler != null) {
|
||||
if (!batched && handler != null) {
|
||||
try {
|
||||
handler.close();
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -88,13 +88,12 @@ public class InsertHandler extends DmlHandler {
|
||||
}
|
||||
|
||||
SpiTransaction t = persistRequest.getTransaction();
|
||||
boolean isBatch = t.isBatchThisRequest();
|
||||
|
||||
// get the appropriate sql
|
||||
sql = meta.getSql(withId);
|
||||
|
||||
PreparedStatement pstmt;
|
||||
if (isBatch) {
|
||||
if (persistRequest.isBatched()) {
|
||||
pstmt = getPstmt(t, sql, persistRequest, useGeneratedKeys);
|
||||
} else {
|
||||
pstmt = getPstmt(t, sql, useGeneratedKeys);
|
||||
@@ -137,9 +136,7 @@ public class InsertHandler extends DmlHandler {
|
||||
}
|
||||
|
||||
checkRowCount(rc);
|
||||
//setAdditionalProperties();
|
||||
executeDerivedRelationships();
|
||||
|
||||
persistRequest.postInsert();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,10 +40,9 @@ public class UpdateHandler extends DmlHandler {
|
||||
sql = updatePlan.getSql();
|
||||
|
||||
SpiTransaction t = persistRequest.getTransaction();
|
||||
boolean isBatch = t.isBatchThisRequest();
|
||||
|
||||
PreparedStatement pstmt;
|
||||
if (isBatch) {
|
||||
if (persistRequest.isBatched()) {
|
||||
pstmt = getPstmt(t, sql, persistRequest, false);
|
||||
} else {
|
||||
pstmt = getPstmt(t, sql, false);
|
||||
|
||||
Reference in new issue
Block a user