Search in sources :

Example 46 with SirixException

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;
}
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 47 with SirixException

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);
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) SirixException(org.sirix.exception.SirixException) SunburstContainer(org.sirix.gui.view.sunburst.SunburstContainer)

Example 48 with SirixException

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;
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SirixException(org.sirix.exception.SirixException) ResourceManager(org.sirix.api.ResourceManager)

Example 49 with SirixException

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());
    }
}
Also used : Path(java.nio.file.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException) ResourceManager(org.sirix.api.ResourceManager)

Example 50 with SirixException

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;
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) CollectionParser(org.brackit.xquery.node.parser.CollectionParser) SubtreeHandler(org.brackit.xquery.node.parser.SubtreeHandler) SirixException(org.sirix.exception.SirixException) ResourceManager(org.sirix.api.ResourceManager)

Aggregations

SirixException (org.sirix.exception.SirixException)74 DocumentException (org.brackit.xquery.xdm.DocumentException)25 IOException (java.io.IOException)18 Database (org.sirix.api.Database)17 JaxRxException (org.jaxrx.core.JaxRxException)14 NodeReadTrx (org.sirix.api.NodeReadTrx)13 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)13 SessionConfiguration (org.sirix.access.conf.SessionConfiguration)12 Session (org.sirix.api.Session)12 ResourceManager (org.sirix.api.ResourceManager)10 WebApplicationException (javax.ws.rs.WebApplicationException)8 Path (java.nio.file.Path)7 XMLStreamException (javax.xml.stream.XMLStreamException)7 QNm (org.brackit.xquery.atomic.QNm)7 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)6 OutputStream (java.io.OutputStream)5 SubtreeListener (org.brackit.xquery.node.parser.SubtreeListener)5 AbstractTemporalNode (org.brackit.xquery.xdm.AbstractTemporalNode)5 StreamingOutput (javax.ws.rs.core.StreamingOutput)4 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)4