public void updatePrivilege(Privilege pvlg) throws EntityExistException {
   updator.updateByIdColumns(pvlg);
   if (pvlg.getType() == Privilege.BUSINESS_PRIVILEGE) {
     businessPrivilegeTreeChanged = true;
   } else if (pvlg.getType() == Privilege.NON_ROLE_PRIVILEGE) {
     nonRolePrivilegeTreeChanged = true;
   }
 }
  public PrivilegeManagerImpl(String appName) {
    this.appName = appName;
    this.tableName = appName + "_privilege";
    TableNewer newer = new TableNewer();
    newer.setTableName(tableName);
    newer.setColumnNames(
        new String[] {
          "id",
          "pid",
          "name",
          "description",
          "isleaf",
          "display",
          "decisionPolicyCombAlg",
          "queryPolicyCombAlg",
          "type",
          "constantName",
          "url",
          "target",
          "orderNum"
        });
    newer.setIdColumnNames(new String[] {"id"});
    newer.setUniqueColumnNames(new String[] {"name"});
    newer.setMappingClass(Privilege.class.getName());
    newer.put("id", new JavaBeanColumnAdapter("id", "int"));
    newer.put("pid", new JavaBeanColumnAdapter("pid", "int"));
    newer.put("name", new JavaBeanColumnAdapter("name", "java.lang.String"));
    newer.put("description", new JavaBeanColumnAdapter("description", "java.lang.String"));
    newer.put("isleaf", new JavaBeanColumnAdapter("isLeaf", "boolean"));
    newer.put("display", new JavaBeanColumnAdapter("display", "boolean"));
    newer.put("decisionPolicyCombAlg", new JavaBeanColumnAdapter("decisionPolicyCombAlg", "int"));
    newer.put("queryPolicyCombAlg", new JavaBeanColumnAdapter("queryPolicyCombAlg", "int"));
    newer.put("type", new JavaBeanColumnAdapter("type", "int"));
    newer.put("constantName", new JavaBeanColumnAdapter("constantName", "java.lang.String"));
    newer.put("url", new JavaBeanColumnAdapter("url", "java.lang.String"));
    newer.put("target", new JavaBeanColumnAdapter("target", "java.lang.String"));
    newer.put("orderNum", new JavaBeanColumnAdapter("orderNum", "int"));

    newer.setId(DBPower.getTableId(null, newer.getTableName()));
    table = newer.getTable();
    selector = new TableSelectorImpl();
    selector.setObjectNewer(new JavaBeanObjectNewer(newer.getMappingClass()));
    saver = new TableSaverImpl();
    updator = new TableUpdatorImpl();
    deletor = new TableDeletorImpl();
    selector.setTable(table);
    saver.setTable(table);
    updator.setTable(table);
    deletor.setTable(table);
  }
  public void movePrivilege(Privilege privilege, Privilege target, int newOrderNum) {
    try {
      if (privilege.getId() <= 0) {
        throw new RalasafeException("Cannot move reserved privilege.");
      }

      privilege = getPrivilege(privilege.getId());
      target = getPrivilege(target.getId());
      if (privilege.getType() != target.getType()) {
        throw new RalasafeException("Cannot move privilege out of the tree.");
      }
      if (target.getIsLeaf()) {
        throw new RalasafeException("Canot move privilege to a leaf node.");
      }
      if (privilege == target || isCascadeChild(privilege.getId(), target.getId())) {
        throw new RalasafeException("This move will produce a cycle.");
      }

      Collection children = getChildren(target);
      ArrayList list = new ArrayList();
      if (children != null) {
        list.addAll(children);
      }

      // If it still be a child of the original parent node
      if (privilege.getPid() == target.getId()) {
        list.remove(privilege);
      }

      privilege.setPid(target.getId());

      // reset orderNum(s), and update to db
      list.add(newOrderNum, privilege);
      for (int i = 0, size = list.size(); i < size; i++) {
        Privilege p = (Privilege) list.get(i);
        p.setOrderNum(i);

        updator.updateByIdColumns(p);
      }

      if (target.getType() == Privilege.BUSINESS_PRIVILEGE) {
        businessPrivilegeTreeChanged = true;
      } else if (target.getType() == Privilege.NON_ROLE_PRIVILEGE) {
        nonRolePrivilegeTreeChanged = true;
      }
    } catch (EntityExistException e) {
      throw new DBLevelException(e);
    }
  }