Search in sources :

Example 6 with DiffTuple

use of org.sirix.diff.DiffTuple in project sirix by sirixdb.

the class TraverseCompareTree method detectMoves.

/**
 * Detect moves.
 */
private void detectMoves() {
    // berkeleydb database.
    if (mDiffs.size() <= DIFF_THRESHOLD) {
        for (final DiffTuple diffCont : mDiffs.values()) {
            final Integer newIndex = mNewKeys.get(diffCont.getOldNodeKey());
            if (newIndex != null && (diffCont.getDiff() == DiffType.DELETED || diffCont.getDiff() == DiffType.MOVEDFROM)) {
                LOGWRAPPER.debug("new node key: " + mDiffs.get(newIndex).getNewNodeKey());
                mDiffs.get(newIndex).setDiff(DiffType.MOVEDTO);
            }
            final Integer oldIndex = mOldKeys.get(diffCont.getNewNodeKey());
            if (oldIndex != null && (diffCont.getDiff() == DiffType.INSERTED || diffCont.getDiff() == DiffType.MOVEDTO)) {
                mDiffs.get(oldIndex).setDiff(DiffType.MOVEDFROM).setIndex(mNewKeys.get(diffCont.getNewNodeKey()));
            }
        }
    }
}
Also used : DiffTuple(org.sirix.diff.DiffTuple)

Example 7 with DiffTuple

use of org.sirix.diff.DiffTuple 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;
}
Also used : DiffOptimized(org.sirix.diff.DiffFactory.DiffOptimized) DiffSunburstAxis(org.sirix.gui.view.sunburst.axis.DiffSunburstAxis) DiffTuple(org.sirix.diff.DiffTuple) ExecutorService(java.util.concurrent.ExecutorService) SirixException(org.sirix.exception.SirixException) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with DiffTuple

use of org.sirix.diff.DiffTuple in project sirix by sirixdb.

the class Modifications method countDiffs.

/**
 * Count how many differences in the subtree exists and add descendant-or-self
 * count.
 *
 * @return number of differences and descendants
 * @throws SirixException
 *           if sirix can't close the transaction
 */
public Modification countDiffs() throws SirixException {
    int index = mIndex;
    final DiffTuple diffCont = mDiffs.get(index);
    final DiffType diff = diffCont.getDiff();
    final int rootDepth = (diff == DiffType.DELETED || diff == DiffType.MOVEDFROM || diff == DiffType.REPLACEDOLD) ? diffCont.getDepth().getOldDepth() : diffCont.getDepth().getNewDepth();
    int diffCounts = 0;
    int descendantCounts = 1;
    boolean subtract = false;
    diffCounts = incrDiffCounter(index, diffCounts);
    index++;
    if (diffCounts == 1 && index < mDiffs.size()) {
        final DiffTuple cont = mDiffs.get(index);
        final int depth = (cont.getDiff() == DiffType.DELETED || cont.getDiff() == DiffType.MOVEDFROM || cont.getDiff() == DiffType.REPLACEDOLD) ? cont.getDepth().getOldDepth() : cont.getDepth().getNewDepth();
        if (depth == rootDepth + 1) {
            // Current node is modified and has at least one child.
            subtract = true;
        }
    }
    boolean done = false;
    while (!done && index < mDiffs.size()) {
        final DiffTuple currDiffCont = mDiffs.get(index);
        final DiffType currDiff = currDiffCont.getDiff();
        final DiffDepth currDepth = currDiffCont.getDepth();
        final int depth = (currDiff == DiffType.DELETED || currDiff == DiffType.MOVEDFROM || currDiff == DiffType.REPLACEDOLD) ? currDepth.getOldDepth() : currDepth.getNewDepth();
        if (depth <= rootDepth) {
            done = true;
        }
        if (!done) {
            descendantCounts++;
            if (currDiff != DiffType.SAME && currDiff != DiffType.SAMEHASH) {
                diffCounts++;
            }
            index++;
        }
    }
    // Add a factor to add some weighting to the diffCounts.
    return new Modification(TraverseModel.FACTOR * diffCounts, descendantCounts, subtract);
}
Also used : DiffTuple(org.sirix.diff.DiffTuple) DiffType(org.sirix.diff.DiffFactory.DiffType) DiffDepth(org.sirix.diff.DiffDepth)

Example 9 with DiffTuple

use of org.sirix.diff.DiffTuple in project sirix by sirixdb.

the class DiffSunburstAxis method setTempKey.

/**
 * Set temporal key which is the next following node of an {@code inserted},
 * {@code deleted}, {@code updated} or {@code same} node.
 */
private void setTempKey() {
    final int index = mIndex + mPrunedNodes + mDescendantCount;
    final boolean isOldTransaction = (mDiff == DiffType.DELETED || mDiff == DiffType.MOVEDFROM || mDiff == DiffType.REPLACEDOLD);
    final DiffDepth depthCont = mDiffCont.getDepth();
    final int depth = isOldTransaction ? depthCont.getOldDepth() : depthCont.getNewDepth();
    if (index < mSize) {
        DiffTuple nextDiffCont = mDiffs.get(index);
        DiffType nextDiff = nextDiffCont.getDiff();
        boolean nextIsOldTransaction = (nextDiff == DiffType.DELETED || nextDiff == DiffType.MOVEDFROM || nextDiff == DiffType.REPLACEDOLD);
        DiffDepth nextDepthCont = nextDiffCont.getDepth();
        int nextDepth = nextIsOldTransaction ? nextDepthCont.getOldDepth() : nextDepthCont.getNewDepth();
        assert nextDepth <= depth;
        mTempKey = nextIsOldTransaction ? nextDiffCont.getOldNodeKey() : nextDiffCont.getNewNodeKey();
    }
}
Also used : DiffTuple(org.sirix.diff.DiffTuple) DiffDepth(org.sirix.diff.DiffDepth) DiffType(org.sirix.diff.DiffFactory.DiffType)

Aggregations

DiffTuple (org.sirix.diff.DiffTuple)9 DiffType (org.sirix.diff.DiffFactory.DiffType)7 DiffDepth (org.sirix.diff.DiffDepth)4 ExecutionException (java.util.concurrent.ExecutionException)3 SirixException (org.sirix.exception.SirixException)2 DatabaseException (com.sleepycat.je.DatabaseException)1 ExecutorService (java.util.concurrent.ExecutorService)1 QNm (org.brackit.xquery.atomic.QNm)1 NodeReadTrx (org.sirix.api.NodeReadTrx)1 DiffOptimized (org.sirix.diff.DiffFactory.DiffOptimized)1 NodeRelations (org.sirix.gui.view.sunburst.NodeRelations)1 SunburstItem (org.sirix.gui.view.sunburst.SunburstItem)1 EStructType (org.sirix.gui.view.sunburst.SunburstItem.EStructType)1 DiffSunburstAxis (org.sirix.gui.view.sunburst.axis.DiffSunburstAxis)1