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

📄 dbprofilemanager.java~4~

📁 一套完整的工商12315的源程序jsp部分在12315里,后台JAVA部分在gs12315src里,没有打包数据库.
💻 JAVA~4~
📖 第 1 页 / 共 4 页
字号:
    //If cache is not enabled, do a new lookup of object
    if (!cacheManager.isCacheEnabled()) {
      return new DbGroup(groupID, factory);
    }
    //Cache is enabled.
    Integer groupIDInteger = new Integer(groupID);
    DbGroup group = (DbGroup) cacheManager.get(
        DbCacheManager.GROUP_CACHE,
        groupIDInteger
        );
    if (group == null) {
      group = new DbGroup(groupID, factory);
      cacheManager.add(DbCacheManager.GROUP_CACHE, groupIDInteger, group);
    }
    return group;
  }

  //oringinal copy
  public Group getGroup(String name) throws GroupNotFoundException {
    DbCacheManager cacheManager = factory.getCacheManager();
    //If cache is not enabled, do a new lookup of object
    if (!cacheManager.isCacheEnabled()) {
      Group group = new DbGroup(name, null, factory); //look up groups from DB
      return getGroup(group.getID());
    }
    //Cache is enabled.
    CacheableInteger groupIDInteger = (CacheableInteger) cacheManager.get(
        DbCacheManager.GROUP_ID_CACHE,
        name
        );
    //if id wan't found in cache, load it up and put it there.
    if (groupIDInteger == null) {
      Group group = new DbGroup(name, null, factory);
      groupIDInteger = new CacheableInteger(new Integer(group.getID()));
      cacheManager.add(DbCacheManager.GROUP_ID_CACHE, name, groupIDInteger);
    }
    return getGroup(groupIDInteger.getInteger().intValue());
  }

  public synchronized void deleteGroup(Group group) throws
      UnauthorizedException {
    int groupID = group.getID();
    int[] members = new int[group.getMemberCount()];
    Iterator iter = group.members();
    for (int i = 0; i < members.length; i++) {
      User user = (User) iter.next();
      members[i] = user.getID();
    }

    Connection con = null;
    PreparedStatement pstmt = null;
    try {
      con = DbConnectionManager.getConnection();
      //delete user group link
      pstmt = con.prepareStatement(DELETE_GROUP_USERS);
      pstmt.setInt(1, groupID);
      pstmt.execute();
      pstmt.close();
      //delete all group record
      pstmt = con.prepareStatement(DELETE_GROUP);
      pstmt.setInt(1, groupID);
      pstmt.execute();
      pstmt.close();
      //remove all permissions given to user
      pstmt = con.prepareStatement(DELETE_GROUP_ALLPERM);
      pstmt.setInt(1, groupID);
      pstmt.execute();
      pstmt.close();

    }
    catch (SQLException sqle) {
      sqle.printStackTrace();
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }

    //Finally, expire all relevant caches
    DbCacheManager cacheManager = factory.getCacheManager();
    cacheManager.remove(DbCacheManager.GROUP_ID_CACHE, group.getName());
    cacheManager.remove(DbCacheManager.GROUP_CACHE, new Integer(groupID));
    //Removing a group can change the permissions of all the users in that
    //group. Therefore, remove each user from the user perms cache.
    for (int i = 0; i < members.length; i++) {
      cacheManager.removeUserPerm(new Integer(members[i]));
    }
  }

  public int getGroupCount() {
    int count = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(GROUP_COUNT);
      ResultSet rs = pstmt.executeQuery();
      if (rs.next()) {
        count = rs.getInt(1);
      }
    }
    catch (SQLException sqle) {
      sqle.printStackTrace();
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    return count;
  }

  public Iterator groups() {
    return new DbGroupIterator(this);
  }

  public Iterator groups(int startIndex, int numResults) {
    return new DbGroupIterator(this, startIndex, numResults);
  }

  /**
   * Returns an array of all the groups that the user belongs to.
   */
  protected int[] getUserGroups(int userID) {
    Connection con = null;
    PreparedStatement pstmt = null;
    int[] groups = new int[0];
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(USER_GROUPS);
      pstmt.setInt(1, userID);
      ResultSet rs = pstmt.executeQuery();
      ArrayList groupList = new ArrayList();
      while (rs.next()) {
        groupList.add(new Integer(rs.getInt("groupid")));
      }
      groups = new int[groupList.size()];
      for (int i = 0; i < groups.length; i++) {
        groups[i] = ( (Integer) groupList.get(i)).intValue();
      }
    }
    catch (SQLException sqle) {
      sqle.printStackTrace();
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    return groups;
  }

  //******************************************************
   // Unit management functions
   //:  the DbProfileManager just Keep a

   public Unit getRootUnit() {
     try {
       return getUnit("0");
     }
     catch (UnitNotFoundException e) {
       System.err.println(
           "UnitNotFoundException in DbProfileManager.java: root unit lost " +
           e);
       return null;
     }
   }

  //public Unit getUnit(String[] unitPath ) throws UnitNotFoundException;

  public Unit getUnit(String unitID) throws UnitNotFoundException {
    DbCacheManager cacheManager = factory.getCacheManager();
    //If cache is not enabled, do a new lookup of object
    if (!cacheManager.isCacheEnabled()) {
      return new DbUnit(unitID, factory);
    }
    //Cache is enabled.
    DbUnit unit = (DbUnit) cacheManager.get(
        DbCacheManager.UNIT_CACHE,
        unitID
        );
    if (unit == null) {
      unit = new DbUnit(unitID, factory);
      cacheManager.add(DbCacheManager.UNIT_CACHE, unitID, unit);
    }
    return unit;
  }

  public synchronized Unit createUnit(Unit parent, String newUnitID,
                                      String unitName, String phone, String lxr,
                                      String inside) throws
      UnauthorizedException, UnitCreationFailureException {
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(INSERT_SUB_UNIT);
      pstmt.setString(1, newUnitID);
      pstmt.setString(2, unitName);
      pstmt.setString(3, phone);
      pstmt.setString(4, lxr);
      pstmt.setString(5, parent.getID());
      pstmt.setString(6, inside);
      pstmt.executeUpdate();
    }
    catch (SQLException sqle) {
      System.err.println("SQLException in DbProfileManager.java:" +
                         "createUnit():cannot insert sub unit data " + sqle);
      throw new UnitCreationFailureException();
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    Unit newUnit = null;
    try {
      newUnit = getUnit(newUnitID);
    }
    catch (Exception e) {
    }
    return newUnit;
  }

  public synchronized void deleteUnit(Unit unit) throws UnauthorizedException {
    Iterator groupIterator = unit.getAssociateGroupsIterator();
    Iterator subunitIterator = unit.getSubUnitsIterator();
    //first delete all associate groups
    while (groupIterator.hasNext()) {
      Group group = (Group) groupIterator.next();
      group.unlinkUnit();
      DbCacheManager cacheManager = factory.getCacheManager();
      cacheManager.remove(DbCacheManager.GROUP_ID_CACHE, group.getName());
      cacheManager.remove(DbCacheManager.GROUP_CACHE, new Integer(group.getID()));
    }

    //delete all subunits
    while (subunitIterator.hasNext())
      deleteUnit( (Unit) subunitIterator.next());

    String unitID = unit.getID();
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
      con = DbConnectionManager.getConnection();

      pstmt = con.prepareStatement(DELETE_UNIT);
      pstmt.setString(1, unitID);
      pstmt.execute();
      pstmt.close();
    }
    catch (SQLException sqle) {
      sqle.printStackTrace();
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }

    //Finally, expire all relevant caches
    DbCacheManager cacheManager = factory.getCacheManager();
    cacheManager.remove(DbCacheManager.UNIT_CACHE, new Integer(unitID));

  }

  public int[] getUnitFreeGroups() {
    Connection con = null;
    PreparedStatement pstmt = null;
    int[] groups = new int[0];
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(GET_UNIT_FREE_GROUPS);
      ResultSet rs = pstmt.executeQuery();
      ArrayList groupList = new ArrayList();
      while (rs.next()) {
        groupList.add(new Integer(rs.getInt(1)));
      }
      groups = new int[groupList.size()];
      for (int i = 0; i < groups.length; i++) {
        groups[i] = ( (Integer) groupList.get(i)).intValue();
      }
    }
    catch (SQLException sqle) {
      sqle.printStackTrace();
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    return groups;
  }

  public int[] getGroupsExistUserID(int userid) {
    Connection con = null;
    PreparedStatement pstmt = null;
    int[] groups = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(GET_GROUPS_USERID);
      pstmt.setInt(1, userid);
      ResultSet rs = pstmt.executeQuery();
      ArrayList groupList = new ArrayList();
      while (rs.next()) {
        groupList.add(new Integer(rs.getInt(1)));
      }
      groups = new int[groupList.size()];
      for (int i = 0; i < groups.length; i++) {
        groups[i] = ( (Integer) groupList.get(i)).intValue();
      }
    }
    catch (SQLException sqle) {
      sqle.printStackTrace();
    }
    finally {
      try {
        pstmt.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      try {
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    return groups;
  }

  //////////////////////////
  public ArrayList getGroupsExistUserID_new(int userid) {
    Connection con = null;
    PreparedStatement pstmt = null;
    ArrayList groupList = new ArrayList();
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(GET_GROUPS_USERID);
      pstmt.setInt(1, userid);
      ResultSet rs = pstmt.executeQuery();
      while (rs.next()) {
        groupList.add(new Integer(rs.getInt(1)));
      }

    }
    catch (SQLException sqle) {

⌨️ 快捷键说明

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