Search in sources :

Example 16 with SirixException

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;
}
Also used : Path(java.nio.file.Path) XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SirixException(org.sirix.exception.SirixException) SirixIOException(org.sirix.exception.SirixIOException) IOException(java.io.IOException) ResourceManager(org.sirix.api.ResourceManager) ResourceConfiguration(org.sirix.access.conf.ResourceConfiguration)

Example 17 with SirixException

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);
    }
}
Also used : SirixException(org.sirix.exception.SirixException) DeleteFMSEVisitor(org.sirix.axis.visitor.DeleteFMSEVisitor)

Example 18 with SirixException

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;
}
Also used : NodeReadTrx(org.sirix.api.NodeReadTrx) SirixException(org.sirix.exception.SirixException) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) DescendantAxis(org.sirix.axis.DescendantAxis)

Example 19 with SirixException

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;
    }
}
Also used : NodeReadTrx(org.sirix.api.NodeReadTrx) NodeInfo(net.sf.saxon.om.NodeInfo) SirixException(org.sirix.exception.SirixException)

Example 20 with SirixException

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()]));
}
Also used : Path(java.nio.file.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) ArrayStream(org.brackit.xquery.node.stream.ArrayStream) DocumentException(org.brackit.xquery.xdm.DocumentException) ArrayList(java.util.ArrayList) 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