Search in sources :

Example 1 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.

the class LocalRepositoryManagerTest method testRemoveFromSystemRepository.

@Test
public void testRemoveFromSystemRepository() {
    RepositoryConfig config = manager.getRepositoryConfig(TEST_REPO);
    manager.addRepositoryConfig(new RepositoryConfig(SystemRepository.ID, new SystemRepositoryConfig()));
    manager.shutDown();
    manager = new LocalRepositoryManager(datadir);
    manager.initialize();
    try (RepositoryConnection con = manager.getSystemRepository().getConnection()) {
        Model model = new TreeModel();
        config.setID("changed");
        config.export(model, con.getValueFactory().createBNode());
        con.begin();
        con.add(model, con.getValueFactory().createBNode());
        con.commit();
    }
    assertTrue(manager.hasRepositoryConfig("changed"));
    try (RepositoryConnection con = manager.getSystemRepository().getConnection()) {
        con.begin();
        con.clear(RepositoryConfigUtil.getContext(con, config.getID()));
        con.commit();
    }
    assertFalse(manager.hasRepositoryConfig(config.getID()));
}
Also used : SailRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig) ProxyRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.ProxyRepositoryConfig) RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Test(org.junit.Test)

Example 2 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.

the class LocalRepositoryManagerTest method testRestartManagerWithTransaction.

@Test
public void testRestartManagerWithTransaction() throws Exception {
    Repository rep = manager.getRepository(TEST_REPO);
    assertNotNull("Expected repository to exist.", rep);
    assertTrue("Expected repository to be initialized.", rep.isInitialized());
    RepositoryConnection conn = rep.getConnection();
    try {
        conn.begin();
        conn.add(conn.getValueFactory().createIRI("urn:sesame:test:subject"), RDF.TYPE, OWL.ONTOLOGY);
        conn.commit();
        assertEquals(1, conn.size());
    } finally {
        conn.close();
        rep.shutDown();
        manager.shutDown();
    }
    manager = new LocalRepositoryManager(datadir);
    manager.initialize();
    Repository rep2 = manager.getRepository(TEST_REPO);
    assertNotNull("Expected repository to exist.", rep2);
    assertTrue("Expected repository to be initialized.", rep2.isInitialized());
    RepositoryConnection conn2 = rep2.getConnection();
    try {
        assertEquals(1, conn2.size());
    } finally {
        conn2.close();
        rep2.shutDown();
        manager.shutDown();
    }
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Repository(org.eclipse.rdf4j.repository.Repository) Test(org.junit.Test)

Example 3 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.

the class LocalRepositoryManagerTest method testAddToSystemRepository.

@Test
public void testAddToSystemRepository() {
    RepositoryConfig config = manager.getRepositoryConfig(TEST_REPO);
    manager.addRepositoryConfig(new RepositoryConfig(SystemRepository.ID, new SystemRepositoryConfig()));
    manager.shutDown();
    manager = new LocalRepositoryManager(datadir);
    manager.initialize();
    try (RepositoryConnection con = manager.getSystemRepository().getConnection()) {
        Model model = new TreeModel();
        config.setID("changed");
        config.export(model, con.getValueFactory().createBNode());
        con.begin();
        con.add(model, con.getValueFactory().createBNode());
        con.commit();
    }
    assertTrue(manager.hasRepositoryConfig("changed"));
}
Also used : SailRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig) ProxyRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.ProxyRepositoryConfig) RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Test(org.junit.Test)

Example 4 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.

the class LocalRepositoryManagerTest method testModifySystemRepository.

@Test
public void testModifySystemRepository() {
    RepositoryConfig config = manager.getRepositoryConfig(TEST_REPO);
    manager.addRepositoryConfig(new RepositoryConfig(SystemRepository.ID, new SystemRepositoryConfig()));
    manager.shutDown();
    manager = new LocalRepositoryManager(datadir);
    manager.initialize();
    try (RepositoryConnection con = manager.getSystemRepository().getConnection()) {
        Model model = new TreeModel();
        config.setTitle("Changed");
        config.export(model, con.getValueFactory().createBNode());
        Resource ctx = RepositoryConfigUtil.getContext(con, config.getID());
        con.begin();
        con.clear(ctx);
        con.add(model, ctx == null ? con.getValueFactory().createBNode() : ctx);
        con.commit();
    }
    assertEquals("Changed", manager.getRepositoryConfig(TEST_REPO).getTitle());
}
Also used : SailRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig) ProxyRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.ProxyRepositoryConfig) RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) Test(org.junit.Test)

Example 5 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection in project nextprot-api by calipho-sib.

the class PhenotypicTTLIntegrationTest method doTupleQuery.

private TupleQueryResult doTupleQuery(String sparqlQuery) throws RepositoryException, QueryEvaluationException, MalformedQueryException {
    RepositoryConnection conn = testRepo.getConnection();
    TupleQuery query = (TupleQuery) conn.prepareQuery(QueryLanguage.SPARQL, sparqlQuery);
    TupleQueryResult result = query.evaluate();
    return result;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Aggregations

RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)34 Test (org.junit.Test)21 Repository (org.eclipse.rdf4j.repository.Repository)18 IRI (org.eclipse.rdf4j.model.IRI)6 Resource (org.eclipse.rdf4j.model.Resource)6 Statement (org.eclipse.rdf4j.model.Statement)6 Model (org.eclipse.rdf4j.model.Model)5 QueryLanguage (org.eclipse.rdf4j.query.QueryLanguage)5 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)4 RepositoryConfig (org.eclipse.rdf4j.repository.config.RepositoryConfig)4 Value (org.eclipse.rdf4j.model.Value)3 TreeModel (org.eclipse.rdf4j.model.impl.TreeModel)3 Dataset (org.eclipse.rdf4j.query.Dataset)3 ProxyRepositoryConfig (org.eclipse.rdf4j.repository.sail.config.ProxyRepositoryConfig)3 SailRepositoryConfig (org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig)3 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)2 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)2 Update (org.eclipse.rdf4j.query.Update)2 AbstractUpdate (org.eclipse.rdf4j.query.impl.AbstractUpdate)2 InterceptingRepositoryConnectionWrapper (org.eclipse.rdf4j.repository.event.base.InterceptingRepositoryConnectionWrapper)2