use of edu.mit.simile.backstage.model.data.Database in project backstage by zepheira.
the class ListFacet method createComponentState.
protected List<FacetChoice> createComponentState(TupleQueryResult queryResult) throws QueryEvaluationException {
List<FacetChoice> facetChoices = new ArrayList<FacetChoice>();
Database database = _context.getDatabase();
while (queryResult.hasNext()) {
BindingSet bindingSet = queryResult.next();
Value value = bindingSet.getValue(_valueVar.getName());
Value count = bindingSet.getValue(_countVar.getName());
String s = valueToString(value);
int c = Integer.parseInt(count.stringValue());
FacetChoice fc = new FacetChoice();
fc._value = value;
fc._valueString = s;
fc._count = c;
fc._label = database.valueToLabel(value);
facetChoices.add(fc);
}
return facetChoices;
}
use of edu.mit.simile.backstage.model.data.Database 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