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