use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class TraverseCompareTree method call.
@Override
public Void call() {
final long startTime = System.nanoTime();
LOGWRAPPER.debug("Build sunburst items.");
try {
firePropertyChange("progress", null, 0);
// Invoke diff.
LOGWRAPPER.debug("CountDownLatch: " + mStart.getCount());
POOL.submit(new Callable<Void>() {
@Override
public Void call() throws SirixException {
DiffOptimized optimized = DiffOptimized.NO;
if (mPrune == Pruning.DIFF || mPrune == Pruning.DIFF_WITHOUT_SAMEHASHES) {
optimized = DiffOptimized.HASHED;
}
DiffFactory.invokeStructuralDiff(new DiffFactory.Builder(mDb.getSession(), mNewRevision, mOldRtx.getRevisionNumber(), optimized, ImmutableSet.of(mObserver)).setNewDepth(mDepth).setOldDepth(mDepth).setNewStartKey(mNewStartKey).setOldStartKey(mOldStartKey));
return null;
}
});
if (PROCESSORS == 2) {
final ExecutorService pool = Executors.newSingleThreadExecutor();
mDepthMax = pool.submit(new Callable<Integer>() {
@Override
public Integer call() {
// Maximum depth in old revision.
return getDepthMax();
}
}).get();
pool.shutdown();
} else {
mDepthMax = POOL.submit(new Callable<Integer>() {
@Override
public Integer call() {
// Maximum depth in old revision.
return getDepthMax();
}
}).get();
}
// Wait for diff list to complete.
final boolean done = mStart.await(TIMEOUT_S, TimeUnit.SECONDS);
if (!done) {
LOGWRAPPER.error("Diff failed - Timeout occured after " + TIMEOUT_S + " seconds!");
}
final int size = mDiffs.size();
if (mEntries > DIFF_THRESHOLD) {
final int mapSize = mDiffDatabase.getMap().size();
LOGWRAPPER.debug("mapSize: " + mapSize);
}
LOGWRAPPER.debug("size: " + size);
int i = 0;
if (mMoveDetection) {
detectMoves();
}
i = 0;
final Map<Integer, DiffTuple> diffs = mEntries > DIFF_THRESHOLD ? mDiffDatabase.getMap() : mDiffs;
firePropertyChange("diffs", null, diffs);
for (mAxis = new DiffSunburstAxis(IncludeSelf.YES, this, mNewRtx, mOldRtx, diffs, mDepthMax, mDepth, mPrune); mAxis.hasNext(); i++) {
mAxis.next();
if (mCompare == ECompare.SINGLEINCREMENTAL) {
final int progress = (int) ((i / (float) size) * 100);
firePropertyChange("progress", null, progress);
}
}
} catch (final InterruptedException | ExecutionException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
try {
mOldRtx.close();
mNewRtx.close();
} catch (final SirixException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
LOGWRAPPER.info(mItems.size() + " SunburstItems created!");
LOGWRAPPER.debug("oldMaxDepth: " + mDepthMax);
mLock.acquireUninterruptibly();
// Order of property changes is significant.
firePropertyChange("oldRev", null, mOldRevision);
firePropertyChange("newRev", null, mNewRevision);
firePropertyChange("oldmaxdepth", null, mDepthMax);
firePropertyChange("maxDepth", null, mNewDepthMax);
firePropertyChange("items", null, mItems);
firePropertyChange("updated", null, mHasUpdatedNodes);
firePropertyChange("revision", null, mNewRevision);
firePropertyChange("done", null, true);
firePropertyChange("progress", null, 100);
LOGWRAPPER.debug("Property changes sent!");
// Lock is released in the controller.
// mDiffDatabase.close();
final long endTime = System.nanoTime();
System.out.println((endTime - startTime) * 1e-6 / 1000);
return null;
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class SunburstModel method traverseTree.
@Override
public void traverseTree(@Nonnull final Container<SunburstContainer> pContainer) {
final SunburstContainer container = (SunburstContainer) checkNotNull(pContainer);
checkArgument(container.getNewStartKey() >= 0);
checkArgument(container.getOldStartKey() >= 0);
final ExecutorService executor = Executors.newSingleThreadExecutor();
try {
executor.submit(new TraverseTree(container.getNewStartKey(), container.getPruning(), container.getGUI(), this));
} catch (final SirixException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
shutdown(executor);
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class DBCollection method add.
public DBNode add(final String resourceName, final XMLEventReader reader) throws OperationNotSupportedException, DocumentException {
try {
mDatabase.createResource(ResourceConfiguration.newBuilder(resourceName, mDatabase.getDatabaseConfig()).useDeweyIDs(true).build());
final ResourceManager resource = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resourceName).build());
final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx();
wtx.insertSubtreeAsFirstChild(reader);
wtx.moveToDocumentRoot();
return new DBNode(wtx, this);
} 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 getDocument.
@Override
public DBNode getDocument(@Nonnegative final int revision) throws DocumentException {
final List<Path> resources = mDatabase.listResources();
if (resources.size() > 1) {
throw new DocumentException("More than one document stored in database/collection!");
}
try {
final ResourceManager session = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resources.get(0).getFileName().toString()).build());
final int version = revision == -1 ? session.getMostRecentRevisionNumber() : revision;
final XdmNodeReadTrx rtx = session.beginNodeReadTrx(version);
return new DBNode(rtx, this);
} catch (final SirixException e) {
throw new DocumentException(e.getCause());
}
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class DBCollection method add.
public DBNode add(final String resName, SubtreeParser parser) throws OperationNotSupportedException, DocumentException {
try {
final String resource = new StringBuilder(2).append("resource").append(mDatabase.listResources().size() + 1).toString();
mDatabase.createResource(ResourceConfiguration.newBuilder(resource, mDatabase.getDatabaseConfig()).useDeweyIDs(true).useTextCompression(true).buildPathSummary(true).build());
final ResourceManager manager = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resource).build());
final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx();
final SubtreeHandler handler = new SubtreeBuilder(this, wtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
// Make sure the CollectionParser is used.
if (!(parser instanceof CollectionParser)) {
parser = new CollectionParser(parser);
}
parser.parse(handler);
return new DBNode(wtx, this);
} catch (final SirixException e) {
LOGGER.error(e.getMessage(), e);
return null;
}
}
Aggregations