Search in sources :

Example 1 with Indexes

use of org.sirix.index.Indexes 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)

Aggregations

FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DocumentException (org.brackit.xquery.xdm.DocumentException)1 SirixException (org.sirix.exception.SirixException)1 SirixIOException (org.sirix.exception.SirixIOException)1 IndexDef (org.sirix.index.IndexDef)1 Indexes (org.sirix.index.Indexes)1