Search in sources :

Example 91 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx 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)

Example 92 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.

the class DBCollection method add.

@Override
public DBNode add(SubtreeParser parser) throws OperationNotSupportedException, DocumentException {
    try {
        final String resourceName = new StringBuilder(2).append("resource").append(mDatabase.listResources().size() + 1).toString();
        mDatabase.createResource(ResourceConfiguration.newBuilder(resourceName, mDatabase.getDatabaseConfig()).useDeweyIDs(true).useTextCompression(true).buildPathSummary(true).build());
        final ResourceManager resource = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resourceName).build());
        final XdmNodeWriteTrx wtx = resource.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)

Example 93 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.

the class DBNode method delete.

@Override
public void delete() throws DocumentException {
    if (mIsWtx) {
        moveRtx();
        final XdmNodeWriteTrx wtx = (XdmNodeWriteTrx) mRtx;
        try {
            wtx.remove();
        } catch (final SirixException e) {
            wtx.rollback();
            wtx.close();
            throw new DocumentException(e);
        }
    } else {
        final XdmNodeWriteTrx wtx = getWtx();
        try {
            wtx.remove();
        } catch (final SirixException e) {
            wtx.rollback();
            wtx.close();
            throw new DocumentException(e);
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException)

Example 94 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.

the class DBNode method append.

private DBNode append(XdmNodeReadTrx rtx, SubtreeParser parser) throws DocumentException {
    try {
        if (rtx.hasFirstChild()) {
            rtx.moveToLastChild();
        }
        parser.parse(new SubtreeBuilder(mCollection, (XdmNodeWriteTrx) rtx, Insert.ASRIGHTSIBLING, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList()));
        moveRtx();
        rtx.moveToFirstChild();
    } catch (final SirixException e) {
        throw new DocumentException(e);
    }
    return new DBNode(rtx, mCollection);
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SubtreeListener(org.brackit.xquery.node.parser.SubtreeListener) DocumentException(org.brackit.xquery.xdm.DocumentException) AbstractTemporalNode(org.brackit.xquery.xdm.AbstractTemporalNode) SirixException(org.sirix.exception.SirixException)

Example 95 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.

the class DBNode method setName.

@Override
public void setName(final QNm name) throws OperationNotSupportedException, DocumentException {
    if (mIsWtx) {
        moveRtx();
        final XdmNodeWriteTrx wtx = (XdmNodeWriteTrx) mRtx;
        if (wtx.isNameNode()) {
            try {
                wtx.setName(name);
            } catch (final SirixException e) {
                throw new DocumentException(e);
            }
        } else {
            throw new DocumentException("Node has no name!");
        }
    } else {
        final XdmNodeWriteTrx wtx = getWtx();
        try {
            wtx.setName(name);
        } catch (final SirixException e) {
            wtx.rollback();
            wtx.close();
            throw new DocumentException(e);
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException)

Aggregations

XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)101 Test (org.junit.Test)61 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)48 ResourceManager (org.sirix.api.ResourceManager)33 Database (org.sirix.api.Database)22 QNm (org.brackit.xquery.atomic.QNm)15 SirixException (org.sirix.exception.SirixException)15 Path (java.nio.file.Path)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 DocumentException (org.brackit.xquery.xdm.DocumentException)7 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)7 DescendantAxis (org.sirix.axis.DescendantAxis)7 XMLSerializerBuilder (org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder)7 IOException (java.io.IOException)5 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)5 SirixIOException (org.sirix.exception.SirixIOException)5 SirixDeweyID (org.sirix.node.SirixDeweyID)5 DBNode (org.sirix.xquery.node.DBNode)5 XMLEventReader (javax.xml.stream.XMLEventReader)4 QueryException (org.brackit.xquery.QueryException)4