Search in sources :

Example 1 with SubtreeListener

use of org.brackit.xquery.node.parser.SubtreeListener 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 2 with SubtreeListener

use of org.brackit.xquery.node.parser.SubtreeListener in project sirix by sirixdb.

the class DBNode method prepend.

private DBNode prepend(XdmNodeWriteTrx wtx, Node<?> child) throws DocumentException {
    try {
        SubtreeBuilder builder = null;
        if (wtx.hasFirstChild()) {
            wtx.moveToFirstChild();
            builder = new SubtreeBuilder(mCollection, wtx, Insert.ASLEFTSIBLING, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
        } else {
            builder = new SubtreeBuilder(mCollection, wtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
        }
        child.parse(builder);
        wtx.moveTo(builder.getStartNodeKey());
    } catch (final SirixException e) {
        throw new DocumentException(e);
    }
    return new DBNode(wtx, mCollection);
}
Also used : 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 3 with SubtreeListener

use of org.brackit.xquery.node.parser.SubtreeListener in project sirix by sirixdb.

the class DBNode method prepend.

private DBNode prepend(XdmNodeWriteTrx wtx, SubtreeParser parser) throws DocumentException {
    try {
        parser.parse(new SubtreeBuilder(mCollection, wtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList()));
        moveRtx();
        wtx.moveToFirstChild();
    } catch (final SirixException e) {
        throw new DocumentException(e);
    }
    return new DBNode(wtx, mCollection);
}
Also used : 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 4 with SubtreeListener

use of org.brackit.xquery.node.parser.SubtreeListener in project sirix by sirixdb.

the class DBNode method createBuilder.

private SubtreeBuilder createBuilder(final XdmNodeWriteTrx wtx) throws DocumentException {
    SubtreeBuilder builder = null;
    try {
        if (wtx.hasLeftSibling()) {
            wtx.moveToLeftSibling();
            builder = new SubtreeBuilder(mCollection, wtx, Insert.ASRIGHTSIBLING, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
        } else {
            wtx.moveToParent();
            builder = new SubtreeBuilder(mCollection, wtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
        }
    } catch (final SirixException e) {
        throw new DocumentException(e);
    }
    return builder;
}
Also used : 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 SubtreeListener

use of org.brackit.xquery.node.parser.SubtreeListener in project sirix by sirixdb.

the class DBStore method create.

public TemporalCollection<?> create(final String collName, final Optional<String> optResName, final SubtreeParser parser) throws DocumentException {
    final DatabaseConfiguration dbConf = new DatabaseConfiguration(mLocation.resolve(collName));
    try {
        Databases.truncateDatabase(dbConf);
        Databases.createDatabase(dbConf);
        try (final Database database = Databases.openDatabase(dbConf.getFile())) {
            mDatabases.add(database);
            final String resName = optResName.isPresent() ? optResName.get() : new StringBuilder(3).append("resource").append(database.listResources().size() + 1).toString();
            database.createResource(ResourceConfiguration.newBuilder(resName, dbConf).useDeweyIDs(true).useTextCompression(true).buildPathSummary(true).storageType(mStorageType).build());
            final DBCollection collection = new DBCollection(collName, database);
            mCollections.put(database, collection);
            try (final ResourceManager resource = database.getResourceManager(new ResourceManagerConfiguration.Builder(resName).build());
                final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx()) {
                parser.parse(new SubtreeBuilder(collection, wtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList()));
                wtx.commit();
            }
            return collection;
        }
    } catch (final SirixException e) {
        throw new DocumentException(e.getCause());
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SubtreeListener(org.brackit.xquery.node.parser.SubtreeListener) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) AbstractTemporalNode(org.brackit.xquery.xdm.AbstractTemporalNode) ResourceManager(org.sirix.api.ResourceManager) DocumentException(org.brackit.xquery.xdm.DocumentException) Database(org.sirix.api.Database) SirixException(org.sirix.exception.SirixException)

Aggregations

SubtreeListener (org.brackit.xquery.node.parser.SubtreeListener)7 AbstractTemporalNode (org.brackit.xquery.xdm.AbstractTemporalNode)7 DocumentException (org.brackit.xquery.xdm.DocumentException)7 SirixException (org.sirix.exception.SirixException)6 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)4 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)2 Database (org.sirix.api.Database)2 ResourceManager (org.sirix.api.ResourceManager)2 ExecutorService (java.util.concurrent.ExecutorService)1 SubtreeParser (org.brackit.xquery.node.parser.SubtreeParser)1 SirixRuntimeException (org.sirix.exception.SirixRuntimeException)1