@Test
public void testStoreBNode() throws SQLException {
KiWiConnection connection = persistence.getConnection();
try {
// add a new URI to the triple store and check if it exists afterwards, before and after commit
KiWiAnonResource bnode = new KiWiAnonResource(RandomStringUtils.randomAlphanumeric(8));
connection.storeNode(bnode, false);
// check if it then has a database ID
Assert.assertNotNull(bnode.getId());
KiWiNode testBNode1 = connection.loadNodeById(bnode.getId());
// needs to be equal, and should also be the identical object!
Assert.assertEquals(bnode,testBNode1);
Assert.assertTrue(bnode == testBNode1);
connection.commit();
KiWiNode testBNode2 = connection.loadNodeById(bnode.getId());
// needs to be equal, and should also be the identical object!
Assert.assertEquals(bnode,testBNode2);
Assert.assertTrue(bnode == testBNode2);
KiWiNode testBNode3 = connection.loadAnonResource(bnode.stringValue());
// needs to be equal, and should also be the identical object!
Assert.assertEquals(bnode,testBNode3);
Assert.assertTrue(bnode == testBNode3);
connection.commit();
Assert.assertEquals(1,Iterations.asList(connection.listResources()).size());
// clear cache and test again
persistence.clearCache();
KiWiNode testBNode4 = connection.loadNodeById(bnode.getId());
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(bnode,testBNode4);
Assert.assertTrue(bnode != testBNode4);
KiWiNode testBNode5 = connection.loadAnonResource(bnode.stringValue());
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(bnode,testBNode5);
Assert.assertTrue(bnode != testBNode5);
connection.commit();
// finally do a test on the nodes table, it should contain exactly one entry
PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes");
ResultSet result = checkNodeStmt.executeQuery();
Assert.assertTrue(result.next());
Assert.assertEquals((long)bnode.getId(),result.getLong("id"));
Assert.assertEquals(bnode.stringValue(),result.getString("svalue"));
Assert.assertEquals("bnode",result.getString("ntype"));
result.close();
connection.commit();
} finally {