Exemplo n.º 1
0
 public static void main(String[] args) {
   conn = getConnection();
   QueryRunner qr = new QueryRunner();
   try {
     conn.setAutoCommit(false);
     List<Syuser> al =
         (List)
             qr.query(
                 conn, "SELECT syuser.* FROM syuser", new BeanListHandler<Syuser>(Syuser.class));
     for (Syuser u : al) {
       List<Syrole> rl =
           qr.query(
               conn,
               "SELECT syrole.* FROM syrole JOIN syuser_syrole ON syuser_syrole.SYROLE_ID = syrole.ID WHERE syuser_syrole.SYUSER_ID = ?",
               new BeanListHandler<Syrole>(Syrole.class),
               u.getId());
       u.getSyroles().addAll(rl);
       System.out.println(u.getLoginname());
       System.out.println(JSON.toJSONString(u.getSyroles()));
     }
   } catch (SQLException e) {
     e.printStackTrace();
     try {
       DbUtils.rollback(conn);
     } catch (SQLException e1) {
       e1.printStackTrace();
     }
   } finally {
     try {
       DbUtils.commitAndClose(conn);
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  *
  * <p>此操作会清空 Cache 中 authorities 对应的 value,下次请求时装载。
  *
  * @see #getAll()
  */
 public void delete(Authority auth) throws JibuException {
   Connection conn = null;
   try {
     conn = ConnectionUtils.getConnection();
     authDAO.delete(conn, auth);
     DbUtils.commitAndClose(conn);
     Cache cache = CacheUtils.getAuthCache();
     cache.remove("authorities");
   } catch (SQLException e) {
     DbUtils.rollbackAndCloseQuietly(conn);
     throw new JibuException(e.getMessage());
   }
 }