@Override public void write(List<? extends String> items) throws Exception { DocumentWriteSet set = mgr.newWriteSet(); int size = items.size(); logger.info("Building set of documents to write"); for (int i = 0; i < size; i++) { String xml = items.get(i); String uri = generateUri(xml, i + 1 + ""); set.add(uri, buildMetadata(), new StringHandle(xml)); } logger.info("Writing set of documents, size: " + size); mgr.write(set); logger.info("Finished writing set of documents"); }
@Override public void write(List<? extends Document> items) throws Exception { XMLDocumentManager docMgr = client.newXMLDocumentManager(); for (Document doc : items) { DOMHandle handle = new DOMHandle(doc); docMgr.write(doc.getDocumentURI(), handle); } }
@Override public void finishBatch() { docMgr.write(writeSet); writeSet = docMgr.newWriteSet(); }
public static void writeDoc() throws Exception { Document domDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element root = domDocument.createElement("root"); root.setAttribute("xml:lang", "en"); root.setAttribute("foo", "bar"); root.appendChild(domDocument.createElement("child")); root.appendChild(domDocument.createTextNode("mixed")); domDocument.appendChild(root); @SuppressWarnings("unused") String domString = ((DOMImplementationLS) DocumentBuilderFactory.newInstance().newDocumentBuilder() .getDOMImplementation()).createLSSerializer().writeToString(domDocument); XMLDocumentManager docMgr = client.newXMLDocumentManager(); docMgr.write(docId, new DOMHandle().with(domDocument)); }
@Override public void finishBatch() { if ( writeSet.size() > 0 ) { docMgr.write(writeSet); // while this test is usually just 10 records so no more than one write set, // we're ready to do more batches if we want to do performance testing here writeSet = docMgr.newWriteSet(); } } @Override
public void loadXMLDocuments() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, TransformerException { int count = 1; XMLDocumentManager docMgr = client.newXMLDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); for (int i = 0; i < 102; i++) { Document doc = this.getDocumentContent("This is so foo with a bar " + i); Element childElement = doc.createElement("author"); childElement.appendChild(doc.createTextNode("rhiea")); doc.getElementsByTagName("foo").item(0).appendChild(childElement); writeset.add(DIRECTORY + "foo" + i + ".xml", new DOMHandle(doc)); if (count % BATCH_SIZE == 0) { docMgr.write(writeset); writeset = docMgr.newWriteSet(); } count++; } if (count % BATCH_SIZE > 0) { docMgr.write(writeset); } }
@BeforeClass public static void setupTestOptions() throws FileNotFoundException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { Common.connectAdmin(); QueryOptionsManager queryOptionsManager = Common.adminClient.newServerConfigManager().newQueryOptionsManager(); File options = new File("src/test/resources/alerting-options.xml"); queryOptionsManager.writeOptions("alerts", new FileHandle(options)); Common.adminClient.newServerConfigManager().setServerRequestLogging(true); Common.connect(); JSONDocumentManager jsonDocMgr = Common.client.newJSONDocumentManager(); jsonDocMgr.write("/basic1.json", new FileHandle(new File("src/test/resources/basic1.json"))); // write three files for alert tests. XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.write("/alert/first.xml", new FileHandle(new File("src/test/resources/alertFirst.xml"))); docMgr.write("/alert/second.xml", new FileHandle(new File("src/test/resources/alertSecond.xml"))); docMgr.write("/alert/third.xml", new FileHandle(new File("src/test/resources/alertThird.xml"))); }
public void run() { String filename = "flipper.xml"; try { DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); XMLDocumentManager docMgr = client.newXMLDocumentManager(); for (int i = 1; i <= 15; i++) { System.out.println("Writing document " + i + " from: " + msg); // write docs String docId = "/multithread-write/filename" + i + ".xml"; docMgr.write(docId, new FileHandle().with(file)); Random rand = new Random(); int r = rand.nextInt(2000) + 1000; try { Thread.sleep(r); } catch (InterruptedException e) { e.printStackTrace(); } } // release client client.release(); } catch (KeyManagementException | NoSuchAlgorithmException | IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
@BeforeClass public static void setupTestOptions() throws FileNotFoundException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { Common.connectAdmin(); QueryOptionsManager queryOptionsManager = Common.adminClient.newServerConfigManager().newQueryOptionsManager(); File options = new File("src/test/resources/alerting-options.xml"); queryOptionsManager.writeOptions("alerts", new FileHandle(options)); Common.adminClient.newServerConfigManager().setServerRequestLogging(true); Common.connect(); JSONDocumentManager jsonDocMgr = Common.client.newJSONDocumentManager(); jsonDocMgr.write("/basic1.json", new FileHandle(new File("src/test/resources/basic1.json"))); // write three files for alert tests. XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.write("/alert/first.xml", new FileHandle(new File("src/test/resources/alertFirst.xml"))); docMgr.write("/alert/second.xml", new FileHandle(new File("src/test/resources/alertSecond.xml"))); docMgr.write("/alert/third.xml", new FileHandle(new File("src/test/resources/alertThird.xml"))); }
public void loadXMLDocuments() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, TransformerException { int count = 1; XMLDocumentManager docMgr = client.newXMLDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); for (int i = 0; i < 102; i++) { writeset.add(DIRECTORY + "foo" + i + ".xml", new DOMHandle(getDocumentContent("This is so foo with a bar " + i))); if (count % BATCH_SIZE == 0) { docMgr.write(writeset); writeset = docMgr.newWriteSet(); } count++; } if (count % BATCH_SIZE > 0) { docMgr.write(writeset); } }
public void loadXMLDocuments() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, TransformerException { int count = 1; XMLDocumentManager docMgr = client.newXMLDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); for (int i = 0; i < 102; i++) { writeset.add(DIRECTORY + "foo" + i + ".xml", new DOMHandle(getDocumentContent("This is so foo with a bar " + i))); if (count % BATCH_SIZE == 0) { docMgr.write(writeset); writeset = docMgr.newWriteSet(); } count++; } if (count % BATCH_SIZE > 0) { docMgr.write(writeset); } }
@Override public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(incrementer.nextLongValue()); XMLDocumentManager xmlDocMgr = databaseClient.newXMLDocumentManager(); String uri = SPRING_BATCH_DIR + jobExecution.getJobInstance().getId().toString() + ".xml"; DocumentDescriptor desc = xmlDocMgr.exists(uri); JAXBHandle<MarkLogicJobInstance> handle = new JAXBHandle<>(jaxbContext()); xmlDocMgr.read(uri, handle); MarkLogicJobInstance mji = handle.get(); mji.addJobExecution(jobExecution); //Set document metadata DocumentMetadataHandle jobInstanceMetadata = new DocumentMetadataHandle(); jobInstanceMetadata.getCollections().add(COLLECTION_JOB_INSTANCE); xmlDocMgr.write(desc, jobInstanceMetadata, handle); logger.info("insert JobExecution:" + uri + "," + desc.getVersion()); }
@BeforeClass public static void setup() throws FileNotFoundException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { XMLUnit.setIgnoreWhitespace(true); queryOptionsManager = adminClient.newServerConfigManager() .newQueryOptionsManager(); File options = new File("src/test/resources/alerting-options.xml"); queryOptionsManager.writeOptions("alerts", new FileHandle(options)); queryManager = adminClient.newQueryManager(); transformManager = adminClient.newServerConfigManager().newTransformExtensionsManager(); File ruleTransform = new File("src/test/resources/rule-transform.xqy"); transformManager.writeXQueryTransform("ruleTransform", new FileHandle(ruleTransform)); adminClient.newServerConfigManager().setServerRequestLogging(true); Common.connect(); // write three files for alert tests. XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.write("/alert/first.xml", new FileHandle(new File( "src/test/resources/alertFirst.xml"))); docMgr.write("/alert/second.xml", new FileHandle(new File( "src/test/resources/alertSecond.xml"))); docMgr.write("/alert/third.xml", new FileHandle(new File( "src/test/resources/alertThird.xml"))); ruleManager = Common.client.newRuleManager(); setupMatchRules(); }
@BeforeClass public static void setup() throws FileNotFoundException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { XMLUnit.setIgnoreWhitespace(true); Common.connectAdmin(); writeOptions(Common.adminClient); Common.adminClient.newServerConfigManager().setServerRequestLogging(true); Common.connect(); // write three files for alert tests. XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.write("/sample/suggestion.xml", new StringHandle("<suggest><string>FINDME</string>Something I love to suggest is sugar with savory succulent limes.</suggest>")); docMgr.write("/sample2/suggestion.xml", new StringHandle("<suggest>Something I hate to suggest is liver with lard.</suggest>")); }
xmlDocMgr.write(desc, jobExecutionMetadata, handle); logger.info("update JobExecution:" + uri + "," + desc.getVersion());
@Test public void testWriteMultipleXMLDoc() throws KeyManagementException, NoSuchAlgorithmException, Exception { String docId[] = { "/foo/test/Foo1.xml", "/foo/test/Foo2.xml", "/foo/test/Foo3.xml" }; XMLDocumentManager docMgr = client.newXMLDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); writeset.add(docId[0], new DOMHandle(getDocumentContent("This is so foo1"))); writeset.add(docId[1], new DOMHandle().with(getDocumentContent("This is so foo2"))); writeset.add(docId[2], new DOMHandle().with(getDocumentContent("This is so foo3"))); docMgr.write(writeset); DOMHandle dh = new DOMHandle(); docMgr.read(docId[0], dh); assertEquals("xml document write difference", "This is so foo1", dh.get().getChildNodes().item(0).getTextContent()); docMgr.read(docId[1], dh); assertEquals("xml document write difference", "This is so foo2", dh.get().getChildNodes().item(0).getTextContent()); docMgr.read(docId[2], dh); assertEquals("xml document write difference", "This is so foo3", dh.get().getChildNodes().item(0).getTextContent()); // Bulk delete on XMLDocumentManager docMgr.delete(docId[0], docId[1], docId[2]); }
@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())); }
docMgr.write(docId, writeHandle);
@Test public void testWriteMultipleXMLDocWithDefaultMetadata() throws KeyManagementException, NoSuchAlgorithmException, Exception { String docId[] = { "/foo/test/Foo1.xml", "/foo/test/Foo2.xml", "/foo/test/Foo3.xml" }; XMLDocumentManager docMgr = client.newXMLDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); // put metadata DocumentMetadataHandle mh = setMetadata(); writeset.addDefault(mh); writeset.add(docId[0], new DOMHandle(getDocumentContent("This is so foo1"))); writeset.add(docId[1], new DOMHandle().with(getDocumentContent("This is so foo2"))); writeset.add(docId[2], new DOMHandle().with(getDocumentContent("This is so foo3"))); docMgr.write(writeset); DocumentPage page = docMgr.read(docId); assertTrue("DocumentPage Size did not return expected value:: returned== " + page.size(), page.size() == 3); while (page.hasNext()) { DocumentRecord rec = page.next(); docMgr.readMetadata(rec.getUri(), mh); validateMetadata(mh); } validateMetadata(mh); }