public void addMovieTx(Integer id, String director, String title, String synopsis) { Movie movie = new Movie(); movie.setId(id); movie.setDirector(director); movie.setTitle(title); movie.setSynopsis(synopsis); Movie movie0 = new Movie(); movie0.setId(101); movie0.setDirector("d"); movie0.setTitle("t"); movie0.setSynopsis("s"); Session session = sf.getCurrentSession(); org.hibernate.Transaction tx = session.beginTransaction(); try { session.save(movie0); session.save(movie); tx.commit(); } catch (HibernateException e) { System.out.println("Caught an hibernate exception."); if (tx != null) { System.out.println("Rolling back the transaction."); tx.rollback(); } } }
private void extractListFromJSON(String jsonStr) { try { moviesList.clear(); JSONObject moviesJson = new JSONObject(jsonStr); JSONArray moviesArray = moviesJson.getJSONArray("results"); for (int i = 0; i < moviesArray.length(); i++) { Movie tempMovie = new Movie(); JSONObject jo = moviesArray.getJSONObject(i); tempMovie.setTitle(jo.getString(getString(R.string.ORIGIONAL_TITLE_PARAM))); tempMovie.setId(jo.getString(getString(R.string.ID))); tempMovie.setPoster_Location(jo.getString(getString(R.string.POSTER_PATH_PARAM))); tempMovie.setBackdrop_path(jo.getString(getString(R.string.BACKDROP_PATH_PARAM))); tempMovie.setOverview(jo.getString(getString(R.string.OVERVIEW_PARAM))); tempMovie.setRelease_Date(jo.getString(getString(R.string.RELEASE_DATE_PARAM))); tempMovie.setRating(jo.getString(getString(R.string.RATING_PARAM))); tempMovie.setPopularity(jo.getString(getString(R.string.POPULARITY_PARAM))); moviesList.add(tempMovie); } } catch (JSONException e) { e.printStackTrace(); } }
public void addMovie(Integer id, String director, String title, String synopsis) { Movie movie = new Movie(); movie.setId(id); movie.setDirector(director); movie.setTitle(title); movie.setSynopsis(synopsis); Session session = sf.getCurrentSession(); session.beginTransaction(); session.save(movie); session.getTransaction().commit(); }
private static Movie buildMovieInfo( String category, String title, String description, String studio, String videoUrl, String cardImageUrl, String bgImageUrl) { Movie movie = new Movie(); movie.setId(Movie.getCount()); Movie.incCount(); movie.setTitle(title); movie.setDescription(description); movie.setStudio(studio); movie.setCategory(category); movie.setCardImageUrl(cardImageUrl); movie.setBackgroundImageUrl(bgImageUrl); movie.setVideoUrl(videoUrl); return movie; }
private void extractMovieFromJSON(String jsonStr) { try { JSONObject jo = new JSONObject(jsonStr); Movie tempMovie = new Movie(); tempMovie.setTitle(jo.getString(getString(R.string.ORIGIONAL_TITLE_PARAM))); tempMovie.setId(jo.getString(getString(R.string.ID))); tempMovie.setPoster_Location(jo.getString(getString(R.string.POSTER_PATH_PARAM))); tempMovie.setBackdrop_path(jo.getString(getString(R.string.BACKDROP_PATH_PARAM))); tempMovie.setOverview(jo.getString(getString(R.string.OVERVIEW_PARAM))); tempMovie.setRelease_Date(jo.getString(getString(R.string.RELEASE_DATE_PARAM))); tempMovie.setRating(jo.getString(getString(R.string.RATING_PARAM))); tempMovie.setPopularity(jo.getString(getString(R.string.POPULARITY_PARAM))); moviesList.add(tempMovie); } catch (JSONException e) { e.printStackTrace(); } }
public ArrayList<Movie> loadMovies() { ArrayList<Movie> movies = new ArrayList<Movie>(); Cursor movieCursor = mContext .getContentResolver() .query(MovieContract.MovieEntry.CONTENT_URI, null, null, null, null); movieCursor.moveToFirst(); do { Integer movieId = movieCursor.getInt(movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_MOVIE_ID)); String title = movieCursor.getString(movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_TITLE)); boolean adult = movieCursor.getInt(movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_ADULT)) != 0 ? true : false; String backDropPath = movieCursor.getString( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_BACKDROP_PATH)); String genreIdsString = movieCursor.getString( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_GENRE_IDS)); String[] genreStrings = genreIdsString.split(","); ArrayList<Integer> genreIds = new ArrayList<Integer>(); for (String s : genreStrings) { genreIds.add(Integer.parseInt(s)); } String orgLanguage = movieCursor.getString( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_ORIGINAL_LANGUAGE)); String orgTitle = movieCursor.getString( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_ORIGINAL_TITLE)); String overview = movieCursor.getString( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_OVERVIEW)); String releasString = movieCursor.getString( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_RELEASE_DATE)); SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us")); Date releaseDate = new Date(); try { releaseDate = sdf.parse(releasString); } catch (ParseException e) { e.printStackTrace(); } String posterPath = movieCursor.getString( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_POSTER_PATH)); Double popularity = movieCursor.getDouble( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_POPULARITY)); boolean isVideo = movieCursor.getInt(movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_VIDEO)) != 0 ? true : false; Double voteAverage = movieCursor.getDouble( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_VOTE_AVERAGE)); Integer voteCount = movieCursor.getInt( movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_VOTE_COUNT)); Movie movie = new Movie(); movie.setId(movieId); movie.setTitle(title); movie.setAdult(adult); movie.setBackdrop_path(backDropPath); movie.setOriginal_language(orgLanguage); movie.setOriginal_title(orgTitle); movie.setOverview(overview); movie.setRelease_date(releaseDate); movie.setPoster_path(posterPath); movie.setPopularity(popularity); movie.setVideo(isVideo); movie.setVote_average(voteAverage); movie.setVote_count(voteCount); movies.add(movie); } while (movieCursor.moveToNext()); return movies; }
/** Add a new {@link Movie}. */ void add(Movie aMovie) { String id = nextId(); aMovie.setId(id.toString()); fTable.put(id, aMovie); }