Search in sources :

Example 41 with Serializer

use of org.exist.storage.serializers.Serializer in project exist by eXist-db.

the class CopyCollectionRecoveryTest method read.

private void read() throws EXistException, PermissionDeniedException, SAXException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("destination/test3/test.xml"), LockMode.READ_LOCK)) {
            assertNotNull("Document should not be null", lockedDoc);
            serializer.serialize(lockedDoc.getDocument());
        } finally {
            broker.returnSerializer(serializer);
        }
    }
}
Also used : LockedDocument(org.exist.dom.persistent.LockedDocument) Serializer(org.exist.storage.serializers.Serializer)

Example 42 with Serializer

use of org.exist.storage.serializers.Serializer in project exist by eXist-db.

the class CopyResourceRecoveryTest method read.

private void read(final String testCollectionName) throws EXistException, PermissionDeniedException, SAXException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append("new_test.xml"), LockMode.READ_LOCK)) {
            assertNotNull("Document should not be null", lockedDoc);
            final String data = serializer.serialize(lockedDoc.getDocument());
            assertNotNull(data);
        } finally {
            broker.returnSerializer(serializer);
        }
    }
}
Also used : LockedDocument(org.exist.dom.persistent.LockedDocument) Serializer(org.exist.storage.serializers.Serializer)

Example 43 with Serializer

use of org.exist.storage.serializers.Serializer in project exist by eXist-db.

the class CopyResourceRecoveryTest method readAborted.

private void readAborted(final String testCollectionName, final String subCollection) throws EXistException, PermissionDeniedException, SAXException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append(subCollection).append("test2.xml"), LockMode.READ_LOCK)) {
            assertNotNull("Document should not be null", lockedDoc);
            final String data = serializer.serialize(lockedDoc.getDocument());
            assertNotNull(data);
        } finally {
            broker.returnSerializer(serializer);
        }
        try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append("new_test2.xml"), LockMode.READ_LOCK)) {
            assertNull("Document should not exist as copy was not committed", lockedDoc);
        }
    }
}
Also used : LockedDocument(org.exist.dom.persistent.LockedDocument) Serializer(org.exist.storage.serializers.Serializer)

Example 44 with Serializer

use of org.exist.storage.serializers.Serializer in project exist by eXist-db.

the class AbstractUpdateTest method read.

private void read(final BrokerPool pool) throws EXistException, PermissionDeniedException, SAXException, XPathException {
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(TEST_COLLECTION_URI.append("test2/test.xml"), LockMode.READ_LOCK)) {
            assertNotNull("Document '" + TEST_COLLECTION_URI.append("test2/test.xml") + "' should not be null", lockedDoc);
            final String data = serializer.serialize(lockedDoc.getDocument());
        } finally {
            broker.returnSerializer(serializer);
        }
        final XQuery xquery = pool.getXQueryService();
        final Sequence seq = xquery.execute(broker, "/products/product[last()]", null);
        for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
            Item next = i.nextItem();
        }
    }
}
Also used : Item(org.exist.xquery.value.Item) SequenceIterator(org.exist.xquery.value.SequenceIterator) XQuery(org.exist.xquery.XQuery) LockedDocument(org.exist.dom.persistent.LockedDocument) Sequence(org.exist.xquery.value.Sequence) Serializer(org.exist.storage.serializers.Serializer)

Example 45 with Serializer

use of org.exist.storage.serializers.Serializer in project exist by eXist-db.

the class DocumentImpl method copyStartNode.

private void copyStartNode(final NodeImpl node, final DocumentBuilderReceiver receiver, final boolean expandRefs) throws SAXException {
    final int nr = node.nodeNumber;
    switch(node.getNodeType()) {
        case Node.ELEMENT_NODE:
            {
                final QName nodeName = document.nodeName[nr];
                receiver.startElement(nodeName, null);
                int attr = document.alpha[nr];
                if (-1 < attr) {
                    while ((attr < document.nextAttr) && (document.attrParent[attr] == nr)) {
                        final QName attrQName = document.attrName[attr];
                        receiver.attribute(attrQName, attrValue[attr]);
                        ++attr;
                    }
                }
                int ns = document.alphaLen[nr];
                if (-1 < ns) {
                    while ((ns < document.nextNamespace) && (document.namespaceParent[ns] == nr)) {
                        final QName nsQName = document.namespaceCode[ns];
                        receiver.addNamespaceNode(nsQName);
                        ++ns;
                    }
                }
                break;
            }
        case Node.TEXT_NODE:
            receiver.characters(document.characters, document.alpha[nr], document.alphaLen[nr]);
            break;
        case Node.CDATA_SECTION_NODE:
            receiver.cdataSection(document.characters, document.alpha[nr], document.alphaLen[nr]);
            break;
        case Node.ATTRIBUTE_NODE:
            final QName attrQName = document.attrName[nr];
            receiver.attribute(attrQName, attrValue[nr]);
            break;
        case Node.COMMENT_NODE:
            receiver.comment(document.characters, document.alpha[nr], document.alphaLen[nr]);
            break;
        case Node.PROCESSING_INSTRUCTION_NODE:
            final QName piQName = document.nodeName[nr];
            final String data = new String(document.characters, document.alpha[nr], document.alphaLen[nr]);
            receiver.processingInstruction(piQName.getLocalPart(), data);
            break;
        case NodeImpl.NAMESPACE_NODE:
            receiver.addNamespaceNode(document.namespaceCode[nr]);
            break;
        case NodeImpl.REFERENCE_NODE:
            if (expandRefs) {
                try (final DBBroker broker = getDatabase().getBroker()) {
                    final Serializer serializer = broker.borrowSerializer();
                    try {
                        serializer.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
                        serializer.setReceiver(receiver);
                        serializer.toReceiver(document.references[document.alpha[nr]], false, false);
                    } finally {
                        broker.returnSerializer(serializer);
                    }
                } catch (final EXistException e) {
                    throw new SAXException(e);
                }
            } else {
                receiver.addReferenceNode(document.references[document.alpha[nr]]);
            }
            break;
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) QName(org.exist.dom.QName) EXistException(org.exist.EXistException) Serializer(org.exist.storage.serializers.Serializer) SAXException(org.xml.sax.SAXException)

Aggregations

Serializer (org.exist.storage.serializers.Serializer)64 SAXException (org.xml.sax.SAXException)21 DBBroker (org.exist.storage.DBBroker)16 LockedDocument (org.exist.dom.persistent.LockedDocument)15 SAXSerializer (org.exist.util.serializer.SAXSerializer)14 BrokerPool (org.exist.storage.BrokerPool)11 Properties (java.util.Properties)10 Sequence (org.exist.xquery.value.Sequence)10 Txn (org.exist.storage.txn.Txn)8 XPathException (org.exist.xquery.XPathException)8 StringWriter (java.io.StringWriter)7 Collection (org.exist.collections.Collection)7 IOException (java.io.IOException)6 Item (org.exist.xquery.value.Item)6 Path (java.nio.file.Path)5 EXistException (org.exist.EXistException)5 SequenceIterator (org.exist.xquery.value.SequenceIterator)5 NodeProxy (org.exist.dom.persistent.NodeProxy)4 TransactionManager (org.exist.storage.txn.TransactionManager)4 NodeValue (org.exist.xquery.value.NodeValue)4