@Override public void commit(RequestScope scope) { // flush all before commit flush(scope); transactions.values().forEach(dataStoreTransaction -> dataStoreTransaction.commit(scope)); }
@Override public void commit(RequestScope scope) { // flush all before commits flush(scope); ArrayList<DataStore> commitList = new ArrayList<>(); for (Entry<DataStore, DataStoreTransaction> entry : transactions.entrySet()) { try { entry.getValue().commit(scope); commitList.add(entry.getKey()); } catch (HttpStatusException | WebApplicationException e) { reverseTransactions(commitList, e, scope); throw e; } catch (Error | RuntimeException e) { TransactionException transactionException = new TransactionException(e); reverseTransactions(commitList, transactionException, scope); throw transactionException; } } }
@Test public void verifySession() throws IOException { try (DataStoreTransaction tx = dataStore.beginTransaction()) { tx.commit(null); } }
/** * Attempt to reverse changes of last commit since not all transactions successfully committed. * @param restoreList List of database managers to reverse the last commit * @param cause cause to add any suppressed exceptions */ private void reverseTransactions(ArrayList<DataStore> restoreList, Throwable cause, RequestScope requestScope) { for (DataStore dataStore : restoreList) { try (DataStoreTransaction transaction = dataStore.beginTransaction()) { List<Object> list = dirtyObjects.get(dataStore); for (Object dirtyObject : list == null ? Collections.emptyList() : list) { Object cloned = clonedObjects.get(dirtyObject); if (cloned == NEWLY_CREATED_OBJECT) { transaction.delete(dirtyObject, requestScope); } else { transaction.save(cloned, requestScope); } } transaction.commit(requestScope); } catch (RuntimeException | IOException e) { cause.addSuppressed(e); } } }
@Test (dataProvider = "like_queries_hql") public void testSpecialCharacterLikeQueryHQL(FilterPredicate filterPredicate, int noOfRecords) throws Exception { DataStoreTransaction tx = dataStore.beginReadTransaction(); RequestScope scope = mock(RequestScope.class); EntityDictionary dictionary = new EntityDictionary(new HashMap<>()); dictionary.bindEntity(Book.class); when(scope.getDictionary()).thenReturn(dictionary); Pagination pagination = mock(Pagination.class); when(pagination.isGenerateTotals()).thenReturn(true); tx.loadObjects(Book.class, Optional.of(filterPredicate), Optional.empty(), Optional.of(pagination), scope); tx.commit(scope); tx.close(); verify(pagination).setPageTotals(noOfRecords); }
tx.commit(requestScope); requestScope.runQueuedPostCommitTriggers();
@Test public void accessParentBean() throws IOException { DataStoreTransaction tx = dataStore.beginTransaction(); Parent parent = new Parent(); parent.setChildren(new HashSet<>()); parent.setSpouses(new HashSet<>()); tx.createObject(parent, null); tx.commit(null); tx.close(); } }
tx.commit(requestScope); requestScope.runQueuedPostCommitTriggers();
tx.commit(requestScope); requestScope.runQueuedPostCommitTriggers();
tx.commit(requestScope); requestScope.runQueuedPostCommitTriggers();
@BeforeClass public static void setup() throws IOException { DataStoreTransaction tx = dataStore.beginTransaction(); Embedded embedded = new Embedded(); // id 1 embedded.setSegmentIds(ImmutableSet.of(3L, 4L, 5L)); tx.createObject(embedded, null); Left left = new Left(); Right right = new Right(); left.setOne2one(right); right.setOne2one(left); tx.createObject(left, null); tx.createObject(right, null); tx.commit(null); tx.close(); }
tx.createObject(etb, null); tx.commit(null); tx.close();