List of usage examples for org.hibernate.type StringType INSTANCE
StringType INSTANCE
To view the source code for org.hibernate.type StringType INSTANCE.
Click Source Link
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
public void getEpisodeList(ApiWrapperList<ApiEpisodeDTO> wrapper) { OptionsEpisode options = (OptionsEpisode) wrapper.getOptions(); SqlScalars sqlScalars = new SqlScalars(); sqlScalars.addToSql("SELECT ser.id AS seriesId, sea.id AS seasonId, sea.season, vid.episode, "); sqlScalars.addToSql(/*www .j av a2s.com*/ "vid.id, vid.title, vid.title_original as originalTitle, vid.release_date as firstAired, "); sqlScalars.addToSql("(vid.watched_nfo or vid.watched_file or vid.watched_api) as watched, "); if (options.hasDataItem(DataItem.PLOT)) { sqlScalars.addToSql("vid.plot, "); sqlScalars.addScalar("plot", StringType.INSTANCE); } if (options.hasDataItem(DataItem.OUTLINE)) { sqlScalars.addToSql("vid.outline, "); sqlScalars.addScalar("outline", StringType.INSTANCE); } sqlScalars.addToSql("ag.cache_filename AS cacheFilename, ag.cache_dir AS cacheDir"); sqlScalars.addToSql("FROM season sea, series ser, videodata vid, artwork a"); sqlScalars.addToSql(SQL_LEFT_JOIN_ARTWORK_LOCATED); sqlScalars.addToSql(SQL_LEFT_JOIN_ARTWORK_GENERATED); sqlScalars.addToSql("WHERE sea.series_id=ser.id"); sqlScalars.addToSql("AND vid.season_id=sea.id"); sqlScalars.addToSql("AND a.videodata_id=vid.id"); if (options.getSeriesid() > 0L) { sqlScalars.addToSql("AND ser.id=:seriesid"); sqlScalars.addParameter("seriesid", options.getSeriesid()); if (options.getSeason() > 0L) { sqlScalars.addToSql("AND sea.season=:season"); sqlScalars.addParameter(SEASON, options.getSeason()); } } if (options.getSeasonid() > 0L) { sqlScalars.addToSql("AND sea.id=:seasonid"); sqlScalars.addParameter("seasonid", options.getSeasonid()); } if (options.getWatched() != null && options.getWatched()) { sqlScalars.addToSql(" AND (vid.watched_nfo=1 or vid.watched_file=1 or vid.watched_api=1)"); } else if (options.getWatched() != null && !options.getWatched()) { sqlScalars.addToSql(" AND vid.watched_nfo=0 AND vid.watched_file=0 AND vid.watched_api=0"); } sqlScalars.addToSql(" ORDER BY seriesId, season, episode"); LOG.debug("getEpisodeList SQL: {}", sqlScalars.getSql()); sqlScalars.addScalar(ID, LongType.INSTANCE); sqlScalars.addScalar(SERIES_ID, LongType.INSTANCE); sqlScalars.addScalar(SEASON_ID, LongType.INSTANCE); sqlScalars.addScalar(SEASON, LongType.INSTANCE); sqlScalars.addScalar(EPISODE, LongType.INSTANCE); sqlScalars.addScalar(TITLE, StringType.INSTANCE); sqlScalars.addScalar(ORIGINAL_TITLE, StringType.INSTANCE); sqlScalars.addScalar(CACHE_FILENAME, StringType.INSTANCE); sqlScalars.addScalar(CACHE_DIR, StringType.INSTANCE); sqlScalars.addScalar("firstAired", DateType.INSTANCE); sqlScalars.addScalar(WATCHED, BooleanType.INSTANCE); List<ApiEpisodeDTO> results = executeQueryWithTransform(ApiEpisodeDTO.class, sqlScalars, wrapper); if (CollectionUtils.isNotEmpty(results)) { if (options.hasDataItem(DataItem.FILES)) { for (ApiEpisodeDTO episode : results) { episode.setFiles(getFilesForId(MetaDataType.EPISODE, episode.getId())); } } if (options.hasDataItem(DataItem.GENRE)) { // use series genres Map<Long, List<ApiGenreDTO>> map = new HashMap<>(); for (ApiEpisodeDTO episode : results) { List<ApiGenreDTO> genres = map.get(episode.getSeriesId()); if (genres == null) { genres = getGenresForId(MetaDataType.SERIES, episode.getSeriesId()); map.put(episode.getSeriesId(), genres); } episode.setGenres(genres); } } if (options.hasDataItem(DataItem.COUNTRY)) { // use series countries Map<Long, List<ApiCountryDTO>> map = new HashMap<>(); for (ApiEpisodeDTO episode : results) { List<ApiCountryDTO> countries = map.get(episode.getSeriesId()); if (countries == null) { countries = getCountriesForId(MetaDataType.SERIES, episode.getSeriesId()); map.put(episode.getSeriesId(), countries); } episode.setCountries(countries); } } if (options.hasDataItem(DataItem.STUDIO)) { // use series studios Map<Long, List<Studio>> map = new HashMap<>(); for (ApiEpisodeDTO episode : results) { List<Studio> studios = map.get(episode.getSeriesId()); if (studios == null) { studios = getStudiosForId(MetaDataType.SERIES, episode.getSeriesId()); map.put(episode.getSeriesId(), studios); } episode.setStudios(studios); } } if (options.hasDataItem(DataItem.CERTIFICATION)) { // use series certifications Map<Long, List<ApiCertificationDTO>> map = new HashMap<>(); for (ApiEpisodeDTO episode : results) { List<ApiCertificationDTO> certifications = map.get(episode.getSeriesId()); if (certifications == null) { certifications = getCertificationsForId(MetaDataType.SERIES, episode.getSeriesId()); map.put(episode.getSeriesId(), certifications); } episode.setCertifications(certifications); } } if (options.hasDataItem(DataItem.AWARD)) { // use series awards Map<Long, List<ApiAwardDTO>> map = new HashMap<>(); for (ApiEpisodeDTO episode : results) { List<ApiAwardDTO> awards = map.get(episode.getSeriesId()); if (awards == null) { awards = getAwardsForId(MetaDataType.SERIES, episode.getSeriesId()); map.put(episode.getSeriesId(), awards); } episode.setAwards(awards); } } if (options.hasDataItem(DataItem.RATING)) { // use episode certifications for (ApiEpisodeDTO episode : results) { episode.setRatings(getRatingsForId(MetaDataType.EPISODE, episode.getId())); } } if (MapUtils.isNotEmpty(options.splitJobs())) { Set<String> jobs = options.getJobTypesAsSet(); for (ApiEpisodeDTO episode : results) { List<ApiPersonDTO> cast = getCastForId(MetaDataType.EPISODE, episode.getId(), options.splitDataItems(), jobs); // just add given amount for jobs to cast Map<JobType, Integer> jobMap = new HashMap<>(options.splitJobs()); for (ApiPersonDTO entry : cast) { Integer amount = jobMap.get(entry.getJobType()); if (amount == null) { episode.addCast(entry); } else if (amount > 0) { episode.addCast(entry); amount--; jobMap.put(entry.getJobType(), amount); } } } } else if (options.isAllJobTypes()) { for (ApiEpisodeDTO episode : results) { episode.setCast( getCastForId(MetaDataType.EPISODE, episode.getId(), options.splitDataItems(), null)); } } } wrapper.setResults(results); }
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
public void getSingleVideo(ApiWrapperSingle<ApiVideoDTO> wrapper) { OptionsIndexVideo options = (OptionsIndexVideo) wrapper.getOptions(); IndexParams params = new IndexParams(options); MetaDataType type = MetaDataType.fromString(options.getType()); if (CollectionUtils.isNotEmpty(params.getDataItems())) { LOG.trace("Getting additional data items: {} ", params.getDataItems()); }//from w w w.jav a 2 s.co m String sql; if (type == MetaDataType.MOVIE) { sql = generateSqlForVideo(true, params); } else if (type == MetaDataType.SERIES) { sql = generateSqlForSeries(params); } else if (type == MetaDataType.SEASON) { sql = generateSqlForSeason(params); } else { throw new UnsupportedOperationException( "Unable to process type '" + type + "' (Original: '" + options.getType() + "')"); } LOG.trace("SQL for {}-{}: {}", type, params.getId(), sql); SqlScalars sqlScalars = new SqlScalars(sql); sqlScalars.addScalar(ID, LongType.INSTANCE); sqlScalars.addScalar("videoTypeString", StringType.INSTANCE); sqlScalars.addScalar(TITLE, StringType.INSTANCE); sqlScalars.addScalar(ORIGINAL_TITLE, StringType.INSTANCE); sqlScalars.addScalar(VIDEO_YEAR, IntegerType.INSTANCE); sqlScalars.addScalar(SERIES_ID, LongType.INSTANCE); sqlScalars.addScalar(SEASON_ID, LongType.INSTANCE); sqlScalars.addScalar(SEASON, LongType.INSTANCE); sqlScalars.addScalar(WATCHED, BooleanType.INSTANCE); // add Scalars for additional data item columns DataItemTools.addDataItemScalars(sqlScalars, params.getDataItems()); // add additional parameters params.addScalarParameters(sqlScalars); List<ApiVideoDTO> queryResults = executeQueryWithTransform(ApiVideoDTO.class, sqlScalars, wrapper); LOG.trace("Found {} results for ID {}", queryResults.size(), params.getId()); if (CollectionUtils.isNotEmpty(queryResults)) { ApiVideoDTO video = queryResults.get(0); if (params.hasDataItem(DataItem.GENRE)) { LOG.trace("Adding genres for ID {}", options.getId()); video.setGenres(getGenresForId(type, options.getId())); } if (params.hasDataItem(DataItem.STUDIO)) { LOG.trace("Adding studios for ID {}", options.getId()); video.setStudios(getStudiosForId(type, options.getId())); } if (options.hasDataItem(DataItem.COUNTRY)) { LOG.trace("Adding countries for ID {}", options.getId()); video.setCountries(getCountriesForId(type, options.getId())); } if (params.hasDataItem(DataItem.CERTIFICATION)) { LOG.trace("Adding certifications for ID {}", options.getId()); video.setCertifications(getCertificationsForId(type, options.getId())); } if (params.hasDataItem(DataItem.RATING)) { LOG.trace("Adding ratings for ID {}", options.getId()); video.setRatings(getRatingsForId(type, options.getId())); } if (options.hasDataItem(DataItem.AWARD)) { LOG.trace("Adding awards for ID {}", options.getId()); video.setAwards(getAwardsForId(type, options.getId())); } if (options.hasDataItem(DataItem.EXTERNALID)) { LOG.trace("Adding external IDs for ID {}", options.getId()); video.setExternalIds(getExternalIdsForId(type, options.getId())); } if (options.hasDataItem(DataItem.BOXSET)) { LOG.trace("Adding boxed sets for ID {}", options.getId()); video.setBoxedSets(getBoxedSetsForId(type, options.getId())); } if (params.hasDataItem(DataItem.ARTWORK)) { LOG.trace("Adding artwork for ID {}", options.getId()); Map<Long, List<ApiArtworkDTO>> artworkList; if (CollectionUtils.isNotEmpty(options.getArtworkTypes())) { artworkList = getArtworkForId(type, options.getId(), options.getArtworkTypes()); } else { artworkList = getArtworkForId(type, options.getId()); } if (artworkList.containsKey(options.getId())) { video.setArtwork(artworkList.get(options.getId())); } } if (params.hasDataItem(DataItem.FILES)) { LOG.trace("Adding files for ID {}", options.getId()); video.setFiles(getFilesForId(type, options.getId())); } if (params.hasDataItem(DataItem.TRAILER)) { LOG.trace("Adding trailers for ID {}", options.getId()); video.setTrailers(getTrailersForId(type, options.getId())); } if (MapUtils.isNotEmpty(options.splitJobs())) { Set<String> jobs = options.getJobTypesAsSet(); LOG.trace("Adding jobs for ID {}: {}", options.getId(), jobs); List<ApiPersonDTO> cast = getCastForId(type, options.getId(), options.splitDataItems(), jobs); // just add given amount for jobs to cast Map<JobType, Integer> jobMap = new HashMap<>(options.splitJobs()); for (ApiPersonDTO entry : cast) { Integer amount = jobMap.get(entry.getJobType()); if (amount == null) { video.addCast(entry); } else if (amount > 0) { video.addCast(entry); amount--; jobMap.put(entry.getJobType(), amount); } } } else if (options.isAllJobTypes()) { LOG.trace("Adding all jobs for ID {}", options.getId()); video.setCast(getCastForId(type, options.getId(), params.getDataItems(), null)); } wrapper.setResult(video); } else { wrapper.setResult(null); } wrapper.setStatusCheck(); }
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
/** * Get a list of the files associated with a video ID. * * @param type/*from w w w.j a v a2s .com*/ * @param id * @return */ private List<ApiFileDTO> getFilesForId(MetaDataType type, Long id) { // Build the SQL statement StringBuilder sbSQL = new StringBuilder(); sbSQL.append( "SELECT mf.id as id, mf.extra as extra, mf.part as part, mf.part_title as partTitle, mf.movie_version as version, "); sbSQL.append( "mf.container as container, mf.codec as codec, mf.codec_format as codecFormat, mf.codec_profile as codecProfile, "); sbSQL.append("mf.bitrate as bitrate, mf.overall_bitrate as overallBitrate, mf.fps as fps, "); sbSQL.append( "mf.width as width, mf.height as height, mf.aspect_ratio as aspectRatio, mf.runtime as runtime, mf.video_source as videoSource, "); sbSQL.append( "sf.id as fileId, sf.full_path as fileName, sf.file_date as fileDate, sf.file_size as fileSize, "); if (type == MetaDataType.MOVIE) { sbSQL.append("null as season, null as episode "); sbSQL.append("FROM mediafile_videodata mv, mediafile mf, stage_file sf "); sbSQL.append("WHERE mv.videodata_id=:id "); } else if (type == MetaDataType.SERIES) { sbSQL.append("sea.season, vd.episode "); sbSQL.append("FROM mediafile_videodata mv, mediafile mf, stage_file sf, season sea, videodata vd "); sbSQL.append("WHERE sea.series_id=:id "); sbSQL.append("and vd.season_id=sea.id "); sbSQL.append("and mv.videodata_id=vd.id "); } else if (type == MetaDataType.SEASON) { sbSQL.append("sea.season, vd.episode "); sbSQL.append("FROM mediafile_videodata mv, mediafile mf, stage_file sf, season sea, videodata vd "); sbSQL.append("WHERE sea.id=:id "); sbSQL.append("and vd.season_id=sea.id "); sbSQL.append("and mv.videodata_id=vd.id "); } else if (type == MetaDataType.EPISODE) { sbSQL.append("sea.season, vd.episode "); sbSQL.append("FROM mediafile_videodata mv, mediafile mf, stage_file sf, season sea, videodata vd "); sbSQL.append("WHERE vd.id=:id "); sbSQL.append("and vd.season_id=sea.id "); sbSQL.append("and mv.videodata_id=vd.id "); } sbSQL.append("and mv.mediafile_id=mf.id "); sbSQL.append("and sf.mediafile_id=mf.id "); sbSQL.append("and sf.file_type='"); sbSQL.append(FileType.VIDEO.toString()); sbSQL.append("' and sf.status not in ('"); sbSQL.append(StatusType.DUPLICATE.toString()); sbSQL.append("','"); sbSQL.append(StatusType.DELETED.toString()); sbSQL.append("') "); if (type == MetaDataType.SERIES || type == MetaDataType.SEASON) { sbSQL.append("ORDER BY sea.season ASC, vd.episode ASC"); } SqlScalars sqlScalars = new SqlScalars(sbSQL); sqlScalars.addScalar(ID, LongType.INSTANCE); sqlScalars.addScalar("extra", BooleanType.INSTANCE); sqlScalars.addScalar("part", IntegerType.INSTANCE); sqlScalars.addScalar("partTitle", StringType.INSTANCE); sqlScalars.addScalar("version", StringType.INSTANCE); sqlScalars.addScalar("container", StringType.INSTANCE); sqlScalars.addScalar("codec", StringType.INSTANCE); sqlScalars.addScalar("codecFormat", StringType.INSTANCE); sqlScalars.addScalar("codecProfile", StringType.INSTANCE); sqlScalars.addScalar("bitrate", IntegerType.INSTANCE); sqlScalars.addScalar("overallBitrate", IntegerType.INSTANCE); sqlScalars.addScalar("fps", FloatType.INSTANCE); sqlScalars.addScalar("width", IntegerType.INSTANCE); sqlScalars.addScalar("height", IntegerType.INSTANCE); sqlScalars.addScalar("aspectRatio", StringType.INSTANCE); sqlScalars.addScalar("runtime", IntegerType.INSTANCE); sqlScalars.addScalar("videoSource", StringType.INSTANCE); sqlScalars.addScalar("fileId", LongType.INSTANCE); sqlScalars.addScalar("fileName", StringType.INSTANCE); sqlScalars.addScalar("fileDate", TimestampType.INSTANCE); sqlScalars.addScalar("fileSize", LongType.INSTANCE); sqlScalars.addScalar(SEASON, LongType.INSTANCE); sqlScalars.addScalar(EPISODE, LongType.INSTANCE); sqlScalars.addParameter(ID, id); List<ApiFileDTO> results = executeQueryWithTransform(ApiFileDTO.class, sqlScalars, null); if (CollectionUtils.isNotEmpty(results)) { for (ApiFileDTO file : results) { file.setAudioCodecs(this.getAudioCodecs(file.getId())); file.setSubtitles(this.getSubtitles(file.getId())); } } return results; }
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
/** * Get a list of the files associated with a video ID. * * @param type/*w w w . j a va 2 s . com*/ * @param id * @return */ private List<ApiTrailerDTO> getTrailersForId(MetaDataType type, Long id) { if (MetaDataType.SERIES != type && MetaDataType.MOVIE != type) { // just for movies and series return Collections.emptyList(); } // Build the SQL statement StringBuilder sbSQL = new StringBuilder(); sbSQL.append( "SELECT t.id, t.title, t.url, t.source, t.hash_code as hashCode, t.cache_dir as cacheDir, t.cache_filename as cacheFilename "); sbSQL.append("FROM trailer t "); if (type == MetaDataType.SERIES) { sbSQL.append("WHERE t.series_id=:id "); } else { sbSQL.append("WHERE t.videodata_id=:id "); } sbSQL.append("and t.status not in ('IGNORE','DELETED') "); sbSQL.append("order by t.id "); SqlScalars sqlScalars = new SqlScalars(sbSQL); sqlScalars.addScalar(ID, LongType.INSTANCE); sqlScalars.addScalar(TITLE, StringType.INSTANCE); sqlScalars.addScalar("url", StringType.INSTANCE); sqlScalars.addScalar("source", StringType.INSTANCE); sqlScalars.addScalar("hashCode", StringType.INSTANCE); sqlScalars.addScalar("cacheDir", StringType.INSTANCE); sqlScalars.addScalar("cacheFilename", StringType.INSTANCE); sqlScalars.addParameter(ID, id); return executeQueryWithTransform(ApiTrailerDTO.class, sqlScalars, null); }
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
private List<ApiAudioCodecDTO> getAudioCodecs(long mediaFileId) { StringBuilder sbSQL = new StringBuilder(); sbSQL.append(/*from w ww. j a v a2 s . co m*/ "SELECT ac.codec, ac.codec_format as codecFormat, ac.bitrate, ac.channels, ac.language_code as languageCode "); sbSQL.append("FROM audio_codec ac "); sbSQL.append("WHERE ac.mediafile_id=:id "); sbSQL.append("ORDER BY ac.counter ASC"); SqlScalars sqlScalars = new SqlScalars(sbSQL); sqlScalars.addScalar("codec", StringType.INSTANCE); sqlScalars.addScalar("codecFormat", StringType.INSTANCE); sqlScalars.addScalar("bitrate", IntegerType.INSTANCE); sqlScalars.addScalar("channels", IntegerType.INSTANCE); sqlScalars.addScalar("languageCode", StringType.INSTANCE); sqlScalars.addParameter(ID, mediaFileId); return executeQueryWithTransform(ApiAudioCodecDTO.class, sqlScalars, null); }
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
private List<ApiSubtitleDTO> getSubtitles(long mediaFileId) { StringBuilder sbSQL = new StringBuilder(); sbSQL.append(/*from w ww . java 2s . co m*/ "SELECT st.counter, st.format, st.language_code as languageCode, st.default_flag AS defaultFlag,"); sbSQL.append("st.forced_flag AS forcedFlag, sf.full_path as filePath "); sbSQL.append("FROM subtitle st "); sbSQL.append("LEFT OUTER JOIN stage_file sf ON sf.id=st.stagefile_id "); sbSQL.append("WHERE st.mediafile_id=:id "); sbSQL.append("ORDER BY sf.full_path DESC, st.counter ASC"); SqlScalars sqlScalars = new SqlScalars(sbSQL); sqlScalars.addScalar("format", StringType.INSTANCE); sqlScalars.addScalar("languageCode", StringType.INSTANCE); sqlScalars.addScalar("defaultFlag", BooleanType.INSTANCE); sqlScalars.addScalar("forcedFlag", BooleanType.INSTANCE); sqlScalars.addScalar("filePath", StringType.INSTANCE); sqlScalars.addParameter(ID, mediaFileId); return executeQueryWithTransform(ApiSubtitleDTO.class, sqlScalars, null); }
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
/** * Get a list of the genres for a given video ID * * @param type/*from w w w . j ava 2s . c om*/ * @param id * @return */ private List<ApiGenreDTO> getGenresForId(MetaDataType type, Long id) { SqlScalars sqlScalars = new SqlScalars(); sqlScalars.addToSql("SELECT DISTINCT "); sqlScalars.addToSql("CASE "); sqlScalars.addToSql(" WHEN target_api is not null THEN target_api "); sqlScalars.addToSql(" WHEN target_xml is not null THEN target_xml "); sqlScalars.addToSql(" ELSE name "); sqlScalars.addToSql("END as name "); if (type == MetaDataType.SERIES) { sqlScalars.addToSql("FROM series_genres sg, genre g "); sqlScalars.addToSql("WHERE sg.series_id=:id "); sqlScalars.addToSql("AND sg.genre_id=g.id "); } else if (type == MetaDataType.SEASON) { sqlScalars.addToSql("FROM season sea, series_genres sg, genre g "); sqlScalars.addToSql("WHERE sea.id=:id "); sqlScalars.addToSql("AND sg.series_id=sea.series_id "); sqlScalars.addToSql("AND sg.genre_id=g.id "); } else { // defaults to movie sqlScalars.addToSql("FROM videodata_genres vg, genre g "); sqlScalars.addToSql("WHERE vg.data_id=:id "); sqlScalars.addToSql("AND vg.genre_id=g.id "); } sqlScalars.addToSql("ORDER BY name"); sqlScalars.addScalar("name", StringType.INSTANCE); sqlScalars.addParameter(ID, id); return executeQueryWithTransform(ApiGenreDTO.class, sqlScalars, null); }
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
/** * Get a list of the studios for a given video ID * * @param type//from w ww . j a va 2 s.c o m * @param id * @return */ private List<Studio> getStudiosForId(MetaDataType type, Long id) { SqlScalars sqlScalars = new SqlScalars(); sqlScalars.addToSql("SELECT DISTINCT s.id, s.name "); sqlScalars.addToSql("FROM studio s "); if (type == MetaDataType.SERIES) { sqlScalars.addToSql("JOIN series_studios ss ON s.id=ss.studio_id and ss.series_id=:id "); } else if (type == MetaDataType.SEASON) { sqlScalars.addToSql("JOIN season sea ON sea.id = :id "); sqlScalars.addToSql("JOIN series_studios ss ON s.id=ss.studio_id and ss.series_id=sea.series_id "); } else { // defaults to movie sqlScalars.addToSql("JOIN videodata_studios vs ON s.id=vs.studio_id and vs.data_id=:id "); } sqlScalars.addToSql("ORDER BY name"); sqlScalars.addScalar(ID, LongType.INSTANCE); sqlScalars.addScalar("name", StringType.INSTANCE); sqlScalars.addParameter(ID, id); return executeQueryWithTransform(Studio.class, sqlScalars, null); }
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
/** * Get a list of the genres for a given video ID * * @param type// www . j a va2 s .c o m * @param id * @return */ private List<ApiCountryDTO> getCountriesForId(MetaDataType type, Long id) { SqlScalars sqlScalars = new SqlScalars(); sqlScalars.addToSql("SELECT c.id, c.country_code as countryCode "); if (type == MetaDataType.SERIES) { sqlScalars.addToSql("FROM series_countries sc, country c "); sqlScalars.addToSql("WHERE sc.series_id=:id "); sqlScalars.addToSql("AND sc.country_id=c.id "); } else if (type == MetaDataType.SEASON) { sqlScalars.addToSql("FROM season sea, series_countries sc, country c "); sqlScalars.addToSql("WHERE sea.id=:id "); sqlScalars.addToSql("AND sc.series_id=sea.series_id "); sqlScalars.addToSql("AND sc.country_id=c.id "); } else { // defaults to movie sqlScalars.addToSql("FROM videodata_countries vc, country c "); sqlScalars.addToSql("WHERE vc.data_id=:id "); sqlScalars.addToSql("AND vc.country_id=c.id "); } sqlScalars.addScalar(ID, LongType.INSTANCE); sqlScalars.addScalar("countryCode", StringType.INSTANCE); sqlScalars.addParameter(ID, id); return executeQueryWithTransform(ApiCountryDTO.class, sqlScalars, null); }
From source file:org.yamj.core.database.dao.ApiDao.java
License:Open Source License
/** * Get a list of the certifications for a given video ID * * @param type// w ww .j a va2 s .com * @param id * @return */ private List<ApiCertificationDTO> getCertificationsForId(MetaDataType type, Long id) { SqlScalars sqlScalars = new SqlScalars(); sqlScalars.addToSql("SELECT DISTINCT c.id, c.country_code as countryCode, c.certificate "); sqlScalars.addToSql("FROM certification c "); if (type == MetaDataType.SERIES) { sqlScalars.addToSql("JOIN series_certifications sc ON c.id=sc.cert_id and sc.series_id=:id "); } else if (type == MetaDataType.SEASON) { sqlScalars.addToSql("JOIN season sea ON sea.id = :id "); sqlScalars.addToSql("JOIN series_certifications sc ON c.id=sc.cert_id and sc.series_id=sea.series_id "); } else { // defaults to movie sqlScalars.addToSql("JOIN videodata_certifications vc ON c.id=vc.cert_id and vc.data_id=:id "); } sqlScalars.addToSql("ORDER BY country_code, certificate"); sqlScalars.addScalar(ID, LongType.INSTANCE); sqlScalars.addScalar("countryCode", StringType.INSTANCE); sqlScalars.addScalar("certificate", StringType.INSTANCE); sqlScalars.addParameter(ID, id); return executeQueryWithTransform(ApiCertificationDTO.class, sqlScalars, null); }