[hibernate-commits] Hibernate SVN: r11203 - in branches/Branch_3_2/HibernateExt/entitymanager/src: test/org/hibernate/ejb/test/emops and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Feb 13 20:17:32 EST 2007


Author: epbernard
Date: 2007-02-13 20:17:31 -0500 (Tue, 13 Feb 2007)
New Revision: 11203

Added:
   branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Cat.java
   branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Decorate.java
   branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Dog.java
   branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java
   branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Pet.java
Modified:
   branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/Ejb3Configuration.java
Log:
EJB-722 tests

Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/Ejb3Configuration.java	2007-02-14 00:15:37 UTC (rev 11202)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/Ejb3Configuration.java	2007-02-14 01:17:31 UTC (rev 11203)
@@ -131,7 +131,7 @@
 
 	/**
 	 * Used to inject a datasource object as the connection provider.
-	 * If used, be sure to <b>not override</b> the {@link Environment.CONNECTION_PROVIDER}
+	 * If used, be sure to <b>not override</b> the hibernate.connection.provider_class
 	 * property
 	 */
 	public void setDataSource(DataSource ds) {

Added: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Cat.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Cat.java	                        (rev 0)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Cat.java	2007-02-14 01:17:31 UTC (rev 11203)
@@ -0,0 +1,20 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+ at Entity
+ at Inheritance( strategy = InheritanceType.JOINED )
+public class Cat extends Pet {
+	int lives;
+
+	public int getLives() {
+		return lives;
+	}
+
+	public void setLives(int lives) {
+		this.lives = lives;
+	}
+}
\ No newline at end of file

Added: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Decorate.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Decorate.java	                        (rev 0)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Decorate.java	2007-02-14 01:17:31 UTC (rev 11203)
@@ -0,0 +1,51 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+
+ at Entity
+public class Decorate implements java.io.Serializable {
+
+	private int id;
+
+	private String name;
+
+	private Pet pet;
+
+	public Decorate() {
+		super();
+
+	}
+
+	@Id
+	@GeneratedValue( strategy = GenerationType.AUTO )
+	public int getId() {
+		return id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	@OneToOne( fetch = FetchType.LAZY )
+	public Pet getPet() {
+		return pet;
+	}
+
+	public void setId(int id) {
+		this.id = id;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public void setPet(Pet pet) {
+		this.pet = pet;
+	}
+}

Added: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Dog.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Dog.java	                        (rev 0)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Dog.java	2007-02-14 01:17:31 UTC (rev 11203)
@@ -0,0 +1,20 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+ at Entity
+ at Inheritance( strategy = InheritanceType.JOINED )
+public class Dog extends Pet {
+	private int numBones;
+
+	public int getNumBones() {
+		return numBones;
+	}
+
+	public void setNumBones(int numBones) {
+		this.numBones = numBones;
+	}
+}

Added: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java	                        (rev 0)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java	2007-02-14 01:17:31 UTC (rev 11203)
@@ -0,0 +1,124 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.HashSet;
+
+import javax.persistence.Query;
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.test.TestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class FlushTest extends TestCase {
+	private static Set<String> names= new HashSet<String>();
+	static {
+		names.add("Toonses");
+		names.add("Sox");
+		names.add("Winnie");
+		names.add("Junior");
+	}
+
+	//Test for EJBTHREE-722
+	public void testFlushOnDetached() throws Exception {
+		EntityManager manager = factory.createEntityManager( );
+
+		manager.getTransaction().begin();
+		Pet p1 = createCat("Toonses", 15.0, 9, manager);
+		manager.flush();
+		manager.clear();
+
+		Pet p2 = createCat("Sox", 10.0, 5, manager);
+		manager.flush();
+		manager.clear();
+
+		Pet p3 = createDog("Winnie", 70.0, 5, manager);
+		manager.flush();
+		manager.clear();
+
+		Pet p4 = createDog("Junior", 11.0, 1, manager);
+		manager.flush();
+		manager.clear();
+
+		Decorate d1 = createDecorate("Test", p1, manager);
+		manager.flush();
+		manager.clear();
+
+		Decorate d2 = createDecorate("Test2", p2, manager);
+		manager.flush();
+		manager.clear();
+
+		List l = findByWeight(14.0, manager);
+		manager.flush();
+		manager.clear();
+		for (Object o : l) {
+			assertTrue( names.contains( ( (Pet) o).getName() ) );
+		}
+
+		Collection<Decorate> founds = getDecorate(manager);
+		manager.flush();
+		manager.clear();
+		for (Decorate value : founds) {
+			assertTrue( names.contains( value.getPet().getName() ) );
+		}
+		
+	}
+
+	public Dog createDog(String name, double weight, int bones, EntityManager manager) {
+		Dog dog = new Dog();
+		dog.setName(name);
+		dog.setWeight(weight);
+		dog.setNumBones(bones);
+		manager.persist(dog);
+		return dog;
+	}
+
+	public Cat createCat(String name, double weight, int lives, EntityManager manager) {
+		Cat cat = new Cat();
+		cat.setName(name);
+		cat.setWeight(weight);
+		cat.setLives(lives);
+		manager.persist(cat);
+		return cat;
+	}
+
+	public List findByWeight(double weight, EntityManager manager) {
+		return manager.createQuery(
+				"select p from Pet p where p.weight < :weight").setParameter(
+				"weight", weight).getResultList();
+	}
+
+	public Decorate createDecorate(String name, Pet pet, EntityManager manager) {
+		Decorate dec = new Decorate();
+		dec.setName(name);
+		dec.setPet(pet);
+		manager.persist(dec);
+		return dec;
+	}
+
+	public Collection<Decorate> getDecorate(EntityManager manager) {
+		Collection<Decorate> founds = new ArrayList<Decorate>();
+		Query query = manager.createQuery("SELECT o FROM Decorate o");
+		List list = query.getResultList();
+		for (Object obj : list) {
+			if (obj instanceof Decorate) {
+				founds.add((Decorate) obj);
+			}
+		}
+		return founds;
+	}
+
+	public Class[] getAnnotatedClasses() {
+		return new Class[] {
+				Pet.class,
+				Dog.class,
+				Cat.class,
+				Decorate.class
+		};
+	}
+}

Added: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Pet.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Pet.java	                        (rev 0)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/Pet.java	2007-02-14 01:17:31 UTC (rev 11203)
@@ -0,0 +1,43 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+ at Entity
+ at Inheritance( strategy = InheritanceType.JOINED )
+public class Pet implements java.io.Serializable {
+	private int id;
+	private String name;
+	private double weight;
+
+	@Id
+	@GeneratedValue( strategy = GenerationType.AUTO )
+	public int getId() {
+		return id;
+	}
+
+	public void setId(int id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public double getWeight() {
+		return weight;
+	}
+
+	public void setWeight(double weight) {
+		this.weight = weight;
+	}
+}




More information about the hibernate-commits mailing list