Search in sources :

Example 1 with Database

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;
}
Also used : BindingSet(org.openrdf.query.BindingSet) ArrayList(java.util.ArrayList) Database(edu.mit.simile.backstage.model.data.Database) Value(org.openrdf.model.Value)

Example 2 with Database

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;
}
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)2 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 ArrayList (java.util.ArrayList)1 Value (org.openrdf.model.Value)1 BindingSet (org.openrdf.query.BindingSet)1