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