marklogic / java-client-api

Java client for the MarkLogic enterprise NoSQL database
https://docs.marklogic.com/guide/java
Apache License 2.0
58 stars 72 forks source link

DocumentWriteSet addAs method throws No factory for class com.marklogic.client.io.DOMHandle #544

Closed georgeajit closed 7 years ago

georgeajit commented 7 years ago

Executing the following snippet throws a java.lang.IllegalArgumentException. The test is trying to verify the addAs() method with signature:

DocumentWriteSet com.marklogic.client.document.DocumentWriteSet.addAs(String docId, DocumentMetadataWriteHandle metadataHandle, Object content, String temporalDocumentURI)

Adds to this write set a document with the given docId (server uri), metadata, temporalDocumentURI and contents. The IO class must have been registered before creating the database client. By default, the provided handles that implement ContentHandle are registered. Learn more about shortcut methods

Parameters:
docId the version URI identifier for the document
metadataHandle a handle for writing the metadata of the document
content an IO representation of the document content
temporalDocumentURI the logical temporal document collection URI
    @Test
        public void testBulkWritReadeWithAddAs() throws Exception {

            boolean tstatus = false;
            DocumentPage termQueryResults = null;

            Transaction tx = writerClient.openTransaction();
            try {
                XMLDocumentManager docMgr = writerClient.newXMLDocumentManager();

                DocumentWriteSet writeset = docMgr.newWriteSet();
                String[] docId = new String[4];
                docId[0] = "1.xml";
                docId[1] = "2.xml";
                docId[2] = "3.xml";
                docId[3] = "4.xml";

                DOMHandle handle1 = getXMLDocumentHandle("2001-01-01T00:00:00",
                        "2011-12-31T23:59:56", "999 Skyway Park - XML", docId[0]);
                DOMHandle handle2 = getXMLDocumentHandle("2001-01-02T00:00:00",
                        "2011-12-31T23:59:57", "999 Skyway Park - XML", docId[1]);
                DOMHandle handle3 = getXMLDocumentHandle("2001-01-03T00:00:00",
                        "2011-12-31T23:59:58", "999 Skyway Park - XML", docId[2]);
                DOMHandle handle4 = getXMLDocumentHandle("2001-01-04T00:00:00",
                        "2011-12-31T23:59:59", "999 Skyway Park - XML", docId[3]);
                DocumentMetadataHandle mh = setMetadata(false);

                String[] versiondocId = new String[4];
                versiondocId[0] = "/version2/1.xml";
                versiondocId[1] = "/version2/2.xml";
                versiondocId[2] = "/version2/3.xml";
                versiondocId[3] = "/version2/4.xml";

                writeset.addAs(docId[0], mh, handle1, versiondocId[0]);
                writeset.addAs(docId[1], mh, handle2, versiondocId[1]);
                writeset.addAs(docId[2], mh, handle3, versiondocId[2]);
                writeset.addAs(docId[3], mh, handle4, versiondocId[3]);
                Map<String, DOMHandle> map = new TreeMap<String, DOMHandle>();
                map.put(docId[0], handle1);
                map.put(docId[1], handle2);
                map.put(docId[2], handle3);
                map.put(docId[3], handle4);

                docMgr.write(writeset, null, null, bulktemporalCollectionName);
}

Here is the exception:

java.lang.IllegalArgumentException: No factory for class com.marklogic.client.io.DOMHandle
    at com.marklogic.client.impl.HandleFactoryRegistryImpl.makeHandle(HandleFactoryRegistryImpl.java:98)
    at com.marklogic.client.impl.DocumentWriteSetImpl.addAs(DocumentWriteSetImpl.java:116)
    at com.marklogic.client.functionaltest.TestBiTemporal.testBulkWritReadeWithAddAs(TestBiTemporal.java:866)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
georgeajit commented 7 years ago

DOMHandle with add() method works fine.

sammefford commented 7 years ago

DOMHandle is supposed to be used with add method.

The addAs method is a convenience for times when you don't want to think about DOMHandle and you'd like to work directly with objects of type org.w3c.dom.Document.

To learn more about the IO shortcut methods, please read www.marklogic.com/blog/io-shortcut-marklogic-java-client-api/

georgeajit commented 7 years ago

The method works with Document.class. Not an issue.