public static int getRecordSize(Dao dao, String s) { Sql _s = Sqls.create("select count(*) nums from ( " + s + " )"); _s.setCallback(Sqls.callback.entity()); _s.setEntity(dao.getEntity(Record.class)); dao.execute(_s); return ((Record) _s.getResult()).getInt("nums"); }
public static Object getRecort(Dao dao, String sql, Class t) { Sql s = Sqls.create(sql); s.setCallback(Sqls.callback.entity()); s.setEntity(dao.getEntity(t)); dao.execute(s); return s.getResult(); }
public static Record getRecord(Dao dao, String sql) { Sql s = Sqls.create(sql); s.setCallback(Sqls.callback.entity()); s.setEntity(dao.getEntity(Record.class)); dao.execute(s); return (Record) s.getResult(); }
/** * 根据用户ID查询出服务时数 * * @return */ public double findTime(int uid) { Sql sql = Sqls.create( "select sum(services_number) as w from t_personservices where uid=" + uid + " and queren=1"); sql.setCallback( new SqlCallback() { public Object invoke(Connection arg0, ResultSet rs, Sql sql) throws SQLException { Object o = new Object(); if (rs.next()) { o = rs.getObject("w"); } rs.close(); return o; } }); dao.execute(sql); Object o = sql.getResult(); if (o != null) { return Double.parseDouble(o.toString()); } return 0; }
/** * 执行sql和callback * * @param dao Dao实例 * @param sql_str sql语句 * @param callback sql回调 * @return 回调的返回值 */ public static Object query(Dao dao, String sql_str, SqlCallback callback) { Sql sql = Sqls.create(sql_str).setCallback(callback); dao.execute(sql); return sql.getResult(); }