本文整理汇总了Java中org.openrdf.repository.RepositoryResult.close方法的典型用法代码示例。如果您正苦于以下问题:Java RepositoryResult.close方法的具体用法?Java RepositoryResult.close怎么用?Java RepositoryResult.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.repository.RepositoryResult
的用法示例。
在下文中一共展示了RepositoryResult.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractAllStatements
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
@Override
public LinkedList<Statement> extractAllStatements(Repository repo, int nrTriples) {
RepositoryConnection con = repo.getConnection();
RepositoryResult<Statement> triples = con.getStatements(null, null,
null, false);
LinkedList<Statement> statements = new LinkedList<Statement>();
try {
System.out.println("triples to extract: "+nrTriples);
if(nrTriples == -1)
Iterations.addAll(triples, statements);
else {
int count = 0;
while(triples.hasNext() && count < nrTriples){
statements.add(triples.next());
count++;
}
}
} finally {
triples.close();
con.close();
}
return statements;
}
示例2: testDuplicateLiterals
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
public void testDuplicateLiterals() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
Literal lit1 = vf.createLiteral(0.0);
Literal lit2 = vf.createLiteral(0.0);
Literal lit3 = vf.createLiteral(0.0);
conn.add(cpu, loadPerc, lit1);
conn.add(cpu, loadPerc, lit2);
conn.add(cpu, loadPerc, lit3);
conn.commit();
RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true, new Resource[0]);
int count = 0;
while (result.hasNext()) {
count++;
result.next();
}
result.close();
assertEquals(1, count);
//clean up
conn.remove(cpu, loadPerc, lit1);
conn.close();
}
示例3: testNotDuplicateUris
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
public void testNotDuplicateUris() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
URI uri1 = vf.createURI(litdupsNS, "uri1");
URI uri2 = vf.createURI(litdupsNS, "uri1");
URI uri3 = vf.createURI(litdupsNS, "uri1");
conn.add(cpu, loadPerc, uri1);
conn.add(cpu, loadPerc, uri2);
conn.add(cpu, loadPerc, uri3);
conn.commit();
RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true, new Resource[0]);
int count = 0;
while (result.hasNext()) {
count++;
result.next();
}
result.close();
assertEquals(1, count);
//clean up
conn.remove(cpu, loadPerc, uri1);
conn.close();
}
示例4: testNamedGraphLoad2
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
public void testNamedGraphLoad2() throws Exception {
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
assertNotNull(stream);
RepositoryConnection conn = repository.getConnection();
conn.add(stream, "", RDFFormat.TRIG);
conn.commit();
RepositoryResult<Statement> statements = conn.getStatements(null, vf.createURI("http://www.example.org/vocabulary#name"), null, true, vf.createURI("http://www.example.org/exampleDocument#G1"));
int count = 0;
while (statements.hasNext()) {
statements.next();
count++;
}
statements.close();
assertEquals(1, count);
conn.close();
}
示例5: getStoredModelIds
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
/**
* Retrieve a collection of all file/stored model ids found in the repo.<br>
* Note: Models may not be loaded at this point.
*
* @return set of modelids.
* @throws IOException
*/
public Set<IRI> getStoredModelIds() throws IOException {
try {
BigdataSailRepositoryConnection connection = repo.getReadOnlyConnection();
try {
RepositoryResult<Resource> graphs = connection.getContextIDs();
Set<IRI> modelIds = new HashSet<>();
while (graphs.hasNext()) {
modelIds.add(IRI.create(graphs.next().stringValue()));
}
graphs.close();
return Collections.unmodifiableSet(modelIds);
} finally {
connection.close();
}
} catch (RepositoryException e) {
throw new IOException(e);
}
}
示例6: loadModelABox
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
@Override
protected OWLOntology loadModelABox(IRI modelId) throws OWLOntologyCreationException {
LOG.info("Load model abox: " + modelId + " from database");
try {
BigdataSailRepositoryConnection connection = repo.getReadOnlyConnection();
try {
//TODO repeated code with loadModel
RepositoryResult<Resource> graphs = connection.getContextIDs();
if (!Iterations.asSet(graphs).contains(new URIImpl(modelId.toString()))) {
throw new OWLOntologyCreationException("No such model in datastore: " + modelId);
}
graphs.close();
RepositoryResult<Statement> statements =
connection.getStatements(null, null, null, false, new URIImpl(modelId.toString()));
OWLOntology abox = loadOntologyDocumentSource(new RioMemoryTripleSource(statements), true);
statements.close();
abox = postLoadFileFilter(abox);
return abox;
} finally {
connection.close();
}
} catch (RepositoryException e) {
throw new OWLOntologyCreationException(e);
}
}
示例7: getTypes
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
public Set<URI> getTypes(Resource res) throws RepositoryException {
if (!readTypes)
return Collections.emptySet();
RepositoryResult<Statement> match = conn.getStatements(res, RDF.TYPE, null);
try {
if (!match.hasNext())
return Collections.emptySet();
Value obj = match.next().getObject();
if (obj instanceof URI && !match.hasNext())
return Collections.singleton((URI) obj);
Set<URI> types = new HashSet<URI>(4);
if (obj instanceof URI) {
types.add((URI) obj);
}
while (match.hasNext()) {
obj = match.next().getObject();
if (obj instanceof URI) {
types.add((URI) obj);
}
}
return types;
} finally {
match.close();
}
}
示例8: getSize
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
private int getSize(Repository repository) throws RepositoryException {
int size = 0;
RepositoryConnection connection = null;
RepositoryResult<Statement> iter = null;
try {
connection = repository.getConnection();
iter = connection.getStatements(null, null, null, false);
while (iter.hasNext()) {
iter.next();
++size;
}
} finally {
if (iter != null)
iter.close();
if (connection != null)
connection.close();
}
return size;
}
示例9: getLastModified
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
/**
* Get the last modification of the set of triples passed as argument.
*
* @return date
* @throws org.openrdf.repository.RepositoryException
*/
public static Date getLastModified(RepositoryConnection conn, Resource resource) throws RepositoryException {
Date last_modified = new Date(0);
RepositoryResult<Statement> triples = conn.getStatements(resource, null, null, false);
try {
while (triples.hasNext()) {
Statement triple = triples.next();
try {
Method m = triple.getClass().getMethod("getCreated", new Class[0]);
Date created = (Date)m.invoke(triple);
if (created.getTime() > last_modified.getTime()) {
last_modified = created;
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassCastException e) {
// do nothing
}
}
} finally {
triples.close();
}
return last_modified;
}
示例10: testSetProperty
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
/**
* Test setting properties
*/
@Test
public void testSetProperty() throws RepositoryException {
RepositoryConnection connection = repository.getConnection();
try {
URI toni = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/toni_schneider");
URI name = connection.getValueFactory().createURI(Namespaces.NS_FOAF + "name");
ResourceUtils.setProperty(connection,toni,"foaf:name","Anton Schneider");
// test if getProperty returns the correct names
Assert.assertEquals("Anton Schneider", ResourceUtils.getProperty(connection,toni,"foaf:name"));
// test if getStatements returns the correct statement
RepositoryResult<Statement> triples = connection.getStatements(toni,name,null,true);
Assert.assertTrue(triples.hasNext());
Assert.assertEquals("Anton Schneider", triples.next().getObject().stringValue());
triples.close();
} finally {
connection.close();
}
}
示例11: testaddOutgoingNodeLabel
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
/**
* Test adding outgoing statements (by string label of the property)
*/
@Test
public void testaddOutgoingNodeLabel() throws RepositoryException {
RepositoryConnection connection = repository.getConnection();
try {
URI toni = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/toni_schneider");
URI name = connection.getValueFactory().createURI(Namespaces.NS_FOAF + "name");
String property = "foaf:name";
Literal value = connection.getValueFactory().createLiteral("Anton Schneider");
ResourceUtils.addOutgoingNode(connection,toni,property,value,null);
// test if getProperty returns the correct names
Assert.assertEquals("Anton Schneider", ResourceUtils.getProperty(connection,toni,"foaf:name"));
// test if getStatements returns the correct statement
RepositoryResult<Statement> triples = connection.getStatements(toni,name,null,true);
Assert.assertTrue(triples.hasNext());
Assert.assertEquals("Anton Schneider", triples.next().getObject().stringValue());
triples.close();
} finally {
connection.close();
}
}
示例12: getLastModified
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
@Override
public Date getLastModified(RepositoryConnection connection, URI uri) throws RepositoryException {
final RepositoryResult<Statement> stmts = connection.getStatements(uri, DCTERMS.modified, null, true, ldpContext);
try {
Date latest = null;
while (stmts.hasNext()) {
Value o = stmts.next().getObject();
if (o instanceof Literal) {
Date d = ((Literal)o).calendarValue().toGregorianCalendar().getTime();
if (latest == null || d.after(latest)) {
latest = d;
}
}
}
return latest;
} finally {
stmts.close();
}
}
示例13: delProperties
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
private void delProperties(final FacadingPredicate predicate, final Locale loc) throws RepositoryException {
for (String v : predicate.getProperties()) {
final URI prop = connection.getValueFactory().createURI(v);
if (!predicate.isInverse() && loc == null) {
// remove all properties prop that have this subject;
connection.remove(delegate, prop, null, context);
} else if (predicate.isInverse() && loc == null) {
// remove all properties prop that have this object;
connection.remove((Resource) null, prop, delegate, context);
} else if (!predicate.isInverse() && loc != null) {
final RepositoryResult<Statement> statements = connection.getStatements(delegate, prop, null, false, context);
try {
while (statements.hasNext()) {
final Statement s = statements.next();
if (FacadingInvocationHelper.checkLocale(loc, s.getObject())) {
connection.remove(s);
}
}
} finally {
statements.close();
}
} else if (predicate.isInverse() && loc != null) { throw new IllegalArgumentException("A combination of @RDFInverse and a Literal is not possible");
}
}
}
示例14: queryOutgoingSingle
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
/**
* Return the single object of type C that is reachable from entity by rdf_property. Returns
* null if there is no such object or if the type of the object does not match the type passed
* as argument.
*
*/
private <C> C queryOutgoingSingle(Resource entity, String rdf_property, Class<C> returnType) throws RepositoryException {
URI property = connection.getValueFactory().createURI(rdf_property);
RepositoryResult<Statement> triples = connection.getStatements(entity, property, null, false);
try {
if (triples.hasNext()) {
Statement triple = triples.next();
Value object = triple.getObject();
if (returnType.isInstance(object)) {
return returnType.cast(object);
} else {
log.error("cannot cast retrieved object {} for property {} to return type {}", object, rdf_property, returnType);
return null;
}
} else {
return null;
}
} finally {
triples.close();
}
}
示例15: getProperties
import org.openrdf.repository.RepositoryResult; //导入方法依赖的package包/类
private Set<String> getProperties(Resource entity, URI property, Locale loc, URI context) throws RepositoryException {
final String lang = loc == null ? null : loc.getLanguage().toLowerCase();
final Set<String> values = new HashSet<String>();
final RepositoryResult<Statement> candidates = connection.getStatements(entity, property, null, false, context);
try {
while (candidates.hasNext()) {
Statement triple = candidates.next();
if (triple.getObject() instanceof Literal) {
Literal l = (Literal) triple.getObject();
if (lang == null || lang.equals(l.getLanguage())) {
values.add(l.stringValue());
}
}
}
} finally {
candidates.close();
}
return values;
}