public void commit() { checkCurrentTransaction(); this.currentTransaction.commit(); this.currentTransaction = null; }
@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
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 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); } }
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); } }
@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; } }
@Test public void testRequestLogger() throws KeyManagementException, NoSuchAlgorithmException, IOException { System.out.println("Running testRequestLogger"); String filename = "bbq1.xml"; String uri = "/request-logger/"; File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create transaction Transaction transaction = client.openTransaction(); // create a manager for XML documents XMLDocumentManager docMgr = client.newXMLDocumentManager(); // create an identifier for the document String docId = uri + filename; // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); // create logger RequestLogger logger = client.newLogger(System.out); logger.setContentMax(RequestLogger.ALL_CONTENT); // start logging docMgr.startLogging(logger); // write the document content docMgr.write(docId, handle, transaction); // commit transaction transaction.commit(); // stop logging docMgr.stopLogging(); String expectedContentMax = "9223372036854775807"; assertEquals("Content log is not equal", expectedContentMax, Long.toString(logger.getContentMax())); }
@Test public void testRequestLogger() throws KeyManagementException, NoSuchAlgorithmException, IOException { System.out.println("Running testRequestLogger"); String filename = "bbq1.xml"; String uri = "/request-logger/"; File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create transaction Transaction transaction = client.openTransaction(); // create a manager for XML documents XMLDocumentManager docMgr = client.newXMLDocumentManager(); // create an identifier for the document String docId = uri + filename; // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); // create logger RequestLogger logger = client.newLogger(System.out); logger.setContentMax(RequestLogger.ALL_CONTENT); // start logging docMgr.startLogging(logger); // write the document content docMgr.write(docId, handle, transaction); // commit transaction transaction.commit(); // stop logging docMgr.stopLogging(); String expectedContentMax = "9223372036854775807"; assertEquals("Content log is not equal", expectedContentMax, Long.toString(logger.getContentMax())); }
transaction.commit();
@Test public void testWrite_triplexml_FileHandle() throws Exception { Transaction trx = writerClient.openTransaction(); GraphManager gmWriter = writerClient.newGraphManager(); File file = new File(datasource + "relative5.xml"); FileHandle filehandle = new FileHandle(); filehandle.set(file); // Write Graph using transaction gmWriter.write("htp://test.sem.graph/tripxml", filehandle.withMimetype(RDFMimeTypes.TRIPLEXML), trx); // Validate graph written to DB by reading within the same transaction StringHandle handle = gmWriter.read("htp://test.sem.graph/tripxml", new StringHandle().withMimetype(RDFMimeTypes.TRIPLEXML), trx); assertTrue("Did not insert document or inserted empty doc", handle.toString().contains("Anna's Homepage")); // Delete Graph in the same transaction gmWriter.delete("htp://test.sem.graph/tripxml", trx); // Validate Graph is deleted try { gmWriter.read("htp://test.sem.graph/tripxml", new StringHandle(), trx); trx.commit(); trx = null; } catch (ResourceNotFoundException e) { System.out.println(e); } finally { if (trx != null) { trx.rollback(); trx = null; } } }
.replaceApply("/root/popularity", xmlPatchBldr.call().multiply(2)).build(); xmlDocMgr.patch(docId, xmlPatch, t); t.commit(); waitForPropertyPropagate(); String content = xmlDocMgr.read(docId, new StringHandle()).get();
@Test public void testPartialUpdateXMLDscriptorTranc() throws IOException { System.out.println("Running testPartialUpdateXMLDescriptorTranc"); String[] filenames = { "constraint1.xml", "constraint2.xml", "constraint3.xml", "constraint4.xml", "constraint5.xml" }; SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("eval-user", "x"); DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, uberPort, dbName, secContext, getConnType()); // write docs for (String filename : filenames) { writeDocumentUsingInputStreamHandle(client, filename, "/partial-update/", "XML"); } String docId = "/partial-update/constraint1.xml"; // create doc manager XMLDocumentManager docMgr = client.newXMLDocumentManager(); // create template DocumentUriTemplate template = docMgr.newDocumentUriTemplate("xml"); template.withDirectory(docId); DocumentDescriptor desc = docMgr.newDescriptor(template.getDirectory()); DocumentPatchBuilder patchBldr = docMgr.newPatchBuilder(); patchBldr.insertFragment("/root", Position.LAST_CHILD, "<modified>2013-03-21</modified>"); DocumentPatchHandle patchHandle = patchBldr.build(); Transaction t = client.openTransaction("Tranc"); docMgr.patch(desc, patchHandle, t); t.commit(); waitForPropertyPropagate(); String content = docMgr.read(docId, new StringHandle()).get(); System.out.println("After" + content); assertTrue("fragment is not inserted", content.contains("<modified>2013-03-21</modified></root>")); // release client client.release(); }
transaction1.commit();
transaction1.commit();
@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); }
writeset.add(docId[2], new StringHandle().with("This is so multipleURI foo 3")); docMgr.write(writeset, transaction); transaction.commit(); transaction = client.openTransaction();
writeset.add(docId[2], new StringHandle().with("This is so transactionURIFoo 3")); docMgr.write(writeset, transaction); transaction.commit(); transaction = client.openTransaction();
transaction.commit();