protected KiWiAnonResource createBNode(String nodeID) { try { // first look in the registry for newly created resources if the resource has already been created and // is still volatile KiWiAnonResource result = connection.loadAnonResource(nodeID); if(result == null) { result = new KiWiAnonResource(nodeID, importDate); storeNode(result); } else { nodesLoaded++; } if(result.getId() < 0) { log.error("node ID is null!"); } return result; } catch (SQLException e) { log.error("database error, could not load anonymous resource",e); throw new IllegalStateException("database error, could not load anonymous resource",e); } }
/** * Efficiently serialize a KiWiAnonResource to a DataOutput destination. * * @param out the destination * @param bnode the KiWiAnonResource to serialize * @throws IOException */ public static void writeBNode(DataOutput out, KiWiAnonResource bnode) throws IOException { if(bnode == null) { out.writeLong(-1L); } else { out.writeLong(bnode.getId()); DataIO.writeString(out, bnode.stringValue()); out.writeLong(bnode.getCreated().getTime()); } }
/** * Read a KiWiAnonResource serialized with writeBNode from a DataInput source * * @param input the source * @return the de-serialized KiWiAnonResource * @throws IOException */ public static KiWiAnonResource readBNode(DataInput input) throws IOException { long id = input.readLong(); if(id == -1) { return null; } else { String anonId = DataIO.readString(input); Date created = new Date(input.readLong()); KiWiAnonResource r = new KiWiAnonResource(anonId,created); r.setId(id); return r; } }
KiWiAnonResource bnode = new KiWiAnonResource(RandomStringUtils.randomAlphanumeric(8)); connection.storeNode(bnode); Assert.assertTrue(bnode.getId() >= 0); KiWiNode testBNode1 = connection.loadNodeById(bnode.getId()); Assert.assertEquals(bnode.getId(), testBNode1.getId()); KiWiNode testBNode2 = connection.loadNodeById(bnode.getId()); Assert.assertEquals(bnode.getId(), testBNode2.getId()); KiWiNode testBNode3 = connection.loadAnonResource(bnode.stringValue()); Assert.assertEquals(bnode.getId(), testBNode3.getId()); KiWiNode testBNode4 = connection.loadNodeById(bnode.getId()); Assert.assertEquals(bnode.getId(), testBNode4.getId()); KiWiNode testBNode5 = connection.loadAnonResource(bnode.stringValue()); Assert.assertEquals(bnode.getId(), testBNode5.getId()); Assert.assertEquals((long)bnode.getId(),result.getLong("id")); Assert.assertEquals(bnode.stringValue(),result.getString("svalue")); Assert.assertEquals("bnode",result.getString("ntype"));
insertNode.setString(2,anonResource.stringValue()); insertNode.setTimestamp(3, new Timestamp(anonResource.getCreated().getTime()), calendarUTC);
@Test @Ignore("MARMOTTA-665: clustered tests fail") public void testClusteredCacheBNode() throws InterruptedException, RepositoryException { log.info("testing cache synchronization ..."); KiWiAnonResource u = (KiWiAnonResource) repositorySync1.getValueFactory().createBNode(); // give the cluster some time to performance asynchronous balancing Thread.sleep(100); log.debug("test if resource is in cache where it was created ..."); KiWiAnonResource u1 = cacheManagerSync1.getBNodeCache().get(u.getID()); Assert.assertNotNull(u1); Assert.assertEquals(u,u1); Assert.assertEquals(u.getId(), u1.getId()); log.debug("test if resource has been synced to other cache in cluster ..."); KiWiAnonResource u2 = cacheManagerSync2.getBNodeCache().get(u.getID()); Assert.assertNotNull(u2); Assert.assertEquals(u, u2); Assert.assertEquals(u.getId(), u2.getId()); }
@Override public boolean equals(Object o) { if (this == o) return true; if(o instanceof BNode) { return this.stringValue().equals(((BNode)o).stringValue()); } return false; }
insertNode.setString(2,anonResource.stringValue()); insertNode.setTimestamp(3, new Timestamp(anonResource.getCreated().getTime()), calendarUTC);
@Override public boolean equals(Object o) { if (this == o) return true; if(o instanceof BNode) { return this.stringValue().equals(((BNode)o).stringValue()); } return false; }
/** * Efficiently serialize a KiWiAnonResource to a DataOutput destination. * * @param out the destination * @param bnode the KiWiAnonResource to serialize * @throws IOException */ public static void writeBNode(DataOutput out, KiWiAnonResource bnode) throws IOException { if(bnode == null) { out.writeLong(-1L); } else { out.writeLong(bnode.getId()); DataIO.writeString(out, bnode.stringValue()); out.writeLong(bnode.getCreated().getTime()); } }
protected KiWiAnonResource createBNode(String nodeID) { try { // first look in the registry for newly created resources if the resource has already been created and // is still volatile KiWiAnonResource result = connection.loadAnonResource(nodeID); if(result == null) { result = new KiWiAnonResource(nodeID, importDate); storeNode(result); } else { nodesLoaded++; } if(result.getId() < 0) { log.error("node ID is null!"); } return result; } catch (SQLException e) { log.error("database error, could not load anonymous resource",e); throw new IllegalStateException("database error, could not load anonymous resource",e); } }
/** * Read a KiWiAnonResource serialized with writeBNode from a DataInput source * * @param input the source * @return the de-serialized KiWiAnonResource * @throws IOException */ public static KiWiAnonResource readBNode(DataInput input) throws IOException { long id = input.readLong(); if(id == -1) { return null; } else { String anonId = DataIO.readString(input); Date created = new Date(input.readLong()); KiWiAnonResource r = new KiWiAnonResource(anonId,created); r.setId(id); return r; } }
} else if(n instanceof KiWiAnonResource) { KiWiAnonResource a = (KiWiAnonResource)n; createNodeList(rowArray, a.getId(), a.getClass(), a.stringValue(), null, null, null, null, null, null, null, a.getCreated()); } else if(n instanceof KiWiIntLiteral) { KiWiIntLiteral l = (KiWiIntLiteral)n;
/** * Creates a new blank node with the given node identifier. * * @param nodeID The blank node identifier. * @return An object representing the blank node. */ @Override public BNode createBNode(String nodeID) { KiWiConnection connection = aqcuireConnection(); try { // first look in the registry for newly created resources if the resource has already been created and // is still volatile KiWiAnonResource result = connection.loadAnonResource(nodeID); if(result == null) { result = new KiWiAnonResource(nodeID); connection.storeNode(result); } if(result.getId() < 0) { log.error("node ID is null!"); } return result; } catch (SQLException e) { log.error("database error, could not load anonymous resource",e); throw new IllegalStateException("database error, could not load anonymous resource",e); } finally { releaseConnection(connection); } }
/** * Creates a new blank node with the given node identifier. * * @param nodeID The blank node identifier. * @return An object representing the blank node. */ @Override public BNode createBNode(String nodeID) { KiWiAnonResource r = new KiWiAnonResource(nodeID, new Date()); r.setId(idGenerator.getId()); return r; }
} else if(n instanceof KiWiAnonResource) { KiWiAnonResource a = (KiWiAnonResource)n; createNodeList(rowArray, a.getId(), a.getClass(), a.stringValue(), null, null, null, null, null, null, null, a.getCreated()); } else if(n instanceof KiWiIntLiteral) { KiWiIntLiteral l = (KiWiIntLiteral)n;
/** * Creates a new blank node with the given node identifier. * * @param nodeID The blank node identifier. * @return An object representing the blank node. */ @Override public BNode createBNode(String nodeID) { KiWiConnection connection = aqcuireConnection(); try { // first look in the registry for newly created resources if the resource has already been created and // is still volatile KiWiAnonResource result = connection.loadAnonResource(nodeID); if(result == null) { result = new KiWiAnonResource(nodeID); connection.storeNode(result); } if(result.getId() < 0) { log.error("node ID is null!"); } return result; } catch (SQLException e) { log.error("database error, could not load anonymous resource",e); throw new IllegalStateException("database error, could not load anonymous resource",e); } finally { releaseConnection(connection); } }
KiWiAnonResource result = new KiWiAnonResource(row.getString(3), new Date(row.getTimestamp(11, calendarUTC).getTime())); result.setId(id);
} else if(n instanceof KiWiAnonResource) { KiWiAnonResource a = (KiWiAnonResource)n; createNodeList(rowArray, a.getId(), a.getClass(), a.stringValue(), null, null, null, null, null, null, null, a.getCreated()); } else if(n instanceof KiWiIntLiteral) { KiWiIntLiteral l = (KiWiIntLiteral)n;
KiWiAnonResource result = new KiWiAnonResource(row.getString(3), new Date(row.getTimestamp(11, calendarUTC).getTime())); result.setId(id);