Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. package com.javaoo.store.drivers;
  2.  
  3. import static com.javaoo.store.JPAUtility.*;
  4. import static java.lang.System.*;
  5. import com.javaoo.store.*;
  6. import java.util.*;
  7. import javax.persistence.*;
  8.  
  9. public class PopulateDatabase {
  10.  
  11. public static void main(String[] args) {
  12. EntityManager em = getEntityManager();
  13.  
  14. List<Book> books = new ArrayList<>();
  15. books.add( new Book( null, "Godzilla on Holiday", 24.95, 5, "Wesley Wyham-Price", "Ransom House", "FICTION" ) );
  16. books.add( new Book( null, "Loch Ness Memories", 49.95, 1, "Freddy McMurrey", "Penguin Press", "FICTION" ) );
  17. books.add( new Book( null, "MVS JCL", 89.95, 3, "Steve Balmer", "Microsoft Press", "NON-FICTION" ) );
  18. books.add( new Book( null, "Lingo in a Nutshell", 19.95, 8, "Bill Bates", "O'Reilly", "NON-FICTION" ) );
  19.  
  20. int i = 1;
  21. for( Book b : books ) {
  22. EntityTransaction trans = em.getTransaction();
  23. trans.begin();
  24. em.persist( b );
  25. trans.commit();
  26. out.printf( "Book: %s%n", i++ );
  27. }
  28.  
  29. List<CD> cds = new ArrayList<>();
  30. cds.add( new CD( null, "Going For The One", 12.95, 4, new Artist( null, "YES" ), new Date( "07/07/1977" ) ) );
  31. cds.add( new CD( null, "Blowing In The Wind", 15.95, 6, new Artist( null, "YES" ), new Date( "09/07/1968" ) ) );
  32. cds.add( new CD( null, "What Could Go Wrong", 11.87, 2, new Artist( null, "NO" ), new Date( "09/09/2018" ) ) );
  33.  
  34. int j = 1;
  35. for( Book b : books ) {
  36. EntityTransaction trans = em.getTransaction();
  37. trans.begin();
  38. em.persist( b );
  39. trans.commit();
  40. out.printf( "CD: %s%n", j++ );
  41. }
  42. /*
  43. String queryName = "BookfindAll";
  44. Query query = em.createNamedQuery( queryName );
  45. */
  46. closeEntityManagerFactory();
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement