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);
}
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();
}
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();
}
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);
}
}
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();
}
Aggregations