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);
}
}
}
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);
}
}
}
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);
}
}
}
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();
}
}
}
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;
}
}
Aggregations