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

📄 subscribermanagementsystembean.java

📁 Sun公司Dream项目
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            return null;

        }

    }

    

    /**

     * Create a subscriber object for a given userid and ipAddress.

     * @param userid: userid of the subscriber.

     * @param ipAddress: ipAddress of the browser or set top box that the user is on.

     * @return the subscriber's detailed info

     * @exception RemoteException

     */

    public Subscriber getSubscriber(String userid, String ipAddress) throws java.rmi.RemoteException, SQLException {

        

        Subscriber[] subs = getSubscriberList(ipAddress);

        Subscriber subscriber = null;

        for (int i=0; i<subs.length; i++) {

            if (subs[i].login.equals(userid)) {

                subscriber = subs[i];

                i=subs.length;

            }

        }

        

        if (subscriber == null) {

            //TODO: throw an exception as the JSP shouldn't have to check for null return values.

            //TODO: Remove printlns

            System.out.println("No subscribers match userid");

            return null;

        }

        

        // get db connection from pool

        Connection conn = dataSource.getConnection();

        

        // get rentals

        PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT movieid, bookmark, shorttitle FROM subscrentals, moviecatalog WHERE (subscrentals.subscrid = ?) AND (subscrentals.movieid = moviecatalog.id) AND (subscrentals.starttimest >= ?) ORDER BY moviecatalog.shorttitle"); // AND (subscrentals.starttimest >= ?)

        

        Timestamp yesterday = new Timestamp(System.currentTimeMillis() - (24*60*60*1000));

        

        stmt.setQueryTimeout(QUERYTIMEOUT);

        if (subscriber.ismaster) {

            stmt.setLong(1, subscriber.masterid);

        } else {

            stmt.setLong(1, subscriber.id);

        }

        stmt.setTimestamp(2, yesterday);

        

        ResultSet rs = stmt.executeQuery();

        Vector v = new Vector();

        while (rs.next()) {

            Rental r = new Rental();

            r.id = rs.getLong(1);

            r.bookmark = rs.getString(2);

            r.shorttitle = rs.getString(3);

            v.addElement(r);

        }

        rs.close();

        stmt.close();

        subscriber.rentals = new Rental[v.size()];

        for (int i=0; i<v.size(); i++) {

            subscriber.rentals[i] = (Rental) v.elementAt(i);

        }

        

        // get categories

        stmt = conn.prepareStatement("SELECT genreid, genre, assetcount FROM subscrgenres, moviegenres WHERE (subscrgenres.subscrid = ?) AND (subscrgenres.genreid = moviegenres.id)");

        

        stmt.setQueryTimeout(QUERYTIMEOUT);

        if (subscriber.ismaster) {

            stmt.setLong(1, subscriber.masterid);

        } else {

            stmt.setLong(1, subscriber.id);

        }

        rs = stmt.executeQuery();

        v = new Vector();

        while (rs.next()) {

            MovieCategory r = new MovieCategory();

            r.genreid = rs.getInt(1);

            r.genrename = rs.getString(2);

            r.count = rs.getInt(3);

            v.addElement(r);

        }

        rs.close();

        stmt.close();

        subscriber.categories = new MovieCategory[v.size()];

        for (int i=0; i<v.size(); i++) {

            subscriber.categories[i] = (MovieCategory) v.elementAt(i);

        }

        

        // get account balance

        stmt = conn.prepareStatement("SELECT subscracct.balance FROM subscracct WHERE (subscracct.subscrid = ?)");

        

        stmt.setQueryTimeout(QUERYTIMEOUT);

        stmt.setLong(1, subscriber.masterid);

        rs = stmt.executeQuery();

        float balance = 0;

        if (rs.next()) {

            balance = rs.getFloat(1);

        }

        rs.close();

        stmt.close();

        subscriber.balance = balance;

        

        conn.close();

        return subscriber;

    }

    

    

    /**

     * Store the watch position in a movie.

     * @param subscriber the subscriber.

     * @param rental the movie.

     * @return nothing

     * @exception RemoteException

     */

    public void storeBookmark(Subscriber subscriber, Rental rental) throws java.rmi.RemoteException, SQLException {

        

        // get db connection from pool

        Connection conn = dataSource.getConnection();

        

        PreparedStatement stmt = conn.prepareStatement("UPDATE subscrentals SET bookmark = ? WHERE (subscrid = ?) AND (movieid = ?)");

        

        stmt.setQueryTimeout(QUERYTIMEOUT);

        if ((rental.bookmark == null) || (rental.bookmark.equals(""))) {

            rental.bookmark = "0.0";

        }

        stmt.setString(1, rental.bookmark);

        if (subscriber.ismaster) {

            stmt.setLong(2, subscriber.masterid);

        } else {

            stmt.setLong(2, subscriber.id);

        }

        stmt.setLong(3, rental.id);

        stmt.executeUpdate();

        stmt.close();

        conn.close();

    }

    

    /**

     *Retrieves the rights of a particular userfrom the database

     *

     **/

    

    public RightsInfo[] getUserRightsInfo(Subscriber subscriber) throws SQLException,java.rmi.RemoteException {

        

        Connection conn = dataSource.getConnection();

        PreparedStatement stmt = conn.prepareStatement("SELECT  moviecatalog.cid,moviecatalog.id,opera_license_info.remaining,opera_license_info.endtime,opera_license_info.userid FROM opera_license_info, moviecatalog WHERE (opera_license_info.userid = ?) AND (moviecatalog.cid = opera_license_info.contentid)");

        PreparedStatement stmt2 = conn.prepareStatement("SELECT  rights_info.verbname, rights_info.verbargname, rights_info.verbargval FROM rights_info, opera_license_info WHERE (opera_license_info.userid = ?) AND (opera_license_info.contentid = ?) AND (rights_info.rightskey = opera_license_info.rightskey)");

        stmt.setQueryTimeout(QUERYTIMEOUT);

        stmt2.setQueryTimeout(QUERYTIMEOUT);

        /*if (subscriber.ismaster) {

            stmt.setLong(1, subscriber.masterid);

        } else {

            stmt.setLong(1, subscriber.id);

        }*/

        stmt.setString(1, subscriber.login);

        ResultSet rs = stmt.executeQuery();

        

        Vector v = new Vector();

        while (rs.next()) {

            RightsInfo rightsdet = new RightsInfo();

            rightsdet.userID = rs.getString(5);

            rightsdet.movieName = rs.getString(1);

            rightsdet.movieid = rs.getInt(2);

            rightsdet.remainingRights = rs.getInt(3);

            

            System.out.println("userid in getuserrightsInfo - outerloop" + rightsdet.userID);

            System.out.println("moviename in getuserrightsInfo - outerloop" + rightsdet.movieName);

            //System.out.println("movieid" + rightsdet.movieid);

            //System.out.println("reamining rights" + rightsdet.remainingRights);

            // For now just using remaining license to determine expired.

            // We can also use end date on timed license type in future.

            

            if (rightsdet.remainingRights > 0)

                rightsdet.expired = false;

            else

                rightsdet.expired = true;

            

            stmt2.setString(1, rightsdet.userID);

            stmt2.setString(2, rightsdet.movieName);

            ResultSet rs2 = stmt2.executeQuery();

            Vector v2 = new Vector();

            while (rs2.next()) {

                VerbElement verbElement = new VerbElement();

                verbElement.verbName = rs2.getString(1);

                verbElement.verbArgName = rs2.getString(2);

                verbElement.verbArgValue = rs2.getString(3);

                v2.addElement(verbElement);

                System.out.println("inside inner loop");

            }

            System.out.println("About to close rs2");

            //rs2.close();

            VerbElement[] verbElements = new VerbElement[v2.size()];

            for (int i=0; i<v2.size(); i++) {

                verbElements[i] = new VerbElement();

                verbElements[i] = (VerbElement) v2.elementAt(i);

            }

            rightsdet.verbElements = verbElements;

            v.addElement(rightsdet);

        }

        stmt2.close();

        System.out.println("About to close rs");

        //rs.close();

        stmt.close();

        RightsInfo[] rights = new RightsInfo[v.size()];

        for (int i=0; i<v.size(); i++) {

            rights[i] = (RightsInfo) v.elementAt(i);

        }

        

        

        conn.close();

        return rights;

    }

    

    

    public Subscriber getSubscriberInfoFromID(String userID) throws java.rmi.RemoteException, SQLException {

        

        Subscriber s = new Subscriber();

        // get db connection from pool

        Connection conn = dataSource.getConnection();

        PreparedStatement stmt = null;

        ResultSet rs = null;

        

        // check if user is a master subscriber

        stmt = conn.prepareStatement("SELECT * FROM MASTERSUBSCRIBERS WHERE MASTERSUBSCRIBERS.LOGIN = ?");

        stmt.setQueryTimeout(QUERYTIMEOUT);

        stmt.setString(1, userID);

        rs = stmt.executeQuery();

        

        if (rs.next()) {

            s.ismaster = true;

            s.masterid = rs.getLong(1);

            s.id = rs.getLong(1);

            s.login = rs.getString(2);

            s.pin = rs.getString(3);

            s.firstname = rs.getString(4);

            s.lastname = rs.getString(5);

            s.SimCardNum = rs.getString(11);

        } else {

            // check if user is a sub subscriber

            rs.close();

            stmt.close();

            stmt = conn.prepareStatement("SELECT * FROM  SUBSUBSCRIBERS WHERE (SUBSUBSCRIBERS.LOGIN = ?)");

            stmt.setQueryTimeout(QUERYTIMEOUT);

            stmt.setString(1, userID);

            rs = stmt.executeQuery();

            

            if (rs.next()) {

                s.masterid = rs.getInt(1);

                s.id = rs.getLong(2);

                s.login = rs.getString(3);

                s.pin = rs.getString(4);

                s.firstname = rs.getString(5);

                s.lastname = rs.getString(6);

                s.SimCardNum = rs.getString(7);

            } else {

                s = null;

            }

        }

        rs.close();

        stmt.close();

        conn.close();

        return s;

    }

    

    public Subscriber getSubscriberInfoFromSIMID(String SIMNumber) throws java.rmi.RemoteException, SQLException {

        

        Subscriber s = new Subscriber();

        // get db connection from pool

        Connection conn = dataSource.getConnection();

        PreparedStatement stmt = null;

        ResultSet rs = null;

        

        // check if user is a master subscriber

        stmt = conn.prepareStatement("SELECT * FROM MASTERSUBSCRIBERS WHERE MASTERSUBSCRIBERS.SIMCARDNUM = ?");

        stmt.setQueryTimeout(QUERYTIMEOUT);

        stmt.setString(1, SIMNumber);

        rs = stmt.executeQuery();

        

        if (rs.next()) {

            s.ismaster = true;

            s.masterid = rs.getLong(1);

            s.id = rs.getLong(1);

            s.login = rs.getString(2);

⌨️ 快捷键说明

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