예제 #1
0
  @SuppressWarnings("unchecked")
  public <T> List<T> findAll(Selector selector) throws DbException {
    if (!tableIsExist(selector.getEntityType())) return null;

    String sql = selector.toString();
    long seq = CursorUtils.FindCacheSequence.getSeq();
    findTempCache.setSeq(seq);
    Object obj = findTempCache.get(sql);
    if (obj != null) {
      return (List<T>) obj;
    }

    List<T> result = new ArrayList<T>();

    Cursor cursor = execQuery(sql);
    if (cursor != null) {
      try {
        while (cursor.moveToNext()) {
          T entity = (T) CursorUtils.getEntity(this, cursor, selector.getEntityType(), seq);
          result.add(entity);
        }
        findTempCache.put(sql, result);
      } catch (Throwable e) {
        throw new DbException(e);
      } finally {
        IOUtils.closeQuietly(cursor);
      }
    }
    return result;
  }
예제 #2
0
  @SuppressWarnings("unchecked")
  public <T> T findFirst(Selector selector) throws DbException {
    if (!tableIsExist(selector.getEntityType())) return null;

    String sql = selector.limit(1).toString();
    long seq = CursorUtils.FindCacheSequence.getSeq();
    findTempCache.setSeq(seq);
    Object obj = findTempCache.get(sql);
    if (obj != null) {
      return (T) obj;
    }

    Cursor cursor = execQuery(sql);
    if (cursor != null) {
      try {
        if (cursor.moveToNext()) {
          T entity = (T) CursorUtils.getEntity(this, cursor, selector.getEntityType(), seq);
          findTempCache.put(sql, entity);
          return entity;
        }
      } catch (Throwable e) {
        throw new DbException(e);
      } finally {
        IOUtils.closeQuietly(cursor);
      }
    }
    return null;
  }
예제 #3
0
  @SuppressWarnings("unchecked")
  public <T> T findById(Class<T> entityType, Object idValue) throws DbException {
    if (!tableIsExist(entityType)) return null;

    Table table = Table.get(this, entityType);
    Selector selector = Selector.from(entityType).where(table.id.getColumnName(), "=", idValue);

    String sql = selector.limit(1).toString();
    long seq = CursorUtils.FindCacheSequence.getSeq();
    findTempCache.setSeq(seq);
    Object obj = findTempCache.get(sql);
    if (obj != null) {
      return (T) obj;
    }

    Cursor cursor = execQuery(sql);
    if (cursor != null) {
      try {
        if (cursor.moveToNext()) {
          T entity = (T) CursorUtils.getEntity(this, cursor, entityType, seq);
          findTempCache.put(sql, entity);
          return entity;
        }
      } catch (Throwable e) {
        throw new DbException(e);
      } finally {
        IOUtils.closeQuietly(cursor);
      }
    }
    return null;
  }
예제 #4
0
 public DbModel findDbModelFirst(SqlInfo sqlInfo) throws DbException {
   Cursor cursor = execQuery(sqlInfo);
   if (cursor != null) {
     try {
       if (cursor.moveToNext()) {
         return CursorUtils.getDbModel(cursor);
       }
     } catch (Throwable e) {
       throw new DbException(e);
     } finally {
       IOUtils.closeQuietly(cursor);
     }
   }
   return null;
 }
예제 #5
0
  public List<DbModel> findDbModelAll(SqlInfo sqlInfo) throws DbException {
    List<DbModel> dbModelList = new ArrayList<DbModel>();

    Cursor cursor = execQuery(sqlInfo);
    if (cursor != null) {
      try {
        while (cursor.moveToNext()) {
          dbModelList.add(CursorUtils.getDbModel(cursor));
        }
      } catch (Throwable e) {
        throw new DbException(e);
      } finally {
        IOUtils.closeQuietly(cursor);
      }
    }
    return dbModelList;
  }
예제 #6
0
  public DbModel findDbModelFirst(DbModelSelector selector) throws DbException {
    if (!tableIsExist(selector.getEntityType())) return null;

    Cursor cursor = execQuery(selector.limit(1).toString());
    if (cursor != null) {
      try {
        if (cursor.moveToNext()) {
          return CursorUtils.getDbModel(cursor);
        }
      } catch (Throwable e) {
        throw new DbException(e);
      } finally {
        IOUtils.closeQuietly(cursor);
      }
    }
    return null;
  }
예제 #7
0
  public List<DbModel> findDbModelAll(DbModelSelector selector) throws DbException {
    if (!tableIsExist(selector.getEntityType())) return null;

    List<DbModel> dbModelList = new ArrayList<DbModel>();

    Cursor cursor = execQuery(selector.toString());
    if (cursor != null) {
      try {
        while (cursor.moveToNext()) {
          dbModelList.add(CursorUtils.getDbModel(cursor));
        }
      } catch (Throwable e) {
        throw new DbException(e);
      } finally {
        IOUtils.closeQuietly(cursor);
      }
    }
    return dbModelList;
  }