public boolean completeTransaction(TransactionInfo transactionInfo) { boolean completed = false; try { if ( transactionInfo.alive.get() == true && transactionInfo.inProcess.get() <= 0 && transactionInfo.written.get() == true ) { if ( transactionInfo.throwable.get() != null ) { transactionInfo.transaction.rollback(); sendThrowableToListeners(transactionInfo.throwable.get(), "Failure during transaction: {}", transactionInfo.batches); } else { transactionInfo.transaction.commit(); sendSuccessToListeners(transactionInfo.batches); } completed = true; } } catch (Throwable t) { transactionInfo.throwable.set(t); sendThrowableToListeners(t, "Failure to complete transaction: {}", transactionInfo.batches); } return completed; }
private String getTransactionId(Transaction transaction) { if ( transaction == null ) return null; return transaction.getTransactionId(); }
@Override public <T extends StructureReadHandle> T readStatus(T handle) { return realTransaction.readStatus(handle); } @Override
@Override public void commit() { host.releaseTransactionInfo(transactionInfo); boolean alive = transactionInfo.alive.getAndSet(false); if ( alive == true ) { realTransaction.commit(); logger.trace("committed transaction {}", realTransaction.getTransactionId()); } } @Override
@Override public void rollback() { host.releaseTransactionInfo(transactionInfo); boolean alive = transactionInfo.alive.getAndSet(false); if ( alive == true ) { realTransaction.rollback(); logger.trace("rolled back transaction {}", realTransaction.getTransactionId()); } } };
public void commit() { checkCurrentTransaction(); this.currentTransaction.commit(); this.currentTransaction = null; }
public void abort() { try { checkCurrentTransaction(); currentTransaction.rollback(); } finally { currentTransaction = null; } }
@Test public void testCommit() throws XpathException { String docId1 = "/test/testExists1.txt"; String docId2 = "/test/testExists2.txt"; TextDocumentManager docMgr = Common.client.newTextDocumentManager(); docMgr.write(docId1,new StringHandle().with("A simple text document")); String transactionName = "java-client-" + seed.nextLong(); Transaction transaction = Common.client.openTransaction(transactionName); StringHandle docHandle = docMgr.read(docId1, new StringHandle(), transaction); docMgr.write(docId2, docHandle, transaction); docMgr.delete(docId1, transaction); Document status = transaction.readStatus(new DOMHandle()).get(); assertXpathExists("//*[local-name() = 'transaction-name' and "+ "string(.) = '"+transactionName+"']", status); transaction.commit(); assertTrue("Document 1 exists", docMgr.exists(docId1)==null); assertTrue("Document 2 doesn't exist", docMgr.exists(docId2)!=null); docMgr.delete(docId2); }
@Override public List<ClientCookie> getCookies() { return realTransaction.getCookies(); } @Override
@Override public String getHostId() { return realTransaction.getHostId(); } @Override
private void testConnection(DatabaseClient client) { try { // Since creating client is not enough for verifying established connection, need to make fake call. client.openTransaction().commit(); } catch (Exception e) { MarkLogicErrorCode errorCode = new MarkLogicErrorCode( e instanceof FailedRequestException ? MESSAGES.getMessage("error.invalid.credentials") : MESSAGES.getMessage("error.server.notReachable")); throw new MarkLogicException(errorCode, e); } }
t2.rollback(); t2 = null;
client = getDatabaseClient("usr1", "password", getConnType()); Transaction t = client.openTransaction(); System.out.println("Transaction is = " + t.getTransactionId()); XMLDocumentManager docMgr = client.newXMLDocumentManager(); Map<String, String> map = new HashMap<>(); t.commit(); count = 0; DocumentPage page = docMgr.read(uris);
private Request.Builder addTransactionScopedCookies(Request.Builder requestBldr, Transaction transaction) { if ( transaction != null && transaction.getCookies() != null ) { if ( requestBldr == null ) { throw new MarkLogicInternalException("no requestBldr available to get the URI"); } requestBldr = addCookies( requestBldr, transaction.getCookies(), ((TransactionImpl) transaction).getCreatedTimestamp() ); } return requestBldr; }
private void testConnection(DatabaseClient client) { try { // Since creating client is not enough for verifying established connection, need to make fake call. client.openTransaction().commit(); } catch (Exception e) { MarkLogicErrorCode errorCode = new MarkLogicErrorCode( e instanceof FailedRequestException ? MESSAGES.getMessage("error.invalid.credentials") : MESSAGES.getMessage("error.server.notReachable")); throw new MarkLogicException(errorCode, e); } }
@Override public String getTransactionId() { return realTransaction.getTransactionId(); } @Override
@Override public void run() { Transaction t2 = writeclient.openTransaction(); try { System.out.println("In ExecuteAskSecondThreadFalse run method"); SPARQLQueryManager sparqlQmgrTh = writeclient.newSPARQLQueryManager(); StringBuffer sparqlQueryTh = new StringBuffer(); sparqlQueryTh.append("ASK FROM <rdfxml> where { <http://example.org/kennedy/person1> <http://purl.org/dc/elements/1.1/title> \"Person\'s title\"@en }"); SPARQLQueryDefinition qdefTh = sparqlQmgrTh.newQueryDefinition(sparqlQueryTh.toString()); // Verify result in t2 transaction. boolean bAskInTransT2 = sparqlQmgrTh.executeAsk(qdefTh, t2); System.out.println("Method ExecuteAskSecondThreadFalse Run result is " + bAskInTransT2); assertFalse("Class ExecuteAskSecondThreadFalse Run result is incorrect. No Records should be returned.", bAskInTransT2); setbCompleted(true); } catch (ForbiddenUserException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FailedRequestException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (t2 != null) { t2.rollback(); t2 = null; } } } }
@Test public void testMergeAs_jsonxml_Trx_FileHandle() throws Exception { Transaction trx = writerClient.openTransaction(); GraphManager gmWriter = writerClient.newGraphManager(); gmWriter.setDefaultMimetype(RDFMimeTypes.RDFJSON); File file = new File(datasource + "bug25348.json"); FileInputStream fis = new FileInputStream(file); Object graphData = convertInputStreamToString(fis); fis.close(); gmWriter.writeAs("htp://test.sem.graph/jsonMergeAsTrx", graphData, trx); File file2 = new File(datasource + "relative6.json"); Object graphData2 = convertFileToString(file2); gmWriter.mergeAs("htp://test.sem.graph/jsonMergeAsTrx", graphData2, trx); File readFile = gmWriter.readAs("htp://test.sem.graph/jsonMergeAsTrx", File.class, trx); String expectedContent = convertFileToString(readFile); assertTrue("Did not insert document or inserted empty doc", expectedContent.contains("http://example.com/ns/person#firstName") && expectedContent.contains("Anna's Homepage")); try { trx.commit(); trx = null; } catch (Exception e) { System.out.println(e); } finally { if (trx != null) { trx.rollback(); trx = null; } } }
@Test public void testWriteMergeDelete_Trx() throws Exception { Transaction trx = writerClient.openTransaction(); GraphManager gmWriter = writerClient.newGraphManager(); File file = new File(datasource + "triplexml1.xml"); gmWriter.write("htp://test.sem.graph/mergetrx", new FileHandle(file).withMimetype(RDFMimeTypes.TRIPLEXML), trx); file = new File(datasource + "bug25348.json"); gmWriter.merge("htp://test.sem.graph/mergetrx", new FileHandle(file).withMimetype(RDFMimeTypes.RDFJSON), trx); FileHandle handle = gmWriter.read("htp://test.sem.graph/mergetrx", new FileHandle(), trx); File readFile = handle.get(); String expectedContent = convertFileToString(readFile); try { assertTrue("Did not Merge document or inserted empty doc", expectedContent.contains("Michelle") && expectedContent.contains("Anna's Homepage")); gmWriter.delete("htp://test.sem.graph/mergetrx", trx); trx.commit(); trx = null; StringHandle readContent = gmWriter.read("htp://test.sem.graph/mergetrx", new StringHandle(), trx); assertTrue("Unexpected Content from read, expecting null", readContent == null); } catch (Exception e) { assertTrue("Unexpected Exception Thrown", e.toString().contains("ResourceNotFoundException")); } finally { if (trx != null) trx.commit(); trx = null; } }