Esempio n. 1
0
 /**
  * Join another table.
  *
  * @param alias an alias for the table to join
  * @return the joined query
  */
 @SuppressWarnings("unchecked")
 public <U> QueryJoin innerJoin(U alias) {
   TableDefinition<T> def = (TableDefinition<T>) db.define(alias.getClass());
   SelectTable<T> join = new SelectTable(db, this, alias, false);
   def.initSelectObject(join, alias, aliasMap);
   joins.add(join);
   return new QueryJoin(this, join);
 }
Esempio n. 2
0
 @SuppressWarnings("unchecked")
 static <T> Query<T> from(Db db, T alias) {
   Query<T> query = new Query<T>(db);
   TableDefinition<T> def = (TableDefinition<T>) db.define(alias.getClass());
   query.from = new SelectTable<T>(db, query, alias, false);
   def.initSelectObject(query.from, alias, query.aliasMap);
   return query;
 }
Esempio n. 3
0
 private <X> List<X> select(Class<X> clazz, X x, boolean distinct) {
   List<X> result = New.arrayList();
   TableDefinition<X> def = db.define(clazz);
   SQLStatement stat = getSelectStatement(distinct);
   def.appendSelectList(stat, this, x);
   appendFromWhere(stat);
   ResultSet rs = stat.executeQuery();
   Statement s = null;
   try {
     s = rs.getStatement();
     while (rs.next()) {
       X row = ClassUtils.newObject(clazz);
       def.readRow(row, rs);
       result.add(row);
     }
   } catch (SQLException e) {
     throw new RuntimeException(e);
   } finally {
     JdbcUtils.closeSilently(rs);
     JdbcUtils.closeSilently(s);
   }
   return result;
 }