Search in sources :

Example 21 with DocumentException

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

the class IndexController method containsIndex.

/**
 * Determines if an index of the specified type is available.
 *
 * @param type type of index to lookup
 * @param resourceManager the {@link ResourceManager} this index controller is bound to
 * @return {@code true} if an index of the specified type exists, {@code false} otherwise
 * @throws SirixIOException if an I/O exception occurs while deserializing the index configuration
 *         for the specified {@code revision}
 */
public boolean containsIndex(final IndexType type, final ResourceManager resourceManager, final int revision) throws SirixIOException {
    final Indexes indexes = new Indexes();
    final java.nio.file.Path indexesFile = resourceManager.getResourceConfig().mPath.resolve(ResourceConfiguration.ResourcePaths.INDEXES.getFile() + String.valueOf(revision) + ".xml");
    try {
        if (Files.exists(indexesFile) && Files.size(indexesFile) > 0) {
            try (final InputStream in = new FileInputStream(indexesFile.toFile())) {
                indexes.init(deserialize(in).getFirstChild());
            }
        }
    } catch (IOException | DocumentException | SirixException e) {
        throw new SirixIOException("Index definitions couldn't be deserialized!", e);
    }
    for (final IndexDef indexDef : indexes.getIndexDefs()) {
        if (indexDef.getType() == type)
            return true;
    }
    return false;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException) SirixIOException(org.sirix.exception.SirixIOException) IOException(java.io.IOException) Indexes(org.sirix.index.Indexes) SirixIOException(org.sirix.exception.SirixIOException) IndexDef(org.sirix.index.IndexDef) FileInputStream(java.io.FileInputStream)

Example 22 with DocumentException

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

the class IndexController method deserialize.

/**
 * Deserialize from an {@link InputStream}.
 *
 * @param out the {@link InputStream} from which to deserialize the XML fragment
 * @throws SirixException if an exception occurs during serialization
 */
public Node<?> deserialize(final InputStream in) throws SirixException {
    try {
        final DocumentParser parser = new DocumentParser(in);
        final D2NodeBuilder builder = new D2NodeBuilder();
        parser.parse(builder);
        return builder.root();
    } catch (final DocumentException e) {
        throw new SirixException(e);
    }
}
Also used : DocumentParser(org.brackit.xquery.node.parser.DocumentParser) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException) D2NodeBuilder(org.brackit.xquery.node.d2linked.D2NodeBuilder)

Example 23 with DocumentException

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

Example 24 with DocumentException

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

the class Indexes method init.

@Override
public synchronized void init(final Node<?> root) throws DocumentException {
    final QNm name = root.getName();
    if (!INDEXES_TAG.equals(name)) {
        throw new DocumentException("Expected tag '%s' but found '%s'", INDEXES_TAG, name);
    }
    final Stream<? extends Node<?>> children = root.getChildren();
    try {
        Node<?> child;
        while ((child = children.next()) != null) {
            QNm childName = child.getName();
            if (!childName.equals(IndexDef.INDEX_TAG)) {
                throw new DocumentException("Expected tag '%s' but found '%s'", IndexDef.INDEX_TAG, childName);
            }
            final IndexDef indexDefinition = new IndexDef();
            indexDefinition.init(child);
            mIndexes.add(indexDefinition);
        }
    } finally {
        children.close();
    }
}
Also used : QNm(org.brackit.xquery.atomic.QNm) DocumentException(org.brackit.xquery.xdm.DocumentException)

Example 25 with DocumentException

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

the class IndexDef method init.

@Override
public void init(Node<?> root) throws DocumentException {
    QNm name = root.getName();
    if (!name.equals(INDEX_TAG)) {
        throw new DocumentException("Expected tag '%s' but found '%s'", INDEX_TAG, name);
    }
    Node<?> attribute;
    attribute = root.getAttribute(ID_ATTRIBUTE);
    if (attribute != null) {
        mID = Integer.valueOf(attribute.getValue().stringValue());
    }
    attribute = root.getAttribute(TYPE_ATTRIBUTE);
    if (attribute != null) {
        mType = (IndexType.valueOf(attribute.getValue().stringValue()));
    }
    attribute = root.getAttribute(CONTENT_TYPE_ATTRIBUTE);
    if (attribute != null) {
        mContentType = (resolveType(attribute.getValue().stringValue()));
    }
    attribute = root.getAttribute(UNIQUE_ATTRIBUTE);
    if (attribute != null) {
        mUnique = (Boolean.valueOf(attribute.getValue().stringValue()));
    }
    final Stream<? extends Node<?>> children = root.getChildren();
    try {
        Node<?> child;
        while ((child = children.next()) != null) {
            // if (child.getName().equals(IndexStatistics.STATISTICS_TAG)) {
            // indexStatistics = new IndexStatistics();
            // indexStatistics.init(child);
            // } else {
            QNm childName = child.getName();
            String value = child.getValue().stringValue();
            if (childName.equals(PATH_TAG)) {
                final String path = value;
                mPaths.add(Path.parse(path));
            } else if (childName.equals(INCLUDING_TAG)) {
                for (final String s : value.split(",")) {
                    if (s.length() > 0) {
                        mIncluded.add(new QNm(s));
                    // String includeString = s;
                    // String[] tmp = includeString.split("@");
                    // included.put(new QNm(tmp[0]),
                    // Cluster.valueOf(tmp[1]));
                    }
                }
            } else if (childName.equals(EXCLUDING_TAG)) {
                for (final String s : value.split(",")) {
                    if (s.length() > 0)
                        mExcluded.add(new QNm(s));
                }
            }
        // }
        }
    } finally {
        children.close();
    }
}
Also used : QNm(org.brackit.xquery.atomic.QNm) DocumentException(org.brackit.xquery.xdm.DocumentException)

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