Example #1
0
 public <T> T newObj(Class<T> c) {
   try {
     return newObj(c.getConstructor().newInstance());
   } catch (Exception e) {
     LOG.warning(e);
   }
   return null;
 }
Example #2
0
 public <T> T saveObj(T obj) {
   PersistenceManager pm = pmf.getPersistenceManager();
   try {
     return pm.makePersistent(obj);
   } catch (Throwable e) {
     LOG.warning(e);
   } finally {
     pm.close();
   }
   return obj;
 }
Example #3
0
 public <T> T getArbitrary(Class<T> classObj) {
   PersistenceManager pm = pmf.getPersistenceManager();
   try {
     Extent<T> result = pm.getExtent(classObj, false);
     return result.iterator().next();
   } catch (Throwable e) {
     LOG.warning(e);
   } finally {
     pm.close();
   }
   return null;
 }
Example #4
0
 public <T> List<T> getAll(Class<T> c) {
   PersistenceManager pm = pmf.getPersistenceManager();
   try {
     Extent<T> result = pm.getExtent(c, false);
     List<T> buffer = new ArrayList<T>();
     for (T t : result) {
       buffer.add(t);
     }
     return buffer;
   } catch (Throwable e) {
     LOG.warning(e);
   } finally {
     pm.close();
   }
   return new ArrayList<T>();
 }
Example #5
0
 public <T> List<T> getQuery(
     Class<T> c, String queryString, String parameterDeclaration, Object... parameters) {
   PersistenceManager pm = pmf.getPersistenceManager();
   try {
     Query query = pm.newQuery(c, queryString);
     query.declareParameters(parameterDeclaration);
     List<T> list = (List<T>) query.executeWithArray(parameters);
     List<T> buffer = new ArrayList<T>();
     for (T t : list) {
       buffer.add(t);
     }
     query.closeAll();
     return buffer;
   } catch (Throwable e) {
     LOG.warning(e);
   } finally {
     pm.close();
   }
   return new ArrayList<T>();
 }