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;
}
Aggregations