Search in sources :

Example 1 with Storage

use of org.sirix.io.Storage in project sirix by sirixdb.

the class ResourceStore method openResource.

/**
 * Open a resource, that is get an instance of a {@link ResourceManager} in order to read/write
 * from the resource.
 *
 * @param database The database.
 * @param resourceConfig The resource configuration.
 * @param resourceManagerConfig The resource manager configuration.
 * @param bufferManager The buffer manager.
 * @param resourceFile The resource to open.
 * @return A resource manager.
 */
public ResourceManager openResource(@Nonnull final DatabaseImpl database, @Nonnull final ResourceConfiguration resourceConfig, @Nonnull final ResourceManagerConfiguration resourceManagerConfig, @Nonnull final BufferManager bufferManager, @Nonnull final Path resourceFile) {
    checkNotNull(database);
    checkNotNull(resourceConfig);
    return mResourceManagers.computeIfAbsent(resourceFile, k -> {
        final Storage storage = StorageType.getStorage(resourceConfig);
        final UberPage uberPage;
        if (storage.exists()) {
            try (final Reader reader = storage.createReader()) {
                final PageReference firstRef = reader.readUberPageReference();
                if (firstRef.getPage() == null) {
                    uberPage = (UberPage) reader.read(firstRef, null);
                } else {
                    uberPage = (UberPage) firstRef.getPage();
                }
            }
        } else {
            // Bootstrap uber page and make sure there already is a root node.
            uberPage = new UberPage();
        }
        final ResourceManager resourceManager = new XdmResourceManager(database, this, resourceConfig, resourceManagerConfig, bufferManager, StorageType.getStorage(resourceConfig), uberPage, mReadSemaphore, mWriteSempahore);
        Databases.putResourceManager(resourceFile, resourceManager);
        return resourceManager;
    });
}
Also used : PageReference(org.sirix.page.PageReference) Storage(org.sirix.io.Storage) UberPage(org.sirix.page.UberPage) Reader(org.sirix.io.Reader) ResourceManager(org.sirix.api.ResourceManager)

Aggregations

ResourceManager (org.sirix.api.ResourceManager)1 Reader (org.sirix.io.Reader)1 Storage (org.sirix.io.Storage)1 PageReference (org.sirix.page.PageReference)1 UberPage (org.sirix.page.UberPage)1