Search in sources :

Example 1 with TreeModel

use of org.eclipse.rdf4j.model.impl.TreeModel 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 TreeModel

use of org.eclipse.rdf4j.model.impl.TreeModel 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 3 with TreeModel

use of org.eclipse.rdf4j.model.impl.TreeModel 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 4 with TreeModel

use of org.eclipse.rdf4j.model.impl.TreeModel in project rdf4j by eclipse.

the class StatementsTest method testMultipleContexts.

@Test
public void testMultipleContexts() {
    Resource c1 = vf.createIRI("urn:c1");
    Resource c2 = vf.createIRI("urn:c1");
    Resource c3 = vf.createIRI("urn:c1");
    Model m = Statements.create(vf, FOAF.AGE, RDF.TYPE, RDF.PROPERTY, new TreeModel(), c1, c2, null, c3);
    assertFalse(m.isEmpty());
    assertTrue(m.contains(FOAF.AGE, RDF.TYPE, RDF.PROPERTY, (Resource) null));
    assertTrue(m.contains(FOAF.AGE, RDF.TYPE, RDF.PROPERTY, c1));
    assertTrue(m.contains(FOAF.AGE, RDF.TYPE, RDF.PROPERTY, c2));
    assertTrue(m.contains(FOAF.AGE, RDF.TYPE, RDF.PROPERTY, c3));
}
Also used : TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Model(org.eclipse.rdf4j.model.Model) Test(org.junit.Test)

Example 5 with TreeModel

use of org.eclipse.rdf4j.model.impl.TreeModel in project rdf4j by eclipse.

the class RDFCollectionsTest method testRemove.

@Test
public void testRemove() {
    Resource head = vf.createBNode();
    Model m = RDFCollections.asRDF(values, head, new TreeModel());
    // add something to the model that is not part of the RDF collection.
    m.add(RDF.TYPE, RDF.TYPE, RDF.PROPERTY);
    // remove the entire collection
    RDFCollections.extract(m, head, st -> m.remove(st));
    assertFalse(m.contains(null, RDF.FIRST, a));
    assertFalse(m.contains(null, RDF.FIRST, b));
    assertFalse(m.contains(null, RDF.FIRST, c));
    assertFalse(m.contains(head, null, null));
    assertTrue(m.contains(RDF.TYPE, RDF.TYPE, RDF.PROPERTY));
}
Also used : TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Test(org.junit.Test)

Aggregations

Model (org.eclipse.rdf4j.model.Model)11 TreeModel (org.eclipse.rdf4j.model.impl.TreeModel)11 Test (org.junit.Test)9 Resource (org.eclipse.rdf4j.model.Resource)5 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)3 RepositoryConfig (org.eclipse.rdf4j.repository.config.RepositoryConfig)3 ProxyRepositoryConfig (org.eclipse.rdf4j.repository.sail.config.ProxyRepositoryConfig)3 SailRepositoryConfig (org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig)3 Value (org.eclipse.rdf4j.model.Value)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URISyntaxException (java.net.URISyntaxException)1 IRI (org.eclipse.rdf4j.model.IRI)1 RepositoryConfigException (org.eclipse.rdf4j.repository.config.RepositoryConfigException)1 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)1 UnsupportedRDFormatException (org.eclipse.rdf4j.rio.UnsupportedRDFormatException)1