Examples of KiWiIntLiteral


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

            Random rnd = new Random();
            long value = rnd.nextLong();

                    // add a new URI to the triple store and check if it exists afterwards, before and after commit
            KiWiIntLiteral literal = new KiWiIntLiteral(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='int'");
            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.getLong("ivalue"));
            Assert.assertEquals("int",result.getString("ntype"));
            Assert.assertNull(result.getString("lang"));
            Assert.assertEquals((long) uri.getId(), result.getLong("ltype"));

View Full Code Here

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

                createNodeList(rowArray, u.getId(), u.getClass(), u.stringValue(), null, null, null, null, null, null, u.getCreated());
            } else if(n instanceof KiWiAnonResource) {
                KiWiAnonResource a = (KiWiAnonResource)n;
                createNodeList(rowArray, a.getId(), a.getClass(), a.stringValue(), null, null, null, null, null, null, a.getCreated());
            } else if(n instanceof KiWiIntLiteral) {
                KiWiIntLiteral l = (KiWiIntLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), l.getDoubleContent(), l.getIntContent(), null, null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiDoubleLiteral) {
                KiWiDoubleLiteral l = (KiWiDoubleLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), l.getDoubleContent(), null, null, null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiBooleanLiteral) {
                KiWiBooleanLiteral l = (KiWiBooleanLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), null, null, null, l.booleanValue(), l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiDateLiteral) {
                KiWiDateLiteral l = (KiWiDateLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), null, null, l.getDateContent(), null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiStringLiteral) {
                KiWiStringLiteral l = (KiWiStringLiteral)n;

                Double dbl_value = null;
                Long   lng_value = null;
                if(l.getContent().length() < 64 && NumberUtils.isNumber(l.getContent()))  {
                    try {
                        dbl_value = Double.parseDouble(l.getContent());
                        lng_value = Long.parseLong(l.getContent());
                    } catch (NumberFormatException ex) {
                        // ignore, keep NaN
                    }
                }
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), dbl_value, lng_value, null, null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else {
                log.warn("unknown node type, cannot flush to import stream: {}", n.getClass());
            }

            writer.write(row, nodeProcessors);
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.