use of edu.mit.simile.backstage.model.data.InMemHostedDatabase 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;
}
Aggregations