Skip to content

Commit

Permalink
FIX: Put the delete statements into the correct flush-queue, so they …
Browse files Browse the repository at this point in the history
…do not conflict with the following inserts
  • Loading branch information
jonasPoehler committed Jun 16, 2023
1 parent 09f616a commit b63445e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public interface Persister {
/**
* Execute or queue the update.
*/
void executeOrQueue(SpiSqlUpdate update, SpiTransaction t, boolean queue);
void executeOrQueue(SpiSqlUpdate update, SpiTransaction t, boolean queue, int queuePosition);

/**
* Queue the SqlUpdate for execution with position 0, 1 or 2 defining
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public final class BatchControl {

private final Queue[] queues = new Queue[3];

static final int DELETE_QUEUE = 1;
static final int INSERT_QUEUE = 2;

/**
* Create for a given transaction, PersistExecute, default size and getGeneratedKeys.
*/
Expand Down Expand Up @@ -267,8 +270,8 @@ public void clear() {
private void flushBuffer(boolean reset) throws BatchedSqlException {
flushQueue(queues[0]);
flushInternal(reset);
flushQueue(queues[1]);
flushQueue(queues[2]);
flushQueue(queues[DELETE_QUEUE]);
flushQueue(queues[INSERT_QUEUE]);
}

private void flushQueue(Queue queue) throws BatchedSqlException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public int[] executeBatch(SpiSqlUpdate sqlUpdate, SpiTransaction transaction) {
}

@Override
public void executeOrQueue(SpiSqlUpdate update, SpiTransaction t, boolean queue) {
public void executeOrQueue(SpiSqlUpdate update, SpiTransaction t, boolean queue, int queuePosition) {
if (queue) {
addToFlushQueue(update, t, 2);
addToFlushQueue(update, t, queuePosition);
} else {
executeSqlUpdate(update, t);
}
Expand Down Expand Up @@ -907,7 +907,7 @@ private SaveManyBase saveManyRequest(boolean insertedParent, BeanPropertyAssocMa
void deleteManyIntersection(EntityBean bean, BeanPropertyAssocMany<?> many, SpiTransaction t, boolean publish, boolean queue) {
SpiSqlUpdate sqlDelete = deleteAllIntersection(bean, many, publish);
if (queue) {
addToFlushQueue(sqlDelete, t, 1);
addToFlushQueue(sqlDelete, t, BatchControl.DELETE_QUEUE);
} else {
executeSqlUpdate(sqlDelete, t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class SaveManyBase implements SaveMany {
final void preElementCollectionUpdate() {
if (!insertedParent) {
request.preElementCollectionUpdate();
persister.addToFlushQueue(many.deleteByParentId(request.beanId(), null), transaction, 1);
persister.addToFlushQueue(many.deleteByParentId(request.beanId(), null), transaction, BatchControl.DELETE_QUEUE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private void saveAssocManyIntersection(boolean queue) {
// build a intersection row for 'delete'
IntersectionRow intRow = many.buildManyToManyMapBean(parentBean, otherDelete, publish);
SpiSqlUpdate sqlDelete = intRow.createDelete(server, DeleteMode.HARD);
persister.executeOrQueue(sqlDelete, transaction, queue);
persister.executeOrQueue(sqlDelete, transaction, queue, BatchControl.DELETE_QUEUE);
}
}
if (additions != null && !additions.isEmpty()) {
Expand All @@ -314,7 +314,7 @@ private void saveAssocManyIntersection(boolean queue) {
// build a intersection row for 'insert'
IntersectionRow intRow = many.buildManyToManyMapBean(parentBean, otherBean, publish);
SpiSqlUpdate sqlInsert = intRow.createInsert(server);
persister.executeOrQueue(sqlInsert, transaction, queue);
persister.executeOrQueue(sqlInsert, transaction, queue, BatchControl.INSERT_QUEUE);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void saveCollection() {
final SpiSqlUpdate sqlInsert = proto.copy();
sqlInsert.setParameter(parentId);
many.bindElementValue(sqlInsert, value);
persister.addToFlushQueue(sqlInsert, transaction, 2);
persister.addToFlushQueue(sqlInsert, transaction, BatchControl.INSERT_QUEUE);
}
resetModifyState();
postElementCollectionUpdate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void saveCollection() {
sqlInsert.setParameter(parentId);
sqlInsert.setParameter(entry.getKey());
many.bindElementValue(sqlInsert, entry.getValue());
persister.addToFlushQueue(sqlInsert, transaction, 2);
persister.addToFlushQueue(sqlInsert, transaction, BatchControl.INSERT_QUEUE);
}
resetModifyState();
postElementCollectionUpdate();
Expand Down

0 comments on commit b63445e

Please sign in to comment.