protected void flushDbOperationManager() { // obtain totally ordered operation list from operation manager List<DbOperation> operationsToFlush = dbOperationManager.calculateFlush(); if (operationsToFlush == null || operationsToFlush.size() == 0) { return; } LOG.databaseFlushSummary(operationsToFlush); // If we want to delete all table data as bulk operation, on tables which have self references, // We need to turn the foreign key check off on MySQL and MariaDB. // On other databases we have to do nothing, the mapped statement will be empty. if (isIgnoreForeignKeysForNextFlush) { persistenceSession.executeNonEmptyUpdateStmt(TOGGLE_FOREIGN_KEY_STMT, false); persistenceSession.flushOperations(); } try { final List<List<DbOperation>> batches = CollectionUtil.partition(operationsToFlush, BATCH_SIZE); for (List<DbOperation> batch : batches) { flushDbOperations(batch); } } finally { if (isIgnoreForeignKeysForNextFlush) { persistenceSession.executeNonEmptyUpdateStmt(TOGGLE_FOREIGN_KEY_STMT, true); persistenceSession.flushOperations(); isIgnoreForeignKeysForNextFlush = false; } } }
protected void flushDbOperationManager() { // obtain totally ordered operation list from operation manager List<DbOperation> operationsToFlush = dbOperationManager.calculateFlush(); if (operationsToFlush == null || operationsToFlush.size() == 0) { return; } LOG.databaseFlushSummary(operationsToFlush); // If we want to delete all table data as bulk operation, on tables which have self references, // We need to turn the foreign key check off on MySQL and MariaDB. // On other databases we have to do nothing, the mapped statement will be empty. if (isIgnoreForeignKeysForNextFlush) { persistenceSession.executeNonEmptyUpdateStmt(TOGGLE_FOREIGN_KEY_STMT, false); persistenceSession.flushOperations(); } try { final List<List<DbOperation>> batches = CollectionUtil.partition(operationsToFlush, BATCH_SIZE); for (List<DbOperation> batch : batches) { flushDbOperations(batch); } } finally { if (isIgnoreForeignKeysForNextFlush) { persistenceSession.executeNonEmptyUpdateStmt(TOGGLE_FOREIGN_KEY_STMT, true); persistenceSession.flushOperations(); isIgnoreForeignKeysForNextFlush = false; } } }
@Test public void testInsertSingleEntity() { entityManager.insert(execution1); entityManager.flushEntityCache(); List<DbOperation> flush = entityManager.getDbOperationManager().calculateFlush(); assertEquals(1, flush.size()); }
@Test public void testInsertIdOrdering() { entityManager.insert(execution1); entityManager.insert(execution2); entityManager.flushEntityCache(); List<DbOperation> insertOperations = entityManager.getDbOperationManager().calculateFlush(); assertHappensAfter(execution2, execution1, insertOperations); }
@Test public void testInsertReferenceOrdering() { execution2.setParentExecution(execution3); entityManager.insert(execution2); entityManager.insert(execution3); // the parent (3) is inserted before the child (2) entityManager.flushEntityCache(); List<DbOperation> flush = entityManager.getDbOperationManager().calculateFlush(); assertHappensAfter(execution2, execution3, flush); }
@Test public void testInsertReferenceOrderingAndIdOrdering() { execution2.setParentExecution(execution3); entityManager.insert(execution2); entityManager.insert(execution3); entityManager.insert(execution1); // the parent (3) is inserted before the child (2) entityManager.flushEntityCache(); List<DbOperation> flush = entityManager.getDbOperationManager().calculateFlush(); assertHappensAfter(execution2, execution3, flush); assertHappensAfter(execution3, execution1, flush); assertHappensAfter(execution2, execution1, flush); }
@Test public void testDeleteReferenceOrdering() { // given execution1.setParentExecution(execution2); entityManager.getDbEntityCache().putPersistent(execution1); entityManager.getDbEntityCache().putPersistent(execution2); // when deleting the entities entityManager.delete(execution1); entityManager.delete(execution2); entityManager.flushEntityCache(); // then the flush is based on the persistent relationships List<DbOperation> deleteOperations = entityManager.getDbOperationManager().calculateFlush(); assertHappensBefore(execution1, execution2, deleteOperations); }
@Test public void testDeleteReferenceOrderingAfterTransientUpdate() { // given execution1.setParentExecution(execution2); entityManager.getDbEntityCache().putPersistent(execution1); entityManager.getDbEntityCache().putPersistent(execution2); // when reverting the relation in memory execution1.setParentExecution(null); execution2.setParentExecution(execution1); // and deleting the entities entityManager.delete(execution1); entityManager.delete(execution2); entityManager.flushEntityCache(); // then the flush is based on the persistent relationships List<DbOperation> deleteOperations = entityManager.getDbOperationManager().calculateFlush(); assertHappensBefore(execution1, execution2, deleteOperations); }
@Test public void testInsertReferenceOrderingMultipleTrees() { // tree1 execution3.setParentExecution(execution4); execution2.setParentExecution(execution4); execution5.setParentExecution(execution3); // tree2 execution1.setParentExecution(execution8); entityManager.insert(execution8); entityManager.insert(execution6); entityManager.insert(execution2); entityManager.insert(execution5); entityManager.insert(execution1); entityManager.insert(execution4); entityManager.insert(execution7); entityManager.insert(execution3); // the parent (3) is inserted before the child (2) entityManager.flushEntityCache(); List<DbOperation> insertOperations = entityManager.getDbOperationManager().calculateFlush(); assertHappensAfter(execution3, execution4, insertOperations); assertHappensAfter(execution2, execution4, insertOperations); assertHappensAfter(execution5, execution3, insertOperations); assertHappensAfter(execution1, execution8, insertOperations); }
protected void flushDbOperationManager() { // obtain totally ordered operation list from operation manager List<DbOperation> operationsToFlush = dbOperationManager.calculateFlush(); if (operationsToFlush == null || operationsToFlush.size() == 0) { return; } LOG.databaseFlushSummary(operationsToFlush); // If we want to delete all table data as bulk operation, on tables which have self references, // We need to turn the foreign key check off on MySQL and MariaDB. // On other databases we have to do nothing, the mapped statement will be empty. if (isIgnoreForeignKeysForNextFlush) { persistenceSession.executeNonEmptyUpdateStmt(TOGGLE_FOREIGN_KEY_STMT, false); persistenceSession.flushOperations(); } try { final List<List<DbOperation>> batches = CollectionUtil.partition(operationsToFlush, BATCH_SIZE); for (List<DbOperation> batch : batches) { flushDbOperations(batch); } } finally { if (isIgnoreForeignKeysForNextFlush) { persistenceSession.executeNonEmptyUpdateStmt(TOGGLE_FOREIGN_KEY_STMT, true); persistenceSession.flushOperations(); isIgnoreForeignKeysForNextFlush = false; } } }
@Test public void testInsertSingleEntity() { entityManager.insert(execution1); entityManager.flushEntityCache(); List<DbOperation> flush = entityManager.getDbOperationManager().calculateFlush(); assertEquals(1, flush.size()); }
@Test public void testInsertIdOrdering() { entityManager.insert(execution1); entityManager.insert(execution2); entityManager.flushEntityCache(); List<DbOperation> insertOperations = entityManager.getDbOperationManager().calculateFlush(); assertHappensAfter(execution2, execution1, insertOperations); }
@Test public void testInsertReferenceOrdering() { execution2.setParentExecution(execution3); entityManager.insert(execution2); entityManager.insert(execution3); // the parent (3) is inserted before the child (2) entityManager.flushEntityCache(); List<DbOperation> flush = entityManager.getDbOperationManager().calculateFlush(); assertHappensAfter(execution2, execution3, flush); }
@Test public void testInsertReferenceOrderingAndIdOrdering() { execution2.setParentExecution(execution3); entityManager.insert(execution2); entityManager.insert(execution3); entityManager.insert(execution1); // the parent (3) is inserted before the child (2) entityManager.flushEntityCache(); List<DbOperation> flush = entityManager.getDbOperationManager().calculateFlush(); assertHappensAfter(execution2, execution3, flush); assertHappensAfter(execution3, execution1, flush); assertHappensAfter(execution2, execution1, flush); }
@Test public void testDeleteReferenceOrdering() { // given execution1.setParentExecution(execution2); entityManager.getDbEntityCache().putPersistent(execution1); entityManager.getDbEntityCache().putPersistent(execution2); // when deleting the entities entityManager.delete(execution1); entityManager.delete(execution2); entityManager.flushEntityCache(); // then the flush is based on the persistent relationships List<DbOperation> deleteOperations = entityManager.getDbOperationManager().calculateFlush(); assertHappensBefore(execution1, execution2, deleteOperations); }
@Test public void testDeleteReferenceOrderingAfterTransientUpdate() { // given execution1.setParentExecution(execution2); entityManager.getDbEntityCache().putPersistent(execution1); entityManager.getDbEntityCache().putPersistent(execution2); // when reverting the relation in memory execution1.setParentExecution(null); execution2.setParentExecution(execution1); // and deleting the entities entityManager.delete(execution1); entityManager.delete(execution2); entityManager.flushEntityCache(); // then the flush is based on the persistent relationships List<DbOperation> deleteOperations = entityManager.getDbOperationManager().calculateFlush(); assertHappensBefore(execution1, execution2, deleteOperations); }
@Test public void testInsertReferenceOrderingMultipleTrees() { // tree1 execution3.setParentExecution(execution4); execution2.setParentExecution(execution4); execution5.setParentExecution(execution3); // tree2 execution1.setParentExecution(execution8); entityManager.insert(execution8); entityManager.insert(execution6); entityManager.insert(execution2); entityManager.insert(execution5); entityManager.insert(execution1); entityManager.insert(execution4); entityManager.insert(execution7); entityManager.insert(execution3); // the parent (3) is inserted before the child (2) entityManager.flushEntityCache(); List<DbOperation> insertOperations = entityManager.getDbOperationManager().calculateFlush(); assertHappensAfter(execution3, execution4, insertOperations); assertHappensAfter(execution2, execution4, insertOperations); assertHappensAfter(execution5, execution3, insertOperations); assertHappensAfter(execution1, execution8, insertOperations); }