本文整理汇总了Java中org.openrdf.repository.Repository.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java Repository.getConnection方法的具体用法?Java Repository.getConnection怎么用?Java Repository.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.repository.Repository
的用法示例。
在下文中一共展示了Repository.getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() throws IOException, RepositoryException, RDFParseException {
int port;
try (final ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
}
server = CommunityServerBuilder.server()
.onPort(port)
.withThirdPartyJaxRsPackage("de.unikiel.inf.comsys.neo4j", "/rdf")
.build();
server.start();
GraphDatabaseService db = server.getDatabase().getGraph();
Repository rep = RepositoryRegistry.getInstance(db).getRepository();
conn = rep.getConnection();
InputStream testdata = RDFServerExtensionTest.class.getResourceAsStream("/sp2b.n3");
conn.add(testdata, "http://example.com/", RDFFormat.N3);
}
示例2: setUp
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
Repository fromrepo = new SailRepository( new MemoryStore() );
Repository torepo = new SailRepository( new MemoryStore() );
fromrepo.initialize();
torepo.initialize();
from = fromrepo.getConnection();
to = torepo.getConnection();
from.add( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "test" ) ) );
from.add( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "test2" ) ) );
from.setNamespace( OWL.PREFIX, OWL.NAMESPACE );
}
示例3: testUpdateDate2
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Test
public void testUpdateDate2() throws Exception {
Repository repo = new SailRepository( new MemoryStore() );
repo.initialize();
RepositoryConnection rc = repo.getConnection();
URI base = Utility.getUniqueUri();
Date now = new Date();
rc.add( new StatementImpl( base, MetadataConstants.DCT_MODIFIED,
rc.getValueFactory().createLiteral( now ) ) );
AbstractSesameEngine.updateLastModifiedDate( rc, null );
List<Statement> stmts = Iterations.asList( eng.getRawConnection().
getStatements( eng.getBaseUri(), MetadataConstants.DCT_MODIFIED,
null, false ) );
Literal val = Literal.class.cast( stmts.get( 0 ).getObject() );
Date upd = getDate( val.calendarValue() );
rc.close();
repo.shutDown();
// the 100 is to remove the ms, which aren't always the same because
// they're not stored in the RDF
assertEquals( now.getTime(), upd.getTime(), 100 );
}
示例4: extractAllStatements
import org.openrdf.repository.Repository; //导入方法依赖的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;
}
示例5: testAddStatement
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Ignore
@Test
public void testAddStatement() throws Exception {
SailRepositoryFactory f = new SailRepositoryFactory();
Repository r = f.getRepository(getConfig());
r.initialize();
RepositoryConnection rc = r.getConnection();
ValueFactory vf = rc.getValueFactory();
Statement s = vf.createStatement(vf.createURI("u:a"), vf.createURI("u:b"), vf.createURI("u:c"));
assertFalse(rc.hasStatement(s, false));
rc.add(s);
Assert.assertTrue(rc.hasStatement(s, false));
rc.close();
}
示例6: getDeleteDataResult
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
/**
* Delete data from the graph.
*
* @param repository the Repository object
* @param request the HttpServletRequest object
* @param response the HttpServletResponse object
* @return the EmptySuccessView if successes
* @throws ClientHTTPException throws when there are errors in getting the name of the Graph
* @throws ServerHTTPException throws when errors happens update the data
*/
private ModelAndView getDeleteDataResult(final Repository repository,
final HttpServletRequest request, final HttpServletResponse response)
throws ClientHTTPException, ServerHTTPException {
ProtocolUtil.logRequestParameters(request);
ValueFactory vf = repository.getValueFactory();
URI graph = getGraphName(request, vf);
try {
RepositoryConnection repositoryCon = repository.getConnection();
synchronized (repositoryCon) {
repositoryCon.clear(graph);
}
repositoryCon.close();
return new ModelAndView(EmptySuccessView.getInstance());
} catch (RepositoryException e) {
throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
}
}
示例7: question7
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
public static Map<String, Repository> question7(Repository rep) {
RepositoryConnection conn = null;
RepositoryConnection fc_conn = null;
SailRepository fc_rep = new SailRepository(
new ForwardChainingRDFSInferencer(new MemoryStore()));
try {
conn = rep.getConnection();
fc_rep.initialize();
fc_conn = fc_rep.getConnection();
RepositoryResult<Statement> statements = conn.getStatements(null,
null, null, true);
fc_conn.add(statements);
conn.clear();
conn.add(fc_conn.getStatements(null, null, null, true));
} catch (RepositoryException e) {
e.printStackTrace();
} finally {
closeRepositoryConnection(fc_conn);
closeRepositoryConnection(conn);
}
question4(fc_rep, "8");
Map<String, Repository> map = new HashMap<String, Repository>();
map.put("fc_rep", fc_rep);
map.put("rep", rep);
return map;
}
示例8: executeSelectQuery
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
public static TupleQueryResult executeSelectQuery(Repository repo, String query,
QueryLanguage ql) throws OpenRDFException {
RepositoryConnection cxn;
if (repo instanceof BigdataSailRepository) {
cxn = ((BigdataSailRepository) repo).getReadOnlyConnection();
} else {
cxn = repo.getConnection();
}
try {
final TupleQuery tupleQuery = cxn.prepareTupleQuery(ql, query);
tupleQuery.setIncludeInferred(true /* includeInferred */);
return tupleQuery.evaluate();
} finally {
// close the repository connection
cxn.close();
}
}
示例9: getSize
import org.openrdf.repository.Repository; //导入方法依赖的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;
}
示例10: createRc
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Override
protected void createRc( Properties props ) throws RepositoryException {
String url = props.getProperty( REPOSITORY_KEY );
insightsloc = props.getProperty( INSIGHTS_KEY );
boolean remote = Boolean.parseBoolean( props.getProperty( REMOTE_KEY,
Boolean.FALSE.toString() ) );
if ( remote ) {
setProperty( Constants.SMSS_LOCATION, url );
}
Repository repo = getRawRepository( url );
repo.initialize();
data = repo.getConnection();
}
示例11: createRc
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Override
protected final void createRc( Properties p ) {
if ( null != rc ) {
// we've already have our rc created, so there's nothing to do here
return;
}
Security.getSecurity().associateUser( this, new LocalUserImpl() );
MemoryStore memstore = ( p.containsKey( MEMSTORE_DIR )
? new MemoryStore( new File( p.getProperty( MEMSTORE_DIR ) ) )
: new MemoryStore() );
if ( p.containsKey( SYNC_DELAY ) ) {
memstore.setSyncDelay( Long.parseLong( p.getProperty( SYNC_DELAY ) ) );
}
Sail sail = ( p.containsKey( INFER )
? new ForwardChainingRDFSInferencer( memstore )
: memstore );
Repository repo = new SailRepository( sail );
try {
repo.initialize();
rc = repo.getConnection();
}
catch ( Exception e ) {
try {
repo.shutDown();
}
catch ( Exception ex ) {
log.error( ex, ex );
}
}
setRepositoryConnection( rc, true );
}
示例12: testCreateFromRepository
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Test
public void testCreateFromRepository() throws Exception {
Repository repo = new SailRepository( new MemoryStore() );
repo.initialize();
RepositoryConnection rc = repo.getConnection();
rc.add( SRCFILE, null, RDFFormat.TURTLE );
rc.commit();
rc.close();
InsightManager imi = InsightManagerImpl.createFromRepository( repo );
repo.shutDown();
assertEquals( 1, imi.getPerspectives().size() );
}
示例13: populateSesame
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
private void populateSesame(Repository testRepo) throws RepositoryException {
RepositoryConnection con = testRepo.getConnection();
ValueFactory f = testRepo.getValueFactory();
con.setNamespace("rdf", RDF_NS);
con.setNamespace("rdfs", RDFS_NS);
con.setNamespace("xsd", XSD_NS);
con.setNamespace("xsd", XSD_NS);
URI alice = f.createURI("http://example.org/people/alice");
URI bob = f.createURI("http://example.org/people/bob");
URI person = f.createURI("http://example.org/ontology/Person");
URI label = f.createURI(RDFS_NS, "label");
URI birthplace = f.createURI("http://example.org/ontology/birthplace");
Literal bobsName = f.createLiteral("Bob", "en");
Literal alicesName = f.createLiteral("Alice", "en");
Literal birthplaceLabel = f.createLiteral("birth place", "en");
Literal londonLabel = f.createLiteral("London", "en");
try {
con.add(birthplace, label, birthplaceLabel);
con.add(alice, RDF.TYPE, person);
con.add(alice, label, alicesName);
con.add(alice, birthplace, londonLabel);
con.add(bob, RDF.TYPE, person);
con.add(bob, label, bobsName);
con.add(bob, birthplace, londonLabel);
} finally {
con.close();
}
}
示例14: testCreateAccumuloSail
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Ignore
@Test
public void testCreateAccumuloSail() throws Exception {
SailRepositoryFactory f = new SailRepositoryFactory();
Repository r = f.getRepository(getConfig());
r.initialize();
RepositoryConnection rc = r.getConnection();
rc.close();
}
示例15: getDeleteDataResult
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
/**
* Delete data from the repository.
*
* @param repository the Repository object
* @param request the HttpServletRequest object
* @param response the HttpServletResponse object
* @return EmptySuccessView if success
* @throws HTTPException throws when there are repository update errors
*/
private ModelAndView getDeleteDataResult(final Repository repository, final HttpServletRequest request,
final HttpServletResponse response)
throws HTTPException {
ProtocolUtil.logRequestParameters(request);
ValueFactory vf = repository.getValueFactory();
Resource subj = ProtocolUtil.parseResourceParam(request, SUBJECT_PARAM_NAME, vf);
URI pred = ProtocolUtil.parseURIParam(request, PREDICATE_PARAM_NAME, vf);
Value obj = ProtocolUtil.parseValueParam(request, OBJECT_PARAM_NAME, vf);
Resource[] contexts = ProtocolUtil.parseContextParam(request, CONTEXT_PARAM_NAME, vf);
try {
RepositoryConnection repositoryCon = repository.getConnection();
synchronized (repositoryCon) {
repositoryCon.remove(subj, pred, obj, contexts);
}
repositoryCon.close();
return new ModelAndView(EmptySuccessView.getInstance());
} catch (RepositoryException e) {
if (e.getCause() != null && e.getCause() instanceof HTTPException) {
// custom signal from the backend, throw as HTTPException directly
// (see SES-1016).
throw (HTTPException) e.getCause();
} else {
throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
}
}
}