All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sirix.access.ResourceSessionModule Maven / Gradle / Ivy

Go to download

SirixDB is a hybrid on-disk and in-memory document oriented, versioned database system. It has a lightweight buffer manager, stores everything in a huge persistent and durable tree and allows efficient reconstruction of every revision. Furthermore, SirixDB implements change tracking, diffing and supports time travel queries.

There is a newer version: 0.11.0
Show newest version
package io.sirix.access;

import dagger.Module;
import dagger.Provides;
import io.sirix.dagger.ResourceSessionScope;
import io.sirix.io.IOStorage;
import io.sirix.io.Reader;
import io.sirix.io.StorageType;
import io.sirix.page.PageReference;
import io.sirix.page.UberPage;

import java.util.concurrent.Semaphore;

/**
 * A module with all the common bindings between resource sessions.
 *
 * @author Joao Sousa
 */
@Module
public interface ResourceSessionModule {

    @Provides
    @ResourceSessionScope
    static IOStorage ioStorage(final ResourceConfiguration resourceConfiguration) {
        return StorageType.getStorage(resourceConfiguration);
    }

    @Provides
    @ResourceSessionScope
    static Semaphore writeLock(final WriteLocksRegistry registry, final ResourceConfiguration resourceConfiguration) {
        return registry.getWriteLock(resourceConfiguration.getResource());
    }

    @Provides
    @ResourceSessionScope
    static UberPage rootPage(final IOStorage storage) {
        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();
        }
        return uberPage;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy