Search in sources :

Example 36 with ResourceManager

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

Example 37 with ResourceManager

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;
}
Also used : Path(java.nio.file.Path) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) ResourceConfiguration(org.sirix.access.conf.ResourceConfiguration)

Example 38 with ResourceManager

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;
}
Also used : Path(java.nio.file.Path) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) ResourceConfiguration(org.sirix.access.conf.ResourceConfiguration)

Example 39 with ResourceManager

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

Example 40 with ResourceManager

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());
    }
}
Also used : Path(java.nio.file.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException) ResourceManager(org.sirix.api.ResourceManager)

Aggregations

ResourceManager (org.sirix.api.ResourceManager)46 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)33 Database (org.sirix.api.Database)30 Path (java.nio.file.Path)16 Test (org.junit.Test)14 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)14 SirixException (org.sirix.exception.SirixException)12 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 XMLSerializerBuilder (org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder)8 IOException (java.io.IOException)5 ResourceConfiguration (org.sirix.access.conf.ResourceConfiguration)5 XMLEventReader (javax.xml.stream.XMLEventReader)4 DocumentException (org.brackit.xquery.xdm.DocumentException)4 OutputStream (java.io.OutputStream)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 QNm (org.brackit.xquery.atomic.QNm)3 DescendantAxis (org.sirix.axis.DescendantAxis)3 File (java.io.File)2 Files (java.nio.file.Files)2