Search in sources :

Example 26 with DocumentException

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

the class IndexDef method toString.

@Override
public String toString() {
    try {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        SubtreePrinter.print(materialize(), new PrintStream(buf));
        return buf.toString();
    } catch (DocumentException e) {
        return e.getMessage();
    }
}
Also used : PrintStream(java.io.PrintStream) DocumentException(org.brackit.xquery.xdm.DocumentException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 27 with DocumentException

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

the class DBCollection method getDocument.

@Override
public DBNode getDocument(@Nonnegative final int revision) throws DocumentException {
    final List<Path> resources = mDatabase.listResources();
    if (resources.size() > 1) {
        throw new DocumentException("More than one document stored in database/collection!");
    }
    try {
        final ResourceManager session = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resources.get(0).getFileName().toString()).build());
        final int version = revision == -1 ? session.getMostRecentRevisionNumber() : revision;
        final XdmNodeReadTrx rtx = session.beginNodeReadTrx(version);
        return new DBNode(rtx, this);
    } catch (final SirixException e) {
        throw new DocumentException(e.getCause());
    }
}
Also used : Path(java.nio.file.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException) ResourceManager(org.sirix.api.ResourceManager)

Example 28 with DocumentException

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

the class DBNode method insertBefore.

private DBNode insertBefore(XdmNodeWriteTrx wtx, SubtreeParser parser) throws DocumentException {
    try {
        final SubtreeBuilder builder = new SubtreeBuilder(mCollection, wtx, Insert.ASLEFTSIBLING, 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 29 with DocumentException

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

the class DBNode method insertAfter.

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

Example 30 with DocumentException

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

the class DBNode method delete.

@Override
public void delete() throws DocumentException {
    if (mIsWtx) {
        moveRtx();
        final XdmNodeWriteTrx wtx = (XdmNodeWriteTrx) mRtx;
        try {
            wtx.remove();
        } catch (final SirixException e) {
            wtx.rollback();
            wtx.close();
            throw new DocumentException(e);
        }
    } else {
        final XdmNodeWriteTrx wtx = getWtx();
        try {
            wtx.remove();
        } catch (final SirixException e) {
            wtx.rollback();
            wtx.close();
            throw new DocumentException(e);
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) 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