use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class DiffTestHelper method setUpEighth.
static void setUpEighth(final Holder holder) throws SirixException, IOException, XMLStreamException {
final XdmNodeWriteTrx wtx = holder.getWriter();
DocumentCreater.create(wtx);
wtx.commit();
final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx(1);
rtx.moveTo(11);
wtx.moveTo(5);
wtx.replaceNode(rtx);
wtx.commit();
rtx.close();
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class DiffTestHelper method setUpThird.
static void setUpThird(final Holder holder) throws SirixException, IOException, XMLStreamException {
new XMLShredder.Builder(holder.getWriter(), XMLShredder.createFileReader(Paths.get(RESOURCES + File.separator + "revXMLsDelete1" + File.separator + "1.xml")), Insert.ASFIRSTCHILD).commitAfterwards().build().call();
final XdmNodeWriteTrx wtx = holder.getWriter();
wtx.moveToDocumentRoot();
wtx.moveToFirstChild();
wtx.moveToFirstChild();
wtx.remove();
wtx.moveToRightSibling();
wtx.remove();
wtx.moveToFirstChild();
wtx.remove();
wtx.moveToRightSibling();
wtx.remove();
wtx.commit();
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class WikipediaImport method updateShredder.
/**
* Update shredder.
*/
private void updateShredder() throws SirixException, IOException, XMLStreamException {
final Path path = Files.createTempDirectory("sdbtmp");
final DatabaseConfiguration dbConf = new DatabaseConfiguration(path);
Databases.truncateDatabase(dbConf);
Databases.createDatabase(dbConf);
final Database db = Databases.openDatabase(path);
db.createResource(new ResourceConfiguration.Builder("wiki", dbConf).build());
final ResourceManager resourceManager = db.getResourceManager(new ResourceManagerConfiguration.Builder("wiki").build());
if (mPageEvents.peek().isStartElement() && !mPageEvents.peek().asStartElement().getName().getLocalPart().equals("root")) {
mPageEvents.addFirst(XMLEventFactory.newInstance().createStartElement(new QName("root"), null, null));
mPageEvents.addLast(XMLEventFactory.newInstance().createEndElement(new QName("root"), null));
}
final XdmNodeWriteTrx wtx = resourceManager.beginNodeWriteTrx();
final XMLShredder shredder = new XMLShredder.Builder(wtx, XMLShredder.createQueueReader(mPageEvents), Insert.ASFIRSTCHILD).commitAfterwards().build();
shredder.call();
wtx.close();
mPageEvents = new ArrayDeque<>();
final XdmNodeReadTrx rtx = resourceManager.beginNodeReadTrx();
rtx.moveToFirstChild();
rtx.moveToFirstChild();
final long nodeKey = mWtx.getNodeKey();
try (final FMSE fmse = new FMSE()) {
fmse.diff(mWtx, rtx);
}
mWtx.moveTo(nodeKey);
rtx.close();
resourceManager.close();
db.close();
Databases.truncateDatabase(dbConf);
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class XMLShredder method main.
/**
* Main method.
*
* @param args input and output files
* @throws XMLStreamException if the XML stream isn't valid
* @throws IOException if an I/O error occurs
* @throws SirixException if a Sirix error occurs
*/
public static void main(final String... args) throws SirixException, IOException, XMLStreamException {
if (args.length != 2 && args.length != 3) {
throw new IllegalArgumentException("Usage: XMLShredder XMLFile Database [true/false] (shredder comment|PI)");
}
LOGWRAPPER.info("Shredding '" + args[0] + "' to '" + args[1] + "' ... ");
final long time = System.nanoTime();
final Path target = Paths.get(args[1]);
final DatabaseConfiguration config = new DatabaseConfiguration(target);
Databases.truncateDatabase(config);
Databases.createDatabase(config);
try (final Database db = Databases.openDatabase(target)) {
db.createResource(new ResourceConfiguration.Builder("shredded", config).build());
try (final ResourceManager resMgr = db.getResourceManager(new ResourceManagerConfiguration.Builder("shredded").build());
final XdmNodeWriteTrx wtx = resMgr.beginNodeWriteTrx()) {
final XMLEventReader reader = createFileReader(Paths.get(args[0]));
final boolean includeCoPI = args.length == 3 ? Boolean.parseBoolean(args[2]) : false;
final XMLShredder shredder = new XMLShredder.Builder(wtx, reader, Insert.ASFIRSTCHILD).commitAfterwards().includeComments(includeCoPI).includePIs(includeCoPI).build();
shredder.call();
}
}
LOGWRAPPER.info(" done [" + (System.nanoTime() - time) / 1000000 + " ms].");
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class FMSEImport method dataImport.
/**
* Import the data.
*
* @param resOldRev {@link File} for old revision (sirix resource)
* @param resNewRev {@link File} for new revision (XML resource)
*/
private void dataImport(final Path resOldRev, @Nonnull final Path resNewRev) {
try {
final Path newRevTarget = Files.createTempDirectory(resNewRev.toAbsolutePath().toString());
if (Files.exists(newRevTarget)) {
SirixFiles.recursiveRemove(newRevTarget);
}
shredder(checkNotNull(resNewRev), newRevTarget);
try (final Database databaseOld = Databases.openDatabase(resOldRev);
final ResourceManager resMgrOld = databaseOld.getResourceManager(new ResourceManagerConfiguration.Builder("shredded").build());
final XdmNodeWriteTrx wtx = resMgrOld.beginNodeWriteTrx();
final Database databaseNew = Databases.openDatabase(newRevTarget);
final ResourceManager resourceNew = databaseNew.getResourceManager(new ResourceManagerConfiguration.Builder("shredded").build());
final XdmNodeReadTrx rtx = resourceNew.beginNodeReadTrx();
final FMSE fmes = new FMSE()) {
fmes.diff(wtx, rtx);
}
} catch (final SirixException | IOException | XMLStreamException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
}
Aggregations