本文整理汇总了Java中org.eclipse.rdf4j.repository.Repository.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java Repository.getConnection方法的具体用法?Java Repository.getConnection怎么用?Java Repository.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.rdf4j.repository.Repository
的用法示例。
在下文中一共展示了Repository.getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLdpath
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
private LDPath<Value> createLdpath(Model model) {
Repository repository = new SailRepository(new MemoryStore());
Rdf4jRepositoryBackend repositoryBackend;
try {
repository.initialize();
repositoryBackend = new Rdf4jRepositoryBackend(repository);
final RepositoryConnection connection = repository.getConnection();
connection.add(model);
connection.close();
} catch (RepositoryException re) {
throw new LdPathExecutorRuntimeException("Unable to initialize RDF4JRepository.", re);
}
LDPath<Value> result = new LDPath<>(repositoryBackend, LD_PATH_CONFIG);
result.registerFunction(new SortByPropertyFunction<>(ldpathNamespaces));
return result;
}
示例2: testGetRepository
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
@Test
public void testGetRepository() throws Exception {
MarkLogicRepositoryConfig config = new MarkLogicRepositoryConfig();
config.setHost(host);
config.setPort(port);
config.setUser(adminUser);
config.setPassword(adminPassword);
config.setAuth("DIGEST");
RepositoryFactory factory = new MarkLogicRepositoryFactory();
Assert.assertEquals("marklogic:MarkLogicRepository", factory.getRepositoryType());
Repository repo = factory.getRepository(config);
repo.initialize();
Assert.assertTrue(repo.getConnection() instanceof MarkLogicRepositoryConnection);
Repository otherrepo = factory.getRepository(config);
otherrepo.initialize();
RepositoryConnection oconn = otherrepo.getConnection();
Assert.assertTrue(oconn instanceof MarkLogicRepositoryConnection);
}
示例3: createRepconn
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
private void createRepconn() throws Exception {
RepositoryConnection repConn1 = null;
Repository tempRep2 = null;
try {
MarkLogicRepositoryConfig tempConfig2 = new MarkLogicRepositoryConfig();
tempConfig2.setHost(host);
tempConfig2.setAuth("DIGEST");
tempConfig2.setUser("admin");
tempConfig2.setPassword("admin");
tempConfig2.setPort(restPort);
tempRep2 = new MarkLogicRepositoryFactory().getRepository(tempConfig2);
tempRep2.initialize();
repConn1 = tempRep2.getConnection();
assertThat(repConn1.hasStatement(john, fname, johnfname, false), is(equalTo(false)));
} catch (Exception e) {
logger.debug(e.getMessage());
} finally {
if (repConn1.isActive())
repConn1.rollback();
tempRep2.shutDown();
repConn1.close();
repConn1 = null;
tempRep2 = null;
}
}
示例4: persistSavesNewReportIntoUniqueContext
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
@Test
public void persistSavesNewReportIntoUniqueContext() throws Exception {
final EntityManager em = emf.createEntityManager();
RepositoryConnection connection = null;
try {
final Repository repository = em.unwrap(Repository.class);
connection = repository.getConnection();
assertFalse(connection.getContextIDs().hasNext());
final OccurrenceReport report = OccurrenceReportGenerator.generateOccurrenceReportWithFactorGraph();
report.getAuthor().generateUri();
final Map<String, URI> ctx = dao.persist(report);
assertTrue(connection.getContextIDs().hasNext());
final Set<URI> contexts = getContexts(connection);
assertTrue(ctx.containsKey(OccurrenceReportFormGenDao.REPORT_CONTEXT_NAME));
assertTrue(contexts.contains(ctx.get(OccurrenceReportFormGenDao.REPORT_CONTEXT_NAME)));
} finally {
em.close();
if (connection != null) {
connection.close();
}
}
}
示例5: persistExportsE5xDataIntoSeparateContextAndReturnsItsUri
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
@Test
public void persistExportsE5xDataIntoSeparateContextAndReturnsItsUri() throws Exception {
final EntityManager em = mainEmf.createEntityManager();
RepositoryConnection sourceConnection = null;
try {
final Repository repository = em.unwrap(Repository.class);
sourceConnection = repository.getConnection();
final OccurrenceReport report = OccurrenceReportGenerator.generateOccurrenceReportWithFactorGraph();
report.setUri(Generator.generateUri());
final Collection<Statement> e5Data = persistE5Data(report.getUri(), sourceConnection);
report.getAuthor().generateUri();
final Map<String, URI> ctx = dao.persist(report);
assertTrue(ctx.containsKey(OccurrenceReportFormGenDao.REPORT_CONTEXT_NAME));
assertTrue(ctx.containsKey(OccurrenceReportFormGenDao.DATA_CONTEXT_NAME));
verifyStatementPresence(e5Data, ctx.get(OccurrenceReportFormGenDao.DATA_CONTEXT_NAME));
} finally {
em.close();
if (sourceConnection != null) {
sourceConnection.close();
}
}
}
示例6: verifyStatementPresence
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
private void verifyStatementPresence(Collection<Statement> statements, URI contextUri) throws Exception {
final EntityManager em = emf.createEntityManager();
final Repository repo = em.unwrap(Repository.class);
try (final RepositoryConnection connection = repo.getConnection()) {
final ValueFactory vf = connection.getValueFactory();
final org.eclipse.rdf4j.model.IRI context = vf.createIRI(contextUri.toString());
for (Statement s : statements) {
final RepositoryResult rr = connection
.getStatements(s.getSubject(), s.getPredicate(), s.getObject(), false, context);
assertTrue(rr.hasNext());
rr.close();
}
} finally {
em.close();
}
}
示例7: persistTestData
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
public void persistTestData(Collection<Triple> data, EntityManager em) throws Exception {
final Repository repository = em.unwrap(Repository.class);
try (final RepositoryConnection connection = repository.getConnection()) {
final ValueFactory vf = connection.getValueFactory();
connection.begin();
for (Triple t : data) {
if (t.getValue() instanceof URI) {
connection.add(vf.createIRI(t.getSubject().toString()), vf.createIRI(t.getProperty().toString()),
vf.createIRI(t.getValue().toString()));
} else {
connection.add(vf.createIRI(t.getSubject().toString()), vf.createIRI(t.getProperty().toString()),
SesameUtils.createDataPropertyLiteral(t.getValue(), t.getLanguage(), vf));
}
}
connection.commit();
}
}
示例8: verifyDataPresence
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
public void verifyDataPresence(Collection<Triple> data, EntityManager em) throws Exception {
final Repository repository = em.unwrap(Repository.class);
try (final RepositoryConnection connection = repository.getConnection()) {
final ValueFactory vf = connection.getValueFactory();
for (Triple t : data) {
final boolean found;
if (t.getValue() instanceof URI) {
found = connection.hasStatement(vf.createIRI(t.getSubject().toString()),
vf.createIRI(t.getProperty().toString()), vf.createIRI(t.getValue().toString()), false);
} else {
found = connection.hasStatement(vf.createIRI(t.getSubject().toString()),
vf.createIRI(t.getProperty().toString()),
SesameUtils.createDataPropertyLiteral(t.getValue(), t.getLanguage(), vf), false);
}
assertTrue(found);
}
}
}
示例9: initTestData
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
public static GeneratedData initTestData(Repository repository) throws RepositoryException {
final RepositoryConnection connection = repository.getConnection();
connection.begin();
final ValueFactory vf = connection.getValueFactory();
final GeneratedData data = new GeneratedData();
int classCount = randomPositiveInt(10);
for (int i = 0; i < classCount; i++) {
final String cls = "http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClass" + RAND.nextInt();
data.classes.add(cls);
int individualCount = randomPositiveInt(20);
for (int j = 0; j < individualCount; j++) {
final String ind = cls + "_instance-" + RAND.nextInt();
data.individuals.add(ind);
final IRI indUri = vf.createIRI(ind);
generatePropertiesWithValues(indUri, data, connection);
connection.add(indUri, RDF.TYPE, vf.createIRI(cls));
data.addValue(ind, Assertion.createClassAssertion(false), java.net.URI.create(cls));
}
}
connection.commit();
connection.close();
return data;
}
示例10: getConnection
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
public RepositoryConnection getConnection(URL endpoint) throws RepositoryException {
Repository repo = null;
if (!repoMap.containsKey(endpoint)) {
repo = new SPARQLRepository(endpoint.toString());
repoMap.put(endpoint,repo);
} else {
repo = repoMap.get(endpoint);
}
if (!repo.isInitialized())
repo.initialize();
RepositoryConnection conn = repo.getConnection();
logger.info("Open [{}] (currently open={})", conn, countconn);
synchronized(this) { countconn++; }
return conn;
}
示例11: initializeMetadata
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
public void initializeMetadata(Repository metadata, String filename)
throws RepositoryException, IOException, RDFParseException
{
RepositoryConnection conn = null;
try {
File file = new File(filename);
metadata.initialize();
conn = metadata.getConnection();
RDFFormat fileFormat = RDFFormat.matchFileName(file.getAbsolutePath(), RDFParserRegistry.getInstance().getKeys()).orElse(RDFFormat.NTRIPLES);
conn.add(file, file.toURI().toString(), fileFormat);
} finally {
if (conn != null)
conn.close();
}
}
示例12: getAllStatements
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
public static List<Statement> getAllStatements(Repository repository) throws RepositoryException {
RepositoryConnection connection = repository.getConnection();
try {
List<Statement> result = new ArrayList<>();
RepositoryResult<Statement> repositoryResult = connection.getStatements(null, null, null, false);
try {
while (repositoryResult.hasNext()) {
result.add(repositoryResult.next());
}
} finally {
repositoryResult.close();
}
return result;
} finally {
connection.close();
}
}
示例13: negativeTestRepo2
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
@Test
public void negativeTestRepo2()
throws Exception {
Repository rep = new MarkLogicRepository(host, port, new DatabaseClientFactory.DigestAuthContext(user, password));
rep.initialize();
rep.shutDown();
// should throw error as we shutdown repo
exception.expect(RepositoryException.class);
exception.expectMessage("MarkLogicRepository not initialized.");
@SuppressWarnings("unused")
RepositoryConnection conn = rep.getConnection();
}
示例14: TestRepoWithJavaAPIClientDatabaseClient
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
@Test
public void TestRepoWithJavaAPIClientDatabaseClient()
throws Exception {
DatabaseClient databaseClient = DatabaseClientFactory.newClient(host, port, new DatabaseClientFactory.DigestAuthContext(user, password));
Repository rep = new MarkLogicRepository(databaseClient);
rep.initialize();
Assert.assertTrue(rep instanceof Repository);
RepositoryConnection conn = rep.getConnection();
Assert.assertTrue(conn instanceof RepositoryConnection);
conn.close();
rep.shutDown();
}
示例15: testNestedConnections
import org.eclipse.rdf4j.repository.Repository; //导入方法依赖的package包/类
@Test
public void testNestedConnections()
throws RDF4JException {
MarkLogicRepositoryConfig config = new MarkLogicRepositoryConfig();
config.setHost(host);
config.setPort(port);
config.setUser(user);
config.setPassword(password);
config.setAuth("DIGEST");
MarkLogicRepositoryFactory FACTORY = new MarkLogicRepositoryFactory();
ValueFactory vf = conn.getValueFactory();
IRI tommy = vf.createIRI("http://marklogicsparql.com/id#4444");
IRI lname = vf.createIRI("http://marklogicsparql.com/addressbook#lastName");
Literal tommylname = vf.createLiteral("Ramone");
Statement stmt = vf.createStatement(tommy, lname, tommylname);
conn.add(stmt);
conn.begin();
Repository repo2 = FACTORY.getRepository(config);
repo2.initialize();
RepositoryConnection conn2 = repo2.getConnection();
conn2.begin();
Assert.assertEquals("The size of repository must be zero", 1, conn.size());
conn2.commit();
conn2.close();
repo2.shutDown();
conn.commit();
}