diff --git a/.project b/.project
new file mode 100644
index 0000000..631bea5
--- /dev/null
+++ b/.project
@@ -0,0 +1,11 @@
+
+
+ Bookstore.git
+
+
+
+
+
+
+
+
diff --git a/assembly.xml b/assembly.xml
new file mode 100644
index 0000000..4dd0ed6
--- /dev/null
+++ b/assembly.xml
@@ -0,0 +1,18 @@
+
+ source
+ /
+
+ zip
+
+
+
+
+ readme.md
+ assembly.xml
+ pom.xml
+ src/
+
+
+
+
\ No newline at end of file
diff --git a/java/bookstore/Author.java b/java/bookstore/Author.java
new file mode 100644
index 0000000..268d64f
--- /dev/null
+++ b/java/bookstore/Author.java
@@ -0,0 +1,53 @@
+package bookstore;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Author {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name="first_name", length=50)
+ protected String firstName;
+
+ @Column(name="surname", length=50)
+ protected String surname;
+
+ public Author(String firstName, String surname) {
+ this.firstName = firstName;
+ this.surname = surname;
+ }
+
+ public Author(){
+
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getSurname() {
+ return surname;
+ }
+
+ public void setSurname(String surname) {
+ this.surname = surname;
+ }
+
+}
diff --git a/java/bookstore/Book.java b/java/bookstore/Book.java
new file mode 100644
index 0000000..9ef5dec
--- /dev/null
+++ b/java/bookstore/Book.java
@@ -0,0 +1,83 @@
+package bookstore;
+
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Book {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name = "title", length = 50)
+ protected String title;
+
+ @Column(name = "genre", length = 50)
+ protected String genre;
+
+ @Column(name = "author", length = 50)
+ protected Author author;
+
+ @Column(name = "format", length = 50)
+ protected String format;
+
+ public Book(String title, String genre, Author author, String format) {
+ this.title = title;
+ this.genre = genre;
+ this.author = author;
+ this.format = format;
+ }
+
+ public Book(){
+
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getGenre() {
+ return genre;
+ }
+
+ public void setGenre(String genre) {
+ this.genre = genre;
+ }
+
+ public Author getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(Author author) {
+ this.author = author;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+
+
+
+
+
+}
diff --git a/java/bookstore/Customers.java b/java/bookstore/Customers.java
new file mode 100644
index 0000000..0e5460b
--- /dev/null
+++ b/java/bookstore/Customers.java
@@ -0,0 +1,89 @@
+package bookstore;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Customers {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name="first_name",length=50)
+ protected String firstName;
+
+ @Column(name="surname", length=50)
+ protected String surname;
+
+ @Column(name="member", length=10)
+ protected Boolean member;
+
+ @Column(name="email", length=50)
+ protected String email;
+
+ @Column(name="password", length = 50)
+ protected String password;
+
+ public Customers() {
+
+ }
+
+ public Customers(String firstName, String surname, Boolean member, String email, String password) {
+ this.firstName = firstName;
+ this.surname = surname;
+ this.member = member;
+ this.email = email;
+ this.password = password;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getSurame() {
+ return surname;
+ }
+
+ public void setSurame(String surname) {
+ this.surname = surname;
+ }
+
+ public boolean getMember() {
+ return member;
+ }
+
+ public void setMember(Boolean member) {
+ this.member = member;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+
+}
diff --git a/java/bookstore/OrderLines.java b/java/bookstore/OrderLines.java
new file mode 100644
index 0000000..034c704
--- /dev/null
+++ b/java/bookstore/OrderLines.java
@@ -0,0 +1,52 @@
+package bookstore;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class OrderLines {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name = "book_id", length = 50)
+ protected Long bookId;
+
+ @Column(name = "quantity", length =50)
+ protected int quantity;
+
+ public OrderLines(){
+
+ }
+
+ public OrderLines(Long bookId, int quantity){
+ this.bookId = bookId;
+ this.quantity = quantity;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getBookId() {
+ return bookId;
+ }
+
+ public void setBookId(Long bookId) {
+ this.bookId = bookId;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+}
diff --git a/java/bookstore/Orders.java b/java/bookstore/Orders.java
new file mode 100644
index 0000000..430e1ca
--- /dev/null
+++ b/java/bookstore/Orders.java
@@ -0,0 +1,78 @@
+package bookstore;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.OneToMany;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+@Entity
+public class Orders {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @OneToMany(cascade = CascadeType.ALL)
+ private Set orderLines = new HashSet<>();
+
+ @Column(name = "address", length = 50)
+ private String address;
+
+ @Column(name = "customer_id", length = 50)
+ private Long customerId;
+
+ @Column(name = "store_id", length=50)
+ private Long storeId;
+
+ public Orders(){
+
+ }
+
+ public Orders(String address, Long customerId){
+ this.address = address;
+ this.customerId = customerId;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public Long getCustomerId() {
+ return customerId;
+ }
+
+ public void setCustomerId(Long customerId) {
+ this.customerId = customerId;
+ }
+
+ public Set getOrderLines() {
+ return orderLines;
+ }
+
+ public void setOrderLines(Set orderLines) {
+ this.orderLines = orderLines;
+ }
+
+ public Long getStoreId() {
+ return storeId;
+ }
+
+ public void setStoreId(Long storeId) {
+ this.storeId = storeId;
+ }
+
+}
diff --git a/java/bookstore/Store.java b/java/bookstore/Store.java
new file mode 100644
index 0000000..dd0146d
--- /dev/null
+++ b/java/bookstore/Store.java
@@ -0,0 +1,40 @@
+package bookstore;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Store {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name="location", length=50)
+ protected String location;
+
+ public Store() {
+
+ }
+
+ public Store(String location) {
+ this.location = location;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLcoation(String location) {
+ this.location = location;
+ }
+
+}
diff --git a/java/bookstore/other/Main.java b/java/bookstore/other/Main.java
new file mode 100644
index 0000000..f5c9265
--- /dev/null
+++ b/java/bookstore/other/Main.java
@@ -0,0 +1,78 @@
+package bookstore.other;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+
+import bookstore.Author;
+import bookstore.Book;
+import bookstore.Customers;
+import bookstore.OrderLines;
+import bookstore.Orders;
+import bookstore.Store;
+
+
+/*import com.qa.persistence.CD;
+import com.qa.persistence.Musician;
+import com.qa.persistence.demo01.CDService;
+import com.qa.persistence.demo01.Main;*/
+
+
+public class Main {
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ System.out.println("\n\n>>> Executing : " + Main.class.toString() + " <<<\n");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("module04-persistence-unit");
+ EntityManager em = emf.createEntityManager();
+ EntityTransaction tx = em.getTransaction();
+
+ StoreService service = new StoreService(em);
+
+ // Creates and persists a CD
+ tx.begin();
+ Set orderLines = new HashSet<>();
+ Author author1 = new Author("JK", "Rowling");
+ Author author2 = new Author("Anthony", "Burgess");
+ Book book1 = new Book("Harry Potter","fantasy",author1,"paperback");
+ Book book2 = new Book("A Clockwork Orange","science fiction",author2,"paperback");
+ orderLines.add(new OrderLines(book1.getId(),1));
+ orderLines.add(new OrderLines(book2.getId(),1));
+ Orders order1 = new Orders();
+ order1.setOrderLines(orderLines);
+ Customers customer1 = new Customers("John","Smith",true, "jsmith@gmail.com","password");
+ order1.setAddress("test address");
+ order1.setCustomerId(customer1.getId());
+ order1 = service.createOrder(order1);
+ tx.commit();
+
+ System.out.println("Order Persisted : " + order1);
+ //
+ tx.commit();
+
+ // Finds the order
+ order1 = service.findOrder(order1.getId());
+
+ System.out.println("Order Found : " + order1);
+ System.out.println(" Books : " + order1.getOrderLines());
+
+ // Removes the order
+ tx.begin();
+ service.removeOrder(order1.getId());
+ tx.commit();
+
+ System.out.println("Order Removed");
+
+ // Finds the order
+ order1 = service.findOrder(order1.getId());
+
+ System.out.println("Order Not Found : " + order1);
+
+ em.close();
+ emf.close();
+
+ }
+}
diff --git a/java/bookstore/other/StoreService.java b/java/bookstore/other/StoreService.java
new file mode 100644
index 0000000..baa9dda
--- /dev/null
+++ b/java/bookstore/other/StoreService.java
@@ -0,0 +1,42 @@
+package bookstore.other;
+
+import javax.persistence.EntityManager;
+
+import bookstore.Orders;
+
+public class StoreService {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ private EntityManager em;
+
+ // ======================================
+ // = Constructors =
+ // ======================================
+
+ public StoreService(EntityManager em) {
+ this.em = em;
+ }
+
+ // ======================================
+ // = Public Methods =
+ // ======================================
+
+ public Orders createOrder(Orders order) {
+ em.persist(order);
+ return order;
+ }
+
+ public void removeOrder(Long id) {
+ Orders order = em.find(Orders.class, id);
+ if (order != null)
+ em.remove(order);
+ }
+
+ public Orders findOrder(Long id) {
+ return em.find(Orders.class, id);
+ }
+
+}
diff --git a/java/com/qa/persistence/CD.java b/java/com/qa/persistence/CD.java
new file mode 100644
index 0000000..bbb6a36
--- /dev/null
+++ b/java/com/qa/persistence/CD.java
@@ -0,0 +1,123 @@
+package com.qa.persistence;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+
+@Entity
+public class CD extends Item {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ @Column(name = "total_duration")
+ private Float totalDuration;
+
+ private String genre;
+
+ @OneToMany(cascade = CascadeType.ALL)
+ private Set musicians = new HashSet<>();
+
+ // ======================================
+ // = Constructors =
+ // ======================================
+
+ public CD() {
+ }
+
+ public CD(String title) {
+ this.title = title;
+ }
+
+ public CD(String title, String genre) {
+ this.title = title;
+ this.genre = genre;
+ }
+
+ public CD(String title, String description, Float unitCost, Float totalDuration, String genre) {
+ this.title = title;
+ this.description = description;
+ this.unitCost = unitCost;
+ this.totalDuration = totalDuration;
+ this.genre = genre;
+ }
+
+ // ======================================
+ // = Getters & Setters =
+ // ======================================
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Float getUnitCost() {
+ return unitCost;
+ }
+
+ public void setUnitCost(Float unitCost) {
+ this.unitCost = unitCost;
+ }
+
+ public Float getTotalDuration() {
+ return totalDuration;
+ }
+
+ public void setTotalDuration(Float totalDuration) {
+ this.totalDuration = totalDuration;
+ }
+
+ public String getGenre() {
+ return genre;
+ }
+
+ public void setGenre(String genre) {
+ this.genre = genre;
+ }
+
+ public Set getMusicians() {
+ return musicians;
+ }
+
+ public void setMusicians(Set musicians) {
+ this.musicians = musicians;
+ }
+
+ // ======================================
+ // = hashcode, equals & toString =
+ // ======================================
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("CD{");
+ sb.append("id=").append(id);
+ sb.append(", title='").append(title).append('\'');
+ sb.append(", genre='").append(genre).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/java/com/qa/persistence/Item.java b/java/com/qa/persistence/Item.java
new file mode 100644
index 0000000..fd3e3ba
--- /dev/null
+++ b/java/com/qa/persistence/Item.java
@@ -0,0 +1,111 @@
+package com.qa.persistence;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+@Entity
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+public class Item {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ @Id
+ @GeneratedValue
+ protected Long id;
+
+ @Column(length = 100)
+ protected String title;
+
+ @Column(length = 3000)
+ protected String description;
+
+ @Column(name = "unit_cost")
+ protected Float unitCost;
+
+ // ======================================
+ // = Getters & Setters =
+ // ======================================
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Float getUnitCost() {
+ return unitCost;
+ }
+
+ public void setUnitCost(Float unitCost) {
+ this.unitCost = unitCost;
+ }
+
+ // ======================================
+ // = hashcode, equals & toString =
+ // ======================================
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Item item = (Item) o;
+
+ if (description != null ? !description.equals(item.description) : item.description != null)
+ return false;
+ if (id != null ? !id.equals(item.id) : item.id != null)
+ return false;
+ if (!title.equals(item.title))
+ return false;
+ if (unitCost != null ? !unitCost.equals(item.unitCost) : item.unitCost != null)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id != null ? id.hashCode() : 0;
+ result = 31 * result + title.hashCode();
+ result = 31 * result + (description != null ? description.hashCode() : 0);
+ result = 31 * result + (unitCost != null ? unitCost.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("Item{");
+ sb.append("id=").append(id);
+ sb.append(", title='").append(title).append('\'');
+ sb.append(", description='").append(description).append('\'');
+ sb.append(", unitCost=").append(unitCost);
+ sb.append('}');
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/java/com/qa/persistence/Musician.java b/java/com/qa/persistence/Musician.java
new file mode 100644
index 0000000..f8bd9b5
--- /dev/null
+++ b/java/com/qa/persistence/Musician.java
@@ -0,0 +1,150 @@
+package com.qa.persistence;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Musician {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name = "first_name", length = 50)
+ protected String firstName;
+
+ @Column(name = "last_name", length = 50)
+ protected String lastName;
+
+ @Column(length = 5000)
+ protected String bio;
+
+ @Column(name = "date_of_birth")
+ @Temporal(TemporalType.DATE)
+ protected Date dateOfBirth;
+
+ @Column(name = "Dead_or_Alive", length = 50)
+ protected String deadOrAlive;
+
+ @Transient
+ protected Integer age;
+
+ @Column(name = "preferred_instrument")
+ private String preferredInstrument;
+
+ // ======================================
+ // = Constructors =
+ // ======================================
+
+ public Musician() {
+ }
+
+ public Musician(String firstName, String lastName, String bio, Date dateOfBirth, String deadOrAlive, Integer age,
+ String preferredInstrument) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.bio = bio;
+ this.dateOfBirth = dateOfBirth;
+ this.deadOrAlive = deadOrAlive;
+ this.age = age;
+ this.preferredInstrument = preferredInstrument;
+ }
+
+ public Musician(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ // ======================================
+ // = Getters & Setters =
+ // ======================================
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getBio() {
+ return bio;
+ }
+
+ public void setBio(String bio) {
+ this.bio = bio;
+ }
+
+ public Date getDateOfBirth() {
+ return dateOfBirth;
+ }
+
+ public void setDateOfBirth(Date dateOfBirth) {
+ this.dateOfBirth = dateOfBirth;
+ }
+
+ public String getDeadOrAlive() {
+ return deadOrAlive;
+ }
+
+ public void setDeadOrAlive(String deadOrAlive) {
+ this.deadOrAlive = deadOrAlive;
+ }
+
+ public Integer getAge() {
+ return age;
+ }
+
+ public void setAge(Integer age) {
+ this.age = age;
+ }
+
+ public String getPreferredInstrument() {
+ return preferredInstrument;
+ }
+
+ public void setPreferredInstrument(String preferredInstrument) {
+ this.preferredInstrument = preferredInstrument;
+ }
+
+ // ======================================
+ // = hashcode, equals & toString =
+ // ======================================
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("Musician{");
+ sb.append("id=").append(id);
+ sb.append(", firstName='").append(firstName).append('\'');
+ sb.append(", lastName='").append(lastName).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/java/com/qa/persistence/demo01/CDService.java b/java/com/qa/persistence/demo01/CDService.java
new file mode 100644
index 0000000..ee9efa3
--- /dev/null
+++ b/java/com/qa/persistence/demo01/CDService.java
@@ -0,0 +1,41 @@
+package com.qa.persistence.demo01;
+
+import javax.persistence.EntityManager;
+
+import com.qa.persistence.CD;
+
+public class CDService {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ private EntityManager em;
+
+ // ======================================
+ // = Constructors =
+ // ======================================
+
+ public CDService(EntityManager em) {
+ this.em = em;
+ }
+
+ // ======================================
+ // = Public Methods =
+ // ======================================
+
+ public CD createCD(CD cd) {
+ em.persist(cd);
+ return cd;
+ }
+
+ public void removeCD(Long id) {
+ CD cd = em.find(CD.class, id);
+ if (cd != null)
+ em.remove(cd);
+ }
+
+ public CD findCD(Long id) {
+ return em.find(CD.class, id);
+ }
+}
\ No newline at end of file
diff --git a/java/com/qa/persistence/demo01/Main.java b/java/com/qa/persistence/demo01/Main.java
new file mode 100644
index 0000000..afa496e
--- /dev/null
+++ b/java/com/qa/persistence/demo01/Main.java
@@ -0,0 +1,61 @@
+package com.qa.persistence.demo01;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+
+import com.qa.persistence.CD;
+import com.qa.persistence.Musician;
+
+public class Main {
+
+ public static void main(String[] args) {
+
+ System.out.println("\n\n>>> Executing : " + Main.class.toString() + " <<<\n");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("module04-persistence-unit");
+ EntityManager em = emf.createEntityManager();
+ EntityTransaction tx = em.getTransaction();
+
+ CDService service = new CDService(em);
+
+ // Creates and persists a CD
+ tx.begin();
+ Set beatles = new HashSet<>();
+ beatles.add(new Musician("John", "Lennon")); //Dead - Assassinated!
+ beatles.add(new Musician("Paul", "McCartney")); //Alive
+ beatles.add(new Musician("Ringo", "Starr")); //Alive
+ beatles.add(new Musician("Georges", "Harrison")); //Dead
+ CD sergentPepper = new CD("Sergent Pepper");
+ sergentPepper.setMusicians(beatles);
+ sergentPepper = service.createCD(sergentPepper);
+ tx.commit();
+
+ System.out.println("CD Persisted : " + sergentPepper);
+
+ // Finds the cd
+ sergentPepper = service.findCD(sergentPepper.getId());
+
+ System.out.println("CD Found : " + sergentPepper);
+ System.out.println(" Musicians : " + sergentPepper.getMusicians());
+
+ // Removes the cd
+ tx.begin();
+ service.removeCD(sergentPepper.getId());
+ tx.commit();
+
+ System.out.println("CD Removed");
+
+ // Finds the cd
+ sergentPepper = service.findCD(sergentPepper.getId());
+
+ System.out.println("CD Not Found : " + sergentPepper);
+
+ em.close();
+ emf.close();
+ }
+}
diff --git a/module04-create.ddl b/module04-create.ddl
new file mode 100644
index 0000000..db2c6c1
--- /dev/null
+++ b/module04-create.ddl
@@ -0,0 +1,8 @@
+CREATE TABLE CD (ID BIGINT NOT NULL, DESCRIPTION VARCHAR(3000), GENRE VARCHAR(255), TITLE VARCHAR(100), total_duration FLOAT, unit_cost FLOAT, PRIMARY KEY (ID))
+CREATE TABLE MUSICIAN (ID BIGINT NOT NULL, BIO VARCHAR(5000), date_of_birth DATE, first_name VARCHAR(50), last_name VARCHAR(50), preferred_instrument VARCHAR(255), PRIMARY KEY (ID))
+CREATE TABLE ITEM (ID BIGINT NOT NULL, DESCRIPTION VARCHAR(3000), TITLE VARCHAR(100), unit_cost FLOAT, PRIMARY KEY (ID))
+CREATE TABLE CD_MUSICIAN (CD_ID BIGINT NOT NULL, musicians_ID BIGINT NOT NULL, PRIMARY KEY (CD_ID, musicians_ID))
+ALTER TABLE CD_MUSICIAN ADD CONSTRAINT CD_MUSICIAN_CD_ID FOREIGN KEY (CD_ID) REFERENCES CD (ID)
+ALTER TABLE CD_MUSICIAN ADD CONSTRAINT CDMSICIANmsciansID FOREIGN KEY (musicians_ID) REFERENCES MUSICIAN (ID)
+CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))
+INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0)
diff --git a/module04-drop.ddl b/module04-drop.ddl
new file mode 100644
index 0000000..6499f06
--- /dev/null
+++ b/module04-drop.ddl
@@ -0,0 +1,7 @@
+ALTER TABLE CD_MUSICIAN DROP CONSTRAINT CD_MUSICIAN_CD_ID
+ALTER TABLE CD_MUSICIAN DROP CONSTRAINT CDMSICIANmsciansID
+DROP TABLE CD
+DROP TABLE MUSICIAN
+DROP TABLE ITEM
+DROP TABLE CD_MUSICIAN
+DELETE FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN'
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..eff57a2
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,155 @@
+
+
+
+ 4.0.0
+ com.qa.persistence
+ module04
+ jar
+ 1.0
+ This is an example project
+
+
+ 1.7
+
+ 1.1.0.Final
+ 2.5.1
+ 4.3.1.Final
+ 10.10.1.1
+
+ 4.11
+
+ 2.4
+ 2.4
+ 3.1
+ 2.8
+ 2.2
+ 2.16
+ 2.9.1
+ 1.2.1
+ 2.4
+
+ UTF-8
+ UTF-8
+
+
+
+
+
+ org.apache.derby
+ derbyclient
+ ${version.derby}
+
+
+
+ junit
+ junit
+ ${version.junit}
+ test
+
+
+
+
+
+
+ eclipselink
+
+ true
+
+
+
+ org.eclipse.persistence
+ org.eclipse.persistence.jpa
+ ${version.eclipselink}
+
+
+
+
+
+ hibernate
+
+
+ org.hibernate
+ hibernate-entitymanager
+ ${version.hibernate}
+
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${version.maven.surefire.plugin}
+
+ -Duser.language=en -Duser.country=EN
+
+
+
+ org.apache.maven.plugins
+ maven-help-plugin
+ ${version.maven.help.plugin}
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${version.maven.compiler.plugin}
+ true
+
+ ${version.java}
+ ${version.java}
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ ${version.maven.jar.plugin}
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ ${version.maven.javadoc.plugin}
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ ${version.maven.dependency.plugin}
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ ${version.maven.exec.plugin}
+
+
+
+ java
+
+
+
+
+ -Duser.language=en -Duser.country=EN
+
+
+
+ com.pluralsight.persistence.module04.demo04.Main
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ ${version.maven.assembly.plugin}
+
+ demos
+ false
+
+ assembly.xml
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/resources/META-INF/persistence.xml b/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..474ce35
--- /dev/null
+++ b/resources/META-INF/persistence.xml
@@ -0,0 +1,25 @@
+
+
+
+
+ org.eclipse.persistence.jpa.PersistenceProvider
+
+ com.qa.persistence.CD
+ com.qa.persistence.Musician
+ com.qa.persistence.Item
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/bookstore/Author.java b/src/main/java/bookstore/Author.java
new file mode 100644
index 0000000..268d64f
--- /dev/null
+++ b/src/main/java/bookstore/Author.java
@@ -0,0 +1,53 @@
+package bookstore;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Author {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name="first_name", length=50)
+ protected String firstName;
+
+ @Column(name="surname", length=50)
+ protected String surname;
+
+ public Author(String firstName, String surname) {
+ this.firstName = firstName;
+ this.surname = surname;
+ }
+
+ public Author(){
+
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getSurname() {
+ return surname;
+ }
+
+ public void setSurname(String surname) {
+ this.surname = surname;
+ }
+
+}
diff --git a/src/main/java/bookstore/Book.java b/src/main/java/bookstore/Book.java
new file mode 100644
index 0000000..9ef5dec
--- /dev/null
+++ b/src/main/java/bookstore/Book.java
@@ -0,0 +1,83 @@
+package bookstore;
+
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Book {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name = "title", length = 50)
+ protected String title;
+
+ @Column(name = "genre", length = 50)
+ protected String genre;
+
+ @Column(name = "author", length = 50)
+ protected Author author;
+
+ @Column(name = "format", length = 50)
+ protected String format;
+
+ public Book(String title, String genre, Author author, String format) {
+ this.title = title;
+ this.genre = genre;
+ this.author = author;
+ this.format = format;
+ }
+
+ public Book(){
+
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getGenre() {
+ return genre;
+ }
+
+ public void setGenre(String genre) {
+ this.genre = genre;
+ }
+
+ public Author getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(Author author) {
+ this.author = author;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+
+
+
+
+
+}
diff --git a/src/main/java/bookstore/Customers.java b/src/main/java/bookstore/Customers.java
new file mode 100644
index 0000000..0e5460b
--- /dev/null
+++ b/src/main/java/bookstore/Customers.java
@@ -0,0 +1,89 @@
+package bookstore;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Customers {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name="first_name",length=50)
+ protected String firstName;
+
+ @Column(name="surname", length=50)
+ protected String surname;
+
+ @Column(name="member", length=10)
+ protected Boolean member;
+
+ @Column(name="email", length=50)
+ protected String email;
+
+ @Column(name="password", length = 50)
+ protected String password;
+
+ public Customers() {
+
+ }
+
+ public Customers(String firstName, String surname, Boolean member, String email, String password) {
+ this.firstName = firstName;
+ this.surname = surname;
+ this.member = member;
+ this.email = email;
+ this.password = password;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getSurame() {
+ return surname;
+ }
+
+ public void setSurame(String surname) {
+ this.surname = surname;
+ }
+
+ public boolean getMember() {
+ return member;
+ }
+
+ public void setMember(Boolean member) {
+ this.member = member;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+
+}
diff --git a/src/main/java/bookstore/OrderLines.java b/src/main/java/bookstore/OrderLines.java
new file mode 100644
index 0000000..034c704
--- /dev/null
+++ b/src/main/java/bookstore/OrderLines.java
@@ -0,0 +1,52 @@
+package bookstore;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class OrderLines {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name = "book_id", length = 50)
+ protected Long bookId;
+
+ @Column(name = "quantity", length =50)
+ protected int quantity;
+
+ public OrderLines(){
+
+ }
+
+ public OrderLines(Long bookId, int quantity){
+ this.bookId = bookId;
+ this.quantity = quantity;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getBookId() {
+ return bookId;
+ }
+
+ public void setBookId(Long bookId) {
+ this.bookId = bookId;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+}
diff --git a/src/main/java/bookstore/Orders.java b/src/main/java/bookstore/Orders.java
new file mode 100644
index 0000000..430e1ca
--- /dev/null
+++ b/src/main/java/bookstore/Orders.java
@@ -0,0 +1,78 @@
+package bookstore;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.OneToMany;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+@Entity
+public class Orders {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @OneToMany(cascade = CascadeType.ALL)
+ private Set orderLines = new HashSet<>();
+
+ @Column(name = "address", length = 50)
+ private String address;
+
+ @Column(name = "customer_id", length = 50)
+ private Long customerId;
+
+ @Column(name = "store_id", length=50)
+ private Long storeId;
+
+ public Orders(){
+
+ }
+
+ public Orders(String address, Long customerId){
+ this.address = address;
+ this.customerId = customerId;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public Long getCustomerId() {
+ return customerId;
+ }
+
+ public void setCustomerId(Long customerId) {
+ this.customerId = customerId;
+ }
+
+ public Set getOrderLines() {
+ return orderLines;
+ }
+
+ public void setOrderLines(Set orderLines) {
+ this.orderLines = orderLines;
+ }
+
+ public Long getStoreId() {
+ return storeId;
+ }
+
+ public void setStoreId(Long storeId) {
+ this.storeId = storeId;
+ }
+
+}
diff --git a/src/main/java/bookstore/Store.java b/src/main/java/bookstore/Store.java
new file mode 100644
index 0000000..dd0146d
--- /dev/null
+++ b/src/main/java/bookstore/Store.java
@@ -0,0 +1,40 @@
+package bookstore;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Store {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name="location", length=50)
+ protected String location;
+
+ public Store() {
+
+ }
+
+ public Store(String location) {
+ this.location = location;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLcoation(String location) {
+ this.location = location;
+ }
+
+}
diff --git a/src/main/java/bookstore/other/Main.java b/src/main/java/bookstore/other/Main.java
new file mode 100644
index 0000000..f5c9265
--- /dev/null
+++ b/src/main/java/bookstore/other/Main.java
@@ -0,0 +1,78 @@
+package bookstore.other;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+
+import bookstore.Author;
+import bookstore.Book;
+import bookstore.Customers;
+import bookstore.OrderLines;
+import bookstore.Orders;
+import bookstore.Store;
+
+
+/*import com.qa.persistence.CD;
+import com.qa.persistence.Musician;
+import com.qa.persistence.demo01.CDService;
+import com.qa.persistence.demo01.Main;*/
+
+
+public class Main {
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ System.out.println("\n\n>>> Executing : " + Main.class.toString() + " <<<\n");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("module04-persistence-unit");
+ EntityManager em = emf.createEntityManager();
+ EntityTransaction tx = em.getTransaction();
+
+ StoreService service = new StoreService(em);
+
+ // Creates and persists a CD
+ tx.begin();
+ Set orderLines = new HashSet<>();
+ Author author1 = new Author("JK", "Rowling");
+ Author author2 = new Author("Anthony", "Burgess");
+ Book book1 = new Book("Harry Potter","fantasy",author1,"paperback");
+ Book book2 = new Book("A Clockwork Orange","science fiction",author2,"paperback");
+ orderLines.add(new OrderLines(book1.getId(),1));
+ orderLines.add(new OrderLines(book2.getId(),1));
+ Orders order1 = new Orders();
+ order1.setOrderLines(orderLines);
+ Customers customer1 = new Customers("John","Smith",true, "jsmith@gmail.com","password");
+ order1.setAddress("test address");
+ order1.setCustomerId(customer1.getId());
+ order1 = service.createOrder(order1);
+ tx.commit();
+
+ System.out.println("Order Persisted : " + order1);
+ //
+ tx.commit();
+
+ // Finds the order
+ order1 = service.findOrder(order1.getId());
+
+ System.out.println("Order Found : " + order1);
+ System.out.println(" Books : " + order1.getOrderLines());
+
+ // Removes the order
+ tx.begin();
+ service.removeOrder(order1.getId());
+ tx.commit();
+
+ System.out.println("Order Removed");
+
+ // Finds the order
+ order1 = service.findOrder(order1.getId());
+
+ System.out.println("Order Not Found : " + order1);
+
+ em.close();
+ emf.close();
+
+ }
+}
diff --git a/src/main/java/bookstore/other/StoreService.java b/src/main/java/bookstore/other/StoreService.java
new file mode 100644
index 0000000..baa9dda
--- /dev/null
+++ b/src/main/java/bookstore/other/StoreService.java
@@ -0,0 +1,42 @@
+package bookstore.other;
+
+import javax.persistence.EntityManager;
+
+import bookstore.Orders;
+
+public class StoreService {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ private EntityManager em;
+
+ // ======================================
+ // = Constructors =
+ // ======================================
+
+ public StoreService(EntityManager em) {
+ this.em = em;
+ }
+
+ // ======================================
+ // = Public Methods =
+ // ======================================
+
+ public Orders createOrder(Orders order) {
+ em.persist(order);
+ return order;
+ }
+
+ public void removeOrder(Long id) {
+ Orders order = em.find(Orders.class, id);
+ if (order != null)
+ em.remove(order);
+ }
+
+ public Orders findOrder(Long id) {
+ return em.find(Orders.class, id);
+ }
+
+}
diff --git a/src/main/java/com/qa/persistence/CD.java b/src/main/java/com/qa/persistence/CD.java
new file mode 100644
index 0000000..bbb6a36
--- /dev/null
+++ b/src/main/java/com/qa/persistence/CD.java
@@ -0,0 +1,123 @@
+package com.qa.persistence;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+
+@Entity
+public class CD extends Item {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ @Column(name = "total_duration")
+ private Float totalDuration;
+
+ private String genre;
+
+ @OneToMany(cascade = CascadeType.ALL)
+ private Set musicians = new HashSet<>();
+
+ // ======================================
+ // = Constructors =
+ // ======================================
+
+ public CD() {
+ }
+
+ public CD(String title) {
+ this.title = title;
+ }
+
+ public CD(String title, String genre) {
+ this.title = title;
+ this.genre = genre;
+ }
+
+ public CD(String title, String description, Float unitCost, Float totalDuration, String genre) {
+ this.title = title;
+ this.description = description;
+ this.unitCost = unitCost;
+ this.totalDuration = totalDuration;
+ this.genre = genre;
+ }
+
+ // ======================================
+ // = Getters & Setters =
+ // ======================================
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Float getUnitCost() {
+ return unitCost;
+ }
+
+ public void setUnitCost(Float unitCost) {
+ this.unitCost = unitCost;
+ }
+
+ public Float getTotalDuration() {
+ return totalDuration;
+ }
+
+ public void setTotalDuration(Float totalDuration) {
+ this.totalDuration = totalDuration;
+ }
+
+ public String getGenre() {
+ return genre;
+ }
+
+ public void setGenre(String genre) {
+ this.genre = genre;
+ }
+
+ public Set getMusicians() {
+ return musicians;
+ }
+
+ public void setMusicians(Set musicians) {
+ this.musicians = musicians;
+ }
+
+ // ======================================
+ // = hashcode, equals & toString =
+ // ======================================
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("CD{");
+ sb.append("id=").append(id);
+ sb.append(", title='").append(title).append('\'');
+ sb.append(", genre='").append(genre).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/qa/persistence/Item.java b/src/main/java/com/qa/persistence/Item.java
new file mode 100644
index 0000000..fd3e3ba
--- /dev/null
+++ b/src/main/java/com/qa/persistence/Item.java
@@ -0,0 +1,111 @@
+package com.qa.persistence;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+@Entity
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+public class Item {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ @Id
+ @GeneratedValue
+ protected Long id;
+
+ @Column(length = 100)
+ protected String title;
+
+ @Column(length = 3000)
+ protected String description;
+
+ @Column(name = "unit_cost")
+ protected Float unitCost;
+
+ // ======================================
+ // = Getters & Setters =
+ // ======================================
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Float getUnitCost() {
+ return unitCost;
+ }
+
+ public void setUnitCost(Float unitCost) {
+ this.unitCost = unitCost;
+ }
+
+ // ======================================
+ // = hashcode, equals & toString =
+ // ======================================
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Item item = (Item) o;
+
+ if (description != null ? !description.equals(item.description) : item.description != null)
+ return false;
+ if (id != null ? !id.equals(item.id) : item.id != null)
+ return false;
+ if (!title.equals(item.title))
+ return false;
+ if (unitCost != null ? !unitCost.equals(item.unitCost) : item.unitCost != null)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id != null ? id.hashCode() : 0;
+ result = 31 * result + title.hashCode();
+ result = 31 * result + (description != null ? description.hashCode() : 0);
+ result = 31 * result + (unitCost != null ? unitCost.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("Item{");
+ sb.append("id=").append(id);
+ sb.append(", title='").append(title).append('\'');
+ sb.append(", description='").append(description).append('\'');
+ sb.append(", unitCost=").append(unitCost);
+ sb.append('}');
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/qa/persistence/Musician.java b/src/main/java/com/qa/persistence/Musician.java
new file mode 100644
index 0000000..f8bd9b5
--- /dev/null
+++ b/src/main/java/com/qa/persistence/Musician.java
@@ -0,0 +1,150 @@
+package com.qa.persistence;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+public class Musician {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name = "first_name", length = 50)
+ protected String firstName;
+
+ @Column(name = "last_name", length = 50)
+ protected String lastName;
+
+ @Column(length = 5000)
+ protected String bio;
+
+ @Column(name = "date_of_birth")
+ @Temporal(TemporalType.DATE)
+ protected Date dateOfBirth;
+
+ @Column(name = "Dead_or_Alive", length = 50)
+ protected String deadOrAlive;
+
+ @Transient
+ protected Integer age;
+
+ @Column(name = "preferred_instrument")
+ private String preferredInstrument;
+
+ // ======================================
+ // = Constructors =
+ // ======================================
+
+ public Musician() {
+ }
+
+ public Musician(String firstName, String lastName, String bio, Date dateOfBirth, String deadOrAlive, Integer age,
+ String preferredInstrument) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.bio = bio;
+ this.dateOfBirth = dateOfBirth;
+ this.deadOrAlive = deadOrAlive;
+ this.age = age;
+ this.preferredInstrument = preferredInstrument;
+ }
+
+ public Musician(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ // ======================================
+ // = Getters & Setters =
+ // ======================================
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getBio() {
+ return bio;
+ }
+
+ public void setBio(String bio) {
+ this.bio = bio;
+ }
+
+ public Date getDateOfBirth() {
+ return dateOfBirth;
+ }
+
+ public void setDateOfBirth(Date dateOfBirth) {
+ this.dateOfBirth = dateOfBirth;
+ }
+
+ public String getDeadOrAlive() {
+ return deadOrAlive;
+ }
+
+ public void setDeadOrAlive(String deadOrAlive) {
+ this.deadOrAlive = deadOrAlive;
+ }
+
+ public Integer getAge() {
+ return age;
+ }
+
+ public void setAge(Integer age) {
+ this.age = age;
+ }
+
+ public String getPreferredInstrument() {
+ return preferredInstrument;
+ }
+
+ public void setPreferredInstrument(String preferredInstrument) {
+ this.preferredInstrument = preferredInstrument;
+ }
+
+ // ======================================
+ // = hashcode, equals & toString =
+ // ======================================
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("Musician{");
+ sb.append("id=").append(id);
+ sb.append(", firstName='").append(firstName).append('\'');
+ sb.append(", lastName='").append(lastName).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/qa/persistence/demo01/CDService.java b/src/main/java/com/qa/persistence/demo01/CDService.java
new file mode 100644
index 0000000..ee9efa3
--- /dev/null
+++ b/src/main/java/com/qa/persistence/demo01/CDService.java
@@ -0,0 +1,41 @@
+package com.qa.persistence.demo01;
+
+import javax.persistence.EntityManager;
+
+import com.qa.persistence.CD;
+
+public class CDService {
+
+ // ======================================
+ // = Attributes =
+ // ======================================
+
+ private EntityManager em;
+
+ // ======================================
+ // = Constructors =
+ // ======================================
+
+ public CDService(EntityManager em) {
+ this.em = em;
+ }
+
+ // ======================================
+ // = Public Methods =
+ // ======================================
+
+ public CD createCD(CD cd) {
+ em.persist(cd);
+ return cd;
+ }
+
+ public void removeCD(Long id) {
+ CD cd = em.find(CD.class, id);
+ if (cd != null)
+ em.remove(cd);
+ }
+
+ public CD findCD(Long id) {
+ return em.find(CD.class, id);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/qa/persistence/demo01/Main.java b/src/main/java/com/qa/persistence/demo01/Main.java
new file mode 100644
index 0000000..afa496e
--- /dev/null
+++ b/src/main/java/com/qa/persistence/demo01/Main.java
@@ -0,0 +1,61 @@
+package com.qa.persistence.demo01;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+
+import com.qa.persistence.CD;
+import com.qa.persistence.Musician;
+
+public class Main {
+
+ public static void main(String[] args) {
+
+ System.out.println("\n\n>>> Executing : " + Main.class.toString() + " <<<\n");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("module04-persistence-unit");
+ EntityManager em = emf.createEntityManager();
+ EntityTransaction tx = em.getTransaction();
+
+ CDService service = new CDService(em);
+
+ // Creates and persists a CD
+ tx.begin();
+ Set beatles = new HashSet<>();
+ beatles.add(new Musician("John", "Lennon")); //Dead - Assassinated!
+ beatles.add(new Musician("Paul", "McCartney")); //Alive
+ beatles.add(new Musician("Ringo", "Starr")); //Alive
+ beatles.add(new Musician("Georges", "Harrison")); //Dead
+ CD sergentPepper = new CD("Sergent Pepper");
+ sergentPepper.setMusicians(beatles);
+ sergentPepper = service.createCD(sergentPepper);
+ tx.commit();
+
+ System.out.println("CD Persisted : " + sergentPepper);
+
+ // Finds the cd
+ sergentPepper = service.findCD(sergentPepper.getId());
+
+ System.out.println("CD Found : " + sergentPepper);
+ System.out.println(" Musicians : " + sergentPepper.getMusicians());
+
+ // Removes the cd
+ tx.begin();
+ service.removeCD(sergentPepper.getId());
+ tx.commit();
+
+ System.out.println("CD Removed");
+
+ // Finds the cd
+ sergentPepper = service.findCD(sergentPepper.getId());
+
+ System.out.println("CD Not Found : " + sergentPepper);
+
+ em.close();
+ emf.close();
+ }
+}
diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..474ce35
--- /dev/null
+++ b/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,25 @@
+
+
+
+
+ org.eclipse.persistence.jpa.PersistenceProvider
+
+ com.qa.persistence.CD
+ com.qa.persistence.Musician
+ com.qa.persistence.Item
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/target/classes/META-INF/persistence.xml b/target/classes/META-INF/persistence.xml
new file mode 100644
index 0000000..474ce35
--- /dev/null
+++ b/target/classes/META-INF/persistence.xml
@@ -0,0 +1,25 @@
+
+
+
+
+ org.eclipse.persistence.jpa.PersistenceProvider
+
+ com.qa.persistence.CD
+ com.qa.persistence.Musician
+ com.qa.persistence.Item
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/target/classes/bookstore/Author.class b/target/classes/bookstore/Author.class
new file mode 100644
index 0000000..6a924f4
Binary files /dev/null and b/target/classes/bookstore/Author.class differ
diff --git a/target/classes/bookstore/Book.class b/target/classes/bookstore/Book.class
new file mode 100644
index 0000000..aaa6310
Binary files /dev/null and b/target/classes/bookstore/Book.class differ
diff --git a/target/classes/bookstore/Customers.class b/target/classes/bookstore/Customers.class
new file mode 100644
index 0000000..25dd238
Binary files /dev/null and b/target/classes/bookstore/Customers.class differ
diff --git a/target/classes/bookstore/OrderLines.class b/target/classes/bookstore/OrderLines.class
new file mode 100644
index 0000000..3988412
Binary files /dev/null and b/target/classes/bookstore/OrderLines.class differ
diff --git a/target/classes/bookstore/Orders.class b/target/classes/bookstore/Orders.class
new file mode 100644
index 0000000..e0b0bfe
Binary files /dev/null and b/target/classes/bookstore/Orders.class differ
diff --git a/target/classes/bookstore/Store.class b/target/classes/bookstore/Store.class
new file mode 100644
index 0000000..fed3189
Binary files /dev/null and b/target/classes/bookstore/Store.class differ
diff --git a/target/classes/bookstore/other/Main.class b/target/classes/bookstore/other/Main.class
new file mode 100644
index 0000000..c829ccd
Binary files /dev/null and b/target/classes/bookstore/other/Main.class differ
diff --git a/target/classes/bookstore/other/StoreService.class b/target/classes/bookstore/other/StoreService.class
new file mode 100644
index 0000000..98230c6
Binary files /dev/null and b/target/classes/bookstore/other/StoreService.class differ
diff --git a/target/classes/com/qa/persistence/CD.class b/target/classes/com/qa/persistence/CD.class
new file mode 100644
index 0000000..008c162
Binary files /dev/null and b/target/classes/com/qa/persistence/CD.class differ
diff --git a/target/classes/com/qa/persistence/Item.class b/target/classes/com/qa/persistence/Item.class
new file mode 100644
index 0000000..6598bda
Binary files /dev/null and b/target/classes/com/qa/persistence/Item.class differ
diff --git a/target/classes/com/qa/persistence/Musician.class b/target/classes/com/qa/persistence/Musician.class
new file mode 100644
index 0000000..22f9dbe
Binary files /dev/null and b/target/classes/com/qa/persistence/Musician.class differ
diff --git a/target/classes/com/qa/persistence/demo01/CDService.class b/target/classes/com/qa/persistence/demo01/CDService.class
new file mode 100644
index 0000000..73cddc2
Binary files /dev/null and b/target/classes/com/qa/persistence/demo01/CDService.class differ
diff --git a/target/classes/com/qa/persistence/demo01/Main.class b/target/classes/com/qa/persistence/demo01/Main.class
new file mode 100644
index 0000000..cb63e77
Binary files /dev/null and b/target/classes/com/qa/persistence/demo01/Main.class differ
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..f6a6092
--- /dev/null
+++ b/target/maven-archiver/pom.properties
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Fri Jan 27 10:41:46 GMT 2017
+version=1.0
+groupId=com.qa.persistence
+artifactId=module04
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644
index 0000000..e69de29
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
new file mode 100644
index 0000000..5f697b7
--- /dev/null
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@@ -0,0 +1,5 @@
+C:\Users\Administrator\Desktop\jpa-example\example-project\src\main\java\com\qa\persistence\demo01\CDService.java
+C:\Users\Administrator\Desktop\jpa-example\example-project\src\main\java\com\qa\persistence\CD.java
+C:\Users\Administrator\Desktop\jpa-example\example-project\src\main\java\com\qa\persistence\demo01\Main.java
+C:\Users\Administrator\Desktop\jpa-example\example-project\src\main\java\com\qa\persistence\Item.java
+C:\Users\Administrator\Desktop\jpa-example\example-project\src\main\java\com\qa\persistence\Musician.java
diff --git a/target/module04-1.0.jar b/target/module04-1.0.jar
new file mode 100644
index 0000000..0002211
Binary files /dev/null and b/target/module04-1.0.jar differ