Search in sources :

Example 1 with DocumentException

use of org.brackit.xquery.xdm.DocumentException in project sirix by sirixdb.

the class DBCollection method getDocuments.

@Override
public Stream<DBNode> getDocuments(final boolean updatable) throws DocumentException {
    final List<Path> resources = mDatabase.listResources();
    final List<DBNode> documents = new ArrayList<>(resources.size());
    for (final Path resourcePath : resources) {
        try {
            final String resourceName = resourcePath.getFileName().toString();
            final ResourceManager resource = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resourceName).build());
            final XdmNodeReadTrx trx = updatable ? resource.beginNodeWriteTrx() : resource.beginNodeReadTrx();
            documents.add(new DBNode(trx, this));
        } catch (final SirixException e) {
            throw new DocumentException(e.getCause());
        }
    }
    return new ArrayStream<DBNode>(documents.toArray(new DBNode[documents.size()]));
}
Also used : Path(java.nio.file.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) ArrayStream(org.brackit.xquery.node.stream.ArrayStream) DocumentException(org.brackit.xquery.xdm.DocumentException) ArrayList(java.util.ArrayList) SirixException(org.sirix.exception.SirixException) ResourceManager(org.sirix.api.ResourceManager)

Example 2 with DocumentException

use of org.brackit.xquery.xdm.DocumentException in project sirix by sirixdb.

the class DBNode method append.

@Override
public DBNode append(Kind kind, QNm name, Atomic value) throws DocumentException {
    if (mIsWtx) {
        moveRtx();
        final XdmNodeWriteTrx wtx = (XdmNodeWriteTrx) mRtx;
        try {
            return append(wtx, kind, name, value);
        } catch (final SirixException e) {
            wtx.close();
            throw new DocumentException(e);
        }
    } else {
        final XdmNodeWriteTrx wtx = getWtx();
        try {
            return append(wtx, kind, name, value);
        } catch (final SirixException e) {
            wtx.close();
            throw new DocumentException(e);
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException)

Example 3 with DocumentException

use of org.brackit.xquery.xdm.DocumentException in project sirix by sirixdb.

the class DBNode method insertAfter.

private DBNode insertAfter(XdmNodeWriteTrx wtx, SubtreeParser parser) throws DocumentException {
    try {
        final SubtreeBuilder builder = new SubtreeBuilder(mCollection, wtx, Insert.ASRIGHTSIBLING, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
        parser.parse(builder);
        return new DBNode(wtx.moveTo(builder.getStartNodeKey()).get(), mCollection);
    } catch (final SirixException e) {
        throw new DocumentException(e);
    }
}
Also used : DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException)

Example 4 with DocumentException

use of org.brackit.xquery.xdm.DocumentException in project sirix by sirixdb.

the class DBNode method append.

private DBNode append(XdmNodeReadTrx rtx, Node<?> child) throws DocumentException {
    try {
        SubtreeBuilder builder = null;
        if (rtx.hasFirstChild()) {
            rtx.moveToLastChild();
            builder = new SubtreeBuilder(mCollection, (XdmNodeWriteTrx) rtx, Insert.ASRIGHTSIBLING, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
        } else {
            builder = new SubtreeBuilder(mCollection, (XdmNodeWriteTrx) rtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
        }
        child.parse(builder);
        rtx.moveTo(builder.getStartNodeKey());
    } catch (final SirixException e) {
        throw new DocumentException(e);
    }
    return new DBNode(rtx, mCollection);
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SubtreeListener(org.brackit.xquery.node.parser.SubtreeListener) DocumentException(org.brackit.xquery.xdm.DocumentException) AbstractTemporalNode(org.brackit.xquery.xdm.AbstractTemporalNode) SirixException(org.sirix.exception.SirixException)

Example 5 with DocumentException

use of org.brackit.xquery.xdm.DocumentException in project sirix by sirixdb.

the class DBNode method replaceWith.

private DBNode replaceWith(XdmNodeWriteTrx wtx, SubtreeParser parser) throws DocumentException {
    final SubtreeBuilder builder = createBuilder(wtx);
    parser.parse(builder);
    try {
        return replace(builder.getStartNodeKey(), wtx);
    } catch (final SirixException e) {
        throw new DocumentException(e);
    }
}
Also used : DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException)

Aggregations

DocumentException (org.brackit.xquery.xdm.DocumentException)35 SirixException (org.sirix.exception.SirixException)25 SubtreeListener (org.brackit.xquery.node.parser.SubtreeListener)7 AbstractTemporalNode (org.brackit.xquery.xdm.AbstractTemporalNode)7 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)7 QNm (org.brackit.xquery.atomic.QNm)5 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)5 Database (org.sirix.api.Database)5 SirixRuntimeException (org.sirix.exception.SirixRuntimeException)5 ResourceManager (org.sirix.api.ResourceManager)4 IOException (java.io.IOException)3 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)3 PrintStream (java.io.PrintStream)2 Path (java.nio.file.Path)2 QueryException (org.brackit.xquery.QueryException)2 Sequence (org.brackit.xquery.xdm.Sequence)2 DBCollection (org.sirix.xquery.node.DBCollection)2 DBStore (org.sirix.xquery.node.DBStore)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1