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

📄 dbiofficefactory.java

📁 一套完整的工商12315的源程序jsp部分在12315里,后台JAVA部分在gs12315src里,没有打包数据库.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            }
        }
        catch( SQLException sqle ) {
            System.err.println("Error in DbForum.java:" + sqle);
            sqle.printStackTrace();
        }
        finally {
            try {  pstmt.close(); }
            catch (Exception e) { e.printStackTrace(); }
            try {  con.close();   }
            catch (Exception e) { e.printStackTrace(); }
        }
        return new IofficePermissions(permissions);
    }
    protected void getMaxPermissionID() {
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(COUNT_PERM_INFO);
            ResultSet rs = pstmt.executeQuery();
            if(rs.next()) {
                int maxPerm = rs.getInt(1);
                IofficePermissions.MAX_PREV_NUM = maxPerm+1;
            }
        }
        catch( SQLException sqle ) {
            System.err.println("Error in DbIofficeFactory.java:" + sqle);
            sqle.printStackTrace();
        }
        finally {
            try {  pstmt.close(); }
            catch (Exception e) { e.printStackTrace(); }
            try {  con.close();   }
            catch (Exception e) { e.printStackTrace(); }
        }
    }


    /**
     * Returns the permissions that a particular group has for the forum.
     */
    protected IofficePermissions getGroupPermissions(int groupID) {
        Connection con = null;
        PreparedStatement pstmt = null;
        //Initialize a permissions array with no permissions.
        boolean [] permissions = new boolean[IofficePermissions.MAX_PREV_NUM];
        for (int i=0; i<permissions.length; i++) {
            permissions[i] = false;
        }
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(GET_GROUP_PERMS);
            pstmt.setInt(1, groupID);
            ResultSet rs = pstmt.executeQuery();
            while(rs.next()) {
                int newPerm = rs.getInt("IDMenue");
                permissions[newPerm] = true;
            }
        }
        catch( SQLException sqle ) {
            sqle.printStackTrace();
        }
        finally {
            try {  pstmt.close(); }
            catch (Exception e) { e.printStackTrace(); }
            try {  con.close();   }
            catch (Exception e) { e.printStackTrace(); }
        }
        return new IofficePermissions(permissions);
    }

    //refer to DbFourum.addUserPermission
    public void addUserPermission(User user, int permissionType)
            throws UnauthorizedException
    {
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(ADD_USER_PERM);
            pstmt.setInt(1,user.getID());
            pstmt.setInt(2,permissionType);
            pstmt.execute();
            //Remove user permissions from cache since they've changed.
            cacheManager.removeUserPerm(new Integer(user.getID()));
        }
        catch( SQLException sqle ) {
            System.err.println("Error in DbForum.java:" + sqle);
            sqle.printStackTrace();
        }
        finally {
            try {  pstmt.close(); }
            catch (Exception e) { e.printStackTrace(); }
            try {  con.close();   }
            catch (Exception e) { e.printStackTrace(); }
        }
    }

    public void removeUserPermission(User user, int permissionType)
            throws UnauthorizedException
    {
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(REMOVE_USER_PERM);
            pstmt.setInt(1,user.getID());
            pstmt.setInt(2,permissionType);
            pstmt.execute();
            //Remove user permissions from cache since they've changed.
            cacheManager.removeUserPerm(new Integer(user.getID()));
        }
        catch( SQLException sqle ) {
            System.err.println("Error in DbForum.java:" + sqle);
            sqle.printStackTrace();
        }
        finally {
            try {  pstmt.close(); }
            catch (Exception e) { e.printStackTrace(); }
            try {  con.close();   }
            catch (Exception e) { e.printStackTrace(); }
        }
    }


    public void addGroupPermission(Group group, int permissionType)
            throws UnauthorizedException
    {
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(ADD_GROUP_PERM);
            pstmt.setInt(1,group.getID());
            pstmt.setInt(2,permissionType);
            pstmt.execute();
            //Remove all user permissions from cache since they've changed.
            cacheManager.clear(
                DbCacheManager.USER_PERMS_CACHE
            );
        }
        catch( SQLException sqle ) {
            System.err.println("Error in DbForum.java:" + sqle);
            sqle.printStackTrace();
        }
        finally {
            try {  pstmt.close(); }
            catch (Exception e) { e.printStackTrace(); }
            try {  con.close();   }
            catch (Exception e) { e.printStackTrace(); }
        }
    }



    public void removeGroupPermission(Group group, int permissionType)
            throws UnauthorizedException
    {
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(REMOVE_GROUP_PERM);
            pstmt.setInt(1,group.getID());
            pstmt.setInt(2,permissionType);
            pstmt.execute();
            //Remove user permissions from cache since they've changed. Because
            //of the way that user permtype cache is handled, it is easiest to
            //simply remove all the user permtype cache for the forum. This is ok
            //since happens infrequently.
            cacheManager.clear(
                DbCacheManager.USER_PERMS_CACHE
            );
        }
        catch( SQLException sqle ) {
            System.err.println("Error in DbIofficeFactory.java:" + sqle);
            sqle.printStackTrace();
        }
        finally {
            try {  pstmt.close(); }
            catch (Exception e) { e.printStackTrace(); }
            try {  con.close();   }
            catch (Exception e) { e.printStackTrace(); }
        }
    }

    public int permFromName(String permName)
      throws PermissionNameException
    {
    	if ( permNameToTypeTable == null )
    	{
    		throw new PermissionNameException("cannot load permission name dictionary");
    	}
    	else {
    		Integer permInt =(Integer) permNameToTypeTable.get(permName);
    		if ( permInt == null )
    		{
	    		throw new PermissionNameException("invalid permission name");
    		}
    		else return permInt.intValue();

    	}
    }

    public String getPermName(int permtype)
          throws PermissionNameException
    {
    	if ( permTypeToNameTable == null )
    	{
    		throw new PermissionNameException("cannot load permission name dictionary");
    	}
    	else {
    		String permName =(String) permTypeToNameTable.get(new Integer(permtype));
    		if ( permName == null )
    		{
	    		throw new PermissionNameException("invalid permission type");
    		}
    		else return permName;

    	}
    }

    public int[] getAllPermissionTypes()
    {
        int[] perms = new int[permNameToTypeTable.size()];
        int j=perms.length;
        int i=0;
        Enumeration enum= permNameToTypeTable.elements();
        try {
        while ( enum.hasMoreElements())
        {
            Integer permInt=(Integer)(enum.nextElement());
            perms[i++] = permInt.intValue();
        }
        }
        catch ( Exception e )
        {
        }
        return perms;
    }

    public String[] getAllPermissionNames()
    {
        String[] perms = new String[ permTypeToNameTable.size()];
        int i=0;
        Enumeration enum= permTypeToNameTable.elements();
        while ( enum.hasMoreElements())
        {
            perms[i++] = (String)enum.nextElement();
        }
        return perms;
    }
    /**
     *     return the all of the permissions that the group does not have
     */
    public int[] getAbsentPermissionTypes(Group group)
    {
        int[] all = getAllPermissionTypes();
        int[] me= getGroupPermissionTypes(group);
        ArrayList list=new ArrayList();
        int i,j;
        boolean dup;
        for ( i=0; i<all.length; i++)
        {
            dup = false;
            for ( j=0; j<me.length; j++)
            {
                if ( me[j] == all[i] )
                {
                    dup=true;
                    break;
                }
            }
            if ( !dup ) list.add( new Integer(all[i]));
        }
        //now list contains all the absent permissions
        int[] ab=new int[list.size()];
        for ( i=0; i<list.size(); i++) ab[i]=((Integer)(list.get(i))).intValue();
        return ab;
    }

    /**
     *     return the all of the permissions that the user does not have
     */
    public int[] getAbsentPermissionTypes(User user)
    {
        int[] all = getAllPermissionTypes();
        int[] me= getUserPermissionTypes(user);
        ArrayList list=new ArrayList();
        int i,j;
        boolean dup;
        for ( i=0; i<all.length; i++)
        {
            dup = false;
            for ( j=0; j<me.length; j++)
            {
                if ( me[j] == all[i] )
                {
                    dup=true;
                    break;
                }
            }
            if ( !dup ) list.add( new Integer(all[i]));
        }
        //now list contains all the absent permissions
        int[] ab=new int[list.size()];
        for ( i=0; i<list.size(); i++) ab[i]=((Integer)(list.get(i))).intValue();
        return ab;
    }

    /**
     *   Get all the permissions types that user is endowed
     */
    public int[] getUserPermissionTypes(User user)
    {
        ArrayList list=new ArrayList();
        Connection con = null;
        PreparedStatement pstmt = null;
        int permtype;
        int[] result=null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(USER_PERMISSION);
                pstmt.setInt(1, user.getID());
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                permtype = rs.getInt("IDMenue");
                list.add( new Integer( permtype));
            }
            result = new int[ list.size() ];
            for ( int i=0; i< list.size(); i++)
                result[i]=((Integer)list.get(i)).intValue();

⌨️ 快捷键说明

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