use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class HierarchyFileVisitor method visitFile.
/**
* <p>
* Inserts a {@code file-element} with a {@code name-attribute} for the file which is visited.
* </p>
* <p>
* An optional visitor can be used to add further attributes or metadata. The sirix
* {@link XdmNodeWriteTrx} is located on the new directory before and after using a pluggable
* visitor.
* </p>
*
* @throws NullPointerException if {@code pDir} or {@code pAttrs} is {@code null}
*/
@Override
public FileVisitResult visitFile(final Path pFile, final BasicFileAttributes pAttrs) throws IOException {
checkNotNull(pFile);
checkNotNull(pAttrs);
try {
if (Files.isRegularFile(pFile) | Files.isSymbolicLink(pFile)) {
mIndex.put(pFile, org.sirix.fs.FileSystemPath.ISFILE);
processEmptyElement(new QNm("file"));
mWtx.insertAttribute(new QNm("name"), pFile.getFileName().toString());
mWtx.moveToParent();
final long nodeKey = mWtx.getNodeKey();
processFile(mVisitor, mWtx, pFile, pAttrs);
mWtx.moveTo(nodeKey);
}
} catch (SirixException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
return FileVisitResult.CONTINUE;
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class HierarchyFileVisitor method preVisitDirectory.
/**
* <p>
* Invoked for a directory before directory contents are visited.
* </p>
* <p>
* Inserts a {@code dir-element} with a {@code name-attribute} for the directory to visit.
* </p>
* <p>
* An optional visitor can be used to add further attributes or metadata. The sirix
* {@link XdmNodeWriteTrx} is located on the new directory before and after using a pluggable
* visitor.
* </p>
*
* @throws NullPointerException if {@code pDir} or {@code pAttrs} is {@code null}
*/
@Override
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
checkNotNull(dir);
checkNotNull(attrs);
try {
mIndex.put(dir, org.sirix.fs.FileSystemPath.ISDIRECTORY);
processStartTag(new QNm("dir"));
mWtx.insertAttribute(new QNm("name"), dir.getFileName().toString());
mWtx.moveToParent();
final long nodeKey = mWtx.getNodeKey();
processDirectory(mVisitor, mWtx, dir, attrs);
mWtx.moveTo(nodeKey);
} catch (SirixException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
return FileVisitResult.CONTINUE;
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class DeleteFMSEVisitor method visit.
@Override
public VisitResult visit(final ImmutableElement node) {
final Long partner = mMatching.partner(node.getNodeKey());
if (partner == null) {
VisitResult retVal = delete(node);
if (node.getNodeKey() == mStartKey) {
retVal = VisitResultType.TERMINATE;
}
return retVal;
} else {
mWtx.moveTo(node.getNodeKey());
final long nodeKey = node.getNodeKey();
final List<Long> keysToDelete = new ArrayList<>(mWtx.getAttributeCount() + mWtx.getNamespaceCount());
for (int i = 0, attCount = mWtx.getAttributeCount(); i < attCount; i++) {
mWtx.moveToAttribute(i);
final long attNodeKey = mWtx.getNodeKey();
if (mMatching.partner(attNodeKey) == null) {
keysToDelete.add(attNodeKey);
}
mWtx.moveTo(nodeKey);
}
for (int i = 0, nspCount = mWtx.getNamespaceCount(); i < nspCount; i++) {
mWtx.moveToNamespace(i);
final long namespNodeKey = mWtx.getNodeKey();
if (mMatching.partner(namespNodeKey) == null) {
keysToDelete.add(namespNodeKey);
}
mWtx.moveTo(nodeKey);
}
for (final long keyToDelete : keysToDelete) {
mWtx.moveTo(keyToDelete);
try {
mWtx.remove();
} catch (final SirixException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
}
mWtx.moveTo(nodeKey);
return VisitResultType.CONTINUE;
}
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class ModificationVisitor method modify.
/**
* Determines if a node must be modified. If yes, it is deleted and {@code true} is returned. If
* it must not be deleted {@code false} is returned. The transaction is moved accordingly in case
* of a remove-operation such that the {@link DescendantAxis} can move to the next node after a
* delete occurred.
*
* @param node the node to check and possibly delete
* @return {@code true} if node has been deleted, {@code false} otherwise
*/
private VisitResult modify(final ImmutableNode node) {
assert node != null;
if (mNodeIndex % MODIFY_EVERY == 0) {
mNodeIndex = 1;
try {
switch(mRandom.nextInt(4)) {
case 0:
final QNm insert = new QNm("testInsert");
final long key = mWtx.getNodeKey();
mWtx.insertElementAsLeftSibling(insert);
boolean moved = mWtx.moveTo(key).hasMoved();
assert moved;
return VisitResultType.CONTINUE;
case 1:
if (mWtx.getKind() == Kind.TEXT) {
mWtx.setValue("testUpdate");
} else if (mWtx.getKind() == Kind.ELEMENT) {
mWtx.setName(new QNm("testUpdate"));
}
return VisitResultType.CONTINUE;
case 2:
return delete();
case 3:
mWtx.replaceNode("<foo/>");
return VisitResultType.CONTINUE;
}
} catch (final SirixException | IOException | XMLStreamException e) {
LOGWRAPPER.error(e.getMessage(), e);
return VisitResultType.TERMINATE;
}
} else {
mNodeIndex++;
return VisitResultType.CONTINUE;
}
return VisitResultType.CONTINUE;
}
Aggregations