Search in sources :

Example 86 with XdmNodeWriteTrx

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

the class FMSEImport method shredder.

/**
 * Shredder new revision as temporal resource.
 *
 * @param resNewRev {@link File} reference for new revision (XML resource)
 * @param newRev {@link File} reference for shreddered new revision (sirix resource)
 * @throws SirixException if sirix fails to shredder the file
 * @throws IOException if file couldn't be read
 * @throws XMLStreamException if XML document isn't well formed
 * @throws NullPointerException if {@code resNewRev} or {@code newRev} is {@code null}
 */
private void shredder(final Path resNewRev, @Nonnull Path newRev) throws SirixException, IOException, XMLStreamException {
    assert resNewRev != null;
    assert newRev != null;
    final DatabaseConfiguration conf = new DatabaseConfiguration(newRev);
    Databases.truncateDatabase(conf);
    Databases.createDatabase(conf);
    try (final Database db = Databases.openDatabase(newRev)) {
        db.createResource(new ResourceConfiguration.Builder("shredded", conf).build());
        try (final ResourceManager resMgr = db.getResourceManager(new ResourceManagerConfiguration.Builder("shredded").build());
            final XdmNodeWriteTrx wtx = resMgr.beginNodeWriteTrx()) {
            final XMLEventReader fileReader = XMLShredder.createFileReader(resNewRev);
            final XMLShredder shredder = new XMLShredder.Builder(wtx, fileReader, Insert.ASFIRSTCHILD).commitAfterwards().build();
            shredder.call();
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database) XMLEventReader(javax.xml.stream.XMLEventReader) XMLShredder(org.sirix.service.xml.shredder.XMLShredder) ResourceManager(org.sirix.api.ResourceManager)

Example 87 with XdmNodeWriteTrx

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

the class HashTest method createWtx.

private XdmNodeWriteTrx createWtx(final HashKind kind) throws SirixException {
    final Database database = TestHelper.getDatabase(TestHelper.PATHS.PATH1.getFile());
    database.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH1.getConfig()).build());
    final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeWriteTrx wTrx = manager.beginNodeWriteTrx();
    return wTrx;
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager)

Example 88 with XdmNodeWriteTrx

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

the class HashTest method testRollingSetter.

@Test
public void testRollingSetter() throws SirixException {
    final XdmNodeWriteTrx wtx = createWtx(HashKind.ROLLING);
    testSetter(wtx);
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Test(org.junit.Test)

Example 89 with XdmNodeWriteTrx

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

the class HashTest method testRollingDeep.

@Test
public void testRollingDeep() throws SirixException {
    final XdmNodeWriteTrx wtx = createWtx(HashKind.ROLLING);
    testDeepTree(wtx);
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Test(org.junit.Test)

Example 90 with XdmNodeWriteTrx

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

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