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

📄 conductorbean.java

📁 Sun公司Dream项目
💻 JAVA
字号:
/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the "License").  You may not use this file except
 * in compliance with the License.
 *
 * You can obtain a copy of the license at
 * http://www.opensource.org/licenses/cddl1.php
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL
 * HEADER in each file and include the License file at
 * http://www.opensource.org/licenses/cddl1.php.  If 
 * applicable, add the following below this CDDL HEADER, 
 * with the fields enclosed by brackets "[]" replaced 
 * with your own identifying information: 
 * Portions Copyright [yyyy]
 * [name of copyright owner]
 */ 

/*
 * $(@)conductorBean.java $Revision: 1.3 $ $Date: 2006/08/04 23:42:11 $
 * 
 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
 */


package com.sun.sjc.idtv.vod.server.conductor;

import java.sql.*;
import java.util.*;
import javax.sql.*;
import javax.ejb.*;
import javax.naming.*;
import com.sun.sjc.idtv.vod.shared.data.*;


/**
 * This is the bean class for the conductorBean enterprise bean.
 * Created Oct 10, 2005 2:38:54 PM
 */
public class conductorBean implements javax.ejb.SessionBean {
    
    
    // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">
    // TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
    // TODO Add business methods or web service operations
    /**
     * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
     */
    
    
    /**
     * @see javax.ejb.SessionBean#ejbActivate()
     */
    public void ejbActivate() {
        
    }
    
    /**
     * @see javax.ejb.SessionBean#ejbPassivate()
     */
    public void ejbPassivate() {
        
    }
    
    /**
     * @see javax.ejb.SessionBean#ejbRemove()
     */
    public void ejbRemove() {
        
    }
    // </editor-fold>
    
    private  javax.ejb.SessionContext m_ctx = null;
    public static final int QUERYTIMEOUT = 60;
    private DataSource dataSource;
    
    /**
     * Sets the session context. Required by EJB spec.
     * @param ctx A SessionContext object.
     */
    public void setSessionContext(javax.ejb.SessionContext ctx) {
        m_ctx = ctx;
        try {
            InitialContext ic = new InitialContext();
            //dataSource = (DataSource) ic.lookup("java:comp/env/jdbc/vod");
            dataSource = (DataSource) ic.lookup("jdbc/sample");
        } catch (Exception ex) {
            throw new EJBException("Unable to connect to database. " +
                    ex.getMessage());
        }
    }
    
    /**
     * See section 7.10.3 of the EJB 2.0 specification
     * See section 7.11.3 of the EJB 2.1 specification
     */
    public void ejbCreate() {
        // TODO implement ejbCreate if necessary, acquire resources
        // This method has access to the JNDI context so resource aquisition
        // spanning all methods can be performed here such as home interfaces
        // and data sources.
    }
    
    
    // Add business logic below. (Right-click in editor and choose
    // "EJB Methods > Add Business Method" or "Web Service > Add Operation")
    
    public RightsInfo getUserRightsForContent(String userID, String contentID)throws java.rmi.RemoteException, SQLException {
        Connection conn = dataSource.getConnection();
        System.out.println("Checking inputs for conductor.getUserRightsForContent");
        logStrMessage("userID", userID);
        logStrMessage("contentID", contentID);
        System.out.println("End of Checking inputs for conductor.getUserRightsForContent");
        
        PreparedStatement stmt = conn.prepareStatement("SELECT  licensetype, remaining, starttime, endtime FROM opera_license_info WHERE (opera_license_info.userid = ?) AND (opera_license_info.contentid =?)");
        stmt.setQueryTimeout(QUERYTIMEOUT);
        stmt.setString(1, userID);
        stmt.setString(2, contentID);
        ResultSet rs = stmt.executeQuery();
        RightsInfo rightsdet = null;
        
        while (rs.next()) {
            rightsdet = new RightsInfo();
            rightsdet.userID = userID;
            rightsdet.movieName = contentID;
            rightsdet.rightsType = rs.getInt(1);
            rightsdet.remainingRights = rs.getInt(2);
            rightsdet.rightsStartDate = rs.getDate(3);
            rightsdet.rightsEndDate = rs.getDate(4);
            // 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; */
            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)");
            stmt2.setQueryTimeout(QUERYTIMEOUT);
            stmt2.setString(1, userID);
            stmt2.setString(2, contentID);
            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);
            }
            VerbElement[] verbElements = null;
            if (v2.size() > 0) {
                verbElements = new VerbElement[v2.size()];
                for (int i=0; i<v2.size(); i++) {
                    verbElements[i] = (VerbElement) v2.elementAt(i);
                }
            }
            rightsdet.verbElements = verbElements;
        }
        rs.close();
        stmt.close();
        
        conn.close();
        
        printRightsInfo(rightsdet);
        return rightsdet;
        
        
        
    }
    
    /*
     *Retreives the move information for a particular movie id
     *
     */
    
    public MovieMetaData getMovieInfo(String movieid) throws java.rmi.RemoteException, SQLException {
        
        // get db connection from pool
        Connection conn = dataSource.getConnection();
        
        // get movie
        PreparedStatement stmt = conn.prepareStatement("SELECT * FROM movie_metadata , moviecatalog WHERE ((movie_metadata.movieid = moviecatalog.id) AND (moviecatalog.cid = ?))");
        
        stmt.setQueryTimeout(QUERYTIMEOUT);
        stmt.setString(1, movieid);
        ResultSet rs = stmt.executeQuery();
        
        MovieMetaData m = new MovieMetaData();
        if (rs.next()) {
            m.MovieID = rs.getInt(1);
            m.CreationData = rs.getString(2);
            m.Language = rs.getString(3);
            m.Country = rs.getString(4);
            m.ContentLocation = rs.getString(5);
            m.DataType = rs.getString(6);
            m.Resolution = rs.getString(7);
            m.BitRate = rs.getString(8);
            m.MimeType = rs.getString(9);
            m.DrmType = rs.getString(10);
            m.ContentID = rs.getString(42);
            
            rs.close();
            stmt.close();
            conn.close();
            
        } else{
            m = null;
        }
        return m;
    }

    public String getFairuseUrl(String contentid) throws java.rmi.RemoteException, SQLException {
        
        String url = null;
        
        // get db connection from pool
        Connection conn = dataSource.getConnection();
        
        // get movie url
        PreparedStatement stmt = conn.prepareStatement("SELECT url FROM fairuse_urls WHERE contentid = ?");
        
        stmt.setQueryTimeout(QUERYTIMEOUT);
        stmt.setString(1, contentid);
        ResultSet rs = stmt.executeQuery();
        
        if (rs.next()) {
            System.out.println("Found a fairuse URL");
            url = rs.getString(1);
            rs.close();
            stmt.close();
            conn.close();
            
        } 
        
        return url;
    }
    
    
    private void logStrMessage (String varName, String varVal) {
        if (varVal == null)
            System.out.println("Warning : "+varName+" is null");
        else
            System.out.println("Value of "+varName+" is "+varVal);
    }
    
    private void printRightsInfo (RightsInfo rightsInfo) {
        if (rightsInfo != null) {
            logStrMessage("rightsInfo.userID", rightsInfo.userID);
            logStrMessage("rightsInfo.movieName", rightsInfo.movieName);
            System.out.println("rightsInfo.expired "+rightsInfo.expired);
            System.out.println("rightsInfo.remainingRights"+rightsInfo.remainingRights);
            if (rightsInfo.rightsStartDate!=null)
                logStrMessage("rightsInfo.rightsStartDate",rightsInfo.rightsStartDate.toString());
            if (rightsInfo.rightsEndDate!=null)
                logStrMessage("rightsInfo.rightsEndDate",rightsInfo.rightsEndDate.toString());
            if (rightsInfo.verbElements != null) {
                for(int k=0; k<rightsInfo.verbElements.length; k++) {
                    if (rightsInfo.verbElements[k]!= null){
                        logStrMessage("rightsInfo.verbElements["+k+"].verbName = ", rightsInfo.verbElements[k].verbName);
                        logStrMessage("rightsInfo.verbElements["+k+"].verbArgName = ", rightsInfo.verbElements[k].verbArgName);
                        logStrMessage("rightsInfo.verbElements["+k+"].verbArgValue = ", rightsInfo.verbElements[k].verbArgValue);
                    }
                }
            }
        } else
            System.out.println("rightsInfo is null !!");
    }        
}

⌨️ 快捷键说明

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