Search in sources :

Example 51 with SirixException

use of org.sirix.exception.SirixException in project sirix by sirixdb.

the class DBCollection method add.

@Override
public DBNode add(SubtreeParser parser) throws OperationNotSupportedException, DocumentException {
    try {
        final String resourceName = new StringBuilder(2).append("resource").append(mDatabase.listResources().size() + 1).toString();
        mDatabase.createResource(ResourceConfiguration.newBuilder(resourceName, mDatabase.getDatabaseConfig()).useDeweyIDs(true).useTextCompression(true).buildPathSummary(true).build());
        final ResourceManager resource = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resourceName).build());
        final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx();
        final SubtreeHandler handler = new SubtreeBuilder(this, wtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
        // Make sure the CollectionParser is used.
        if (!(parser instanceof CollectionParser)) {
            parser = new CollectionParser(parser);
        }
        parser.parse(handler);
        return new DBNode(wtx, this);
    } catch (final SirixException e) {
        LOGGER.error(e.getMessage(), e);
        return null;
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) CollectionParser(org.brackit.xquery.node.parser.CollectionParser) SubtreeHandler(org.brackit.xquery.node.parser.SubtreeHandler) SirixException(org.sirix.exception.SirixException) ResourceManager(org.sirix.api.ResourceManager)

Example 52 with SirixException

use of org.sirix.exception.SirixException 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 53 with SirixException

use of org.sirix.exception.SirixException 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 54 with SirixException

use of org.sirix.exception.SirixException 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)

Example 55 with SirixException

use of org.sirix.exception.SirixException in project sirix by sirixdb.

the class DBNode method append.

private DBNode append(XdmNodeReadTrx rtx, SubtreeParser parser) throws DocumentException {
    try {
        if (rtx.hasFirstChild()) {
            rtx.moveToLastChild();
        }
        parser.parse(new SubtreeBuilder(mCollection, (XdmNodeWriteTrx) rtx, Insert.ASRIGHTSIBLING, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList()));
        moveRtx();
        rtx.moveToFirstChild();
    } 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)

Aggregations

SirixException (org.sirix.exception.SirixException)74 DocumentException (org.brackit.xquery.xdm.DocumentException)25 IOException (java.io.IOException)18 Database (org.sirix.api.Database)17 JaxRxException (org.jaxrx.core.JaxRxException)14 NodeReadTrx (org.sirix.api.NodeReadTrx)13 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)13 SessionConfiguration (org.sirix.access.conf.SessionConfiguration)12 Session (org.sirix.api.Session)12 ResourceManager (org.sirix.api.ResourceManager)10 WebApplicationException (javax.ws.rs.WebApplicationException)8 Path (java.nio.file.Path)7 XMLStreamException (javax.xml.stream.XMLStreamException)7 QNm (org.brackit.xquery.atomic.QNm)7 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)6 OutputStream (java.io.OutputStream)5 SubtreeListener (org.brackit.xquery.node.parser.SubtreeListener)5 AbstractTemporalNode (org.brackit.xquery.xdm.AbstractTemporalNode)5 StreamingOutput (javax.ws.rs.core.StreamingOutput)4 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)4