openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [24/39] - in /openjpa/trunk: openjpa-lib/src/test/java/org/apache/openjpa/lib/test/ openjpa-persistence-jdbc/ openjpa-persistence-jdbc/src/test/java/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/ openjpa-per...
Date Fri, 15 Feb 2008 09:20:40 GMT
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEJBQLCondExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEJBQLCondExpression.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEJBQLCondExpression.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEJBQLCondExpression.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,316 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.jpql.expressions;
+
+import java.util.List;
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.common.apps.*;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBQLCondExpression extends AbstractTestCase {
+
+    private int userid1, userid2, userid3, userid4, userid5;
+
+    public TestEJBQLCondExpression(String name) {
+        super(name, "jpqlclausescactusapp");
+    }
+
+    public void setUp() {
+        deleteAll(CompUser.class);
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        Address[] add =
+            new Address[]{ new Address("43 Sansome", "SF", "USA", "94104"),
+                new Address("24 Mink", "ANTIOCH", "USA", "94513"),
+                new Address("23 Ogbete", "CoalCamp", "NIGERIA", "00000"),
+                new Address("10 Wilshire", "Worcester", "CANADA", "80080"),
+                new Address("23 Bellflower", "Ogui", "NIGERIA", "02000") };
+
+        CompUser user1 = createUser("Seetha", "MAC", add[0], 40, true);
+        CompUser user2 = createUser("Shannon", "PC", add[1], 36, false);
+        CompUser user3 = createUser("Ugo", "PC", add[2], 19, true);
+        CompUser user4 = createUser("Jacob", "LINUX", add[3], 10, true);
+        CompUser user5 = createUser("Famzy", "UNIX", add[4], 29, false);
+
+        em.persist(user1);
+        userid1 = user1.getUserid();
+        em.persist(user2);
+        userid2 = user2.getUserid();
+        em.persist(user3);
+        userid3 = user3.getUserid();
+        em.persist(user4);
+        userid4 = user4.getUserid();
+        em.persist(user5);
+        userid5 = user5.getUserid();
+
+        endTx(em);
+        endEm(em);
+    }
+
+    public void testNothing() {
+        EntityManager em = currentEntityManager();
+        String query = "SELECT o FROM CompUser o";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("the list is null", result);
+        assertEquals("the size of the list is not 5", 5, result.size());
+
+        endEm(em);
+    }
+
+    public void testBetweenExpr() {
+        EntityManager em = currentEntityManager();
+        String query =
+            "SELECT o.name FROM CompUser o WHERE o.age BETWEEN 19 AND 40 AND o.computerName = 'PC'";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("the list is null", result);
+        assertEquals("they are not equal", 2, result.size());
+        assertTrue("result dont contain shannon", result.contains("Shannon"));
+        assertTrue("result dont contain ugo", result.contains("Ugo"));
+
+        endEm(em);
+    }
+
+    public void testNotBetweenExpr() {
+        EntityManager em = currentEntityManager();
+        String query =
+            "SELECT o.name FROM CompUser o WHERE o.age NOT BETWEEN 19 AND 40 AND o.computerName= 'PC'";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("the list is null", result);
+        assertEquals("they are not equal", 0, result.size());
+
+        endEm(em);
+    }
+
+    public void testInExpr() {
+        EntityManager em = currentEntityManager();
+        String query =
+            "SELECT o.name FROM CompUser o WHERE o.age IN (29, 40, 10)";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("the list is null", result);
+        assertEquals(3, result.size());
+        assertTrue("seetha is not in the list", result.contains("Seetha"));
+        assertTrue("jacob is not in the list", result.contains("Jacob"));
+        assertTrue("famzy is not in the list", result.contains("Famzy"));
+
+        endEm(em);
+    }
+
+    public void testNotInExpr() {
+        EntityManager em = currentEntityManager();
+        String query =
+            "SELECT o.name FROM CompUser o WHERE o.age NOT IN (29, 40, 10)";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(2, result.size());
+        assertTrue(result.contains("Ugo"));
+        assertTrue(result.contains("Shannon"));
+
+        endEm(em);
+    }
+
+    public void testLikeExpr() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT o.computerName FROM CompUser o WHERE o.name LIKE 'Sha%' AND o.computerName NOT IN ('PC')";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(0, result.size());
+
+        query =
+            "SELECT o.computerName FROM CompUser o WHERE o.name LIKE 'Sha%o_' AND o.computerName NOT IN ('UNIX')";
+
+        result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+
+        query = "SELECT o.name FROM CompUser o WHERE o.name LIKE '_J%'";
+
+        result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(0, result.size());
+
+        endEm(em);
+    }
+
+    public void testNullExpr() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT o.name FROM CompUser o WHERE o.age IS NOT NULL AND o.computerName = 'PC' ";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("the list is null", result);
+        assertEquals("the list size is not 2", 2, result.size());
+        assertTrue("the result doesnt contain ugo", result.contains("Ugo"));
+        assertTrue("the result doesnt contain shannon",
+            result.contains("Shannon"));
+
+        endEm(em);
+    }
+
+    public void testNullExpr2() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT o.name FROM CompUser o WHERE o.address.country IS NULL";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("the list is null", result);
+        assertEquals("they are not equal", 0, result.size());
+
+        endEm(em);
+    }
+
+    public void testIsEmptyExpr() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT o.name FROM CompUser o WHERE o.nicknames IS NOT EMPTY";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("the list is null", result);
+        assertEquals("they are not equal", 0, result.size());
+
+        endEm(em);
+    }
+
+    public void testIsEmptyExpr2() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT o.name FROM CompUser o WHERE o.nicknames IS EMPTY";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("the list is null", result);
+        assertEquals("they are not equal", 5, result.size());
+
+        endEm(em);
+    }
+
+    /**
+     * TO BE TESTED LATER WITH A DIFF DATABASE
+     * public void testMemberOfExpr(){}
+     */
+
+    public void testExistExpr() {
+        EntityManager em = currentEntityManager();
+
+        String query = "SELECT DISTINCT o.name FROM CompUser o WHERE EXISTS" +
+            " (SELECT c FROM Address c WHERE c = o.address )";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("the list is null", result);
+        assertEquals("they are not equal", 5, result.size());
+        assertTrue("Seetha is not list", result.contains("Seetha"));
+        assertTrue("Shannon is not list", result.contains("Shannon"));
+        assertTrue("jacob is not list", result.contains("Jacob"));
+        assertTrue("ugo is not list", result.contains("Ugo"));
+
+        endEm(em);
+    }
+
+    public void testNotExistExpr() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT DISTINCT o.name FROM CompUser o WHERE NOT EXISTS" +
+                " (SELECT s FROM CompUser s WHERE s.address.country = o.address.country)";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("list is null", result);
+        assertEquals("they are not equal", 0, result.size());
+
+        endEm(em);
+    }
+
+    public void testAnyExpr() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT o.name FROM CompUser o WHERE o.address.zipcode = ANY (" +
+                " SELECT s FROM CompUser s WHERE s.address.country IS NOT NULL )";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull("list is null", result);
+        assertEquals("they are not equal", 0, result.size());
+
+        endEm(em);
+    }
+
+    public void testConstructorExpr() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT NEW persistence.common.apps.MaleUser(c.name, c.computerName, c.address, c.age, c.userid)" +
+                " FROM CompUser c WHERE c.name = 'Seetha'";
+
+        MaleUser male = (MaleUser) em.createQuery(query).getSingleResult();
+
+        assertNotNull("the list is null", male);
+        assertEquals("the names dont match", "Seetha", male.getName());
+        assertEquals("computer names dont match", "MAC",
+            male.getComputerName());
+        assertEquals("the ages dont match", 40, male.getAge());
+
+        endEm(em);
+    }
+
+    public CompUser createUser(String name, String cName, Address add, int age,
+        boolean isMale) {
+        CompUser user = null;
+        if (isMale) {
+            user = new MaleUser();
+            user.setName(name);
+            user.setComputerName(cName);
+            user.setAddress(add);
+            user.setAge(age);
+        } else {
+            user = new FemaleUser();
+            user.setName(name);
+            user.setComputerName(cName);
+            user.setAddress(add);
+            user.setAge(age);
+        }
+        return user;
+	}
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/functions/TestEJBQLFunction.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/functions/TestEJBQLFunction.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/functions/TestEJBQLFunction.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/functions/TestEJBQLFunction.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,397 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.jpql.functions;
+
+import java.util.List;
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.common.apps.Address;
+import org.apache.openjpa.persistence.common.apps.CompUser;
+import org.apache.openjpa.persistence.common.apps.FemaleUser;
+import org.apache.openjpa.persistence.common.apps.MaleUser;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBQLFunction extends AbstractTestCase {
+
+    private int userid1, userid2, userid3, userid4, userid5, userid6;
+
+    public TestEJBQLFunction(String name) {
+        super(name, "jpqlclausescactusapp");
+    }
+
+    public void setUp() {
+        deleteAll(CompUser.class);
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        Address[] add = new Address[]{
+            new Address("43 Sansome", "SF", "United-Kingdom", "94104"),
+            new Address("24 Mink", "ANTIOCH", "USA", "94513"),
+            new Address("23 Ogbete", "CoalCamp", "NIGERIA", "00000"),
+            new Address("10 Wilshire", "Worcester", "CANADA", "80080"),
+            new Address("23 Bellflower", "Ogui", null, "02000"),
+            new Address("22 Montgomery", "SF", null, "50054") };
+
+        CompUser user1 = createUser("Seetha", "MAC", add[0], 36, true);
+        CompUser user2 = createUser("Shannon ", "PC", add[1], 36, false);
+        CompUser user3 = createUser("Ugo", "PC", add[2], 19, true);
+        CompUser user4 = createUser("_Jacob", "LINUX", add[3], 10, true);
+        CompUser user5 = createUser("Famzy", "UNIX", add[4], 29, false);
+        CompUser user6 = createUser("Shade", "UNIX", add[5], 23, false);
+
+        em.persist(user1);
+        userid1 = user1.getUserid();
+        em.persist(user2);
+        userid2 = user2.getUserid();
+        em.persist(user3);
+        userid3 = user3.getUserid();
+        em.persist(user4);
+        userid4 = user4.getUserid();
+        em.persist(user5);
+        userid5 = user5.getUserid();
+        em.persist(user6);
+        userid6 = user6.getUserid();
+
+        endTx(em);
+        endEm(em);
+    }
+
+    public void testConcatSubStringFunc() {
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        CompUser user = em.find(CompUser.class, userid1);
+        assertNotNull("user is null", user);
+        assertEquals("the name is not seetha", "Seetha", user.getName());
+
+        String query = "UPDATE CompUser e SET e.name = " +
+            "CONCAT('Ablahum', SUBSTRING(e.name, LOCATE('e', e.name), 4)) " +
+            "WHERE e.name='Seetha'";
+        int result = em.createQuery(query).executeUpdate();
+
+        assertEquals("the result is not 1", 1, result);
+
+        user = em.find(CompUser.class, userid1);
+        em.refresh(user);
+
+        assertNotNull("the user is null", user);
+        assertEquals("the users name is not AblahumSeet", "Ablahumeeth",
+            user.getName());
+
+        endTx(em);
+        endEm(em);
+    }
+
+    public void testConcatFunc2() {
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        CompUser user = em.find(CompUser.class, userid1);
+        assertNotNull("the user is null", user);
+        assertEquals("the users name is not seetha", user.getName(), "Seetha");
+
+        String query = "UPDATE CompUser e " +
+            "SET e.name = " +
+            "CONCAT('', '') WHERE e.name='Seetha'";
+        int result = em.createQuery(query).executeUpdate();
+
+        assertEquals(1, result);
+
+        user = em.find(CompUser.class, userid1);
+        em.refresh(user);
+        assertNotNull(user);
+        assertEquals("", user.getName());
+
+        endTx(em);
+        endEm(em);
+    }
+
+    public void testTrimFunc3() {
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        CompUser user = em.find(CompUser.class, userid2);
+        assertNotNull(user);
+        assertEquals("Shannon ", user.getName());
+
+        String query = "UPDATE CompUser e SET " +
+            "e.name = Trim(e.name) WHERE " +
+            "e.name='Shannon '";
+        int result = em.createQuery(query).executeUpdate();
+
+        user = em.find(CompUser.class, userid2);
+        em.refresh(user);
+        assertNotNull(user);
+        assertEquals("Shannon", user.getName());
+
+        endTx(em);
+        endEm(em);
+    }
+
+    public void testLowerFunc() {
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        CompUser user = em.find(CompUser.class, userid3);
+        assertNotNull(user);
+        assertEquals("Ugo", user.getName());
+
+        String query = "UPDATE CompUser e SET " +
+            "e.name = LOWER(e.name) WHERE e.name='Ugo'";
+
+        int result = em.createQuery(query).executeUpdate();
+
+        user = em.find(CompUser.class, userid3);
+        em.refresh(user);
+        assertNotNull(user);
+        assertEquals("ugo", user.getName());
+
+        endTx(em);
+        endEm(em);
+    }
+
+    public void testUpperFunc() {
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        CompUser user = em.find(CompUser.class, userid3);
+        assertNotNull(user);
+        assertEquals("Ugo", user.getName());
+
+        String query = "UPDATE CompUser e SET " +
+            "e.name = UPPER(e.name) WHERE e.name='Ugo'";
+
+        int result = em.createQuery(query).executeUpdate();
+
+        user = em.find(CompUser.class, userid3);
+        em.refresh(user);
+        assertNotNull(user);
+        assertEquals("UGO", user.getName());
+
+        endTx(em);
+        endEm(em);
+    }
+
+    public void testLengthFunc() {
+        EntityManager em = currentEntityManager();
+
+        String query = "SELECT o.name " +
+            "FROM CompUser o " +
+            "WHERE LENGTH(o.address.country) = 3";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        assertTrue(result.contains("Shannon "));
+
+        endEm(em);
+    }
+
+    public void testArithmFunc() {
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        CompUser user = em.find(CompUser.class, userid1);
+
+        assertNotNull(user);
+        assertEquals("Seetha", user.getName());
+        assertEquals(36, user.getAge());
+
+        String query =
+            "UPDATE CompUser e SET e.age = ABS(e.age) WHERE e.name='Seetha'";
+        int num = em.createQuery(query).executeUpdate();
+
+        assertNotNull(num);
+        assertEquals(1, num);
+
+        user = em.find(CompUser.class, userid1);
+        em.refresh(user);
+
+        assertEquals(36, user.getAge());
+
+        //----------------------ABS Tested
+
+        query =
+            "UPDATE CompUser e SET e.age = SQRT(e.age) WHERE e.name='Seetha'";
+        num = em.createQuery(query).executeUpdate();
+
+        assertNotNull(num);
+        assertEquals(1, num);
+
+        user = em.find(CompUser.class, userid1);
+        em.refresh(user);
+
+        assertEquals(6, user.getAge());
+
+        //-------------------------SQRT Tested
+
+        query =
+            "UPDATE CompUser e SET e.age = MOD(e.age, 4) WHERE e.name='Seetha'";
+        num = em.createQuery(query).executeUpdate();
+
+        assertNotNull(num);
+        assertEquals(1, num);
+
+        user = em.find(CompUser.class, userid1);
+        em.refresh(user);
+
+        assertEquals(2, user.getAge());
+
+        //-------------------------MOD Tested
+
+        query = "SELECT e.name FROM CompUser e WHERE SIZE(e.nicknames) = 6";
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(0, result.size());
+
+        //------------------------SIZE Tested
+
+        endTx(em);
+        endEm(em);
+    }
+
+    public void testGroupByHavingClause() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT c.name FROM CompUser c GROUP BY c.name HAVING c.name LIKE 'S%'";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(3, result.size());
+        assertTrue(result.contains("Shannon "));
+        assertTrue(result.contains("Shade"));
+        assertTrue(result.contains("Seetha"));
+
+        endEm(em);
+    }
+
+    public void testOrderByClause() {
+        EntityManager em = currentEntityManager();
+
+        String query =
+            "SELECT c.name FROM CompUser c WHERE c.name LIKE 'S%' ORDER BY c.name";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(3, result.size());
+        assertTrue(result.contains("Shannon "));
+        assertTrue(result.contains("Seetha"));
+        assertTrue(result.contains("Shade"));
+
+        endEm(em);
+    }
+
+    public void testAVGAggregFunc() {
+        /**
+         * To be Tested: AVG, COUNT, MAX, MIN, SUM
+         */
+
+        EntityManager em = currentEntityManager();
+
+        String query = "SELECT AVG(e.age) FROM CompUser e";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        assertTrue(result.contains(25));
+
+        endEm(em);
+    }
+
+    public void testCOUNTAggregFunc() {
+        EntityManager em = currentEntityManager();
+
+        String query = "SELECT COUNT(c.name) FROM CompUser c";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        assertTrue(result.contains(6l));
+
+        endEm(em);
+    }
+
+    public void testMAXAggregFunc() {
+        EntityManager em = currentEntityManager();
+
+        String query = "SELECT DISTINCT MAX(c.age) FROM CompUser c";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        assertTrue(result.contains(36));
+
+        endEm(em);
+    }
+
+    public void testMINAggregFunc() {
+        EntityManager em = currentEntityManager();
+
+        String query = "SELECT DISTINCT MIN(c.age) FROM CompUser c";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        assertTrue(result.contains(10));
+
+        endEm(em);
+    }
+
+    public void testSUMAggregFunc() {
+        EntityManager em = currentEntityManager();
+
+        String query = "SELECT SUM(c.age) FROM CompUser c";
+
+        List result = em.createQuery(query).getResultList();
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        assertTrue(result.contains(153l));
+
+        endEm(em);
+    }
+
+    public CompUser createUser(String name, String cName, Address add, int age,
+        boolean isMale) {
+        CompUser user = null;
+        if (isMale) {
+            user = new MaleUser();
+            user.setName(name);
+            user.setComputerName(cName);
+            user.setAddress(add);
+            user.setAge(age);
+        } else {
+            user = new FemaleUser();
+            user.setName(name);
+            user.setComputerName(cName);
+            user.setAddress(add);
+            user.setAge(age);
+        }
+        return user;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/joins/TestEJBJoins.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/joins/TestEJBJoins.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/joins/TestEJBJoins.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/joins/TestEJBJoins.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.jpql.joins;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.common.apps.ArtCourse;
+import org.apache.openjpa.persistence.common.apps.Course;
+import org.apache.openjpa.persistence.common.apps.Department;
+import org.apache.openjpa.persistence.common.apps.Student;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBJoins extends AbstractTestCase {
+
+    public TestEJBJoins(String name) {
+        super(name, "jpqlclausescactusapp");
+    }
+
+    public void setUp() {
+        deleteAll(Course.class);
+        deleteAll(Student.class);
+        deleteAll(Department.class);
+
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        String name = "";
+        List<Course> clist = new ArrayList<Course>();
+        List<Department> dlist = new ArrayList<Department>();
+
+        for (int i = 0; i < 5; i++) {
+            Course curr = new Course("Math " + i, i * 2, i);
+            Course acurr = new ArtCourse(i + 20, "English" + (2 * i));
+            Department durr = new Department("CompSci" + i, null, i + 2);
+            clist.add(curr);
+            clist.add(acurr);
+            dlist.add(durr);
+        }
+
+        Student stud = new Student("Jonathan", clist, dlist);
+        Student stud2 = new Student("Stam", null, dlist);
+        Student stud3 = new Student("John", clist, null);
+        Student stud4 = new Student("Bill", null, null);
+
+        em.persist(stud);
+        em.persist(stud2);
+        em.persist(stud3);
+        em.persist(stud4);
+
+        endTx(em);
+        endEm(em);
+    }
+
+    public void testInnerJoin() {
+        EntityManager em = currentEntityManager();
+        String query = "SELECT distinct o.name from Student o JOIN " +
+            "o.course d WHERE d.name" +
+            "='Math 4'";
+
+        List ls = (List) em.createQuery(query)
+            .getResultList();
+
+        assertNotNull(ls);
+
+        if (ls != null) {
+            assertEquals(2, ls.size());
+        }
+        endEm(em);
+    }
+
+    public void testOuterJoin() {
+        EntityManager em = currentEntityManager();
+        String query = "SELECT distinct s.name FROM Student " +
+            "s LEFT JOIN s.department d";
+
+        List ls = (List) em.createQuery(query)
+            .getResultList();
+
+        assertNotNull(ls);
+        assertEquals(4, ls.size());
+
+        endEm(em);
+    }
+
+    public void testFetchJoin1() {
+        EntityManager em = currentEntityManager();
+        String query = "SELECT s FROM Student s JOIN FETCH s.name";
+
+        List ls = em.createQuery(query).getResultList();
+
+        assertNotNull(ls);
+        assertEquals(4, ls.size());
+
+        endEm(em);
+    }
+
+    public void testFetchJoin2() {
+        EntityManager em = currentEntityManager();
+        String query = "SELECT s " +
+            "FROM Student s " +
+            "JOIN FETCH s.name d";
+
+        try {
+            List ls = em.createQuery(query).getResultList();
+            fail(
+                "Not permitted to specify an id variable for entities ref. by the right side of fetch join");
+        }
+        catch (Exception e) {
+            //suppose to throw an exception..should not pass
+        }
+
+        endEm(em);
+    }
+
+    public void testLeftOuterJoin() {
+        EntityManager em = currentEntityManager();
+
+        String ljoin =
+            "SELECT DISTINCT s.name FROM Student s LEFT OUTER JOIN s.department d " +
+                "WHERE d.name = 'CompSci2'";
+
+        List ls = em.createQuery(ljoin).getResultList();
+
+        assertNotNull(ls);
+        assertEquals(2, ls.size());
+
+        assertTrue(ls.contains("Jonathan"));
+        assertTrue(ls.contains("Stam"));
+
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/BaseKernelTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/BaseKernelTest.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/BaseKernelTest.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/BaseKernelTest.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,211 @@
+/*
+ * BaseKernelTest.java
+ *
+ * Created on October 9, 2006, 12:56 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.*;
+import javax.management.IntrospectionException;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.lib.conf.Configurations;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.kernel.common.apps.*;
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public abstract class BaseKernelTest extends org.apache.openjpa.persistence.common.utils.AbstractTestCase
+{    
+    private static Map _sysprops = new HashMap();    
+    
+    /** Creates a new instance of BaseKernelTest */
+    public BaseKernelTest() {
+    }
+    
+    public BaseKernelTest(String name) {
+        super(name, "kernelcactusapp");
+    }
+    
+    protected OpenJPAEntityManager getPM() {
+        return currentEntityManager();
+    }
+    
+    protected OpenJPAEntityManager getPM(boolean optimistic,boolean retainValues) 
+    {
+        OpenJPAEntityManager em = currentEntityManager();
+        em.setNontransactionalRead(true);
+        em.setRetainState(retainValues);
+        if(em.getTransaction().isActive())
+        {
+            em.getTransaction().commit();
+            em.setOptimistic(optimistic);
+        }
+
+        return em;
+    }
+    
+    protected  OpenJPAStateManager getStateManager(Object obj,EntityManager pm) {
+        return getStateManager(obj,pm);
+    }
+    
+    protected Object persist(Object ob) {
+        //FIXME  - this is just a workaround 
+        //  Broker broker = .getBrokerFactory().newBroker();
+        Broker broker = JPAFacadeHelper.toBroker(currentEntityManager());
+        broker.begin();
+        broker.persist(ob, null);
+        Object id = broker.getObjectId(ob);
+        broker.commit();
+        broker.close();
+        return id;
+    }
+    
+
+    protected Properties getProperties() {
+        return getProperties(null);
+    }
+
+    /**
+     * Return the runtime properties, optionally overriding or setting
+     * some via the given array, which should be in the form
+     * { key, val, key, val, ... }.
+     */
+    protected synchronized Properties getProperties(String[] props) {
+        Properties p = new Properties(System.getProperties());
+        String str = p.getProperty("openjpa.properties", "kodo.properties");
+        if (str != null && str.length() > 0) {
+            // cache system properties to reduce load on file system
+            Properties loaded = (Properties) _sysprops.get(str);
+            if (loaded == null) {
+                loaded = new Properties();
+                ConfigurationProvider cp = (ConfigurationProvider) Configurations.getProperty(str, null);
+
+                if (cp != null)
+                    loaded.putAll(cp.getProperties());
+                _sysprops.put(str, loaded);
+            }
+            p.putAll(loaded);
+        }
+
+        for (int i = 0; props != null && i < props.length; i += 2) {
+            if (props[i + 1] != null) {
+                // remove any duplicate kodo/openjpa property so we don't clash
+                if (props[i].startsWith("openjpa."))
+                    p.remove("openjpa." + props[i].substring(5));
+                else if (props[i].startsWith("openjpa."))
+                    p.remove("openjpa." + props[i].substring(8));
+
+                p.setProperty(props[i], props[i + 1]);
+            } else {
+                p.remove(props[i]);
+            }
+        }
+        return p;
+    }
+//
+//
+//    /**
+//     * Assert that the given List contain the exact same
+//     * elements. This is different than the normal List contract, which
+//     * states that list1.equals(list2) if each element e1.equals(e2).
+//     * This method asserts that e1 == n2.
+//     */
+//    public static void assertIdentical(List c1, List c2) {
+//        assertEquals(c1.size(), c2.size());
+//        for (Iterator i1 = c1.iterator(), i2 = c2.iterator();
+//            i1.hasNext() && i2.hasNext();)
+//            assertTrue(i1.next() == i2.next());
+//    }
+//
+//    /**
+//     * Assert that the collection parameter is already ordered
+//     * according to the specified comparator.
+//     */
+//    public void assertOrdered(Collection c, Comparator comp) {
+//        List l1 = new LinkedList(c);
+//        List l2 = new LinkedList(c);
+//        assertEquals(l1, l2);
+//        Collections.sort(l2, comp);
+//        assertEquals(l1, l2);
+//        Collections.sort(l1, comp);
+//        assertEquals(l1, l2);
+//    }
+//
+//    ////////////////////
+//    // Assertion Helpers
+//    ////////////////////
+//
+//    public void assertNotEquals(Object a, Object b) {
+//        if (a == null && b != null)
+//            return;
+//        if (a != null && b == null)
+//            return;
+//        if (!(a.equals(b)))
+//            return;
+//        if (!(b.equals(a)))
+//            return;
+//
+//        fail("expected !<" + a + ">.equals(<" + b + ">)");
+//    }
+//
+//    public void assertSize(int size, Object ob) {
+//        if (ob == null) {
+//            assertEquals(size, 0);
+//            return;
+//        }
+//
+//        if (ob instanceof Collection)
+//            ob = ((Collection) ob).iterator();
+//        if (ob instanceof Iterator) {
+//            Iterator i = (Iterator) ob;
+//            int count = 0;
+//            while (i.hasNext()) {
+//                count++;
+//                i.next();
+//            }
+//
+//            assertEquals(size, count);
+//        } else
+//            fail("assertSize: expected Collection, Iterator, "
+//                + "Query, or Extent, but got "
+//                + ob.getClass().getName());
+//    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/Test2EJBConcurrency.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/Test2EJBConcurrency.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/Test2EJBConcurrency.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/Test2EJBConcurrency.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import javax.persistence.EntityManager;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.Entity1;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class Test2EJBConcurrency extends AbstractTestCase {
+
+    private Object _id = null;
+
+    public Test2EJBConcurrency(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    public void setUp() throws Exception {
+        deleteAll(Entity1.class);
+
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        Entity1 b = new Entity1(3, "STRING", 10);
+        em.persist(b);
+        em.flush();
+
+        endTx(em);
+        endEm(em);
+    }
+
+    /**
+     * Test optimistic concurrency.
+     */
+    public void testOptConcurrency1()
+        throws Exception {
+        EntityManager em1 = currentEntityManager();
+        startTx(em1);
+
+        EntityManager em2 = currentEntityManager();
+        startTx(em2);
+
+        Entity1 b1 = (Entity1) em1.find(Entity1.class, 3);
+        b1.setStringField("STRING2");
+        endTx(em1);
+        assertEquals("b1.getstringField is not STRING2 as exp.", "STRING2",
+            b1.getStringField());
+
+        Entity1 b2 = (Entity1) em2.find(Entity1.class, 3);
+        assertEquals("b2.getstringField is not STRING2 as exp.", "STRING2",
+            b2.getStringField());
+        b2.setStringField("STRING3");
+        endTx(em2);
+        assertEquals("b2.getstringField is not STRING3 as exp.", "STRING3",
+            b2.getStringField());
+
+        startTx(em1);
+        b1 = (Entity1) em1.find(Entity1.class, 3);
+        em1.refresh(b1);
+        assertEquals("b1.getstringField is not STRING3 as exp.", "STRING2",
+            b1.getStringField());
+        b1.setStringField("STRING4");
+        endTx(em1);
+
+        b2 = (Entity1) em2.find(Entity1.class, 3);
+        assertEquals("b2.getstringField is not STRING3 as exp.", "STRING3",
+            b2.getStringField());
+
+        endEm(em1);
+        endEm(em2);
+    }
+
+    /**
+     *	Test optimistic concurrency.
+     */
+//	public void testOptConcurrency2 ()
+//		throws Exception
+//	{
+//		EntityManager em1 = currentEntityManager();		
+//		startTx(em1);
+//
+//		EntityManager em2 = currentEntityManager();		
+//		startTx(em2);
+//
+//		Entity1 b1 = (Entity1) em1.find (Entity1.class, 3);
+//		Entity1 b2 = (Entity1) em2.find (Entity1.class, 3);
+//
+//		assertEquals ("b1.getstringField is not STRING as exp.","STRING", b1.getStringField ());
+//		assertEquals ("b2.getstringField is not STRING as exp.","STRING", b2.getStringField ());
+//
+//		b1.setStringField ("STRING2");
+//		endTx(em1);
+//		assertEquals ("b1.getstringField is not STRING as exp.","STRING2", b1.getStringField ());
+//
+//		assertEquals ("b2.getstringField is not STRING as exp.","STRING", b2.getStringField ());
+//		b2.setStringField ("STRING3");
+//
+//		try
+//		{
+//			endTx(em2);
+//			fail ("OL Violation");
+//		}
+//		catch (Exception ole)
+//		{
+//			// expected
+//		}
+//		
+//		rollbackTx(em2);
+//		
+//
+//    	b2 = (Entity1) em2.find (Entity1.class, 3);
+//		assertEquals ("b2.getstringField is not STRING2 as exp.","STRING2", b2.getStringField ());
+//    	
+//		endEm(em1);
+//		endEm(em2);
+//	}
+}
+

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestAbstractMappedAppIdSuper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestAbstractMappedAppIdSuper.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestAbstractMappedAppIdSuper.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestAbstractMappedAppIdSuper.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,85 @@
+/*
+ * TestAbstractMappedAppIdSuper.java
+ *
+ * Created on October 16, 2006, 2:00 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+
+
+
+
+public class TestAbstractMappedAppIdSuper extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestAbstractMappedAppIdSuper
+     */
+    public TestAbstractMappedAppIdSuper(String name) {
+        super(name);
+    }
+
+    /* Fix Me - aokeke - Takes so much time to run */
+//    public void testQuerySubclassWithDifferentIdClass()
+//    throws Exception {
+//        ConcreteMappedAppIdSub pc = new ConcreteMappedAppIdSub();
+//        String pk = String.valueOf(System.currentTimeMillis());
+//        pc.setPk(pk);
+//        pc.setName("name");
+//        
+//        OpenJPAEntityManager pm = getPM();
+//        pm.begin();
+//        pm.persist(pc);
+//        pm.commit();
+//        String pkd = pc.getPk();
+//        Object oid = pm.getObjectId(pc);
+//        endEm(pm,());
+//        
+//        pm = getPM();
+//        String query = "SELECT DISTINCT o FROM ConcreteMappedAppIdSub o WHERE o.pk = :p ";
+//        OpenJPAQuery q = pm.createQuery(query);
+//        
+////        OpenJPAQuery q = pm.createNativeQuery("pk == :p", ConcreteMappedAppIdSub.class);
+//        //FIXME jthomas
+//        
+//        try 
+//        {
+//            pc = (ConcreteMappedAppIdSub) q.setParameter("p", pkd).getSingleResult();
+//        } 
+//        catch (RuntimeException re) 
+//        {
+////            bug(1170, re, "Cannot query subclass of abstract mapped "
+////                    + "appid type.");
+////            return;
+//        }
+//         
+//        assertNotNull(pc);
+//        assertEquals(pk, pc.getPk());
+//        
+//        pm.begin();
+//        pm.remove(pc);
+//        pm.commit();
+//        endEm(pm,());
+//    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestArrayValues2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestArrayValues2.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestArrayValues2.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestArrayValues2.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,466 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import java.lang.reflect.Array;
+import java.text.Collator;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Date;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.ArraysTest;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+import junit.framework.AssertionFailedError;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+/**
+ * Test varying kinds of array values.
+ *
+ * @author Marc Prud'hommeaux
+ * @author Abe White
+ */
+public class TestArrayValues2 extends BaseKernelTest {
+
+    private static double DOUBLE_PRECISION = 0.01D;
+    public static float FLOAT_PRECISION = 0.01F;
+
+    public void testStringArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        String[] array = new String[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomString();
+        saveArray(array, false, false);
+    }
+
+    public void testLongArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        Long[] array = new Long[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomLong();
+        try {
+            saveArray(array, false, false);
+        } catch (AssertionFailedError afe) {
+        }
+    }
+
+    public void testLongPrimitiveArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        long[] array = new long[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomLong().longValue();
+        try {
+            saveArray(array, true, false);
+        } catch (AssertionFailedError afe) {
+        }
+    }
+
+    public void testShortArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        Short[] array = new Short[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomShort();
+        saveArray(array, false, false);
+    }
+
+    public void testShortPrimitiveArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        short[] array = new short[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomShort().shortValue();
+        saveArray(array, true, false);
+    }
+
+    public void testIntArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        Integer[] array = new Integer[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomInt();
+        saveArray(array, false, false);
+    }
+
+    public void testIntPrimitiveArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        int[] array = new int[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomInt().intValue();
+        saveArray(array, true, false);
+    }
+// FixMe: Both tests hangs on Mysql
+    /*public void testByteArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        Byte[] array = new Byte[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomByte();
+        saveArray(array, false, false);
+    }
+
+    public void testBytePrimitiveArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        byte[] array = new byte[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomByte().byteValue();
+        saveArray(array, true, false);
+    }*/
+
+    public void testBooleanArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        Boolean[] array = new Boolean[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomBoolean();
+        saveArray(array, false, false);
+    }
+
+    public void testCharacterArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        Character[] array = new Character[max];
+        array[0] = new Character((char) 1);
+        for (int i = 1; i < max; i++)
+            array[i] = randomChar();
+        saveArray(array, false, false);
+    }
+
+    public void testCharacterPrimitiveArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        char[] array = new char[max];
+        array[0] = 1;
+        for (int i = 1; i < max; i++)
+            array[i] = randomChar().charValue();
+        saveArray(array, true, false);
+    }
+
+    public void testCharacterPrimitiveClobArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        char[] array = new char[max];
+        array[0] = 1;
+        for (int i = 1; i < max; i++)
+            array[i] = randomChar().charValue();
+        saveArray(array, true, true);
+    }
+
+    public void testBooleanPrimitiveArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        boolean[] array = new boolean[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomBoolean().booleanValue();
+        saveArray(array, true, false);
+    }
+
+    public void testFloatArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        Float[] array = new Float[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomFloat();
+        saveArray(array, false, false);
+    }
+
+    public void testFloatPrimitiveArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        float[] array = new float[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomFloat().floatValue();
+        saveArray(array, true, false);
+    }
+
+    public void testDoubleArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        Double[] array = new Double[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomDouble();
+        saveArray(array, false, false);
+    }
+
+    public void testDoublePrimitiveArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        double[] array = new double[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomDouble().doubleValue();
+        saveArray(array, true, false);
+    }
+
+    public void testDateArray()
+        throws Exception {
+        int max = ((int) (Math.random() * 20)) + 5;
+        Date[] array = new Date[max];
+        for (int i = 0; i < max; i++)
+            array[i] = randomDate();
+        saveArray(array, false, false);
+    }
+
+    /*Fix Me aokeke - Takes a lot of time to run */
+//    public void testFirstClassObjectArray()throws Exception 
+//    {
+//        int max = ((int) (Math.random() * 20)) + 5;
+//        ArraysTest[] array = new ArraysTest[max];
+//        for (int i = 0; i < max; i++)
+//            array[i] = new ArraysTest();
+//        saveArray(array, false, false);
+//    }
+
+    private void saveArray(Object array, boolean primitive, boolean lob)
+        throws Exception {
+        try {
+            saveArrayInternal(array, primitive, lob);
+        } catch (Exception e) {
+            throw e;
+        } catch (Error error) {
+            throw error;
+        } finally {
+            //
+        }
+    }
+
+    private void saveArrayInternal(Object vals, boolean primitive, boolean lob)
+        throws Exception {
+        Object[] array;
+        if (primitive)
+            array = convertPrimitiveArray(vals);
+        else
+            array = (Object[]) vals;
+        Arrays.sort(array, new TestArraySorter());
+
+        OpenJPAEntityManager pm =
+            (OpenJPAEntityManager) currentEntityManager();
+        startTx(pm);
+
+        ArraysTest test = new ArraysTest();
+        pm.persist(test);
+        int testID = test.getId();
+
+        setGetTestArray(test, vals, primitive, lob, true);
+        endTx(pm);
+
+        pm = (OpenJPAEntityManager) currentEntityManager();
+        startTx(pm);
+        ArraysTest retrievedObject = pm.find(ArraysTest.class, testID);
+
+        Object retrievedVals = setGetTestArray(retrievedObject, vals,
+            primitive, lob, false);
+        Object[] retrievedArray;
+        if (primitive)
+            retrievedArray = convertPrimitiveArray(retrievedVals);
+        else
+            retrievedArray = (Object[]) retrievedVals;
+
+        assertNotNull(retrievedArray);
+        assertTrue(array.length != 0);
+        assertEquals(array.length, retrievedArray.length);
+        assertNotNull(array[0]);
+        assertNotNull(retrievedArray[0]);
+
+        // make sure the classes of the keys are the same.
+        assertEquals(array[0].getClass(), retrievedArray[0].getClass());
+        Arrays.sort(retrievedArray, new TestArraySorter());
+        for (int i = 0; i < array.length; i++)
+            assertClassAndValueEquals(array[i], retrievedArray[i]);
+
+        pm.remove(retrievedObject);
+        endTx(pm);
+    }
+
+    private Object[] convertPrimitiveArray(Object array) throws Exception {
+        int length = Array.getLength(array);
+        Class type = Array.get(array, 0).getClass();
+
+        Object[] copy = (Object[]) Array.newInstance(type, length);
+        for (int i = 0; i < length; i++)
+            copy[i] = Array.get(array, i);
+
+        return copy;
+    }
+
+    private void assertClassAndValueEquals(Object o1, Object o2) {
+        assertTrue("First object was null", o1 != null);
+        assertTrue("Second object was null", o2 != null);
+
+        assertTrue("Types did not match (class1="
+            + o1.getClass().getName() + ", class2="
+            + o2.getClass().getName() + ")",
+            o1.getClass().isAssignableFrom(o2.getClass()));
+
+        // floats and doubles are a little special: we only
+        // compare them to a certain precision, after which
+        // we give up.
+        if (o1 instanceof Double)
+            assertEquals(((Double) o1).doubleValue(),
+                ((Double) o2).doubleValue(),
+                DOUBLE_PRECISION);
+        else if (o1 instanceof Float)
+            assertEquals(((Float) o1).floatValue(),
+                ((Float) o2).floatValue(),
+                FLOAT_PRECISION);
+        else
+            assertEquals("Object did not match (class1="
+                + o1.getClass().getName() + ", class2="
+                + o2.getClass().getName() + ")",
+                o1, o2);
+    }
+
+    /**
+     * Generic setter/getter for setting the array.
+     */
+    private Object setGetTestArray(ArraysTest test, Object array,
+        boolean primitive, boolean lob, boolean doSet)
+        throws Exception {
+        if (array == null)
+            return null;
+
+        Object first = Array.get(array, 0);
+        if (first instanceof Date) {
+            if (doSet)
+                test.setDate((Date[]) array);
+            return test.getDate();
+        } else if (first instanceof String) {
+            if (doSet)
+                test.setString((String[]) array);
+            return test.getString();
+        } else if (first instanceof Character) {
+            if (doSet && !primitive)
+                test.setCharacter((Character[]) array);
+            else if (doSet && !lob)
+                test.setCharacterP((char[]) array);
+            else if (doSet)
+                test.setCharacterPClob((char[]) array);
+            else if (!primitive)
+                return test.getCharacter();
+            else if (!lob)
+                return test.getCharacterP();
+            else
+                return test.getCharacterPClob();
+            return null;
+        } else if (first instanceof Double) {
+            if (doSet && !primitive)
+                test.setDouble((Double[]) array);
+            else if (doSet)
+                test.setDoubleP((double[]) array);
+            else if (!primitive)
+                return test.getDouble();
+            else
+                return test.getDoubleP();
+            return null;
+        } else if (first instanceof Byte) {
+            if (doSet && !primitive)
+                test.setByte((Byte[]) array);
+            else if (doSet)
+                test.setByteP((byte[]) array);
+            else if (!primitive)
+                return test.getByte();
+            else
+                return test.getByteP();
+            return null;
+        } else if (first instanceof Float) {
+            if (doSet && !primitive)
+                test.setFloat((Float[]) array);
+            else if (doSet)
+                test.setFloatP((float[]) array);
+            else if (!primitive)
+                return test.getFloat();
+            else
+                return test.getFloatP();
+            return null;
+        } else if (first instanceof Long) {
+            if (doSet && !primitive)
+                test.setLong((Long[]) array);
+            else if (doSet)
+                test.setLongP((long[]) array);
+            else if (!primitive)
+                return test.getLong();
+            else
+                return test.getLongP();
+            return null;
+        } else if (first instanceof Integer) {
+            if (doSet && !primitive)
+                test.setInt((Integer[]) array);
+            else if (doSet)
+                test.setIntP((int[]) array);
+            else if (!primitive)
+                return test.getInt();
+            else
+                return test.getIntP();
+            return null;
+        } else if (first instanceof Short) {
+            if (doSet && !primitive)
+                test.setShort((Short[]) array);
+            else if (doSet)
+                test.setShortP((short[]) array);
+            else if (!primitive)
+                return test.getShort();
+            else
+                return test.getShortP();
+            return null;
+        } else if (first instanceof Boolean) {
+            if (doSet && !primitive)
+                test.setBoolean((Boolean[]) array);
+            else if (doSet)
+                test.setBooleanP((boolean[]) array);
+            else if (!primitive)
+                return test.getBoolean();
+            else
+                return test.getBooleanP();
+            return null;
+        } else if (first instanceof ArraysTest) {
+            if (doSet)
+                test.setArraysTest((ArraysTest[]) array);
+            return test.getArraysTest();
+        }
+
+        fail("Unknown array type");
+        return null;
+    }
+
+    private static class TestArraySorter
+        implements Comparator {
+
+        private Collator collator = Collator.getInstance();
+
+        public int compare(Object o1, Object o2) {
+            if (o1.equals(o2))
+                return 0;
+
+            if (o1 instanceof Number) {
+                return ((Number) o1).doubleValue() >
+                    ((Number) o2).doubleValue() ? 1 : -1;
+            } else if (o1 instanceof Date) {
+                return ((Date) o1).before((Date) o2) ? 1 : -1;
+            } else if (o1 instanceof ArraysTest) {
+                return ((ArraysTest) o1).compareTo(o2);
+            }
+            return collator.compare(o1.toString(), o2.toString());
+        }
+    }
+}
+

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBigDecimals.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBigDecimals.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBigDecimals.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBigDecimals.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,125 @@
+/*
+ * TestBigDecimals.java
+ *
+ * Created on October 9, 2006, 6:07 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import java.math.BigDecimal;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.AllFieldTypesTest;
+import junit.framework.AssertionFailedError;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestBigDecimals extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestBigDecimals
+     */
+    public TestBigDecimals() {
+    }
+
+    public TestBigDecimals(String name) {
+        super(name);
+    }
+
+    public void testBigDecimalDataIntegrity()
+        throws Exception {
+        try {
+            BigDecimal bd = new BigDecimal(Math.random() * 10000000 + "");
+            bd = bd.setScale(100);
+            for (int i = 0; i < 50; i++) {
+                bd = bd.movePointLeft(1);
+                bigDecimalTest(bd);
+            }
+        }
+        catch (AssertionFailedError e) {
+            bug(3, e, "Precision loss for BigDecimals");
+        }
+    }
+//    FixMe aokeke: Passes but takes a long time --commenting for resource sake
+//    public void testBigBigDecimals()
+//        throws Exception {
+//        try {
+//            BigDecimal bd = new BigDecimal("1234567890."
+//                + "12345678901234567890123456789012345678901234567890"
+//                + "12345678901234567890123456789012345678901234567890");
+//
+//            bigDecimalTest(bd);
+//        } catch (AssertionFailedError e) {
+//            bug(3, e, "Precision loss for BigDecimals");
+//        }
+//    }
+
+    public void bigDecimalTest(final BigDecimal bd) {
+        OpenJPAEntityManager pm = null, pm2 = null;
+
+        try {
+            pm = getPM();
+            startTx(pm);
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestBigDecimal(bd);
+            pm.persist(aftt);
+            endTx(pm);
+            Object id = pm.getObjectId(aftt);
+            pm.evict(aftt);
+
+            pm2 = getPM();
+            startTx(pm);
+            AllFieldTypesTest aftt2 = (AllFieldTypesTest) pm2.getObjectId(id);
+
+            // why wouldn't they be two different objects?
+            assertTrue("identitcal field values",
+                bd != aftt2.getTestBigDecimal());
+
+            // this should always succeed
+            assertEquals(bd,
+                aftt2.getTestBigDecimal().setScale(bd.scale()));
+
+            // this will fail if we are losing scale
+            assertEquals(bd, aftt2.getTestBigDecimal());
+
+            rollbackTx(pm);
+        } catch (Throwable afe) {
+            bug(3, afe, "floating point precision loss");
+        } finally {
+            if (pm != null) {
+                //if (pm.getTransaction().isActive())
+                //rollbackTx(pm,());
+                endEm(pm);
+            }
+
+            if (pm2 != null) {
+                //if (pm2.getTransaction().isActive())
+                //rollbackTx(pm2,());
+                //pm2.close();
+                endEm(pm2);
+            }
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactoryPooling.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactoryPooling.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactoryPooling.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactoryPooling.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,50 @@
+/*
+ * TestBrokerFactoryPooling.java
+ *
+ * Created on October 9, 2006, 6:10 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+
+
+
+import org.apache.openjpa.kernel.Bootstrap;
+import org.apache.openjpa.kernel.BrokerFactory;
+
+public class TestBrokerFactoryPooling extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestBrokerFactoryPooling
+     */
+    public TestBrokerFactoryPooling(String name) {
+        super(name);
+    }
+
+    public void testPooling() {
+        BrokerFactory bf0 = Bootstrap.getBrokerFactory();
+        BrokerFactory bf1 = Bootstrap.getBrokerFactory();
+        assertSame(bf0, bf1);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCalendarFields.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCalendarFields.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCalendarFields.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCalendarFields.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,242 @@
+/*
+ * TestCalendarFields.java
+ *
+ * Created on October 9, 2006, 6:12 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.CalendarFields;
+
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.lib.util.JavaVersions;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestCalendarFields extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestCalendarFields
+     */
+    public TestCalendarFields(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(CalendarFields.class);
+    }
+
+    public void testFieldDefaultTimeZone() {
+        CalendarFields cal = new CalendarFields();
+
+        OpenJPAEntityManager pm;
+
+        pm = getPM();
+        startTx(pm);
+        cal.setSingapore(Calendar.
+            getInstance(TimeZone.getTimeZone("America/New_York")));
+        pm.persist(cal);
+        int id = cal.getId();
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        cal = (CalendarFields) pm.find(CalendarFields.class, id);
+        assertEquals(TimeZone.getTimeZone("Asia/Singapore"),
+            cal.getSingapore().getTimeZone());
+        endEm(pm);
+    }
+
+    public void testTimeZoneEquals() {
+        CalendarFields c1 = new CalendarFields();
+        CalendarFields c2 = new CalendarFields();
+        assertTimeZonesEquals(c1, c2);
+
+        OpenJPAEntityManager pm;
+
+        pm = getPM();
+        startTx(pm);
+        pm.persist(c2);
+        int id2 = c2.getId();
+        assertTimeZonesEquals(c1, c2);
+        endTx(pm);
+        assertTimeZonesEquals(c1, c2);
+        endEm(pm);
+
+        pm = getPM();
+        c2 = (CalendarFields) pm.find(CalendarFields.class, id2);
+        assertTimeZonesEquals(c1, c2);
+        assertTimeZonesEquals(c1, (CalendarFields) pm.detach(c2));
+        endEm(pm);
+    }
+
+    public void testCalendarQuery() {
+        long time = 1136660560572L;
+
+        CalendarFields cal = new CalendarFields();
+
+        OpenJPAEntityManager pm;
+
+        pm = getPM();
+        startTx(pm);
+        cal.getSingapore().setTime(new Date(time));
+        pm.persist(cal);
+        int id = cal.getId();
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+
+        //FIXME jthomas       
+        Date date = new Date(time + 100000);
+        Calendar cals = Calendar.getInstance();
+        cals.setTime(date);
+
+        String query =
+            "SELECT o FROM CalendarFields o WHERE o.singapore < :cal";
+        int size = pm.createQuery(query).setParameter("cal", cals).
+            getResultList().size();
+
+        assertEquals(1, size);
+
+//        assertSize(0, pm.newQuery(CalendarFields.class, "singapore < :date").execute(new Date(time - 100000)));
+//
+//        assertSize(0, pm.newQuery(CalendarFields.class, "singapore > :date").execute(new Date(time + 100000)));
+//        assertSize(1, pm.newQuery(CalendarFields.class, "singapore > :date").execute(new Date(time - 100000)));
+//
+//        assertSize(1, pm.newQuery(CalendarFields.class, "singapore < :date").execute(newCalendar(new Date(time + 100000), null)));
+//        assertSize(0, pm.newQuery(CalendarFields.class, "singapore < :date").execute(newCalendar(new Date(time - 100000), null)));
+//
+//        assertSize(0, pm.newQuery(CalendarFields.class, "singapore > :date").execute(newCalendar(new Date(time + 100000), null)));
+//        assertSize(1, pm.newQuery(CalendarFields.class, "singapore > :date").execute(newCalendar(new Date(time - 100000), null)));
+
+        endEm(pm);
+    }
+
+    private static Calendar newCalendar(Date date, String tz) {
+        Calendar cal = Calendar.getInstance(
+            tz == null ? TimeZone.getDefault() : TimeZone.getTimeZone(tz));
+        cal.setTime(date);
+        return cal;
+    }
+
+    public void testMutateCalendarDirties() {
+        CalendarFields c1 = new CalendarFields();
+
+        OpenJPAEntityManager pm;
+
+        pm = getPM();
+        startTx(pm);
+        pm.persist(c1);
+        int id = c1.getId();
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        c1 = pm.find(CalendarFields.class, id);
+
+        startTx(pm);
+
+        OpenJPAStateManager sm = getStateManager(c1, pm);
+
+        assertFalse(sm.getDirty().get(sm.getMetaData().
+            getField("gmt").getIndex()));
+
+        // test setting to same value doesn't dirty the field
+        /*
+        setTimeInMillis(c1.getGmtc1.getGmt().getTime().getTime());
+        c1.getGmt().setTime(c1.getGmt().getTime());
+        assertFalse(sm.getDirty().get(sm.getMetaData().
+            getField("gmt").getIndex()));
+        */
+
+        // test changing time
+        setTimeInMillis(c1.getGmt(), 12345);
+        assertTrue(sm.getDirty().get(sm.getMetaData().
+            getField("gmt").getIndex()));
+
+        assertFalse(sm.getDirty().get(sm.getMetaData().
+            getField("newYork").getIndex()));
+        // test mutate via "add()" method
+        c1.getNewYork().add(Calendar.SECOND, -1);
+        assertTrue(sm.getDirty().get(sm.getMetaData().
+            getField("newYork").getIndex()));
+
+        assertFalse(sm.getDirty().get(sm.getMetaData().
+            getField("berlin").getIndex()));
+        // test mutate via "setTimeZone()" method
+        c1.getBerlin().setTimeZone(TimeZone.getTimeZone("GMT"));
+        assertTrue(sm.getDirty().get(sm.getMetaData().
+            getField("berlin").getIndex()));
+
+        // Calendar.set can only be subclassed in JDK 1.4+ (it is final in
+        // 1.3), so we only run this test in JDK 1.4+
+        if (JavaVersions.VERSION >= 4) {
+            assertFalse(sm.getDirty().get(sm.getMetaData().
+                getField("singapore").getIndex()));
+            // test mutate via "set()" method
+            c1.getSingapore().set(Calendar.YEAR, 1998);
+            assertTrue(sm.getDirty().get(sm.getMetaData().
+                getField("singapore").getIndex()));
+        }
+
+        assertFalse(sm.getDirty().get(sm.getMetaData().
+            getField("pacific").getIndex()));
+        // test mutate via "roll()" method
+        c1.getPacific().roll(Calendar.YEAR, 5);
+        assertTrue(sm.getDirty().get(sm.getMetaData().
+            getField("pacific").getIndex()));
+
+        endTx(pm);
+        endEm(pm);
+    }
+
+    private static void setTimeInMillis(Calendar cal, long millis) {
+        // "setTimeInMillis" is protected in JDK 1.3, put public in 1.4 & 1.5
+        try {
+            // Equivalent to: cal.setTimeInMillis (millis);
+            cal.getClass().getMethod("setTimeInMillis",
+                new Class[]{ long.class }).invoke(cal,
+                new Object[]{ new Long(millis) });
+        } catch (Exception e) {
+            cal.setTime(new Date(millis));
+        }
+    }
+
+    private void assertTimeZonesEquals(CalendarFields c1, CalendarFields c2) {
+        for (int i = 0; i < c1.getCalendars().size(); i++) {
+            Calendar cal1 = (Calendar) c1.getCalendars().get(i);
+            Calendar cal2 = (Calendar) c2.getCalendars().get(i);
+
+            if (cal1 != null && cal2 != null)
+                assertEquals(cal1.getTimeZone().getID(),
+                    cal2.getTimeZone().getID());
+        }
+    }
+}



Mime
View raw message