Search in sources :

Example 11 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class FileRefDatabase method getAll.

/**
     * @return all references under the specified namespace
     */
@Override
public Map<String, String> getAll(String namespace) {
    Preconditions.checkNotNull(namespace);
    File refsRoot;
    try {
        Optional<URL> envHome = new ResolveGeogigDir(platform).call();
        refsRoot = new File(envHome.get().toURI());
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    if (namespace.endsWith("/")) {
        namespace = namespace.substring(0, namespace.length() - 1);
    }
    Map<String, String> refs = Maps.newTreeMap();
    findRefs(refsRoot, namespace, refs);
    return ImmutableMap.copyOf(refs);
}
Also used : ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RepositoryConnectionException(org.locationtech.geogig.repository.RepositoryConnectionException)

Example 12 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class FileRefDatabase method create.

/**
     * Creates the reference database.
     */
@Override
public void create() {
    Optional<URL> envHome = new ResolveGeogigDir(platform).call();
    checkState(envHome.isPresent(), "Not inside a geogig directory");
    final URL envURL = envHome.get();
    if (!"file".equals(envURL.getProtocol())) {
        throw new UnsupportedOperationException("This References Database works only against file system repositories. " + "Repository location: " + envURL.toExternalForm());
    }
    File repoDir;
    try {
        repoDir = new File(envURL.toURI());
    } catch (URISyntaxException e) {
        throw Throwables.propagate(e);
    }
    File refs = new File(repoDir, "refs");
    if (!refs.exists() && !refs.mkdir()) {
        throw new IllegalStateException("Cannot create refs directory '" + refs.getAbsolutePath() + "'");
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL)

Example 13 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class FileObjectDatabase method open.

/**
     * Opens the database for use by GeoGig.
     */
@Override
public void open() {
    if (isOpen()) {
        return;
    }
    final Optional<URL> repoUrl = new ResolveGeogigDir(platform).call();
    checkState(repoUrl.isPresent(), "Can't find geogig repository home");
    try {
        dataRoot = new File(new File(repoUrl.get().toURI()), databaseName);
    } catch (URISyntaxException e) {
        throw Throwables.propagate(e);
    }
    if (!dataRoot.exists() && !dataRoot.mkdirs()) {
        throw new IllegalStateException("Can't create environment: " + dataRoot.getAbsolutePath());
    }
    if (!dataRoot.isDirectory()) {
        throw new IllegalStateException("Environment but is not a directory: " + dataRoot.getAbsolutePath());
    }
    if (!dataRoot.canWrite()) {
        throw new IllegalStateException("Environment is not writable: " + dataRoot.getAbsolutePath());
    }
    dataRootPath = dataRoot.getAbsolutePath();
}
Also used : URISyntaxException(java.net.URISyntaxException) ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL)

Example 14 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class HeapGraphDatabase method open.

@Override
public void open() {
    if (isOpen()) {
        return;
    }
    Optional<URL> url = new ResolveGeogigDir(platform).call();
    if (url.isPresent()) {
        synchronized (graphs) {
            URL key = url.get();
            if (!graphs.containsKey(key)) {
                graphs.put(key, new Ref(new Graph()));
            }
            graph = graphs.get(key).acquire();
        }
    } else {
        graph = new Graph();
    }
}
Also used : ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) URL(java.net.URL)

Aggregations

URL (java.net.URL)14 ResolveGeogigDir (org.locationtech.geogig.api.plumbing.ResolveGeogigDir)14 File (java.io.File)12 URISyntaxException (java.net.URISyntaxException)10 IOException (java.io.IOException)4 RepositoryConnectionException (org.locationtech.geogig.repository.RepositoryConnectionException)3 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 ByteSource (com.google.common.io.ByteSource)1 Environment (com.sleepycat.je.Environment)1 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 Platform (org.locationtech.geogig.api.Platform)1 ConfigException (org.locationtech.geogig.api.porcelain.ConfigException)1 Repository (org.locationtech.geogig.repository.Repository)1 ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)1 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)1