示例#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
  /** @inheritDoc */
  public boolean contains(final Object theObj) {
    assertStateOk(theObj);

    try {
      return DataSourceUtil.exists(getDataSource(), theObj);
    } catch (DataSourceException e) {
      throw new PersistenceException(e);
    }
  }
示例#3
0
  /**
   * Performs the same checks as assertContains, but returns the Graph describing the resource as a
   * result so you do not need to perform a subsequent call to the database to get the data that is
   * checked during containment checks in the first place, thus saving a query to the database.
   *
   * @param theObj the object that should exist.
   * @return The graph describing the resource
   * @throws IllegalArgumentException thrown if the object does not exist in the database
   */
  private ExtGraph assertContainsAndDescribe(Object theObj) {
    assertStateOk(theObj);

    try {
      ExtGraph aGraph = DataSourceUtil.describe(getDataSource(), theObj);

      if (aGraph.isEmpty()) {
        throw new IllegalArgumentException("Entity does not exist: " + theObj);
      }

      return aGraph;
    } catch (QueryException e) {
      throw new PersistenceException(e);
    }
  }