本文整理汇总了Java中org.apache.jena.query.ReadWrite类的典型用法代码示例。如果您正苦于以下问题:Java ReadWrite类的具体用法?Java ReadWrite怎么用?Java ReadWrite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReadWrite类属于org.apache.jena.query包,在下文中一共展示了ReadWrite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listVocabularies
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
public static Set<String> listVocabularies() {
Set<String> tds = new HashSet<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?o a <http://www.w3.org/2002/07/owl#Ontology> } }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
} catch (Exception e) {
throw e;
} finally {
dataset.end();
}
return tds;
}
示例2: get
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
Model result = dataset.getNamedModel(uri.toString());
if (!result.isEmpty()) {
resource.contentType = "text/turtle";
ByteArrayOutputStream out = new ByteArrayOutputStream();
result.write(out, "Turtle");
resource.content = out.toString();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例3: delete
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
@Override
public void delete(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
dataset.getDefaultModel().getResource(uri.toString()).removeProperties();
dataset.removeNamedModel(uri.toString());
deleteToAll(uri.getPath());
dataset.commit();
} catch (Exception e) {
// TODO distinguish between client and server errors
throw new RESTException();
} finally {
dataset.end();
}
}
示例4: get
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?str WHERE { <" + uri + "> <" + DC.source + "> ?str }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
if (result.hasNext()) {
resource.contentType = "application/ld+json";
resource.content = result.next().get("str").asLiteral().getLexicalForm();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例5: delete
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
@Override
public void delete(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
dataset.getDefaultModel().createResource(uri.toString()).removeProperties();
dataset.removeNamedModel(uri.toString());
deleteToAll(uri.getPath());
dataset.commit();
// Remove from priority queue
ThingDescription td = new ThingDescription(uri.toString());
ThingDirectory.get().tdQueue.remove(td);
ThingDirectory.get().setTimer();
} catch (Exception e) {
// TODO distinguish between client and server errors
throw new RESTException();
} finally {
dataset.end();
}
}
示例6: listThingDescriptions
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
public static List<String> listThingDescriptions(String query) {
List<String> tds = new ArrayList<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { " + query + " FILTER NOT EXISTS { ?ontology a <http://www.w3.org/2002/07/owl#Ontology> } } }";
try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
}
catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}
示例7: getThingDescriptionIdFromUri
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
/**
* Returns the ID of a thing description stored in the database given its URI.
* @param uri URI of the thing description we want to return.
* @return the ID of the thing description.
*/
public static String getThingDescriptionIdFromUri(String uri) {
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> <" + uri + ">";
String id = "NOT FOUND";
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?g_id WHERE { GRAPH ?g_id { " + query + " }}";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
id = result.next().get("g_id").toString();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dataset.end();
}
return id;
}
示例8: listThingDescriptionsUri
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
/**
* Returns a list of the thing descriptions URIs.
* @return a list of URIs stored in the database.
*/
public static List<String> listThingDescriptionsUri() {
List<String> tds = new ArrayList<>();
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> ?uri";
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?uri WHERE { GRAPH ?g_id { " + query + " }}";
try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("uri").toString());
}
}
catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}
示例9: queryData
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
public static List<String> queryData(String query){
Dataset db = TDBFactory.createDataset("temp/dataset");
db.begin(ReadWrite.READ);
Model model = db.getDefaultModel();
Query q = QueryFactory.create(query);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
List<String> answer = new ArrayList<String>();
while(results.hasNext()){
QuerySolution t = results.nextSolution();
RDFNode x = t.get("x");
String s = x.toString();
System.out.println(s);
answer.add(s.substring(7));
}
qexec.close();
db.close();
return answer;
}
示例10: begin
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
@Override
public void begin() {
if ( insideBegin ) {
super.begin();
return;
}
insideBegin = true;
try {
// For the sync, we have to assume it will write.
// Any potential write causes a write-sync to be done in "begin".
txnSyncHandler.accept(ReadWrite.WRITE);
if ( transactionMode() == ReadWrite.WRITE )
monitor.txnBegin();
} finally {
insideBegin = false;
}
}
示例11: promote
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
@Override
public boolean promote() {
// Any potential write causes a write-sync to be done in "begin".
// Here we are inside the transaction so calling the sync handler is not possible (nestd transaction risk).
if ( super.transactionMode() == ReadWrite.READ ) {
boolean b = super.promote();
if ( super.transactionMode() == ReadWrite.WRITE ) {
// // Promotion.
// if ( transactionType() == TxnType.READ_COMMITTED_PROMOTE )
// txnSyncHandler.accept(ReadWrite.WRITE);
// We have gone ReadWrite.READ -> ReadWrite.WRITE
monitor.txnBegin();
}
return b;
}
//Already WRITE.
return super.promote();
}
示例12: update_3
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
@Test
public void update_3() {
// Create on the Delta link then setup DeltaClient
DeltaLink dLink = getLink();
String DS_NAME = "12345";
Id dsRef = dLink.newDataSource(DS_NAME, "http://example/datasource_update_3");
DeltaClient dClient = createDeltaClient();
dClient.register(dsRef, LocalStorageType.MEM, TxnSyncPolicy.NONE);
DeltaConnection dConn = dClient.get(DS_NAME);
Quad quad = SSE.parseQuad("(_ :s :p :o)");
DatasetGraph dsg = dConn.getDatasetGraph();
long x0 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) );
assertEquals(0, x0);
dsg.begin(ReadWrite.WRITE);
dsg.add(quad);
dsg.abort();
long x1 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) );
assertEquals(0, x1);
}
示例13: listVocabularies
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
public static Set<String> listVocabularies() {
Set<String> tds = new HashSet<>();
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?o a <http://www.w3.org/2002/07/owl#Ontology> } }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
} catch (Exception e) {
throw e;
} finally {
dataset.end();
}
return tds;
}
示例14: get
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.READ);
try {
Model result = dataset.getNamedModel(uri.toString());
if (!result.isEmpty()) {
resource.contentType = "text/turtle";
ByteArrayOutputStream out = new ByteArrayOutputStream();
result.write(out, "Turtle");
resource.content = out.toString();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例15: delete
import org.apache.jena.query.ReadWrite; //导入依赖的package包/类
@Override
public void delete(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
dataset.getDefaultModel().getResource(uri.toString()).removeProperties();
dataset.removeNamedModel(uri.toString());
deleteToAll(uri.getPath());
dataset.commit();
} catch (Exception e) {
// TODO distinguish between client and server errors
throw new RESTException();
} finally {
dataset.end();
}
}