use of org.sirix.api.ResourceManager in project sirix by sirixdb.
the class HashTest method createWtx.
private XdmNodeWriteTrx createWtx(final HashKind kind) throws SirixException {
final Database database = TestHelper.getDatabase(TestHelper.PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH1.getConfig()).build());
final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
final XdmNodeWriteTrx wTrx = manager.beginNodeWriteTrx();
return wTrx;
}
use of org.sirix.api.ResourceManager in project sirix by sirixdb.
the class Holder method generateDeweyIDResourceMgr.
/**
* Generate a resource with deweyIDs for resources and open a resource.
*
* @return this holder instance
* @throws SirixException if an error occurs
*/
public static Holder generateDeweyIDResourceMgr() throws SirixException {
final Path file = PATHS.PATH1.getFile();
final DatabaseConfiguration config = new DatabaseConfiguration(file);
if (!Files.exists(file)) {
Databases.createDatabase(config);
}
final Database database = Databases.openDatabase(PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH1.getConfig()).useDeweyIDs(true).build());
final ResourceManager resourceManager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
final Holder holder = new Holder();
holder.setDatabase(database);
holder.setResourceManager(resourceManager);
return holder;
}
use of org.sirix.api.ResourceManager in project sirix by sirixdb.
the class Holder method generatePathSummary.
/**
* Generate a resource with a path summary.
*
* @return this holder instance
* @throws SirixException if an error occurs
*/
public static Holder generatePathSummary() throws SirixException {
final Path file = PATHS.PATH1.getFile();
final DatabaseConfiguration config = new DatabaseConfiguration(file);
if (!Files.exists(file)) {
Databases.createDatabase(config);
}
final Database database = Databases.openDatabase(PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH1.getConfig()).buildPathSummary(true).build());
final ResourceManager resourceManager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
final Holder holder = new Holder();
holder.setDatabase(database);
holder.setResourceManager(resourceManager);
return holder;
}
use of org.sirix.api.ResourceManager in project sirix by sirixdb.
the class DBCollection method add.
public DBNode add(final String resourceName, final XMLEventReader reader) throws OperationNotSupportedException, DocumentException {
try {
mDatabase.createResource(ResourceConfiguration.newBuilder(resourceName, mDatabase.getDatabaseConfig()).useDeweyIDs(true).build());
final ResourceManager resource = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resourceName).build());
final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx();
wtx.insertSubtreeAsFirstChild(reader);
wtx.moveToDocumentRoot();
return new DBNode(wtx, this);
} catch (final SirixException e) {
LOGGER.error(e.getMessage(), e);
return null;
}
}
use of org.sirix.api.ResourceManager in project sirix by sirixdb.
the class DBCollection method getDocument.
@Override
public DBNode getDocument(@Nonnegative final int revision) throws DocumentException {
final List<Path> resources = mDatabase.listResources();
if (resources.size() > 1) {
throw new DocumentException("More than one document stored in database/collection!");
}
try {
final ResourceManager session = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resources.get(0).getFileName().toString()).build());
final int version = revision == -1 ? session.getMostRecentRevisionNumber() : revision;
final XdmNodeReadTrx rtx = session.beginNodeReadTrx(version);
return new DBNode(rtx, this);
} catch (final SirixException e) {
throw new DocumentException(e.getCause());
}
}
Aggregations