Esempio n. 1
0
 public <A> QueryWhere<T> where(Filter filter) {
   HashMap<String, Object> fieldMap = New.hashMap();
   for (Field f : filter.getClass().getDeclaredFields()) {
     f.setAccessible(true);
     try {
       Object obj = f.get(filter);
       if (obj == from.getAlias()) {
         List<TableDefinition.FieldDefinition> fields = from.getAliasDefinition().getFields();
         String name = f.getName();
         for (TableDefinition.FieldDefinition field : fields) {
           String n = name + "." + field.field.getName();
           Object o = field.field.get(obj);
           fieldMap.put(n, o);
         }
       }
       fieldMap.put(f.getName(), f.get(filter));
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
   }
   Token filterCode = new ClassReader().decompile(filter, fieldMap, "where");
   // String filterQuery = filterCode.toString();
   conditions.add(filterCode);
   return new QueryWhere<T>(this);
 }
Esempio n. 2
0
 private List<T> select(boolean distinct) {
   List<T> result = New.arrayList();
   TableDefinition<T> def = from.getAliasDefinition();
   SQLStatement stat = getSelectStatement(distinct);
   def.appendSelectList(stat);
   appendFromWhere(stat);
   ResultSet rs = stat.executeQuery();
   Statement s = null;
   try {
     s = rs.getStatement();
     while (rs.next()) {
       T item = from.newObject();
       from.getAliasDefinition().readRow(item, rs);
       result.add(item);
     }
   } catch (SQLException e) {
     throw new RuntimeException(e);
   } finally {
     JdbcUtils.closeSilently(rs);
     JdbcUtils.closeSilently(s);
   }
   return result;
 }