Search in sources :

Example 81 with XdmNodeWriteTrx

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();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx)

Example 82 with XdmNodeWriteTrx

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();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XMLShredder(org.sirix.service.xml.shredder.XMLShredder)

Example 83 with XdmNodeWriteTrx

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);
}
Also used : Path(java.nio.file.Path) XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) QName(javax.xml.namespace.QName) Database(org.sirix.api.Database) FMSE(org.sirix.diff.algorithm.fmse.FMSE) ResourceManager(org.sirix.api.ResourceManager)

Example 84 with XdmNodeWriteTrx

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].");
}
Also used : Path(java.nio.file.Path) XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database) XMLEventReader(javax.xml.stream.XMLEventReader) ResourceManager(org.sirix.api.ResourceManager)

Example 85 with XdmNodeWriteTrx

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);
    }
}
Also used : Path(java.nio.file.Path) XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) XMLStreamException(javax.xml.stream.XMLStreamException) Database(org.sirix.api.Database) FMSE(org.sirix.diff.algorithm.fmse.FMSE) SirixException(org.sirix.exception.SirixException) ResourceManager(org.sirix.api.ResourceManager) IOException(java.io.IOException)

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