org.eclipse.rdf4j.repository.Repository.getConnection()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中org.eclipse.rdf4j.repository.Repository.getConnection方法的一些代码示例,展示了Repository.getConnection的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.getConnection方法的具体详情如下:
包路径:org.eclipse.rdf4j.repository.Repository
类名称:Repository
方法名:getConnection

Repository.getConnection介绍

[英]Opens a connection to this repository that can be used for querying and updating the contents of the repository. Created connections need to be closed to make sure that any resources they keep hold of are released. The best way to do this is to use a try-finally-block as follows:

Connection con = repository.getConnection(); 
try { 
// perform operations on the connection 
} 
finally { 
con.close(); 
}

Note that RepositoryConnection is not guaranteed to be thread-safe! The recommended pattern for repository access in a multithreaded application is to share the Repository object between threads, but have each thread create and use its own RepositoryConnections.
[中]打开与此存储库的连接,该连接可用于查询和更新存储库的内容。创建的连接需要关闭,以确保释放它们保留的任何资源。最好的方法是使用try finally块,如下所示:

Connection con = repository.getConnection(); 
try { 
// perform operations on the connection 
} 
finally { 
con.close(); 
}

注意,RepositoryConnection不保证线程安全!多线程应用程序中存储库访问的推荐模式是在线程之间共享存储库对象,但让每个线程创建并使用自己的RepositoryConnections。

代码示例

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client

public ContextAwareConnection(Repository repository)
  throws RepositoryException
{
  this(repository, repository.getConnection());
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-repository-sparql

protected RepositoryConnection getConnection()
  throws RepositoryException
{
  // use a cache connection if possible
  // (TODO add mechanism to unset/close connection)
  if (conn == null) {
    conn = rep.getConnection();
  }
  return conn;
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client

protected RepositoryConnection getConnection()
  throws RepositoryException
{
  // use a cache connection if possible
  // (TODO add mechanism to unset/close connection)
  if (conn == null) {
    conn = rep.getConnection();
  }
  return conn;
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-repository-sail

@Override
public RepositoryConnection getConnection()
  throws RepositoryException
{
  return getProxiedRepository().getConnection();
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client

public RepositoryConnection getConnection()
  throws RepositoryException
{
  return getDelegate().getConnection();
}

代码示例来源:origin: de.tudarmstadt.ukp.inception.rdf4j/rdf4j-shacl

@Override
public boolean requiresEvaluation(Repository addedStatements, Repository removedStatements) {
  boolean requiresEvalutation;
  try (RepositoryConnection addedStatementsConnection = addedStatements.getConnection()) {
    requiresEvalutation = addedStatementsConnection.hasStatement(null, path, null, false);
  }
  try (RepositoryConnection removedStatementsConnection = removedStatements.getConnection()) {
    requiresEvalutation |= removedStatementsConnection.hasStatement(null, path, null, false);
  }
  return requiresEvalutation;
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-shacl

@Override
public boolean requiresEvaluation(Repository addedStatements, Repository removedStatements) {
  boolean requiresEvalutation;
  try (RepositoryConnection addedStatementsConnection = addedStatements.getConnection()) {
    requiresEvalutation = addedStatementsConnection.hasStatement(null, path, null, false);
  }
  try (RepositoryConnection removedStatementsConnection = removedStatements.getConnection()) {
    requiresEvalutation |= removedStatementsConnection.hasStatement(null, path, null, false);
  }
  return requiresEvalutation;
}

代码示例来源:origin: com.powsybl/powsybl-triple-store-impl-rdf4j

@Override
public Set<String> contextNames() {
  try (RepositoryConnection conn = repo.getConnection()) {
    return Iterations.stream(conn.getContextIDs()).map(Resource::stringValue).collect(Collectors.toSet());
  }
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-shacl

@Override
public boolean requiresEvaluation(Repository addedStatements, Repository removedStatements) {
  boolean requiresEvalutation;
  try (RepositoryConnection addedStatementsConnection = addedStatements.getConnection()) {
    requiresEvalutation = addedStatementsConnection.hasStatement(null, RDF.TYPE, targetClass, false);
  }
  return super.requiresEvaluation(addedStatements, removedStatements) || requiresEvalutation;
}

代码示例来源:origin: com.powsybl/powsybl-triple-store-impl-rdf4j

@Override
public void clear(String contextName) {
  try (RepositoryConnection conn = repo.getConnection()) {
    Resource context = context(conn, contextName);
    conn.clear(context);
  }
}

代码示例来源:origin: com.powsybl/powsybl-triple-store-impl-rdf4j

@Override
public void print(PrintStream out) {
  out.println("TripleStore based on RDF4J. Graph names and sizes");
  try (RepositoryConnection conn = repo.getConnection()) {
    RepositoryResult<Resource> ctxs = conn.getContextIDs();
    while (ctxs.hasNext()) {
      Resource ctx = ctxs.next();
      int size = statementsCount(conn, ctx);
      out.println("    " + ctx + " : " + size);
    }
  }
}

代码示例来源:origin: org.streampipes/streampipes-storage-rdf4j

@Override
public boolean deleteNamespace(String prefix) {
  try {
    RepositoryConnection conn = repo.getConnection();
    conn.removeNamespace(prefix); 
    conn.close();
    return true;
  } catch (RepositoryException e) {
    e.printStackTrace();
    return false;
  } 
}

代码示例来源:origin: org.streampipes/streampipes-storage-rdf4j

public void executeUpdate(String sparqlUpdate) throws UpdateExecutionException, RepositoryException, MalformedQueryException {
 RepositoryConnection connection = repository.getConnection();
 Update tupleQuery;
 tupleQuery = connection.prepareUpdate(QueryLanguage.SPARQL, sparqlUpdate);
 tupleQuery.execute();
 connection.close();
}

代码示例来源:origin: joshsh/sesametools

protected SailConnection getConnectionInternal() throws SailException {
  RepositoryConnection rc;
  try {
    rc = repository.getConnection();
  } catch (RepositoryException e) {
    throw new SailException(e);
  }
  return new RepositorySailConnection(this, rc, inferenceDisabled, this.getValueFactory());
}

代码示例来源:origin: inception-project/inception

@Override
public RepositoryConnection getConnection(KnowledgeBase kb)
{
  assertRegistration(kb);
  return repoManager.getRepository(kb.getRepositoryId()).getConnection();
}

代码示例来源:origin: de.tudarmstadt.ukp.inception.app/inception-kb

@Override
public RepositoryConnection getConnection(KnowledgeBase kb)
{
  assertRegistration(kb);
  return repoManager.getRepository(kb.getRepositoryId()).getConnection();
}

代码示例来源:origin: org.streampipes/streampipes-storage-rdf4j

public TupleQueryResult executeQuery(String sparqlQuery) throws QueryEvaluationException, RepositoryException, MalformedQueryException {
 RepositoryConnection connection = repository.getConnection();
 TupleQuery tupleQuery;
 TupleQueryResult result;
 tupleQuery = connection.prepareTupleQuery(
     QueryLanguage.SPARQL, sparqlQuery);
 result = tupleQuery.evaluate();
 connection.close();
 return result;
}

代码示例来源:origin: org.streampipes/streampipes-storage-rdf4j

@Override
public List<Namespace> getNamespaces() throws RepositoryException {
  
  List<Namespace> result = new ArrayList<>();
  RepositoryResult<org.eclipse.rdf4j.model.Namespace> namespaces = repo.getConnection().getNamespaces();
  
  while(namespaces.hasNext())
  {
    org.eclipse.rdf4j.model.Namespace ns = namespaces.next();
    result.add(new Namespace(ns.getPrefix(), ns.getName()));
  }
  return result;
  
}

代码示例来源:origin: org.streampipes/streampipes-storage-rdf4j

@Override
public boolean addNamespace(Namespace namespace) {
  
  try {
    RepositoryConnection conn = repo.getConnection();
    conn.setNamespace(namespace.getPrefix(), namespace.getNamespaceId());
    conn.close();
    return true;
  } catch (RepositoryException e) {
    e.printStackTrace();
    return false;
  } 
}

代码示例来源:origin: franzinc/agraph-java-client

/**
 * Tests the default dataset in a memory store.
 */
@Test
@Category(TestSuites.NotApplicableForAgraph.class)
public void testMemoryStoreDefaultDataset() throws Exception {
  Repository repo = new SailRepository(new MemoryStore());
  repo.initialize();
  RepositoryConnection conn = repo.getConnection();
  testSesameDefaultDataset(conn);
}

相关文章