?? contentingestbean.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]
*/
/*
* $(@)ContentIngestBean.java $Revision: 1.1.1.1 $ $Date: 2006/03/15 13:12:10 $
*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
*/
/**
*
* @version: 1.0
* @date: Jan 1, 2003
*
*/
package com.sun.sjc.idtv.vod.server.mediaprovisioning;
import java.util.*;
import javax.ejb.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import com.sun.sjc.idtv.vod.shared.data.*;
/**
* Implementation bean for the <code>ContentIngest</code> interface, <code>ContentIngest</code>
* defines all possible business methods for the bean.
*
* @see ContentIngest
* @see ContentIngestHome
*/
public class ContentIngestBean implements SessionBean {
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());
}
}
/**
* Creates a bean. Required by EJB spec.
* @exception throws CreateException.
*/
public void ejbCreate() throws java.rmi.RemoteException, javax.ejb.CreateException {
}
/**
* Removes the bean. Required by EJB spec.
*/
public void ejbRemove() {
}
/**
* Loads the state of the bean from secondary storage. Required by EJB spec.
*/
public void ejbActivate() {
}
/**
* Serializes the state of the bean to secondary storage. Required by EJB spec.
*/
public void ejbPassivate() {
}
/**
* Required by EJB spec.
*/
public void ContentIngestBean() {
}
/**
* Uploads movie metadata into the VAS and the movie into the VOS.
* @param movie the movie metadata to persist in the database
* @return
* @exception RemoteException
*/
public void store(Movie movie) throws java.rmi.RemoteException, SQLException {
// get db connection from pool
Connection conn = dataSource.getConnection();
conn.setAutoCommit(false);
PreparedStatement stmt = null;
try {
// check if movie exists; if so, delete it
stmt = conn.prepareStatement("DELETE moviecatalog WHERE id = ?");
stmt.setQueryTimeout(QUERYTIMEOUT);
stmt.setLong(1, movie.id);
stmt.executeUpdate();
stmt.close();
stmt = conn.prepareStatement("DELETE moviedetail WHERE movieid = ?");
stmt.setQueryTimeout(QUERYTIMEOUT);
stmt.setLong(1, movie.id);
stmt.executeUpdate();
stmt.close();
// insert movie
stmt = conn.prepareStatement("INSERT INTO moviecatalog VALUES (?, ?, ?, ?, ?, ?, ?, ?, (SELECT id FROM moviegenres WHERE genre LIKE ?), ?, ?, ?, ?, ?, ?, (SELECT id FROM ratings WHERE name = ?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
stmt.setQueryTimeout(QUERYTIMEOUT);
stmt.setLong(1, movie.id);
stmt.setString(2, movie.externalid);
stmt.setString(3, movie.fulltitle);
stmt.setString(4, movie.origtitle);
stmt.setString(5, movie.shorttitle);
stmt.setString(6, movie.shortdescr);
stmt.setString(7, movie.longdescr);
stmt.setInt(8, movie.version);
//stmt.setInt(9, movie.genreid);
stmt.setString(9, movie.genrename);
stmt.setString(10, movie.prodcompany);
stmt.setDate(11, new java.sql.Date(movie.proddate.getTime()));
stmt.setString(12, movie.releasedate);
stmt.setString(13, movie.country);
stmt.setInt(14, movie.screenformat);
stmt.setString(15, movie.showing);
//stmt.setInt(16, movie.boxofficeratingid);
stmt.setString(16, movie.boxofficerating);
stmt.setInt(17, movie.parentratingid);
//stmt.setString(17, movie.parentrating);
stmt.setInt(18, movie.duration);
stmt.setBoolean(19, movie.color);
stmt.setBoolean(20, movie.stereo);
stmt.setBoolean(21, movie.surround);
stmt.setBoolean(22, movie.dolby);
stmt.setString(23, movie.dvbcontent);
stmt.setDate(24, new java.sql.Date(movie.startdate.getTime()));
stmt.setDate(25, new java.sql.Date(movie.enddate.getTime()));
stmt.setFloat(26, movie.stdprice);
stmt.setFloat(27, movie.minprice);
stmt.setString(28, movie.movieurl);
stmt.setString(29, movie.posterurl);
stmt.executeUpdate();
stmt.close();
// insert detail records here
stmt = conn.prepareStatement("INSERT INTO moviedetail VALUES (?, ?, ?)");
stmt.setQueryTimeout(QUERYTIMEOUT);
for (int i=0; i<movie.actors.length; i++) {
stmt.setLong(1, movie.id);
stmt.setInt(2, MovieDetail.DETAIL_ACTOR);
stmt.setString(3, movie.actors[i]);
stmt.executeUpdate();
}
for (int i=0; i<movie.producers.length; i++) {
stmt.setLong(1, movie.id);
stmt.setInt(2, MovieDetail.DETAIL_PRODUCER);
stmt.setString(3, movie.producers[i]);
stmt.executeUpdate();
}
for (int i=0; i<movie.directors.length; i++) {
stmt.setLong(1, movie.id);
stmt.setInt(2, MovieDetail.DETAIL_DIRECTOR);
stmt.setString(3, movie.directors[i]);
stmt.executeUpdate();
}
for (int i=0; i<movie.composers.length; i++) {
stmt.setLong(1, movie.id);
stmt.setInt(2, MovieDetail.DETAIL_COMPOSER);
stmt.setString(3, movie.composers[i]);
stmt.executeUpdate();
}
for (int i=0; i<movie.imageurls.length; i++) {
stmt.setLong(1, movie.id);
stmt.setInt(2, MovieDetail.DETAIL_IMAGEURL);
stmt.setString(3, movie.imageurls[i]);
stmt.executeUpdate();
}
for (int i=0; i<movie.trailerurls.length; i++) {
stmt.setLong(1, movie.id);
stmt.setInt(2, MovieDetail.DETAIL_TRAILERURL);
stmt.setString(3, movie.trailerurls[i]);
stmt.executeUpdate();
}
stmt.close();
conn.commit();
conn.close();
return;
} catch (SQLException e) {
stmt.close();
conn.rollback();
conn.close();
throw(e);
}
// log event
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -