⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbunit.java

📁 一套完整的工商12315的源程序jsp部分在12315里,后台JAVA部分在gs12315src里,没有打包数据库.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    //Now copy into an array.
    units = new String[tempUnits.size()];
    for (int i = 0; i < units.length; i++) {
      units[i] = (String) tempUnits.get(i);
    }
    return units;
  }


  public void setPhone(String phone) throws UnauthorizedException {
    this.lxdh = phone;
    updateToDb();
  }

  public void setLxr(String slxr) throws UnauthorizedException {
    this.lxr = slxr;
    updateToDb();
  }

  /**
   * Load the group data from the database.
   */
  private void loadFromDb() throws UnitNotFoundException {
    Object lock = new Object();
    String query;
    query = LOAD_UNIT_BY_ID;
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(query);
      pstmt.setString(1, id);
      ResultSet rs = pstmt.executeQuery();
      if (!rs.next()) {
        throw new UnitNotFoundException();
      }
      this.id = rs.getString("djjg").trim();
      this.name = rs.getString("djjgmc");
      this.lxdh = rs.getString("lxdh");
      this.lxr = rs.getString("lxr");
      this.parentid = rs.getString("sjjg");
      if(parentid!=null)
        parentid = parentid.trim();
      this.inside = rs.getString("inside");
    }
    catch (SQLException sqle) {
      System.err.println("SQLException in DbUnit.java:" +
                         "loadFromDb():reading unit data " + sqle);
      throw new UnitNotFoundException();
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  private void updateToDb() {
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(UPDATE_UNIT);
      pstmt.setString(1, name);
      pstmt.setString(2, lxr);
      pstmt.setString(3, lxdh);
      pstmt.setString(4, parentid);
      pstmt.setString(5, inside);
      pstmt.setString(6, id);
      pstmt.executeUpdate();
    }
    catch (SQLException sqle) {
      System.err.println("SQLException in DbGroup.java:saveToDb(): " + sqle);
      sqle.printStackTrace();
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }

         DbCacheManager cacheManager = factory.getCacheManager();
         cacheManager.remove(DbCacheManager.UNIT_CACHE, id);
         cacheManager.add(DbCacheManager.UNIT_CACHE,id, this);

  }

  //implements Cacheable
  public int getSize() {
    //Approximate the size of the object in bytes by calculating the size
    //of each field.
    int size = 0;
    size += CacheSizes.sizeOfObject(); //overhead of object
    size += CacheSizes.sizeOfInt() * 2; //id, parentid
    size += CacheSizes.sizeOfString(name); //name
    size += CacheSizes.sizeOfString(lxr); //description
    size += CacheSizes.sizeOfObject(); //profile manager ref.
    size += CacheSizes.sizeOfObject(); //forum factory ref.

    return size;

  }

  public boolean isMember(User user) {
    boolean flag = false;
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(UNIT_MEMBERS);
      pstmt.setString(1, id);
      ResultSet rs = pstmt.executeQuery();
      while (rs.next()) {
        if (user.getID() == rs.getInt(1)) {
          flag = true;
          break;
        }

      }
    }
    catch (SQLException sqle) {
      System.err.println("SQLException in DbUnit.java:" +
                         "getUnitMembers:  " + sqle);
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    return flag;
  }

  public int[] getAssociateUsers() {
    Iterator groups = this.getAssociateGroupsIterator();
    Iterator users = null;
    Group group = null;
    User user = null;
    ArrayList userList = new ArrayList();
    int[] userids = null;
    while (groups.hasNext()) {
      group = (Group) groups.next();
      users = group.members();
      while (users.hasNext()) {
        user = (User) users.next();
        userList.add(new Integer(user.getID()));
      }
    }
    userids = new int[userList.size()];
    for (int i = 0; i < userList.size(); i++) {
      userids[i] = ( (Integer) userList.get(i)).intValue();
    }
    return userids;
  }

  public int[] getAssociateUsersAll() {
    Iterator groups = this.getAssociateGroupsIterator();
    Iterator users = null;
    Group group = null;
    User user = null;
    ArrayList userList = new ArrayList();
    int[] userids = null;
    while (groups.hasNext()) {
      group = (Group) groups.next();
      users = group.members();
      while (users.hasNext()) {
        user = (User) users.next();
        userList.add(new Integer(user.getID()));
      }
    }
    userids = new int[userList.size()];
    for (int i = 0; i < userList.size(); i++) {
      userids[i] = ( (Integer) userList.get(i)).intValue();
    }
    return userids;
  }

  public int[] getUsers_ByLevel(int level) {
    Iterator groups = this.getAssociateGroupsIterator();
    Iterator users = null;
    Group group = null;
    User user = null;
    ArrayList userList = new ArrayList();
    int[] userids = null;
    while (groups.hasNext()) {
      group = (Group) groups.next();
      if (group.getPriority() == level) {
        users = group.members();
        while (users.hasNext()) {
          user = (User) users.next();
          userList.add(new Integer(user.getID()));
        }
      }
    }
    userids = new int[userList.size()];
    for (int i = 0; i < userList.size(); i++) {
      userids[i] = ( (Integer) userList.get(i)).intValue();
    }
    return userids;
  }

  public String getName() {
    return this.name;
  }

  /**
   *  Return the level of the unit. Level is counted down from root unit, whose level is 0.
   *  @return level of the unit
   */
  public int getLevel() {
    if (this.parentid == null) {
      return 0;
    }
    return getParentUnit().getLevel() + 1;
  }

  public ArrayList getAllSubUnits(Unit unit) {
    ArrayList list = new ArrayList();
    list.add(unit);
    Iterator iterator = unit.getSubUnitsIterator();
    while (iterator.hasNext()) {
      Unit sub1 = (Unit) iterator.next();
      ArrayList node2 = getAllSubUnits(sub1);
      for (int i = 0; i < node2.size(); i++) {
        list.add( (Unit) node2.get(i));
      }
    }
    return list;
  }
  public ArrayList getAllInsideSubUnits(Unit unit) {
    ArrayList list = new ArrayList();
    list.add(unit);
    Iterator iterator = unit.getInsideSubUnitsIterator();
    while (iterator.hasNext()) {
      Unit sub1 = (Unit) iterator.next();
      ArrayList node2 = getAllInsideSubUnits(sub1);
      for (int i = 0; i < node2.size(); i++) {
        list.add( (Unit) node2.get(i));
      }
    }
    return list;
  }
  public ArrayList getAllExtSubUnits(Unit unit) {
    ArrayList list = new ArrayList();
    list.add(unit);
    Iterator iterator = unit.getInsideSubUnitsIterator();
    while (iterator.hasNext()) {
      Unit sub1 = (Unit) iterator.next();
      ArrayList node2 = getAllExtSubUnits(sub1);
      for (int i = 0; i < node2.size(); i++) {
        list.add( (Unit) node2.get(i));
      }
    }
    return list;
  }



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -