/** @inheritDoc */ public void refresh(Object theObj) { assertStateOk(theObj); assertContains(theObj); Object aDbObj = find(theObj.getClass(), EmpireUtil.asSupportsRdfId(theObj).getRdfId()); Collection<AccessibleObject> aAccessors = new HashSet<AccessibleObject>(); aAccessors.addAll(getAnnotatedFields(aDbObj.getClass())); aAccessors.addAll(getAnnotatedGetters(aDbObj.getClass(), true)); if (theObj instanceof EmpireGenerated) { ((EmpireGenerated) theObj).setAllTriples(((EmpireGenerated) aDbObj).getAllTriples()); ((EmpireGenerated) theObj) .setInstanceTriples(((EmpireGenerated) aDbObj).getInstanceTriples()); } try { for (AccessibleObject aAccess : aAccessors) { Object aValue = safeGet(aAccess, aDbObj); AccessibleObject aSetter = asSetter(aDbObj.getClass(), aAccess); safeSet(aSetter, theObj, aValue); } } catch (InvocationTargetException e) { throw new PersistenceException(e); } }
@Test public void testEmpireUtil() throws Exception { SupportsRdfId aId = new SupportsRdfIdImpl(); assertTrue(EmpireUtil.asResource(aId) == null); Resource aRes = EmpireUtil.asResource(new SupportsRdfIdImpl(new SupportsRdfId.BNodeKey("asdf"))); assertTrue(aRes instanceof BNode); assertEquals(((BNode) aRes).getID(), "asdf"); aId = EmpireUtil.asSupportsRdfId(java.net.URI.create("urn:foo")); assertTrue(aId.getRdfId() instanceof SupportsRdfId.URIKey); assertEquals(aId.getRdfId().value(), java.net.URI.create("urn:foo")); assertTrue(EmpireUtil.getNamedGraph("") == null); SupportsRdfId.RdfKey aKey = EmpireUtil.asPrimaryKey(new URL("http://example.org")); assertTrue(aKey instanceof SupportsRdfId.URIKey); assertEquals(aKey.value(), new URL("http://example.org").toURI()); BNode aAnon = ValueFactoryImpl.getInstance().createBNode("foobar"); aKey = EmpireUtil.asPrimaryKey(aAnon); assertTrue(aKey instanceof SupportsRdfId.BNodeKey); assertEquals(aKey.value(), "foobar"); }
/** * Verify that all the objects to be added/removed were completed successfully. * * @throws PersistenceException if an add or remove failed for any reason */ private void verify() { for (Object aObj : mVerifyRemove) { if (contains(aObj)) { throw new PersistenceException( "Remove failed for object: " + aObj.getClass() + " -> " + EmpireUtil.asSupportsRdfId(aObj).getRdfId()); } } for (Object aObj : mVerifyAdd) { if (!contains(aObj)) { throw new PersistenceException( "Addition failed for object: " + aObj.getClass() + " -> " + EmpireUtil.asSupportsRdfId(aObj).getRdfId()); } } }