use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class DatabaseImpl method createResource.
// //////////////////////////////////////////////////////////
// START Creation/Deletion of Resources /////////////////////
// //////////////////////////////////////////////////////////
@Override
public synchronized boolean createResource(final ResourceConfiguration resConfig) {
boolean returnVal = true;
final Path path = mDBConfig.getFile().resolve(DatabaseConfiguration.DatabasePaths.DATA.getFile()).resolve(resConfig.mPath);
// If file is existing, skip.
if (Files.exists(path)) {
return false;
} else {
try {
Files.createDirectory(path);
} catch (UnsupportedOperationException | IOException | SecurityException e) {
returnVal = false;
}
if (returnVal) {
// Creation of the folder structure.
try {
for (final ResourceConfiguration.ResourcePaths resourcePath : ResourceConfiguration.ResourcePaths.values()) {
final Path toCreate = path.resolve(resourcePath.getFile());
if (resourcePath.isFolder()) {
Files.createDirectory(toCreate);
} else {
returnVal = ResourceConfiguration.ResourcePaths.INDEXES.getFile().equals(resourcePath.getFile()) ? true : Files.createFile(toCreate) != null;
}
if (!returnVal)
break;
}
} catch (UnsupportedOperationException | IOException | SecurityException e) {
returnVal = false;
}
}
}
if (returnVal) {
// If everything was correct so far, initialize storage.
// Serialization of the config.
mResourceID.set(mDBConfig.getMaxResourceID());
ResourceConfiguration.serialize(resConfig.setID(mResourceID.getAndIncrement()));
mDBConfig.setMaximumResourceID(mResourceID.get());
mResources.forcePut(mResourceID.get(), resConfig.getResource().getFileName().toString());
try {
try (final ResourceManager resourceTrxManager = this.getResourceManager(new ResourceManagerConfiguration.Builder(resConfig.getResource().getFileName().toString()).build());
final XdmNodeWriteTrx wtx = resourceTrxManager.beginNodeWriteTrx()) {
wtx.commit();
}
} catch (final SirixException e) {
LOGWRAPPER.error(e.getMessage(), e);
returnVal = false;
}
}
if (!returnVal) {
// If something was not correct, delete the partly created substructure.
SirixFiles.recursiveRemove(resConfig.mPath);
}
return returnVal;
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class FMSE method diff.
@Override
public void diff(final XdmNodeWriteTrx wtx, final XdmNodeReadTrx rtx) throws SirixException {
mWtx = checkNotNull(wtx);
mRtx = checkNotNull(rtx);
mOldStartKey = mWtx.getNodeKey();
mNewStartKey = mRtx.getNodeKey();
mDescendantsOldRev = new HashMap<>();
mDescendantsNewRev = new HashMap<>();
mInOrderOldRev = new HashMap<>();
mInOrderNewRev = new HashMap<>();
mAlreadyInserted = new HashMap<>();
mOldRevVisitor = new FMSEVisitor(mWtx, mInOrderOldRev, mDescendantsOldRev);
mNewRevVisitor = new FMSEVisitor(mRtx, mInOrderNewRev, mDescendantsNewRev);
mLabelOldRevVisitor = new LabelFMSEVisitor(mWtx);
mLabelNewRevVisitor = new LabelFMSEVisitor(mRtx);
init(mWtx, mOldRevVisitor);
init(mRtx, mNewRevVisitor);
mFastMatching = fastMatch(mWtx, mRtx);
mTotalMatching = new Matching(mFastMatching);
firstFMESStep(mWtx, mRtx);
try {
secondFMESStep(mWtx, mRtx);
} catch (final SirixException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class DocumentWrapper method selectID.
@Override
public NodeInfo selectID(final String ID, final boolean getParent) {
try {
final NodeReadTrx rtx = mSession.beginNodeReadTrx();
final Axis axis = new DescendantAxis(rtx, IncludeSelf.YES);
while (axis.hasNext()) {
if (rtx.getKind() == Kind.ELEMENT) {
final int attCount = rtx.getAttributeCount();
if (attCount > 0) {
final long nodeKey = rtx.getNodeKey();
for (int index = 0; index < attCount; index++) {
rtx.moveToAttribute(index);
if ("xml:id".equalsIgnoreCase(rtx.getName().getLocalName()) && ID.equals(rtx.getValue())) {
if (getParent) {
rtx.moveToParent();
}
return new NodeWrapper(this, rtx.getNodeKey());
}
rtx.moveTo(nodeKey);
}
}
}
axis.next();
}
rtx.close();
} catch (final SirixException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
return null;
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class NodeWrapper method getParent.
@Override
public NodeInfo getParent() {
try {
NodeInfo parent = null;
final NodeReadTrx rtx = createRtxAndMove();
if (rtx.hasParent()) {
// Parent transaction.
parent = new NodeWrapper(mDocWrapper, rtx.getParentKey());
}
rtx.close();
return parent;
} catch (final SirixException e) {
LOGGER.error(e.getMessage(), e);
return null;
}
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class DBCollection method getDocuments.
@Override
public Stream<DBNode> getDocuments(final boolean updatable) throws DocumentException {
final List<Path> resources = mDatabase.listResources();
final List<DBNode> documents = new ArrayList<>(resources.size());
for (final Path resourcePath : resources) {
try {
final String resourceName = resourcePath.getFileName().toString();
final ResourceManager resource = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resourceName).build());
final XdmNodeReadTrx trx = updatable ? resource.beginNodeWriteTrx() : resource.beginNodeReadTrx();
documents.add(new DBNode(trx, this));
} catch (final SirixException e) {
throw new DocumentException(e.getCause());
}
}
return new ArrayStream<DBNode>(documents.toArray(new DBNode[documents.size()]));
}
Aggregations