Commits

noll committed f1ad599

OpenJPA-Implementation mit fehlerhafter Persistence

Comments (0)

Files changed (4)

-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
-	<classpathentry kind="lib" path="lib/fpt2011.jar"/>
-	<classpathentry kind="lib" path="lib/xstream-1.4.2.jar"/>
-	<classpathentry kind="lib" path="lib/postgresql-8.4-703.jdbc4.jar"/>
-	<classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="lib" path="lib/fpt2011.jar"/>
+	<classpathentry kind="lib" path="lib/xstream-1.4.2.jar"/>
+	<classpathentry kind="lib" path="lib/postgresql-8.4-703.jdbc4.jar"/>
+	<classpathentry kind="lib" path="lib/javax.persistence.jar"/>
+	<classpathentry kind="lib" path="lib/openjpa-all-2.1.1.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

src/controller/ControllerShop.java

 
 import strategies.BinaryStrategy;
 import strategies.JDBCStrategy;
+import strategies.OpenJPA;
 import strategies.XMLStrategy;
 import strategies.XStreamStrategy;
 
 			strategy = new XStreamStrategy();
 		else if (e.getSource() == view.mi_readJDBC)
 			strategy = new JDBCStrategy();
+		else if (e.getSource() == view.mi_readJPA)
+			strategy = new OpenJPA();
 		else
 			return;
 
 			strategy = new XStreamStrategy();
 		else if (e.getSource() == view.mi_writeJDBC)
 			strategy = new JDBCStrategy();
+		else if (e.getSource() == view.mi_writeJPA)
+			strategy = new OpenJPA();
 		else
 			return;
 

src/hs/Product.java

 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 
+import javax.persistence.*;
+import javax.persistence.SequenceGenerator;
+
+
+
+@Entity()
+@Table(name = "products")
 
 public class Product implements fpt.com.Product{
 	
+
+	
 	/**
 	 * 
 	 */
+
 	private static final long serialVersionUID = 1L;
 
 	private String name;
 	private int quantity;
 	private double price; 
-	
+	@Id
+	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "products_SEQ")
+	@SequenceGenerator(name = "products_SEQ", sequenceName ="products_id_seq", allocationSize = 1) 
 	private long id; // Artikelnummer???
 	
 	public Product() {}
 
 	@Override
 	public void stepQuantityDown(int amount) {
+		
 		if (this.quantity >= amount)
 			this.quantity -= amount;
 		else

src/strategies/JDBCStrategy.java

 		
 		try {
 			open(Type.READ_WRITE);
-			c.test();
+			// c.test();
 		} catch (IOException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 
 			// Produktliste befüllen
             for ( Product p : c.readLast(50)) {
-            	System.out.println(p.getName());
             	pl.add(p);
             }