Search in sources :

Example 31 with DocumentException

use of org.brackit.xquery.xdm.DocumentException 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)

Example 32 with DocumentException

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

the class DBNode method setName.

@Override
public void setName(final QNm name) throws OperationNotSupportedException, DocumentException {
    if (mIsWtx) {
        moveRtx();
        final XdmNodeWriteTrx wtx = (XdmNodeWriteTrx) mRtx;
        if (wtx.isNameNode()) {
            try {
                wtx.setName(name);
            } catch (final SirixException e) {
                throw new DocumentException(e);
            }
        } else {
            throw new DocumentException("Node has no name!");
        }
    } else {
        final XdmNodeWriteTrx wtx = getWtx();
        try {
            wtx.setName(name);
        } 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 33 with DocumentException

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

the class DBStore method create.

@Override
public TemporalCollection<?> create(final String collName, @Nullable final Stream<SubtreeParser> parsers) throws DocumentException {
    if (parsers != null) {
        final DatabaseConfiguration dbConf = new DatabaseConfiguration(mLocation.resolve(collName));
        try {
            Databases.truncateDatabase(dbConf);
            Databases.createDatabase(dbConf);
            final Database database = Databases.openDatabase(dbConf.getFile());
            mDatabases.add(database);
            final ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
            int i = database.listResources().size() + 1;
            try {
                SubtreeParser parser = null;
                while ((parser = parsers.next()) != null) {
                    final SubtreeParser nextParser = parser;
                    final String resourceName = new StringBuilder("resource").append(String.valueOf(i)).toString();
                    pool.submit(() -> {
                        database.createResource(ResourceConfiguration.newBuilder(resourceName, dbConf).storageType(mStorageType).useDeweyIDs(true).useTextCompression(true).buildPathSummary(true).build());
                        try (final ResourceManager resource = database.getResourceManager(new ResourceManagerConfiguration.Builder(resourceName).build());
                            final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx()) {
                            final DBCollection collection = new DBCollection(collName, database);
                            mCollections.put(database, collection);
                            nextParser.parse(new SubtreeBuilder(collection, wtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList()));
                            wtx.commit();
                        }
                        return null;
                    });
                    i++;
                }
            } finally {
                parsers.close();
            }
            pool.shutdown();
            pool.awaitTermination(5, TimeUnit.MINUTES);
            return new DBCollection(collName, database);
        } catch (final SirixRuntimeException | InterruptedException e) {
            throw new DocumentException(e.getCause());
        }
    }
    return null;
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SubtreeListener(org.brackit.xquery.node.parser.SubtreeListener) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) SubtreeParser(org.brackit.xquery.node.parser.SubtreeParser) AbstractTemporalNode(org.brackit.xquery.xdm.AbstractTemporalNode) ResourceManager(org.sirix.api.ResourceManager) SirixRuntimeException(org.sirix.exception.SirixRuntimeException) DocumentException(org.brackit.xquery.xdm.DocumentException) Database(org.sirix.api.Database) ExecutorService(java.util.concurrent.ExecutorService)

Example 34 with DocumentException

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

the class DBStore method drop.

@Override
public void drop(final String name) throws DocumentException {
    final DatabaseConfiguration dbConfig = new DatabaseConfiguration(mLocation.resolve(name));
    if (Databases.existsDatabase(dbConfig)) {
        try {
            Databases.truncateDatabase(dbConfig);
            final Database database = Databases.openDatabase(dbConfig.getFile());
            mDatabases.remove(database);
            mCollections.remove(database);
        } catch (final SirixRuntimeException e) {
            throw new DocumentException(e);
        }
    }
    throw new DocumentException("No collection with the specified name found!");
}
Also used : SirixRuntimeException(org.sirix.exception.SirixRuntimeException) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) DocumentException(org.brackit.xquery.xdm.DocumentException) Database(org.sirix.api.Database)

Example 35 with DocumentException

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

the class SubtreeBuilder method text.

@Override
public void text(final Atomic content) throws DocumentException {
    try {
        processText(content.stringValue());
        mSubtreeProcessor.notifyText(new DBNode(mWtx, mCollection));
    } catch (final SirixException e) {
        throw new DocumentException(e.getCause());
    }
}
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