Search in sources :

Example 11 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration in project sirix by sirixdb.

the class StorageTest method setUp.

@BeforeClass
public void setUp() throws SirixException, IOException {
    TestHelper.closeEverything();
    TestHelper.deleteEverything();
    Files.createDirectories(TestHelper.PATHS.PATH1.getFile());
    Files.createDirectories(TestHelper.PATHS.PATH1.getFile().resolve(ResourceConfiguration.ResourcePaths.DATA.getFile()));
    Files.createFile(TestHelper.PATHS.PATH1.getFile().resolve(ResourceConfiguration.ResourcePaths.DATA.getFile()).resolve("data.sirix"));
    mResourceConfig = new ResourceConfiguration.Builder("shredded", new DatabaseConfiguration(TestHelper.PATHS.PATH1.getFile())).build();
}
Also used : DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) BeforeClass(org.testng.annotations.BeforeClass)

Example 12 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration in project sirix by sirixdb.

the class ResourceTransactionUsage method main.

public static void main(final String[] args) {
    final Path file = LOCATION.resolve("db");
    final DatabaseConfiguration config = new DatabaseConfiguration(file);
    if (Files.exists(file)) {
        Databases.truncateDatabase(config);
    }
    Databases.createDatabase(config);
    try (final Database database = Databases.openDatabase(file)) {
        database.createResource(new ResourceConfiguration.Builder("resource", config).build());
        try (final ResourceManager resource = database.getResourceManager(new ResourceManagerConfiguration.Builder("resource").build());
            final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx()) {
            wtx.insertSubtreeAsFirstChild(XMLShredder.createFileReader(LOCATION.resolve("input.xml")));
            wtx.moveTo(2);
            wtx.moveSubtreeToFirstChild(4).commit();
            final OutputStream out = new ByteArrayOutputStream();
            new XMLSerializer.XMLSerializerBuilder(resource, out).prettyPrint().build().call();
            System.out.println(out);
        }
    } catch (final SirixException | IOException | XMLStreamException e) {
    // LOG or do anything, the database is closed properly.
    }
}
Also used : Path(java.nio.file.Path) XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XMLSerializer(org.sirix.service.xml.serialize.XMLSerializer) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceManager(org.sirix.api.ResourceManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException) Database(org.sirix.api.Database) SirixException(org.sirix.exception.SirixException)

Example 13 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration in project sirix by sirixdb.

the class FileSystemWatcher method main.

/**
 * Main entry point.
 *
 * @param args first argument speficies the path/directory to watch for changes, the second
 *        argument specifies the database to which to append incoming events; <strong>note that
 *        any existing database is truncated first if an optional third argument is set to
 *        {@code true}</strong>
 * @throws SirixException if sirix encounters any error
 * @throws IOException if any I/O error occurs
 */
public static void main(final String[] args) throws SirixException, IOException {
    if (args.length < 2 || args.length > 3) {
        LOGWRAPPER.info("Usage: FileSystemWatcher pathToWatch pathToDatabase [true|false]");
    }
    if (Boolean.parseBoolean(args[2])) {
        Databases.truncateDatabase(new DatabaseConfiguration(Paths.get(args[1])));
    }
    final Path databasePath = Paths.get(args[1]);
    final DatabaseConfiguration conf = new DatabaseConfiguration(databasePath);
    Map<Path, FileSystemPath> index = null;
    if (Files.exists(Paths.get(args[1]))) {
        Databases.truncateDatabase(conf);
    }
    Databases.createDatabase(conf);
    try (final Database database = Databases.openDatabase(databasePath)) {
        database.createResource(new ResourceConfiguration.Builder("shredded", conf).build());
        index = FileHierarchyWalker.parseDir(Paths.get(args[0]), database, Optional.of(new ProcessFileSystemAttributes()));
        assert index != null;
        try (final FileSystemWatcher watcher = FileSystemWatcher.getInstance(Paths.get(args[0]), Databases.openDatabase(databasePath))) {
            watcher.watch(null, index);
        }
    }
}
Also used : Path(java.nio.file.Path) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database)

Example 14 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration 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 15 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration 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)

Aggregations

DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)24 Database (org.sirix.api.Database)19 ResourceManager (org.sirix.api.ResourceManager)11 Path (java.nio.file.Path)10 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)7 DocumentException (org.brackit.xquery.xdm.DocumentException)5 SirixRuntimeException (org.sirix.exception.SirixRuntimeException)5 XMLEventReader (javax.xml.stream.XMLEventReader)4 SirixException (org.sirix.exception.SirixException)4 IOException (java.io.IOException)3 QName (javax.xml.namespace.QName)3 ResourceConfiguration (org.sirix.access.conf.ResourceConfiguration)3 XMLShredder (org.sirix.service.xml.shredder.XMLShredder)3 LinkedList (java.util.LinkedList)2 XMLEventFactory (javax.xml.stream.XMLEventFactory)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 StartElement (javax.xml.stream.events.StartElement)2 SubtreeListener (org.brackit.xquery.node.parser.SubtreeListener)2 AbstractTemporalNode (org.brackit.xquery.xdm.AbstractTemporalNode)2 Ignore (org.junit.Ignore)2