Search in sources :

Example 11 with DocumentException

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

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

Example 13 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 name) throws DocumentException {
    final DatabaseConfiguration dbConf = new DatabaseConfiguration(mLocation.resolve(name));
    try {
        if (Databases.createDatabase(dbConf)) {
            throw new DocumentException("Document with name %s exists!", name);
        }
        final Database database = Databases.openDatabase(dbConf.getFile());
        mDatabases.add(database);
        final DBCollection collection = new DBCollection(name, database);
        mCollections.put(database, collection);
        return collection;
    } catch (final SirixRuntimeException e) {
        throw new DocumentException(e.getCause());
    }
}
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 14 with DocumentException

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

the class DBStore method lookup.

@Override
public TemporalCollection<?> lookup(final String name) throws DocumentException {
    final DatabaseConfiguration dbConf = new DatabaseConfiguration(mLocation.resolve(name));
    if (Databases.existsDatabase(dbConf)) {
        try {
            final Database database = Databases.openDatabase(dbConf.getFile());
            final Optional<Database> storedCollection = mDatabases.stream().findFirst().filter((Database db) -> db.equals(database));
            if (storedCollection.isPresent()) {
                return mCollections.get(storedCollection.get());
            }
            mDatabases.add(database);
            final DBCollection collection = new DBCollection(name, database);
            mCollections.put(database, collection);
            return collection;
        } catch (final SirixRuntimeException e) {
            throw new DocumentException(e.getCause());
        }
    }
    return null;
}
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 15 with DocumentException

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

the class SubtreeBuilder method attribute.

@Override
public void attribute(final QNm name, final Atomic value) throws DocumentException {
    try {
        mWtx.insertAttribute(name, value.stringValue());
        mWtx.moveToParent();
        mSubtreeProcessor.notifyAttribute(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