Search in sources :

Example 1 with SirixRuntimeException

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

the class CASIndexBuilder method process.

private VisitResult process(final ImmutableNode node) {
    try {
        if (node.getKind() == Kind.TEXT) {
            mRtx.moveTo(node.getParentKey());
        }
        final long PCR = mRtx.isDocumentRoot() ? 0 : mRtx.getNameNode().getPathNodeKey();
        if (mPaths.isEmpty() || mPathSummaryReader.getPCRsForPaths(mPaths).contains(PCR)) {
            final Str strValue = new Str(((ImmutableValueNode) node).getValue());
            boolean isOfType = false;
            try {
                if (mType != Type.STR)
                    AtomicUtil.toType(strValue, mType);
                isOfType = true;
            } catch (final SirixRuntimeException e) {
            }
            if (isOfType) {
                final CASValue value = new CASValue(strValue, mType, PCR);
                final Optional<NodeReferences> textReferences = mAVLTreeWriter.get(value, SearchMode.EQUAL);
                if (textReferences.isPresent()) {
                    setNodeReferences(node, textReferences.get(), value);
                } else {
                    setNodeReferences(node, new NodeReferences(), value);
                }
            }
        }
        mRtx.moveTo(node.getNodeKey());
    } catch (final PathException | SirixIOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return VisitResultType.CONTINUE;
}
Also used : Str(org.brackit.xquery.atomic.Str) SirixRuntimeException(org.sirix.exception.SirixRuntimeException) PathException(org.brackit.xquery.util.path.PathException) CASValue(org.sirix.index.avltree.keyvalue.CASValue) NodeReferences(org.sirix.index.avltree.keyvalue.NodeReferences) SirixIOException(org.sirix.exception.SirixIOException)

Example 2 with SirixRuntimeException

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

the class CASIndexListener method insert.

private void insert(final ValueNode node, final long pathNodeKey) throws SirixIOException {
    final Str strValue = new Str(node.getValue());
    boolean isOfType = false;
    try {
        AtomicUtil.toType(strValue, mType);
        isOfType = true;
    } catch (final SirixRuntimeException e) {
    }
    if (isOfType) {
        final CASValue indexValue = new CASValue(strValue, mType, pathNodeKey);
        final Optional<NodeReferences> textReferences = mAVLTreeWriter.get(indexValue, SearchMode.EQUAL);
        if (textReferences.isPresent()) {
            setNodeReferences(node, textReferences.get(), indexValue);
        } else {
            setNodeReferences(node, new NodeReferences(), indexValue);
        }
    }
}
Also used : Str(org.brackit.xquery.atomic.Str) SirixRuntimeException(org.sirix.exception.SirixRuntimeException) CASValue(org.sirix.index.avltree.keyvalue.CASValue) NodeReferences(org.sirix.index.avltree.keyvalue.NodeReferences)

Example 3 with SirixRuntimeException

use of org.sirix.exception.SirixRuntimeException 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 4 with SirixRuntimeException

use of org.sirix.exception.SirixRuntimeException 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 5 with SirixRuntimeException

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

the class IndexController method serialize.

/**
 * Serialize to an {@link OutputStream}.
 *
 * @param out the {@link OutputStream} to serialize to
 * @throws SirixRuntimeException if an exception occurs during serialization
 */
public void serialize(final OutputStream out) {
    try {
        final SubtreePrinter serializer = new SubtreePrinter(new PrintStream(checkNotNull(out)));
        serializer.print(mIndexes.materialize());
        serializer.end();
    } catch (final DocumentException e) {
        throw new SirixRuntimeException(e);
    }
}
Also used : SirixRuntimeException(org.sirix.exception.SirixRuntimeException) SubtreePrinter(org.brackit.xquery.util.serialize.SubtreePrinter) PrintStream(java.io.PrintStream) DocumentException(org.brackit.xquery.xdm.DocumentException)

Aggregations

SirixRuntimeException (org.sirix.exception.SirixRuntimeException)8 DocumentException (org.brackit.xquery.xdm.DocumentException)5 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)5 Database (org.sirix.api.Database)5 Str (org.brackit.xquery.atomic.Str)2 CASValue (org.sirix.index.avltree.keyvalue.CASValue)2 NodeReferences (org.sirix.index.avltree.keyvalue.NodeReferences)2 PrintStream (java.io.PrintStream)1 ExecutorService (java.util.concurrent.ExecutorService)1 SubtreeListener (org.brackit.xquery.node.parser.SubtreeListener)1 SubtreeParser (org.brackit.xquery.node.parser.SubtreeParser)1 PathException (org.brackit.xquery.util.path.PathException)1 SubtreePrinter (org.brackit.xquery.util.serialize.SubtreePrinter)1 AbstractTemporalNode (org.brackit.xquery.xdm.AbstractTemporalNode)1 Ignore (org.junit.Ignore)1 ResourceManager (org.sirix.api.ResourceManager)1 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)1 SirixIOException (org.sirix.exception.SirixIOException)1