@Override public Long call() throws Exception { ((SchemaRepositoryImpl) repo).setClientId(clientId); return txMgr.beginTransaction(txIsolation); }
@POST @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "postTx: starts a new user Transaction in the current session") public Response postTx(String isolation) { TransactionManagement txMgr = getTxManager(); try { long txId = txMgr.beginTransaction(TransactionIsolation.valueOf(isolation)); return Response.created(UriBuilder.fromPath("/tx/" + txId).build()).entity(txId).build(); } catch (Exception ex) { logger.error("postTx.error", ex); throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR); } }
@ManagedOperation(description="Starts new transaction") @ManagedOperationParameters({ @ManagedOperationParameter(name = "txIsolation", description = "Tx isolation level")}) public long beginTransaction(String txIsolation) { try { if (txIsolation == null || txIsolation.length() == 0) { return txMgr.beginTransaction(); } return txMgr.beginTransaction(TransactionIsolation.valueOf(txIsolation)); } catch (BagriException ex) { logger.error("beginTransaction.error: " + ex.getMessage(), ex); } return 0; }
@Override public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { long txId; try { if (arguments.length > 0) { txId = txMgr.beginTransaction(TransactionIsolation.valueOf(arguments[0].head().getStringValue())); } else { txId = txMgr.beginTransaction(); } return new Int64Value(txId); } catch (BagriException ex) { throw new XPathException(ex); } } };
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); }
@Test public void updateSecurityTest() throws Exception { long txId = getTxManagement().beginTransaction(); DocumentAccessor doc = createDocumentTest(sampleRoot + getFileName("security1500.xml")); assertNotNull(doc); String uri = doc.getUri(); txId = getTxManagement().beginTransaction(); doc = updateDocumentTest(uri, sampleRoot + getFileName("security9012.xml")); assertNotNull(doc); getTxManagement().commitTransaction(txId); txId = getTxManagement().beginTransaction(); doc = updateDocumentTest(uri, sampleRoot + getFileName("security5621.xml")); assertNotNull(doc);