Examples of KiWiUriResource


Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

     */
    @Test
    public void testStoreBooleanLiteral() throws SQLException {
        KiWiConnection connection = persistence.getConnection();
        try {
            KiWiUriResource uri = new KiWiUriResource(Namespaces.NS_XSD + "boolean");


            Random rnd = new Random();
            boolean value = rnd.nextBoolean();
            // add a new URI to the triple store and check if it exists afterwards, before and after commit
            KiWiBooleanLiteral literal = new KiWiBooleanLiteral(value, uri);
            connection.storeNode(literal, false);

            // check if it then has a database ID
            Assert.assertNotNull(literal.getId());

            KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral1);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral1).getType());
            Assert.assertTrue(literal == testLiteral1);

            connection.commit();

            KiWiNode testLiteral2 = connection.loadNodeById(literal.getId());

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral2);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral2).getType());
            Assert.assertTrue(literal == testLiteral2);

            KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri);

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral3);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral3).getType());
            Assert.assertTrue(literal == testLiteral3);


            // load by integer value
            KiWiNode testLiteral6 = connection.loadLiteral(value);

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral6);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral6).getType());
            Assert.assertTrue(literal == testLiteral6);


            connection.commit();


            // clear cache and test again
            persistence.clearCache();
            KiWiNode testLiteral4 = connection.loadNodeById(literal.getId());

            // needs to be equal, but now it should not be the same object!
            Assert.assertEquals(literal,testLiteral4);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral4).getType());
            Assert.assertTrue(literal != testLiteral4);

            KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri);

            // needs to be equal, but now it should not be the same object!
            Assert.assertEquals(literal,testLiteral5);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral5).getType());
            Assert.assertTrue(literal != testLiteral5);


            // load by integer value
            KiWiNode testLiteral7 = connection.loadLiteral(value);

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral7);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral7).getType());
            Assert.assertTrue(literal != testLiteral7);

            connection.commit();

            // finally do a test on the nodes table, it should contain exactly one entry
            PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes WHERE ntype='boolean'");
            ResultSet result = checkNodeStmt.executeQuery();

            Assert.assertTrue(result.next());
            Assert.assertEquals((long) literal.getId(), result.getLong("id"));
            Assert.assertEquals(literal.stringValue(),result.getString("svalue"));
            Assert.assertEquals(value,result.getBoolean("bvalue"));
            Assert.assertEquals("boolean",result.getString("ntype"));
            Assert.assertNull(result.getString("lang"));
            Assert.assertEquals((long) uri.getId(), result.getLong("ltype"));

            result.close();
            connection.commit();
        } finally {
            connection.close();
View Full Code Here

Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

     */
    @Test
    public void testStoreDateLiteral() throws SQLException {
        KiWiConnection connection = persistence.getConnection();
        try {
            KiWiUriResource uri = new KiWiUriResource(Namespaces.NS_XSD + "dateTime");


            Date value = new Date();
            // add a new URI to the triple store and check if it exists afterwards, before and after commit
            KiWiDateLiteral literal = new KiWiDateLiteral(value, uri);
            connection.storeNode(literal, false);

            // check if it then has a database ID
            Assert.assertNotNull(literal.getId());

            KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral1);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral1).getType());
            Assert.assertTrue(literal == testLiteral1);

            connection.commit();

            KiWiNode testLiteral2 = connection.loadNodeById(literal.getId());

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral2);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral2).getType());
            Assert.assertTrue(literal == testLiteral2);

            KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri);

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral3);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral3).getType());
            Assert.assertTrue(literal == testLiteral3);


            // load by integer value
            KiWiNode testLiteral6 = connection.loadLiteral(value);

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral6);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral6).getType());
            Assert.assertTrue(literal == testLiteral6);


            connection.commit();


            // clear cache and test again
            persistence.clearCache();
            KiWiNode testLiteral4 = connection.loadNodeById(literal.getId());

            // needs to be equal, but now it should not be the same object!
            Assert.assertEquals(literal,testLiteral4);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral4).getType());
            Assert.assertTrue(literal != testLiteral4);

            KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri);

            // needs to be equal, but now it should not be the same object!
            Assert.assertEquals(literal,testLiteral5);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral5).getType());
            Assert.assertTrue(literal != testLiteral5);


            // load by integer value
            KiWiNode testLiteral7 = connection.loadLiteral(value);

            // needs to be equal, and should also be the identical object!
            Assert.assertEquals(literal,testLiteral7);
            Assert.assertEquals(uri,((KiWiLiteral)testLiteral7).getType());
            Assert.assertTrue(literal != testLiteral7);

            connection.commit();

            // finally do a test on the nodes table, it should contain exactly one entry
            PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes WHERE ntype='date'");
            ResultSet result = checkNodeStmt.executeQuery();

            Assert.assertTrue(result.next());
            Assert.assertEquals((long) literal.getId(), result.getLong("id"));
            Assert.assertEquals(literal.stringValue(),result.getString("svalue"));
            Assert.assertEquals(DateUtils.getDateWithoutFraction(value).getTime(),result.getTimestamp("tvalue").getTime());
            Assert.assertEquals("date",result.getString("ntype"));
            Assert.assertNull(result.getString("lang"));
            Assert.assertEquals((long) uri.getId(), result.getLong("ltype"));

            result.close();
            connection.commit();
        } finally {
            connection.close();
View Full Code Here

Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

     */
    @Test
    public void testStoreTriples() throws Exception {
            KiWiConnection connection = persistence.getConnection();
            try {
                KiWiUriResource stype    = new KiWiUriResource(Namespaces.NS_XSD+"string");
                KiWiUriResource subject  = new KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
                KiWiUriResource pred_1   = new KiWiUriResource("http://localhost/predicate/P1");
                KiWiUriResource pred_2   = new KiWiUriResource("http://localhost/predicate/P2");
                KiWiUriResource object_1 = new KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
                KiWiStringLiteral object_2 = new KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(32),null,stype);
                KiWiUriResource context  = new KiWiUriResource("http://localhost/context/"+RandomStringUtils.randomAlphanumeric(8));

                connection.storeNode(stype, false);
                connection.storeNode(subject, false);
                connection.storeNode(pred_1, false);
                connection.storeNode(pred_2, false);
View Full Code Here

Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

    @Test
    public void testCreateListVersions() throws Exception {
        KiWiVersioningConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            KiWiUriResource subject2  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            KiWiUriResource pred_1   = new KiWiUriResource("http://localhost/predicate/P1");
            KiWiUriResource pred_2   = new KiWiUriResource("http://localhost/predicate/P2");
            KiWiUriResource object_1 = new KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
            KiWiStringLiteral object_2 = new KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(32));
            KiWiUriResource context  = new KiWiUriResource("http://localhost/context/"+RandomStringUtils.randomAlphanumeric(8));

            connection.storeNode(subject1, false);
            connection.storeNode(subject2, false);
            connection.storeNode(pred_1, false);
            connection.storeNode(pred_2, false);
View Full Code Here

Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

     */
    @Test
    public void testCreateListVersionsBetween() throws Exception {
        KiWiVersioningConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            KiWiUriResource pred_1   = new KiWiUriResource("http://localhost/predicate/P1");
            KiWiUriResource pred_2   = new KiWiUriResource("http://localhost/predicate/P2");
            KiWiUriResource object_1 = new KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
            KiWiStringLiteral object_2 = new KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(32));
            KiWiUriResource context  = new KiWiUriResource("http://localhost/context/"+RandomStringUtils.randomAlphanumeric(8));

            connection.storeNode(subject, false);
            connection.storeNode(pred_1, false);
            connection.storeNode(pred_2, false);
            connection.storeNode(object_1, false);
View Full Code Here

Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

    @Test
    public void testCreateRemoveVersions() throws Exception {
        KiWiVersioningConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            KiWiUriResource subject2  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            KiWiUriResource pred_1   = new KiWiUriResource("http://localhost/predicate/P1");
            KiWiUriResource pred_2   = new KiWiUriResource("http://localhost/predicate/P2");
            KiWiUriResource object_1 = new KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
            KiWiStringLiteral object_2 = new KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(32));
            KiWiUriResource context  = new KiWiUriResource("http://localhost/context/"+RandomStringUtils.randomAlphanumeric(8));

            connection.storeNode(subject1, false);
            connection.storeNode(subject2, false);
            connection.storeNode(pred_1, false);
            connection.storeNode(pred_2, false);
View Full Code Here

Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

            if(inferred && inferredContext != null) {
                contextSet.add(valueFactory.createURI(inferredContext));
            }

            KiWiResource    ksubj = valueFactory.convert(subj);
            KiWiUriResource kpred = valueFactory.convert(pred);
            KiWiNode        kobj  = valueFactory.convert(obj);


            Set<KiWiTriple> added = new HashSet<KiWiTriple>();
            for(Resource context : contextSet) {
View Full Code Here

Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

    }

    @Override
    protected CloseableIteration<? extends Statement, SailException> getStatementsInternal(Resource subj, URI pred, Value obj, final boolean includeInferred, Resource... contexts) throws SailException {
        final KiWiResource rsubj    = valueFactory.convert(subj);
        final KiWiUriResource rpred = valueFactory.convert(pred);
        final KiWiNode robj         = valueFactory.convert(obj);

        Set<KiWiResource> contextSet = new HashSet<KiWiResource>();
        contextSet.addAll(Lists.transform(Arrays.asList(contexts), new Function<Resource, KiWiResource>() {
            @Override
View Full Code Here

Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

    @Test
    public void testCreateListEntries() throws Exception {
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            KiWiUriResource subject2  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));

            connection.storeNode(subject1);
            connection.storeNode(subject2);

            KiWiCacheEntry entry1 = new KiWiCacheEntry();
View Full Code Here

Examples of org.apache.marmotta.kiwi.model.rdf.KiWiUriResource

    @Test
    public void testCreateListExpired() throws Exception {
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            KiWiUriResource subject2  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));

            connection.storeNode(subject1);
            connection.storeNode(subject2);

            KiWiCacheEntry entry1 = new KiWiCacheEntry();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.