Search in sources :

Example 1 with OnDiskHostedDatabase

use of edu.mit.simile.backstage.model.data.OnDiskHostedDatabase in project backstage by zepheira.

the class BackstageModule method getDatabase.

public Database getDatabase(DataLink dataLink) {
    Database db = s_linkDatabaseMap.get(dataLink.url.toString());
    if (db == null) {
        // inspect the link to determine our repository type, relativizing
        // against our Butterfly mount point
        URI dbUri = null;
        URI mountUri = null;
        try {
            dbUri = new URI(dataLink.url.toString());
            // awkward!
            mountUri = new URI(this.getMountPoint().getMountPoint());
        } catch (URISyntaxException e) {
            return null;
        }
        URI fullMountUri = dbUri.resolve(mountUri);
        String mountPath = dbUri.toString().substring(fullMountUri.toString().length());
        String[] mountPathSegs = mountPath.toString().split(File.separator);
        if (mountPathSegs.length != 3) {
            return null;
        }
        String repoType = mountPathSegs[1];
        if (repoType.equals(REPOTYPE_MEM)) {
            db = new InMemHostedDatabase(dataLink);
        } else if (repoType.equals(REPOTYPE_DISK)) {
            db = new OnDiskHostedDatabase(dataLink);
        } else {
            return null;
        }
        s_linkDatabaseMap.put(dataLink.url.toString(), db);
        // sanity check
        if (s_databaseRefCountMap.containsKey(db)) {
            _logger.error("This shouldn't happen. A database was erroneously re-created");
        }
        // initialize for incr. code below
        s_databaseRefCountMap.put(db, new Integer(0));
    }
    int refCount = 0;
    if (!s_databaseRefCountMap.containsKey(db)) {
        _logger.error("This shouldn't happen. Database was found in link map but not reference count map");
    }
    refCount = s_databaseRefCountMap.get(db).intValue() + 1;
    s_databaseRefCountMap.put(db, new Integer(refCount));
    return db;
}
Also used : HostedDatabase(edu.mit.simile.backstage.model.data.HostedDatabase) Database(edu.mit.simile.backstage.model.data.Database) InMemHostedDatabase(edu.mit.simile.backstage.model.data.InMemHostedDatabase) OnDiskHostedDatabase(edu.mit.simile.backstage.model.data.OnDiskHostedDatabase) StandaloneDiskHostedDatabase(edu.mit.simile.backstage.model.data.StandaloneDiskHostedDatabase) OnDiskHostedDatabase(edu.mit.simile.backstage.model.data.OnDiskHostedDatabase) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) InMemHostedDatabase(edu.mit.simile.backstage.model.data.InMemHostedDatabase)

Aggregations

Database (edu.mit.simile.backstage.model.data.Database)1 HostedDatabase (edu.mit.simile.backstage.model.data.HostedDatabase)1 InMemHostedDatabase (edu.mit.simile.backstage.model.data.InMemHostedDatabase)1 OnDiskHostedDatabase (edu.mit.simile.backstage.model.data.OnDiskHostedDatabase)1 StandaloneDiskHostedDatabase (edu.mit.simile.backstage.model.data.StandaloneDiskHostedDatabase)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1