openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r777135 [10/10] - in /openjpa/trunk: openjpa-kernel/src/test/java/org/apache/openjpa/meta/ openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/ openjpa-lib/src/test/java/org/apache/openjpa/lib/graph/ openjpa-lib/src/test/java/org/apache/o...
Date Thu, 21 May 2009 14:39:43 GMT
Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java?rev=777135&r1=777134&r2=777135&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java (original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java Thu
May 21 14:39:31 2009
@@ -82,7 +82,8 @@
     public void testOrderedQueryResultWhenOrderableItemSelected() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        Query query = em.createQuery("SELECT p.value,p FROM PObject p ORDER BY p.value ASC");
+        Query query = em.createQuery(
+                "SELECT p.value,p FROM PObject p ORDER BY p.value ASC");
         List result = query.getResultList();
         assertValidResult(result);
         Integer old = Integer.MIN_VALUE;
@@ -100,7 +101,8 @@
     public void testOrderedQueryResultWhenOrderableItemNotSelected() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        Query query = em.createQuery("SELECT p FROM PObject p ORDER BY p.value ASC");
+        Query query =
+            em.createQuery("SELECT p FROM PObject p ORDER BY p.value ASC");
         List<PObject> result = query.getResultList();
         assertValidResult(result);
         Integer old = Integer.MIN_VALUE;
@@ -115,7 +117,8 @@
     public void testOrderedQueryResultWhenNavigatedOrderableItemNotSelected() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        Query query = em.createQuery("SELECT p FROM Person p JOIN p.address a ORDER BY a.zip
ASC, a.city DESC");
+        Query query = em.createQuery(
+     "SELECT p FROM Person p JOIN p.address a ORDER BY a.zip ASC, a.city DESC");
         List<Person> result = query.getResultList();
         assertValidResult(result);
         Integer oldZip = Integer.MIN_VALUE;
@@ -134,11 +137,17 @@
     public void testAggregateQuery() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        Object count = em.createQuery("SELECT COUNT(p) FROM PObject p").getSingleResult();
-        Object max   = em.createQuery("SELECT MAX(p.value) FROM PObject p").getSingleResult();
-        Object min   = em.createQuery("SELECT MIN(p.value) FROM PObject p").getSingleResult();
-        Object sum   = em.createQuery("SELECT SUM(p.value) FROM PObject p").getSingleResult();
-        Object minmax   = em.createQuery("SELECT MIN(p.value),MAX(p.value) FROM PObject p").getSingleResult();
+        Object count = em.createQuery("SELECT COUNT(p) FROM PObject p")
+                .getSingleResult();
+        Object max = em.createQuery("SELECT MAX(p.value) FROM PObject p")
+                .getSingleResult();
+        Object min = em.createQuery("SELECT MIN(p.value) FROM PObject p")
+                .getSingleResult();
+        Object sum = em.createQuery("SELECT SUM(p.value) FROM PObject p")
+                .getSingleResult();
+        Object minmax = em.createQuery(
+                "SELECT MIN(p.value),MAX(p.value) FROM PObject p")
+                .getSingleResult();
         Object min1 = ((Object[])minmax)[0];
         Object max1 = ((Object[])minmax)[1];
         em.getTransaction().rollback();
@@ -146,7 +155,8 @@
         assertEquals(POBJECT_COUNT, ((Number)count).intValue());
         assertEquals(VALUE_MAX, ((Number)max).intValue());
         assertEquals(VALUE_MIN, ((Number)min).intValue());
-        assertEquals((VALUE_MIN+VALUE_MAX)*POBJECT_COUNT, 2*((Number)sum).intValue());
+        assertEquals((VALUE_MIN + VALUE_MAX) * POBJECT_COUNT,
+                2 * ((Number)sum).intValue());
         assertEquals(min, min1);
         assertEquals(max, max1);
     }
@@ -154,7 +164,9 @@
     public void testAggregateQueryWithMissingValueFromSlice() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        Object max   = em.createQuery("SELECT MAX(p.value) FROM PObject p WHERE MOD(p.value,2)=0").getSingleResult();
+        Object max = em.createQuery(
+                "SELECT MAX(p.value) FROM PObject p WHERE MOD(p.value,2)=0")
+                .getSingleResult();
         em.getTransaction().rollback();
         
         assertEquals(VALUE_MAX, ((Number)max).intValue());
@@ -164,8 +176,9 @@
         EntityManager em = emf.createEntityManager();
         int limit = 3;
         em.getTransaction().begin();
-        List<PObject> result = em.createQuery("SELECT p FROM PObject p ORDER BY p.value
ASC")
-            .setMaxResults(limit).getResultList();
+        List<PObject> result =
+            em.createQuery("SELECT p FROM PObject p ORDER BY p.value ASC")
+                .setMaxResults(limit).getResultList();
         assertValidResult(result);
         Integer old = Integer.MIN_VALUE;
         for (PObject pc : result) {
@@ -195,7 +208,8 @@
     public void testInMemoryOrderBy() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        Query query = em.createQuery("SELECT p FROM PObject p ORDER BY p.value");
+        Query query =
+            em.createQuery("SELECT p FROM PObject p ORDER BY p.value");
         List result = query.getResultList();
         em.getTransaction().rollback();
     }
@@ -203,8 +217,9 @@
     public void testQueryParameter() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        Query query = em.createQuery("SELECT p FROM PObject p WHERE p.value > :v")
-        	.setParameter("v", 200);
+        Query query = em.createQuery(
+                "SELECT p FROM PObject p WHERE p.value > :v")
+        	    .setParameter("v", 200);
         List result = query.getResultList();
         em.getTransaction().rollback();
     }
@@ -212,12 +227,14 @@
     public void testQueryParameterEntity() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        Address a = (Address)em.createQuery("select a from Address a where a.city = :city")
-        	.setParameter("city", "Rome").getSingleResult();
+        Address a = (Address)em.createQuery(
+                "select a from Address a where a.city = :city")
+        	    .setParameter("city", "Rome").getSingleResult();
         assertNotNull(a);
         assertEquals("Odd", SlicePersistence.getSlice(a));
-        Query query = em.createQuery("SELECT p FROM Person p WHERE p.address = :a")
-        	.setParameter("a", a);
+        Query query =
+            em.createQuery("SELECT p FROM Person p WHERE p.address = :a")
+            .setParameter("a", a);
         List<Person> result = query.getResultList();
         assertEquals(1, result.size());
         Person p = result.get(0);

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQueryMultiThreaded.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQueryMultiThreaded.java?rev=777135&r1=777134&r2=777135&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQueryMultiThreaded.java
(original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQueryMultiThreaded.java
Thu May 21 14:39:31 2009
@@ -56,7 +56,7 @@
 	}
 
 	public void setUp() throws Exception {
-		super.setUp(PObject.class, Person.class, Address.class, Country.class,
+        super.setUp(PObject.class, Person.class, Address.class, Country.class,
 				CLEAR_TABLES, "openjpa.Multithreaded", "true");
 		int count = count(PObject.class);
 		if (count == 0) {
@@ -85,7 +85,7 @@
 			pc.setValue(VALUE_MIN + i);
 			em.persist(pc);
 			String slice = SlicePersistence.getSlice(pc);
-			String expected = (pc.getValue() % 2 == 0) ? "Even" : "Odd";
+            String expected = (pc.getValue() % 2 == 0) ? "Even" : "Odd";
 			assertEquals(expected, slice);
 		}
 		Person p1 = new Person();
@@ -109,8 +109,8 @@
 	public void testQueryResultIsOrderedAcrossSlice() {
 		final EntityManager em = emf.createEntityManager();
 		em.getTransaction().begin();
-		final Query query = em
-			.createQuery("SELECT p.value,p FROM PObject p ORDER BY p.value ASC");
+        final Query query = em.createQuery(
+                "SELECT p.value,p FROM PObject p ORDER BY p.value ASC");
 		for (int i = 0; i < THREADS; i++) {
 			futures[i] = group.submit(new Callable<Object>() {
 				public Object call() {
@@ -118,11 +118,11 @@
 					Integer old = Integer.MIN_VALUE;
 					for (Object row : result) {
 						Object[] line = (Object[]) row;
-						int value = ((Integer) line[0]).intValue();
+                        int value = ((Integer) line[0]).intValue();
 						PObject pc = (PObject) line[1];
 						assertTrue(value >= old);
 						old = value;
-						assertEquals(value, pc.getValue());
+                        assertEquals(value, pc.getValue());
 					}
 					return null;
 				}
@@ -136,11 +136,12 @@
 	public void testAggregateQuery() {
 		final EntityManager em = emf.createEntityManager();
 		em.getTransaction().begin();
-		final Query countQ = em.createQuery("SELECT COUNT(p) FROM PObject p");
-		final Query maxQ = em.createQuery("SELECT MAX(p.value) FROM PObject p");
-		final Query minQ = em.createQuery("SELECT MIN(p.value) FROM PObject p");
-		final Query sumQ = em.createQuery("SELECT SUM(p.value) FROM PObject p");
-		final Query minmaxQ = em.createQuery("SELECT MIN(p.value),MAX(p.value) FROM PObject p");
+        final Query countQ = em.createQuery("SELECT COUNT(p) FROM PObject p");
+        final Query maxQ = em.createQuery("SELECT MAX(p.value) FROM PObject p");
+        final Query minQ = em.createQuery("SELECT MIN(p.value) FROM PObject p");
+        final Query sumQ = em.createQuery("SELECT SUM(p.value) FROM PObject p");
+        final Query minmaxQ = em.createQuery(
+                "SELECT MIN(p.value),MAX(p.value) FROM PObject p");
 		for (int i = 0; i < THREADS; i++) {
 			futures[i] = group.submit(new Callable<Object>() {
 				public Object call() {
@@ -148,20 +149,20 @@
 					Object max = maxQ.getSingleResult();
 					Object min = minQ.getSingleResult();
 					Object sum = sumQ.getSingleResult();
-					Object minmax = minmaxQ.getSingleResult();
+                    Object minmax = minmaxQ.getSingleResult();
 					
 					Object min1 = ((Object[]) minmax)[0];
 					Object max1 = ((Object[]) minmax)[1];
 
 
-					assertEquals(POBJECT_COUNT, ((Number) count).intValue());
-					assertEquals(VALUE_MAX, ((Number) max).intValue());
-					assertEquals(VALUE_MIN, ((Number) min).intValue());
-					assertEquals((VALUE_MIN + VALUE_MAX) * POBJECT_COUNT,
-							2 * ((Number) sum).intValue());
-					assertEquals(min, min1);
-					assertEquals(max, max1);
-					return null;
+                    assertEquals(POBJECT_COUNT, ((Number) count).intValue());
+                    assertEquals(VALUE_MAX, ((Number) max).intValue());
+                    assertEquals(VALUE_MIN, ((Number) min).intValue());
+                    assertEquals((VALUE_MIN + VALUE_MAX) * POBJECT_COUNT,
+                            2 * ((Number) sum).intValue());
+                    assertEquals(min, min1);
+                    assertEquals(max, max1);
+                    return null;
 				}
 			});
 		}
@@ -172,12 +173,13 @@
 	public void testAggregateQueryWithMissingValueFromSlice() {
 		final EntityManager em = emf.createEntityManager();
 		em.getTransaction().begin();
-		final Query maxQ = em.createQuery("SELECT MAX(p.value) FROM PObject p WHERE MOD(p.value,2)=0");
+        final Query maxQ = em.createQuery(
+                "SELECT MAX(p.value) FROM PObject p WHERE MOD(p.value,2)=0");
 		for (int i = 0; i < THREADS; i++) {
 			futures[i] = group.submit(new Callable<Object>() {
 				public Object call() {
 					Object max = maxQ.getSingleResult();
-					assertEquals(VALUE_MAX, ((Number) max).intValue());
+                    assertEquals(VALUE_MAX, ((Number) max).intValue());
 					return null;
 				}
 			});
@@ -190,15 +192,16 @@
 		final EntityManager em = emf.createEntityManager();
 		final int limit = 3;
 		em.getTransaction().begin();
-		final Query q = em.createQuery("SELECT p.value,p FROM PObject p ORDER BY p.value ASC");
+        final Query q = em.createQuery(
+                "SELECT p.value,p FROM PObject p ORDER BY p.value ASC");
 		for (int i = 0; i < THREADS; i++) {
 			futures[i] = group.submit(new Callable<Object>() {
 				public Object call() {
-					List result = q.setMaxResults(limit).getResultList();
+                    List result = q.setMaxResults(limit).getResultList();
 					int i = 0;
 					for (Object row : result) {
 						Object[] line = (Object[]) row;
-						int value = ((Integer) line[0]).intValue();
+                        int value = ((Integer) line[0]).intValue();
 						PObject pc = (PObject) line[1];
 					}
 					assertEquals(limit, result.size());
@@ -221,11 +224,11 @@
 			futures[i] = group.submit(new Callable<Object>() {
 
 				public Object call() {
-					query.setHint(ProductDerivation.HINT_TARGET, "Even");
+                    query.setHint(ProductDerivation.HINT_TARGET, "Even");
 					List result = query.getResultList();
 					for (Object pc : result) {
-						String slice = SlicePersistence.getSlice(pc);
-						assertTrue(targets.contains(slice));
+                        String slice = SlicePersistence.getSlice(pc);
+                        assertTrue(targets.contains(slice));
 					}
 					return null;
 				}
@@ -239,7 +242,8 @@
 	public void testInMemoryOrderBy() {
 		final EntityManager em = emf.createEntityManager();
 		em.getTransaction().begin();
-		final Query query = em.createQuery("SELECT p FROM PObject p ORDER BY p.value");
+        final Query query =
+            em.createQuery("SELECT p FROM PObject p ORDER BY p.value");
 		for (int i = 0; i < THREADS; i++) {
 			futures[i] = group.submit(new Callable<Object>() {
 				public Object call() {
@@ -255,7 +259,8 @@
 	public void testQueryParameter() {
 		final EntityManager em = emf.createEntityManager();
 		em.getTransaction().begin();
-		final Query query = em.createQuery("SELECT p FROM PObject p WHERE p.value > :v");
+        final Query query =
+            em.createQuery("SELECT p FROM PObject p WHERE p.value > :v");
 		for (int i = 0; i < THREADS; i++) {
 			futures[i] = group.submit(new Callable<Object>() {
 				public Object call() {
@@ -279,21 +284,24 @@
 	public void xtestQueryParameterEntity() {
 		final EntityManager em = emf.createEntityManager();
 		em.getTransaction().begin();
-		final Query addressQ = em.createQuery("select a from Address a where a.city = :city");
-								 
-		final Query personQ = em.createQuery("SELECT p FROM Person p WHERE p.address = :a");
+        final Query addressQ =
+            em.createQuery("select a from Address a where a.city = :city");
+
+        final Query personQ =
+            em.createQuery("SELECT p FROM Person p WHERE p.address = :a");
 		for (int i = 0; i < THREADS; i++) {
 			futures[i] = group.submit(new Callable<Object>() {
 				public Object call() {
-					Address a = (Address) addressQ.setParameter("city", "Rome")
+                    Address a = (Address) addressQ.setParameter("city", "Rome")
 						.getSingleResult();
 					assertNotNull(a);
-					assertEquals("Odd", SlicePersistence.getSlice(a));
-					List<Person> result = personQ.setParameter("a", a).getResultList();
+                    assertEquals("Odd", SlicePersistence.getSlice(a));
+                    List<Person> result =
+                        personQ.setParameter("a", a).getResultList();
 					assertEquals(1, result.size());
 					Person p = result.get(0);
-					assertEquals("Odd", SlicePersistence.getSlice(p));
-					assertEquals("Rome", p.getAddress().getCity());
+                    assertEquals("Odd", SlicePersistence.getSlice(p));
+                    assertEquals("Rome", p.getAddress().getCity());
 					return null;
 				}
 
@@ -309,9 +317,9 @@
 				try {
 					f.get(60, TimeUnit.SECONDS);
 				} catch (TimeoutException te) {
-				    fail("Failed " + te + "\r\n" + getStackDump(te));
+                    fail("Failed " + te + "\r\n" + getStackDump(te));
 				} catch (ExecutionException e) {
-					fail("Failed " + "\r\n" + getStackDump(e.getCause()));
+                    fail("Failed " + "\r\n" + getStackDump(e.getCause()));
 				}
 		} catch (InterruptedException e) {
 

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java?rev=777135&r1=777134&r2=777135&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java
(original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java
Thu May 21 14:39:31 2009
@@ -39,13 +39,13 @@
 	 * Distribute the given instance.
 	 * Assumes that two configured slices are named as <em>One</em> and 
 	 * <em>Two</em>.<br>
-	 * The policy is only implemented for PObject and Person i.e. two of three 
-	 * known classes. No policy is implemented for Address because Address is
-	 * persisted always by cascade and hence Slice should assign automatically
+     * The policy is only implemented for PObject and Person i.e. two of three
+     * known classes. No policy is implemented for Address because Address is
+     * persisted always by cascade and hence Slice should assign automatically
 	 * the same slice as its owner Person. 
 	 * 
 	 */
-	public String distribute(Object pc, List<String> slices, Object context) {
+    public String distribute(Object pc, List<String> slices, Object context) {
 		assertValidSlices(slices);
 		if (pc instanceof PObject)
 			return distribute((PObject)pc);
@@ -58,8 +58,8 @@
 	void assertValidSlices(List<String> slices) {
 		if (slices.contains("One") && slices.contains("Two"))
 			return;
-		throw new RuntimeException("This policy assumes two slices named " +
-				"One and Two. But configured slices are " + slices); 
+        throw new RuntimeException("This policy assumes two slices named " +
+                "One and Two. But configured slices are " + slices);
 	}
 	
 	/**



Mime
View raw message