@Override public Boolean call() throws Exception { txMgr.commitTransaction(txId); return true; }
@PUT @Path("/{txId}") @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "putTx: commits the specified user Transaction") public Response putTx(@PathParam("txId") long txId) { TransactionManagement txMgr = getTxManager(); try { txMgr.commitTransaction(txId); return Response.ok().build(); } catch (Exception ex) { logger.error("putTx.error", ex); throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR); } }
protected void closeTransaction() throws XQException { if (transactional) { if (autoCommit) { try { getTxManager().commitTransaction(txId); } catch (BagriException ex) { throw getXQException(ex); } txId = TX_NO; } else { // ?? } } }
@Override public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { long txId = (Long) SequenceTool.convertToJava(arguments[0].head()); try { txMgr.commitTransaction(txId); return null; } catch (BagriException ex) { throw new XPathException(ex); } } };
@ManagedOperation(description="Commit in-flight transaction") @ManagedOperationParameters({ @ManagedOperationParameter(name = "txId", description = "Tx identifier")}) public boolean commitTransaction(long txId) { try { txMgr.commitTransaction(txId); return true; } catch (BagriException ex) { logger.error("commitTransaction.error: " + ex.getMessage(), ex); } return false; } @ManagedOperation(description="Rollback in-flight transaction")
@Override public void commit() throws XQException { checkState(ex_connection_closed); if (autoCommit) { throw new XQException("The connection is in AutoCommit state, nothing to commit explicitly.", String.valueOf(ecTransWrongState)); } if (transactional) { try { getTxManager().commitTransaction(txId); } catch (BagriException ex) { throw getXQException(ex); } txId = TX_NO; } }
@Override public void setAutoCommit(boolean autoCommit) throws XQException { checkState(ex_connection_closed); if (this.autoCommit == autoCommit) { return; } if (transactional) { if (!this.autoCommit) { try { getTxManager().commitTransaction(txId); } catch (BagriException ex) { throw getXQException(ex); } txId = TX_NO; } } this.autoCommit = autoCommit; }
public void storeCustomerTest() throws Exception { long txId = 0; try { txId = getTxManagement().beginTransaction(); } catch (BagriException ex) { if (ex.getErrorCode() != BagriException.ecTransNoNested) { throw ex; } } uris.add(createDocumentTest(sampleRoot + getFileName("custacc.xml")).getUri()); if (txId > 0) { getTxManagement().commitTransaction(txId); } }
private <V> V executeInTransaction(Callable<V> executor) throws BagriException, XQException { if (autoCommit || txId == TX_NO) { txId = getTxManager().beginTransaction(); } try { V result = executor.call(); if (autoCommit && txId != TX_NO) { getTxManager().commitTransaction(txId); txId = TX_NO; } return result; } catch (Throwable ex) { if (txId != TX_NO) { getTxManager().rollbackTransaction(txId); txId = TX_NO; } if (ex instanceof XQException) { throw (XQException) ex; } if (ex instanceof BagriException) { throw (BagriException) ex; } throw new BagriException(ex, BagriException.ecTransaction); } }
public void storeOrderTest() throws Exception { long txId = 0; try { txId = getTxManagement().beginTransaction(); } catch (BagriException ex) { if (ex.getErrorCode() != BagriException.ecTransNoNested) { throw ex; } } uris.add(createDocumentTest(sampleRoot + getFileName("order123.xml")).getUri()); uris.add(createDocumentTest(sampleRoot + getFileName("order654.xml")).getUri()); if (txId > 0) { getTxManagement().commitTransaction(txId); } }
protected void removeDocumentsTest() throws Exception { if (getTxManagement().isInTransaction()) { getTxManagement().finishCurrentTransaction(true); } long txId = getTxManagement().beginTransaction(); Properties props = getDocumentProperties(); for (String uri: uris) { getDocManagement().removeDocument(uri, props); } uris.clear(); getTxManagement().commitTransaction(txId); }
public void storeSecurityTest() throws Exception { long txId = 0; try { txId = getTxManagement().beginTransaction(); } catch (BagriException ex) { if (ex.getErrorCode() != BagriException.ecTransNoNested) { throw ex; } } uris.add(createDocumentTest(sampleRoot + getFileName("security1500.xml")).getUri()); uris.add(createDocumentTest(sampleRoot + getFileName("security5621.xml")).getUri()); uris.add(createDocumentTest(sampleRoot + getFileName("security9012.xml")).getUri()); uris.add(createDocumentTest(sampleRoot + getFileName("security29674.xml")).getUri()); if (txId > 0) { getTxManagement().commitTransaction(txId); } }
@Test public void selectSecurityTest() throws Exception { long txId = getTxManagement().beginTransaction(); String fileName = sampleRoot + getFileName("security1500.xml"); String xml = readTextFile(fileName); DocumentAccessor doc = createDocumentTest(fileName); assertNotNull(doc); uris.add(doc.getUri()); assertEquals(txId, doc.getTxStart()); assertEquals(0L, doc.getTxFinish()); getTxManagement().commitTransaction(txId); Properties props = getDocumentProperties(); props.setProperty(pn_document_headers, String.valueOf(DocumentAccessor.HDR_CONTENT)); doc = getDocManagement().getDocument(doc.getUri(), props); assertNotNull(doc); assertNotNull(doc.getContent()); String content = doc.getContent(); assertEquals(xml.length(), content.length()); }
@Test public void createSecurityTest() throws Exception { long txId = getTxManagement().beginTransaction(); String uri = getFileName("security1500.xml"); DocumentAccessor doc = createDocumentTest(sampleRoot + uri); assertNotNull(doc); uris.add(doc.getUri()); assertEquals(txId, doc.getTxStart()); assertEquals(0L, doc.getTxFinish()); assertEquals(uri, doc.getUri()); getTxManagement().commitTransaction(txId); }
@Test public void removeSecurityTest() throws Exception { long txId = getTxManagement().beginTransaction(); DocumentAccessor doc = createDocumentTest(sampleRoot + getFileName("security1500.xml")); assertNotNull(doc); uris.add(doc.getUri()); assertEquals(txId, doc.getTxStart()); assertEquals(0L, doc.getTxFinish()); getTxManagement().commitTransaction(txId); long docKey = doc.getDocumentKey(); long txId2 = getTxManagement().beginTransaction(); removeDocumentTest(doc.getUri()); doc = getDocManagement().getDocument(doc.getUri(), getDocumentProperties()); // now it is null.. think about it - is it correct or not? //assertNotNull(doc); //assertEquals(txId, doc.getTxStart()); //assertEquals(txId2, doc.getTxFinish()); //assertEquals(docId, doc.getDocumentId()); //assertEquals(docKey, doc.getDocumentKey()); //assertTrue(doc.getVersion() == ++version); //assertEquals(doc.getUri(), uri); getTxManagement().commitTransaction(txId2); //uris.add(doc.getUri()); //doc = getDocManagement().getDocument(docKey); //assertNull(doc); }
assertEquals(txId, doc.getTxStart()); assertEquals(0L, doc.getTxFinish()); getTxManagement().commitTransaction(txId); int version = doc.getVersion(); String uri = doc.getUri(); assertEquals(++version, doc.getVersion()); assertEquals(uri, doc.getUri()); getTxManagement().commitTransaction(txId); assertEquals(++version, doc.getVersion()); assertEquals(uri, doc.getUri()); getTxManagement().commitTransaction(txId);