package oracle.demo.oow.bd.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import oracle.demo.oow.bd.to.CastCrewTO;
import oracle.demo.oow.bd.to.CastMovieTO;
import oracle.demo.oow.bd.to.CastTO;
import oracle.demo.oow.bd.to.MovieTO;
import oracle.demo.oow.bd.util.KeyUtil;
import oracle.demo.oow.bd.util.StringUtil;
import oracle.kv.Key;
import oracle.kv.Value;
import oracle.kv.ValueVersion;
import oracle.kv.Version;
import oracle.kv.avro.JsonAvroBinding;
import oracle.kv.avro.JsonRecord;
import oracle.kv.table.PrimaryKey;
import oracle.kv.table.Row;
import oracle.kv.table.Table;
import org.apache.avro.Schema;
import org.codehaus.jackson.node.ObjectNode;
public class CastDAO extends BaseDAO {
private static Table castTable = null;
private static Table castCrew = null;
private static Table movieTable = null;
private final static String TABLE_NAME="CAST";
public CastDAO() {
super();
castTable = getKVStore().getTableAPI().getTable(TABLE_NAME);
movieTable = getKVStore().getTableAPI().getTable(MovieDAO.TABLE_NAME);
castCrew = getKVStore().getTableAPI().getTable(MovieDAO.TABLE_NAME+"."+MovieDAO.CHILD_TABLE);
}
/**
* This method inserts Cast information and also index cast ID to the movieId
* so that one can run queries on castId to fetch all the movies in which
* a particular cast worked.
* @param castTO - This is a cast transfer object
* @return - true if insertion is successful
*/
public boolean insertCastInfo(CastTO castTO) {
boolean flag = false;
int castId;
Value value = null;
Version version = null;
if (castTO != null) {
//System.out.println("CT/ " + jsonTxt);
castId = castTO.getId();
/**
* Insert cast json string to the castId
* Key=/CT/castId/-/info
*/
PrimaryKey key = KeyUtil.getCastInfoKey(castId,castTable);
// serialize castTO to byte array using JSONAvroBinding
//Insert castTO into the store
Row row = castTable.createRowFromJson(castTO.toJsonString(),true);
version = getKVStore().getTableAPI().put(row, null,null);
/**
* Create a mapping between movieId & castId, so that one can find
* the casts for a movie.
* Key=/MVCC/movieId/-/cc
*/
insertCast4Movies(castTO);
//Flip the flag to true for success
flag = true;
}
return flag;
} //insertCastInfo
/**
* This method inserts Cast information and also index cast ID to the movieId
* so that one can run queries on castId to fetch all the movies in which
* a particular cast worked.
* @param castTO - This is a cast transfer object
* @return - true if insertion is successful
*/
public boolean insertCastInfoRDBMS(CastTO castTO) {
boolean flag = false;
Connection conn = null;
int castId;
if (castTO != null) {
// Insert record into Oracle RDBMS
try {
conn = super.getOraConnect();
// jsonTxt = castTO.getJsonTxt();
//System.out.println("CT/ " + jsonTxt);
castId = castTO.getId();
/**
* Insert cast id & name
*/
String update = "INSERT INTO MOVIESITE.CAST (CAST_ID, NAME) " + "VALUES (?, ?)";
PreparedStatement stmt = conn.prepareStatement(update);
stmt.setInt(1, castId);
stmt.setString(2, castTO.getName());
try {
stmt.execute();
} catch (SQLException e) {
// Expect many duplicates. Duplicate error code = 1
if (e.getErrorCode() != 1)
System.out.println(e.getErrorCode() + ":" + e.getMessage());
}
stmt.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
return false;
}
/**
* Create a mapping between movieId & castId, so that one can find
* the casts for a movie.
*/
insertCast4MoviesRDBMS(castTO);
}
return flag;
} //insertCastInfo
/**
* This method loops through all the movieId stored in the CastTO and create
* association between movieId and castId and saves CastCrewTO JSON txt as the
* value. Key=/MV/movieId/-/cc
* @param castTO
*/
public void insertCast4Movies(CastTO castTO) {
List<CastMovieTO> castMovieList = null;
CastCrewTO castCrewTO = null;
PrimaryKey key = null;
int movieId = 0;
int castId = 0;
String jsonTxt = null;
int order = -1;
String character = null;
if (castTO != null & castTO.getCastMovieList() != null) {
castMovieList = castTO.getCastMovieList();
castId = castTO.getId();
for (CastMovieTO castMovieTO : castMovieList) {
movieId = castMovieTO.getId();
order = castMovieTO.getOrder();
character = castMovieTO.getCharacter();
//Get Cast detail for the movie and set it into the CastTO
castTO.setOrder(order);
castTO.setCharacter(character);
//make movie to cast association only if order < 15
if (order > -1 && order < 15) {
//get the key
key = KeyUtil.getMovieCastCrewKey(movieId,movieId,movieTable);
//check if CastCrewTO jsonTxt already exit
System.out.println(key.toJsonString(true));
Row jrow = getKVStore().getTableAPI().get(key, null);
if(jrow!=null)
jsonTxt = jrow.toJsonString(true);
//System.out.println("1: " + jsonTxt);
if (StringUtil.isNotEmpty(jsonTxt)) {
castCrewTO = new CastCrewTO(jsonTxt.trim());
} else {
castCrewTO = new CastCrewTO();
castCrewTO.setMovieId(movieId);
}
//add CastTO into castCrewTO
castCrewTO.addCastTO(castTO);
//Convert castCrewTO into json txt
jsonTxt = castCrewTO.getJsonTxt();
//inset movie-cast association into the KV-Store
//System.out.println(jsonTxt);
if(StringUtil.isNotEmpty(jsonTxt)){
Row row = castCrew.createRowFromJson(jsonTxt, false);
getKVStore().getTableAPI().put(row, null,null);
}
} //if (order > -1 && order < 15) {
} //EOF for
} //if (castTO != null & castTO.getCastMovieList() != null)
} //insertCast4Movies
/**
* This method loops through all the movieId stored in the CastTO and create
* association between movieId and castId.
* @param castTO
*/
public void insertCast4MoviesRDBMS(CastTO castTO) {
List<CastMovieTO> castMovieList = null;
int movieId = 0;
int castId = 0;
int order = -1;
String character = null;
Connection conn = super.getOraConnect();
if (castTO != null & castTO.getCastMovieList() != null) {
castMovieList = castTO.getCastMovieList();
castId = castTO.getId();
for (CastMovieTO castMovieTO : castMovieList
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于hadoop实现的电影网站+源代码+文档说明 -------- 不懂运行,下载完可以私聊问,可远程教学 该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! <项目介绍> 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 --------
资源推荐
资源详情
资源评论
收起资源包目录
基于hadoop实现的电影网站+源代码+文档说明 (157个子文件)
.classpath 7KB
org.eclipse.wst.common.component 538B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 14KB
jquery.cluetip.css 5KB
skin.css 5KB
dd.css 4KB
jquery.rating.css 891B
Thumbs.db 78KB
header.gif 8KB
bl.gif 5KB
br.gif 2KB
tl.gif 1KB
arrowup.gif 853B
star.gif 815B
delete.gif 752B
tr.gif 672B
wait.gif 432B
rarrowup.gif 241B
rarrowdown.gif 241B
rarrowleft.gif 235B
rarrowright.gif 232B
dd_arrow.gif 138B
darrowright.gif 77B
arrowright.gif 77B
arrowleft.gif 76B
darrowleft.gif 76B
arrowdown.gif 69B
darrowdown.gif 69B
darrowup.gif 69B
.gitattributes 65B
.gitignore 272B
CastDAO.java 19KB
CustomerDAO.java 18KB
MovieDAO.java 18KB
UserItemLoader.java 17KB
KeyUtil.java 16KB
MovieTO.java 15KB
GenreDAO.java 13KB
MovieUploader.java 13KB
CrewDAO.java 13KB
ActivityDAO.java 12KB
IconDemoApp.java 10KB
ActivityDAO.java 10KB
CastCrewDAO.java 9KB
TestFrame.java 8KB
ActivityTO.java 8KB
SchemaDefinition.java 7KB
CustomerTO.java 7KB
UserDAO.java 7KB
BaseDAO.java 6KB
CustomerProfileLoader.java 6KB
CastTO.java 6KB
MovieDao.java 6KB
CastCrewTO.java 6KB
CrewTO.java 5KB
CastDAO.java 4KB
CustomerRatingDAO.java 4KB
CrewDAO.java 4KB
MovieUploader.java 4KB
ConstantsHBase.java 4KB
Constant.java 4KB
logIn.java 4KB
GenreDao.java 4KB
CustomerGenreTO.java 4KB
UserUploader.java 4KB
URLReader.java 3KB
ScoredGenreTO.java 3KB
MissingIcon.java 3KB
CustomerGenreMovieTO.java 3KB
CastMovieTO.java 2KB
GenreTO.java 2KB
MovieConstant.java 2KB
InitHBase.java 2KB
HBaseDB.java 2KB
IsUserLogued.java 2KB
JsonConstant.java 2KB
MovieRecommendationRefresh.java 2KB
ActivityType.java 2KB
KeyConstant.java 2KB
logout.java 1KB
YouTubeUtil.java 1KB
GenreMovieFormatter.java 1KB
GenreMovieTO.java 1KB
BaseTO.java 1KB
MovieFormatter.java 1KB
GenreFormatter.java 1KB
FileWriterUtil.java 1KB
Test.java 1KB
StringUtil.java 1KB
ImageLoader.java 1KB
RatingType.java 1022B
BooleanType.java 1019B
SearchCriteria.java 933B
HelperUtil.java 842B
StoreConfig.java 203B
movieplex2.jpg 651KB
no-image.jpg 7KB
bright_yellow_star-s5.JPG 1KB
bright_yellow_star-s4.JPG 1KB
共 157 条
- 1
- 2
资源评论
机智的程序员zero
- 粉丝: 1529
- 资源: 4128
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功