class DataStoreImpl implements DataStore {

  @Override
  public <T> Collection<T> findAll(Class<T> clazz, String whereClause) throws PersistenceException {
    checkInitialize();

    EntityManager em = getEntityManager();
    try {
      Collection<T> resources = new HashSet<>();
      DynamicType   type      = getDynamicEntityType(clazz);

      if (type != null) {
        try {
          Query query = em.createQuery(getSelectStatement(clazz, whereClause));

          List dynamicEntities = query.getResultList();

          for (Object dynamicEntity : dynamicEntities) {
            resources.add(toEntity(clazz, type, (DynamicEntity) dynamicEntity));
          }
        } catch (Exception e) {
          throwPersistenceException("Caught exception trying to find " +
              clazz.getName() + " where " + whereClause, e);
        }
      }
      return resources;
    } finally {
      em.close();
    }
  }

}