Search in sources :

Example 6 with NodeWriteTrx

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

the class WorkerHelperTest method testClose.

/**
 * This method tests
 * {@link WorkerHelper#closeWTX(boolean, NodeWriteTrx, Session, Database)}
 */
@Test(expected = IllegalStateException.class)
public void testClose() throws SirixException {
    Database database = Databases.openDatabase(DBFILE.getParentFile());
    Session session = database.getSession(new SessionConfiguration.Builder(DBFILE.getName()).build());
    final NodeWriteTrx wtx = session.beginNodeWriteTrx();
    WorkerHelper.closeWTX(false, wtx, session, database);
    wtx.commit();
    database = Databases.openDatabase(DBFILE.getParentFile());
    session = database.getSession(new SessionConfiguration.Builder(DBFILE.getName()).build());
    final NodeReadTrx rtx = session.beginNodeReadTrx();
    WorkerHelper.closeRTX(rtx, session, database);
    rtx.moveTo(11);
}
Also used : NodeReadTrx(org.sirix.api.NodeReadTrx) Database(org.sirix.api.Database) NodeWriteTrx(org.sirix.api.NodeWriteTrx) SessionConfiguration(org.sirix.access.conf.SessionConfiguration) Session(org.sirix.api.Session) Test(org.junit.Test)

Example 7 with NodeWriteTrx

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

the class BookShredding method shredder.

private static void shredder(final File pBooks) throws Exception {
    final DatabaseConfiguration config = new DatabaseConfiguration(TestHelper.PATHS.PATH1.getFile());
    Databases.truncateDatabase(config);
    Databases.createDatabase(config);
    final Database database = Databases.openDatabase(config.getFile());
    database.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH1.getConfig()).build());
    final Session session = database.getSession(new SessionConfiguration.Builder(TestHelper.RESOURCE).build());
    final NodeWriteTrx wtx = session.beginNodeWriteTrx();
    final XMLEventReader reader = XMLShredder.createFileReader(pBooks);
    final XMLShredder shredder = new XMLShredder.Builder(wtx, reader, Insert.ASFIRSTCHILD).commitAfterwards().build();
    shredder.call();
    wtx.close();
    session.close();
}
Also used : DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database) NodeWriteTrx(org.sirix.api.NodeWriteTrx) XMLEventReader(javax.xml.stream.XMLEventReader) XMLShredder(org.sirix.service.xml.shredder.XMLShredder) Session(org.sirix.api.Session)

Example 8 with NodeWriteTrx

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

the class TestNodeWrapper method testCompareOrder.

@Test
public void testCompareOrder() throws XPathException, SirixException {
    final Processor proc = new Processor(false);
    final Configuration config = proc.getUnderlyingConfiguration();
    final Session session = generateSession();
    final NodeWriteTrx trx = session.beginNodeWriteTrx();
    trx.commit();
    trx.close();
    // Not the same document.
    NodeInfo node = new DocumentWrapper(session, config);
    NodeInfo other = new NodeWrapper(new DocumentWrapper(mHolder.getSession(), config), 3);
    try {
        node.compareOrder(other);
        fail();
    } catch (final IllegalStateException e) {
    }
    // Before.
    node = new DocumentWrapper(mHolder.getSession(), config);
    other = new NodeWrapper(new DocumentWrapper(mHolder.getSession(), config), 3);
    assertEquals(-1, node.compareOrder(other));
    // After.
    node = new NodeWrapper(new DocumentWrapper(mHolder.getSession(), config), 3);
    other = new NodeWrapper(new DocumentWrapper(mHolder.getSession(), config), 0);
    assertEquals(1, node.compareOrder(other));
    // Same.
    node = new NodeWrapper(new DocumentWrapper(mHolder.getSession(), config), 3);
    other = new NodeWrapper(new DocumentWrapper(mHolder.getSession(), config), 3);
    assertEquals(0, node.compareOrder(other));
    session.close();
    mDatabase.close();
}
Also used : Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) ResourceConfiguration(org.sirix.access.conf.ResourceConfiguration) SessionConfiguration(org.sirix.access.conf.SessionConfiguration) NodeInfo(net.sf.saxon.om.NodeInfo) NodeWriteTrx(org.sirix.api.NodeWriteTrx) Session(org.sirix.api.Session) NameTest(net.sf.saxon.pattern.NameTest) Test(org.junit.Test)

Example 9 with NodeWriteTrx

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

the class DatabaseRepresentation method revertToRevision.

/**
 * This method reverts the latest revision data to the requested.
 *
 * @param resourceName
 *          The name of the XML resource.
 * @param backToRevision
 *          The revision value, which has to be set as the latest.
 * @throws WebApplicationException
 * @throws SirixException
 */
public void revertToRevision(final String resourceName, final int backToRevision) throws JaxRxException, SirixException {
    Database database = null;
    Session session = null;
    NodeWriteTrx wtx = null;
    boolean abort = false;
    try {
        database = Databases.openDatabase(mStoragePath);
        session = database.getSession(new SessionConfiguration.Builder(resourceName).build());
        wtx = session.beginNodeWriteTrx();
        wtx.revertTo(backToRevision);
        wtx.commit();
    } catch (final SirixException exce) {
        abort = true;
        throw new JaxRxException(exce);
    } finally {
        WorkerHelper.closeWTX(abort, wtx, session, database);
    }
}
Also used : Database(org.sirix.api.Database) NodeWriteTrx(org.sirix.api.NodeWriteTrx) SirixException(org.sirix.exception.SirixException) SessionConfiguration(org.sirix.access.conf.SessionConfiguration) Session(org.sirix.api.Session) JaxRxException(org.jaxrx.core.JaxRxException)

Example 10 with NodeWriteTrx

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

the class WorkerHelperTest method testShredInputStream.

/**
 * This method tests
 * {@link WorkerHelper#shredInputStream(NodeWriteTrx, InputStream, Insert)}
 */
@Test
public void testShredInputStream() throws SirixException, IOException {
    long lastRevision = sirix.getLastRevision(RESOURCENAME);
    final Database database = Databases.openDatabase(DBFILE.getParentFile());
    final Session session = database.getSession(new SessionConfiguration.Builder(DBFILE.getName()).build());
    final NodeWriteTrx wtx = session.beginNodeWriteTrx();
    wtx.moveToFirstChild();
    final InputStream inputStream = new ByteArrayInputStream("<testNode/>".getBytes());
    WorkerHelper.shredInputStream(wtx, inputStream, Insert.ASFIRSTCHILD);
    assertEquals("test shred input stream", sirix.getLastRevision(RESOURCENAME), ++lastRevision);
    wtx.close();
    session.close();
    database.close();
    inputStream.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Database(org.sirix.api.Database) NodeWriteTrx(org.sirix.api.NodeWriteTrx) Session(org.sirix.api.Session) Test(org.junit.Test)

Aggregations

NodeWriteTrx (org.sirix.api.NodeWriteTrx)10 Session (org.sirix.api.Session)10 Database (org.sirix.api.Database)8 SessionConfiguration (org.sirix.access.conf.SessionConfiguration)7 JaxRxException (org.jaxrx.core.JaxRxException)5 SirixException (org.sirix.exception.SirixException)5 Test (org.junit.Test)4 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)3 XMLShredder (org.sirix.service.xml.shredder.XMLShredder)3 IOException (java.io.IOException)2 XMLEventReader (javax.xml.stream.XMLEventReader)2 NodeInfo (net.sf.saxon.om.NodeInfo)2 NameTest (net.sf.saxon.pattern.NameTest)2 Processor (net.sf.saxon.s9api.Processor)2 ResourceConfiguration (org.sirix.access.conf.ResourceConfiguration)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Configuration (net.sf.saxon.Configuration)1