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();
      }
    }
  }
  public List<Movie> findAllMovies() {
    ArrayList list = new ArrayList<Movie>();

    Movie movie = new Movie();
    movie.setName("Avatar");
    movie.setDirector("J.Cameron");

    list.add(movie);

    Movie movie1 = new Movie();
    movie1.setName("Titanic");
    movie1.setDirector("J.Cameron");

    list.add(movie1);

    Movie movie2 = new Movie();
    movie2.setName("The Terminator");
    movie2.setDirector("J.Cameron");

    list.add(movie2);

    Movie movie3 = new Movie();
    movie3.setName("Jurassic Park");
    movie3.setDirector("S.Spielberg");

    list.add(movie3);

    return list;
  }
  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();
  }
Пример #4
0
  public static Movie parseMovie(Document doc) {
    LOGGER.info("Parsing movie");
    Movie movie = new Movie();

    Element root = doc.getDocumentElement();
    movie.setTitle(getTagValue("title", root));
    movie.setCountry(getTagValue("country", root));
    movie.setGenre(getTagValue("genre", root));
    movie.setSummary(getTagValue("summary", root));
    movie.setYear(getTagValue("year", root));

    NodeList nList = doc.getElementsByTagName("director");

    for (int i = 0; i < nList.getLength(); i++) {
      Node node = nList.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element directorElement = (Element) node;
        Person director = parsePerson(directorElement);
        movie.setDirector(director);
      }
    }

    nList = doc.getElementsByTagName("actor");

    for (int i = 0; i < nList.getLength(); i++) {
      Node node = nList.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element actorElement = (Element) node;
        Person actor = parsePerson(actorElement);
        String role = getTagValue("role", actorElement);
        movie.addActor(actor, role);
      }
    }

    return movie;
  }