Пример #1
0
  /** @inheritDoc */
  public <T> T find(final Class<T> theClass, final Object theObj) {
    assertOpen();

    try {
      AnnotationChecker.assertValid(theClass);
    } catch (EmpireException e) {
      throw new IllegalArgumentException(e);
    }

    try {
      if (DataSourceUtil.exists(getDataSource(), EmpireUtil.asPrimaryKey(theObj))) {
        T aT = RdfGenerator.fromRdf(theClass, EmpireUtil.asPrimaryKey(theObj), getDataSource());

        postLoad(aT);

        return aT;
      } else {
        return null;
      }
    } catch (InvalidRdfException e) {
      throw new IllegalArgumentException(
          "Type is not valid, or object with key is not a valid Rdf Entity.", e);
    } catch (DataSourceException e) {
      throw new PersistenceException(e);
    }
  }
Пример #2
0
  @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");
  }