use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testUpdateWAuthOnConfig.
// Set the persistence visibilites on the config
public void testUpdateWAuthOnConfig() throws Exception {
String sparqlUpdate = getSparqlUpdate();
RdfCloudTripleStore tstore = new MockRdfCloudStore();
NamespaceManager nm = new NamespaceManager(tstore.getRyaDAO(), tstore.getConf());
tstore.setNamespaceManager(nm);
SailRepository repo = new SailRepository(tstore);
tstore.getRyaDAO().getConf().setCv("1|2");
repo.initialize();
RepositoryConnection conn = repo.getConnection();
Update u = conn.prepareUpdate(QueryLanguage.SPARQL, sparqlUpdate);
u.execute();
String query = "PREFIX ex: <http://www.example.org/exampleDocument#>\n" + "PREFIX voc: <http://www.example.org/vocabulary#>\n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "\n" + "SELECT * \n" + // "FROM NAMED <http://www.example.org/exampleDocument#G1>\n" +
"WHERE\n" + "{\n" + " GRAPH ex:G1\n" + " {\n" + " ?m voc:name ?name ;\n" + " voc:homepage ?hp .\n" + " } .\n" + " GRAPH ex:G2\n" + " {\n" + " ?m voc:hasSkill ?skill .\n" + " } .\n" + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, vf.createLiteral("2"));
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(1, tupleHandler.getCount());
// no auth
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(0, tupleHandler.getCount());
conn.close();
repo.shutDown();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testEvaluateMultiLine.
public void testEvaluateMultiLine() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
URI uri1 = vf.createURI(litdupsNS, "uri1");
URI pred2 = vf.createURI(litdupsNS, "pred2");
URI uri2 = vf.createURI(litdupsNS, "uri2");
conn.add(cpu, loadPerc, uri1);
conn.add(cpu, pred2, uri2);
conn.commit();
String query = "select * where {" + "?x <" + loadPerc.stringValue() + "> ?o1." + "?x <" + pred2.stringValue() + "> ?o2." + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERYPLAN_FLAG, RdfCloudTripleStoreConstants.VALUE_FACTORY.createLiteral(true));
CountTupleHandler cth = new CountTupleHandler();
tupleQuery.evaluate(cth);
conn.close();
assertEquals(cth.getCount(), 1);
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class PcjVisibilityIT method visibilitySimplified.
@Test
public void visibilitySimplified() throws Exception {
// Create a PCJ index within Rya.
final String sparql = "SELECT ?customer ?worker ?city " + "{ " + "?customer <" + TALKS_TO + "> ?worker. " + "?worker <" + LIVES_IN + "> ?city. " + "?worker <" + WORKS_AT + "> <" + BURGER_JOINT + ">. " + "}";
final Connector accumuloConn = super.getAccumuloConnector();
final String instanceName = super.getMiniAccumuloCluster().getInstanceName();
final String zookeepers = super.getMiniAccumuloCluster().getZooKeepers();
final RyaClient ryaClient = AccumuloRyaClientFactory.build(createConnectionDetails(), accumuloConn);
final String pcjId = ryaClient.getCreatePCJ().createPCJ(getRyaInstanceName(), sparql);
// Grant the root user the "u" authorization.
super.getAccumuloConnector().securityOperations().changeUserAuthorizations(getUsername(), new Authorizations("u"));
// Setup a connection to the Rya instance that uses the "u" authorizations. This ensures
// any statements that are inserted will have the "u" authorization on them and that the
// PCJ updating application will have to maintain visibilities.
final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration();
ryaConf.setTablePrefix(getRyaInstanceName());
// Accumulo connection information.
ryaConf.setAccumuloUser(getUsername());
ryaConf.setAccumuloPassword(getPassword());
ryaConf.setAccumuloInstance(super.getAccumuloConnector().getInstance().getInstanceName());
ryaConf.setAccumuloZookeepers(super.getAccumuloConnector().getInstance().getZooKeepers());
ryaConf.set(ConfigUtils.CLOUDBASE_AUTHS, "u");
ryaConf.set(RdfCloudTripleStoreConfiguration.CONF_CV, "u");
// PCJ configuration information.
ryaConf.set(ConfigUtils.USE_PCJ, "true");
ryaConf.set(ConfigUtils.USE_PCJ_UPDATER_INDEX, "true");
ryaConf.set(ConfigUtils.FLUO_APP_NAME, super.getFluoConfiguration().getApplicationName());
ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinIndexerConfig.PrecomputedJoinStorageType.ACCUMULO.toString());
ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinIndexerConfig.PrecomputedJoinUpdaterType.FLUO.toString());
Sail sail = null;
RyaSailRepository ryaRepo = null;
RepositoryConnection ryaConn = null;
try {
sail = RyaSailFactory.getInstance(ryaConf);
ryaRepo = new RyaSailRepository(sail);
ryaConn = ryaRepo.getConnection();
// Load a few Statements into Rya.
ryaConn.add(VF.createStatement(ALICE, TALKS_TO, BOB));
ryaConn.add(VF.createStatement(BOB, LIVES_IN, HAPPYVILLE));
ryaConn.add(VF.createStatement(BOB, WORKS_AT, BURGER_JOINT));
// Wait for Fluo to finish processing.
super.getMiniFluo().waitForObservers();
// Fetch the exported result and show that its column visibility has been simplified.
final String pcjTableName = new PcjTableNameFactory().makeTableName(getRyaInstanceName(), pcjId);
final Scanner scan = accumuloConn.createScanner(pcjTableName, new Authorizations("u"));
scan.fetchColumnFamily(new Text("customer;worker;city"));
final Entry<Key, Value> result = scan.iterator().next();
final Key key = result.getKey();
assertEquals(new Text("u"), key.getColumnVisibility());
} finally {
if (ryaConn != null) {
try {
ryaConn.close();
} finally {
}
}
if (ryaRepo != null) {
try {
ryaRepo.shutDown();
} finally {
}
}
if (sail != null) {
try {
sail.shutDown();
} finally {
}
}
}
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class ITBase method shutdownMiniResources.
@AfterClass
public static void shutdownMiniResources() throws RepositoryException {
for (final RyaSailRepository repo : ryaRepos) {
repo.shutDown();
}
for (final RepositoryConnection conn : ryaConns) {
conn.close();
}
for (final MongoClient client : clients) {
client.close();
}
ryaRepos.clear();
ryaConns.clear();
clients.clear();
}
use of org.openrdf.repository.RepositoryConnection in project stanbol by apache.
the class SesameYard method findReferences.
@Override
public QueryResultList<String> findReferences(FieldQuery parsedQuery) throws YardException, IllegalArgumentException {
if (parsedQuery == null) {
throw new IllegalArgumentException("The parsed query MUST NOT be NULL!");
}
final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
RepositoryConnection con = null;
TupleQueryResult results = null;
try {
con = repository.getConnection();
con.begin();
// execute the query
int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(), getConfig().getMaxQueryResultNumber());
results = executeSparqlFieldQuery(con, query, limit, false);
// parse the results
List<String> ids = limit > 0 ? new ArrayList<String>(limit) : new ArrayList<String>();
while (results.hasNext()) {
BindingSet result = results.next();
Value value = result.getValue(query.getRootVariableName());
if (value instanceof Resource) {
ids.add(value.stringValue());
}
}
con.commit();
return new QueryResultListImpl<String>(query, ids, String.class);
} catch (RepositoryException e) {
throw new YardException("Unable to execute findReferences query", e);
} catch (QueryEvaluationException e) {
throw new YardException("Unable to execute findReferences query", e);
} finally {
if (results != null) {
// close the result if present
try {
results.close();
} catch (QueryEvaluationException ignore) {
/* ignore */
}
}
if (con != null) {
try {
con.close();
} catch (RepositoryException ignore) {
/* ignore */
}
}
}
}
Aggregations