openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [27/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/kernel/TestFetchPlan.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchPlan.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchPlan.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchPlan.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,526 @@
+/*
+ * TestFetchPlan.java
+ *
+ * Created on October 16, 2006, 3:02 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.Iterator;
+import java.util.List;
+import java.util.Set;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.PCAddress;
+import org.apache.openjpa.persistence.kernel.common.apps.PCCompany;
+import org.apache.openjpa.persistence.kernel.common.apps.PCCountry;
+import org.apache.openjpa.persistence.kernel.common.apps.PCDepartment;
+import org.apache.openjpa.persistence.kernel.common.apps.PCDirectory;
+import org.apache.openjpa.persistence.kernel.common.apps.PCEmployee;
+import org.apache.openjpa.persistence.kernel.common.apps.PCFile;
+import org.apache.openjpa.persistence.kernel.common.apps.PCPerson;
+
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestFetchPlan extends BaseKernelTest {
+
+    static Object _rootDirId;
+    static Object _rootCompanyId;
+
+    static final int MAX_DEPTH = 5; // Maximum depth of the directories
+    static final int MAX_CHILD = 3; // Maximum number of files/directory
+    static final String quote = "\"";
+    private static boolean firstTime = true;
+
+    /**
+     * Creates a new instance of TestFetchPlan
+     */
+    public TestFetchPlan() {
+    }
+
+    public TestFetchPlan(String name) {
+        super(name);
+    }
+
+    /**
+     * Clears past data and creates new data for test.
+     * Clear test data before and not <em>after</em> such that one can analyze
+     * the database for test failures.
+     */
+    public void setUp() throws Exception {
+        if (firstTime) {
+            firstTime = false;
+            clearTestData();
+            createTestData();
+        }
+    }
+
+    /**
+     * Create a directory tree of MAX_DEPTH with each directory having a single
+     * directory and MAX_CHILD files.
+     * Creates typical Employee-Department-Company-Address instances.
+     *
+     * @return the persitent identifier of the root directory.
+     */
+    void createTestData() {
+        // create a tree of directories with files in them
+        PCDirectory rootDir = new PCDirectory(getDirectoryName(0));
+        PCDirectory parent = rootDir;
+        for (int i = 1; i <= MAX_DEPTH; i++) {
+            PCDirectory dir = new PCDirectory(getDirectoryName(i));
+            parent.add(dir);
+
+            for (int j = 0; j < MAX_CHILD; j++)
+                parent.add(getFileName(j));
+
+            parent = dir;
+        }
+
+        // create a graph
+        //      | ---address-country
+        //      |
+        //  company-dept-employee-address-country
+        //
+        PCCountry country1 = new PCCountry("100", "Employee 1 Country");
+        PCCountry country2 = new PCCountry("200", "Employee 2 Country");
+        PCCountry ccountry = new PCCountry("300", "Company Country");
+
+        PCCompany company = new PCCompany("Company");
+
+        PCDepartment dept1 = new PCDepartment("Department1");
+        PCDepartment dept2 = new PCDepartment("Department2");
+
+        PCEmployee emp1 = new PCEmployee("Employee1");
+        PCEmployee emp2 = new PCEmployee("Employee2");
+
+        PCAddress addr1 = new PCAddress("Street1", "city1", country1);
+        PCAddress addr2 = new PCAddress("Street2", "city2", country2);
+        PCAddress caddr = new PCAddress("Street3", "city3", ccountry);
+
+        dept1.addEmployee(emp1);
+        dept2.addEmployee(emp2);
+
+        company.addDepartment(dept1);
+        company.addDepartment(dept2);
+
+        company.setAddress(caddr);
+
+        emp1.setAddress(addr1);
+        emp2.setAddress(addr2);
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        pm.persist(rootDir);
+        pm.persist(company);
+//        _rootDirId     = pm.getObjectId(rootDir);
+        _rootDirId = rootDir.getId();
+        assertNotNull(_rootDirId);
+//        _rootCompanyId = pm.getObjectId(company);
+        _rootCompanyId = company.getId();
+        assertNotNull(_rootCompanyId);
+        endTx(pm);
+        endEm(pm);
+    }
+
+    /**
+     * Test that the single valued field (_parent) is not traversed when the
+     * fecth group selects only the _name field.
+     */
+    public void testZeroRecursionDepthSingleValuedField() {
+        genericTestForSingleValuedRecursiveField("name", 4, 0);
+    }
+
+    /**
+     * Test that the single valued field (_parent) is traversed once and only
+     * once when the fecth group selects the _parent field with recursion depth
+     * of 1 (default).
+     */
+    public void testOneRecursionDepthSingleValuedField() {
+        genericTestForSingleValuedRecursiveField("name+parent", 4, 1);
+    }
+
+    /**
+     * Test that the single valued field (_parent) is traversed twice and only
+     * twice when the fecth group selects the _parent field with recursion depth
+     * of 2.
+     */
+    public void testTwoRecursionDepthSingleValuedField() {
+        genericTestForSingleValuedRecursiveField("name+parent+grandparent",
+            4, 2);
+    }
+
+    public void testThreeRecursionDepthSingleValuedField() {
+        genericTestForSingleValuedRecursiveField
+            ("name+parent+grandparent+greatgrandparent", 4, 3);
+    }
+
+    public void testInfiniteRecursionDepthSingleValuedField() {
+        genericTestForSingleValuedRecursiveField("allparents", 4, -1);
+    }
+
+    /**
+     * Generically tests recursive traversal of single-valued parent field.
+     *
+     * @param plan a plan that fetches L parents and no children
+     * @param rd the recursion depth of directory from the root
+     * @param fd the fetch depth = number of parents fetched
+     */
+    public void genericTestForSingleValuedRecursiveField(String plan, int rd,
+        int fd) {
+        PCDirectory result = queryDirectoryWithPlan(plan, rd, fd);
+
+        checkParents(result, rd, fd);
+
+        Object children = PCDirectory.reflect(result, "_children");
+        assertNull(children);
+    }
+
+    /**
+     * Query to obtain a single directory at the given depth.
+     * The directory name is constructed by the depth it occurs (d0 for root,
+     * d1 for depth 1 and so on).<BR>
+     * Checks the result for for matching name and size of the result (must
+     * be one).
+     *
+     * @param plan name of a fetch plan
+     * @param depth depth of the directory to be queried
+     * @return the selected directory.
+     */
+    PCDirectory queryDirectoryWithPlan(String plan, int rd, int fd) {
+        OpenJPAEntityManager pm = getPM();
+        pm.getFetchPlan().addFetchGroup(plan);
+        if (fd != 0)
+            pm.getFetchPlan().setMaxFetchDepth(fd);
+
+//        String filter = "_name == " + quoted(getDirectoryName(rd));        
+//        OpenJPAQuery query = pm.createNativeQuery(filter,PCDirectory.class);
+//        List result = (List) query.getResultList();
+
+        String query = "SELECT o FROM PCDirectory o WHERE o._name = '" +
+            getDirectoryName(rd) + "'";
+        List fresult = ((OpenJPAQuery) pm.createQuery(query)).getResultList();
+
+        assertEquals(1, fresult.size());
+        PCDirectory dir = (PCDirectory) fresult.get(0);
+
+        return dir;
+    }
+
+    /**
+     * Asserts that
+     * <LI> the given directory name matches the directory name at depth D.
+     * <LI> the parents upto L recursion is not null and beyond is
+     * null.
+     *
+     * @param result a directory to test
+     * @param D depth at which this directory appears
+     * @param L the number of live (fetched) parents. -1 denotes infinite
+     */
+    void checkParents(PCDirectory result, int D, int L) {
+
+        assertEquals("ge", getDirectoryName(D),
+            PCDirectory.reflect(result, "_name"));
+        PCDirectory[] parents = getParents(result, D);
+        int N = (L == -1) ? D : L;
+        for (int i = 0; i < N; i++) {
+            assertNotNull(i + "-th parent at depth " + D + " is null",
+                parents[i]);
+            assertEquals(getDirectoryName(D - i - 1),
+                PCDirectory.reflect(parents[i], "_name"));
+        }
+        for (int i = N; i < D; i++)
+            assertNull(i + "-th parent at depth " + D + " is not null " +
+                parents[i], parents[i]);
+    }
+
+    /**
+     * Gets an array of parents of the given directory. The zeroth element
+     * is the parent of the given directory and (i+1)-th element is the
+     * parent of the i-th element. Uses reflection to ensure that the
+     * side-effect does not cause a database access for the field.
+     *
+     * @param dir a starting directory
+     * @param depth depth to recurse. must be positive.
+     * @return
+     */
+    PCDirectory[] getParents(PCDirectory dir, int depth) {
+        PCDirectory[] result = new PCDirectory[depth];
+        PCDirectory current = dir;
+        for (int i = 0; i < depth; i++) {
+            result[i] = (PCDirectory) PCDirectory.reflect(current, "_parent");
+            current = result[i];
+        }
+        return result;
+    }
+
+    /**
+     * Checks that the first L elements of the given array is non-null and
+     * the rest are null.
+     *
+     * @param depth
+     */
+    void assertNullParent(PCDirectory[] parents, int L) {
+        for (int i = 0; i < L; i++)
+            assertNotNull(parents[i]);
+        for (int i = L; i < parents.length; i++)
+            assertNull(parents[i]);
+    }
+
+    String getDirectoryName(int depth) {
+        return "d" + depth;
+    }
+
+    String getFileName(int depth) {
+        return "f" + depth;
+    }
+
+    String quoted(String s) {
+        return quote + s + quote;
+    }
+
+    /**
+     * Defines a fetch plan that has several fetch groups to traverse a chain
+     * of relationships.
+     * After getting the root by an extent query, checks (by reflection) that
+     * all the relations in the chain are fetched.
+     * The fetch depth is kept infinite, so what would be fetched is essentially
+     * controlled by the fetch groups.
+     */
+    public void testRelationTraversal() {
+        OpenJPAEntityManager pm = getPM();
+        FetchPlan plan = pm.getFetchPlan();
+        pm.getFetchPlan().setMaxFetchDepth(-1);
+        plan.addFetchGroup("employee.department");
+        plan.addFetchGroup("department.company");
+        plan.addFetchGroup("company.address");
+        plan.addFetchGroup("address.country");
+
+        Iterator employees = pm.createExtent(PCEmployee.class, true).iterator();
+        while (employees.hasNext()) {
+            PCEmployee emp = (PCEmployee) employees.next();
+
+            PCDepartment dept = (PCDepartment) PCEmployee.reflect(emp,
+                "department");
+            assertNotNull(dept);
+
+            PCCompany company = (PCCompany) PCDepartment.reflect(dept,
+                "company");
+            assertNotNull(company);
+
+            PCAddress addr = (PCAddress) PCCompany.reflect(company, "address");
+            assertNotNull(addr);
+
+            PCCountry country = (PCCountry) PCAddress.reflect(addr, "country");
+            assertNotNull(country);
+        }
+    }
+
+    /**
+     * Defines a fetch plan that has several fetch groups to traverse a chain
+     * of relationships but truncated at the last relation.
+     * After getting the root by an extent query, checks (by reflection) that
+     * all but the last relation in the chain are fetched.
+     * The fetch depth is kept infinite, so what would be fetched is essentially
+     * controlled by the fetch groups.
+     */
+    public void testRelationTraversalTruncated() {
+        OpenJPAEntityManager pm = getPM();
+        FetchPlan plan = pm.getFetchPlan();
+        pm.getFetchPlan().setMaxFetchDepth(-1);
+        plan.addFetchGroup("employee.department");
+        plan.addFetchGroup("department.company");
+        plan.addFetchGroup("company.address");
+
+        Iterator employees = pm.createExtent(PCEmployee.class, true).iterator();
+        while (employees.hasNext()) {
+            PCEmployee emp = (PCEmployee) employees.next();
+
+            PCDepartment dept = (PCDepartment) PCEmployee.reflect(emp,
+                "department");
+            assertNotNull(dept);
+
+            PCCompany company = (PCCompany) PCDepartment.reflect(dept,
+                "company");
+            assertNotNull(company);
+
+            PCAddress addr = (PCAddress) PCCompany.reflect(company, "address");
+            assertNotNull(addr);
+
+            PCCountry country = (PCCountry) PCAddress.reflect(addr, "country");
+            assertNull(country);
+        }
+    }
+
+    /**
+     * Gets a Compnay object by getObjectById() method as opposed to query.
+     * The active fetch groups should bring in the multi-valued relationships.
+     * The address->country relationship can be reached in two alternate
+     * paths -- one as company->address->country and the other is
+     * company->department->employee->address->country.
+     * Though active fetch groups allow both the paths -- the max fetch depth
+     * is set such that the shorter path is taken but not the longer one.
+     * Hence the company's address->country should be loaded but not the
+     * employee's.
+     */
+    public void testRelationTraversalWithCompanyAsRoot() {
+        OpenJPAEntityManager pm = getPM();
+        FetchPlan plan = pm.getFetchPlan();
+
+        plan.setMaxFetchDepth(2);
+        plan.addFetchGroup("company.departments");
+        plan.addFetchGroup("company.address");
+        plan.addFetchGroup("department.employees");
+        plan.addFetchGroup("person.address");
+        plan.addFetchGroup("address.country");
+
+        PCCompany company =
+            (PCCompany) pm.find(PCCompany.class, _rootCompanyId);
+        Set departments = (Set) PCCompany.reflect(company, "departments");
+        assertNotNull("department is null", departments);
+        assertEquals("exp. depart size is not 2", 2, departments.size());
+        PCDepartment dept = (PCDepartment) departments.iterator().next();
+        assertNotNull("dept is null", dept);
+        Set employees = (Set) PCDepartment.reflect(dept, "employees");
+        assertNotNull("employees is null", employees);
+        assertEquals(1, employees.size());
+        PCEmployee emp = (PCEmployee) employees.iterator().next();
+        assertNotNull("emp is not null", emp);
+        PCAddress eaddr = (PCAddress) PCPerson.reflect(emp, "address");
+        PCAddress caddr = (PCAddress) PCCompany.reflect(company, "address");
+        assertNull("eaddr is not null", eaddr);
+        assertNotNull("caddr is null", caddr);
+        PCCountry country = (PCCountry) PCAddress.reflect(caddr, "country");
+        assertNotNull("country is null", country);
+    }
+
+    /**
+     * Same as above but the root compnay instance is detached.
+     */
+    public void testDetachedRelationTraversalWithCompanyAsRoot() {
+        OpenJPAEntityManager pm = getPM();
+        FetchPlan plan = pm.getFetchPlan();
+        pm.getFetchPlan().setMaxFetchDepth(2);
+        plan.addFetchGroup("company.departments");
+        plan.addFetchGroup("company.address");
+        plan.addFetchGroup("department.employees");
+        plan.addFetchGroup("person.address");
+        plan.addFetchGroup("address.country");
+
+        PCCompany company1 =
+            (PCCompany) pm.find(PCCompany.class, _rootCompanyId);
+
+        PCCompany company = (PCCompany) pm.detach(company1);
+        assertTrue("company is equal company1", company != company1);
+        Set departments = (Set) PCCompany.reflect(company, "departments");
+        assertNotNull("department is null", departments);
+        assertEquals("department size is not 2", 2, departments.size());
+        PCDepartment dept = (PCDepartment) departments.iterator().next();
+        assertNotNull("dept is null", dept);
+        Set employees = (Set) PCDepartment.reflect(dept, "employees");
+        assertNotNull("employee is null", employees);
+        assertEquals("employees size not 1", 1, employees.size());
+        PCEmployee emp = (PCEmployee) employees.iterator().next();
+        assertNotNull("emp is null", emp);
+        PCAddress eaddr = (PCAddress) PCPerson.reflect(emp, "address");
+        PCAddress caddr = (PCAddress) PCCompany.reflect(company, "address");
+        assertNull("eaddr is not null", eaddr);
+        assertNotNull("caddr is null", caddr);
+        PCCountry country = (PCCountry) PCAddress.reflect(caddr, "country");
+        assertNotNull("country is null", country);
+    }
+
+    public void testDefaultFetchGroup() {
+        OpenJPAEntityManager pm = getPM();
+
+        String squery =
+            "SELECT DISTINCT o FROM PCEmployee o WHERE o.name = 'Employee1'";
+        OpenJPAQuery q = pm.createQuery(squery);
+
+        //FIXME jthomas
+        PCEmployee person = (PCEmployee) q.getSingleResult();
+        assertEquals("Exp. String is not employee1", "Employee1",
+            PCPerson.reflect(person, "name"));
+    }
+
+    public void testDefaultFetchGroupExistsByDefault() {
+        OpenJPAEntityManager pm = getPM();
+        assertTrue("pm does not contain default fetchplan",
+            pm.getFetchPlan().getFetchGroups().contains(
+                FetchPlan.GROUP_DEFAULT));
+    }
+
+    public void testDefaultFetchGroupCanBeRemoved() {
+        OpenJPAEntityManager pm = getPM();
+        assertTrue("does not contain default fetchplan",
+            pm.getFetchPlan().getFetchGroups().contains(
+                FetchPlan.GROUP_DEFAULT));
+
+        pm.getFetchPlan().removeFetchGroup(FetchPlan.GROUP_DEFAULT);
+        assertFalse("does contain default fetchplan",
+            pm.getFetchPlan().getFetchGroups().contains(
+                FetchPlan.GROUP_DEFAULT));
+
+        OpenJPAEntityManager pm2 = getPM();
+        assertTrue("pm2 does not contain default fetchplan",
+            pm2.getFetchPlan().getFetchGroups().contains(
+                FetchPlan.GROUP_DEFAULT));
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    private void clearTestData() throws Exception {
+//        OpenJPAEntityManagerFactory pmf =(OpenJPAEntityManagerFactory) getEmf();
+//        OpenJPAConfiguration conf=pmf.getConfiguration();
+//        
+//        Class.forName(pmf.getConfiguration().getConnection2DriverName());
+//        String url=conf.getConnection2URL();
+//        String user=conf.getConnection2UserName();
+//        String pass=conf.getConnection2Password();
+//        
+//        Connection con = DriverManager.getConnection(
+//                url,
+//                user,
+//                pass);
+//        con.setAutoCommit(true);
+//        con.prepareStatement("DELETE FROM PCDIRECTORY").executeUpdate();
+//        con.prepareStatement("DELETE FROM PCFILE").executeUpdate();
+//        con.prepareStatement("DELETE FROM PCPERSON").executeUpdate();
+//        con.prepareStatement("DELETE FROM PCDEPARTMENT").executeUpdate();
+//        con.prepareStatement("DELETE FROM PCCOMPANY").executeUpdate();
+//        con.prepareStatement("DELETE FROM PCADDRESS").executeUpdate();
+//        con.prepareStatement("DELETE FROM PCCOUNTRY").executeUpdate();
+
+        deleteAll(PCDirectory.class);
+        deleteAll(PCFile.class);
+        deleteAll(PCPerson.class);
+        deleteAll(PCDepartment.class);
+        deleteAll(PCCompany.class);
+        deleteAll(PCAddress.class);
+        deleteAll(PCCountry.class);
+        deleteAll(PCEmployee.class);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldRange.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldRange.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldRange.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldRange.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,383 @@
+/*
+ * TestFieldRange.java
+ *
+ * Created on October 12, 2006, 10:14 AM
+ *
+ * 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.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.AllFieldTypesTest;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestFieldRange extends BaseKernelTest {
+
+    protected static String RANDOM_STRING =
+        "This is my test String with all "
+            + "kinds of wierd characters: "
+            + "!@@#$\\%^&\"*()-=\\|\"\"\"\"\"+_/?.>,<~`"
+            + "'''''''''''\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
+            + "''''''''''''\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
+            + "!@@#$\\%^&\"*()-=\\|+_/?.>,<~`";
+
+    /**
+     * Creates a new instance of TestFieldRange
+     */
+    public TestFieldRange() {
+    }
+
+    public TestFieldRange(String name) {
+        super(name);
+    }
+
+    public void setUp()
+        throws Exception {
+        super.setUp();
+        deleteAll(AllFieldTypesTest.class);
+    }
+
+    public void testSaveState()
+        throws Exception {
+        allFieldSaveState(
+            (int) 259645,
+            (short) 50849,
+            (long) 2349847982L,
+            (float) 43273423.0234723F,
+            (double) 34678.02384723D,
+            (byte) -120,
+            (boolean) true,
+            (char) '%',
+            (Date) new Date(),
+            (Serializable) new StringBuffer(5000),
+            (String) RANDOM_STRING,
+            randomBigInteger(),
+            randomBigDecimal());
+    }
+
+    /**
+     * Test to make sure all the numeric fields can accept the maximum
+     * values for their data size. Note that we subtract one from
+     * each of the values because some databases (like InstantDB)
+     * may consider them to be equivalent to NULL.
+     * FixMe: Hangs for some mysterious reason. aokeke
+     */
+
+//    public void testLargeNumbers()
+//    throws Exception {
+//        try {
+//            allFieldSaveState(
+//                    (int) (Integer.MAX_VALUE - 1),
+//                    (short) (Short.MAX_VALUE - 1),
+//                    (long) (Long.MAX_VALUE - 1l),
+//                    (float) (Float.MAX_VALUE - 1.0f),
+//                    (double) (Double.MAX_VALUE - 1.0d),
+//                    (byte) (Byte.MAX_VALUE),
+//                    (boolean) true,
+//                    (char) 'q',
+//                    (Date) new Date(),
+//                    (Serializable) new StringBuffer(5000),
+//                    (String) RANDOM_STRING,
+//                    randomBigInteger(),
+//                    randomBigDecimal());
+//        } catch (Throwable e) {
+//            bug(3, e, "doubles and floats");
+//        }
+//    }
+
+    /**
+     * Test to make sure all the numeric fields can be set to
+     * very low values. We add one to the minimim value because
+     * some databases (such as InstantDB) consider the MIN_VALUE
+     * to be equivalent to null. This is arguably a bug, but
+     * not a killer one.
+     */
+    public void testLargeNumbersNegative()
+        throws Exception {
+        allFieldSaveState(
+            (int) (Integer.MIN_VALUE + 1),
+            (short) (Short.MIN_VALUE + 1),
+            (long) (Long.MIN_VALUE + 1l),
+            (float) (Float.MIN_VALUE + 1.0f),
+            (double) (Double.MIN_VALUE + 1.0d),
+            (byte) (Byte.MIN_VALUE + 1),
+            (boolean) true,
+            (char) 'q',
+            (Date) new Date(),
+            (Serializable) new StringBuffer(5000),
+            (String) RANDOM_STRING,
+            randomBigInteger(),
+            randomBigDecimal());
+    }
+
+    public void testDoubleAndFloatPrecision()
+        throws Exception {
+        allFieldSaveState(
+            (int) (0),
+            (short) (0),
+            (long) (0l),
+            (float) (10.0f / 3.0f),
+            (double) (100.0d / 3.0d),
+            (byte) (0),
+            (boolean) true,
+            (char) 'q',
+            (Date) new Date(),
+            (Serializable) new StringBuffer(5000),
+            (String) RANDOM_STRING,
+            randomBigInteger(),
+            randomBigDecimal());
+    }
+
+    public void testZeroNumbers()
+        throws Exception {
+        allFieldSaveState(
+            (int) (0),
+            (short) (0),
+            (long) (0l),
+            (float) (0.0f),
+            (double) (0.0d),
+            (byte) (0),
+            (boolean) true,
+            (char) 'q',
+            (Date) new Date(),
+            (Serializable) new StringBuffer(5000),
+            (String) RANDOM_STRING,
+            new BigInteger("0"),
+            new BigDecimal("0.0"));
+    }
+
+    public void testLowDate()
+        throws Exception {
+        dateTest(0);
+    }
+
+    public void testCurDate()
+        throws Exception {
+        dateTest(System.currentTimeMillis());
+    }
+
+    public void testHighDate()
+        throws Exception {
+        try {
+            // postgres will sometimes store the String "invalid" if the
+            // date is too high, which will prevent us from even reading
+            // the records that contain this corrupt value (thus breaking
+            // any subsequent attempts to read instances of AllFieldTypesTest).
+            // An Example of a date like this is:
+            //   (Timestamp) 2038-02-08 22:20:07.65
+            if (getCurrentPlatform() ==
+                AbstractTestCase.Platform.POSTGRESQL)
+                fail("Postgres can't even try to store a high date");
+
+            dateTest(System.currentTimeMillis() * 2);
+        } catch (AssertionFailedError e) {
+            bug(6, e, "Some data stores cannot deal "
+                + "with very high dates");
+        }
+    }
+
+    /**
+     * Some date instances that have been known to have problems.
+     */
+    public void testProblematicDates()
+        throws Exception {
+        dateTest(1047744639);        // pointbase had probs with this
+    }
+
+    private void dateTest(long l)
+        throws Exception {
+        Date d = new Date(l);
+
+        allFieldSaveState(
+            (int) 10,
+            (short) 10,
+            (long) 10,
+            (float) 0,
+            (double) 0,
+            (byte) 10,
+            (boolean) true,
+            (char) 'x',
+            (Date) d,
+            (Serializable) new StringBuffer(10),
+            (String) RANDOM_STRING,
+            new BigInteger("0"),
+            new BigDecimal("0"));
+    }
+
+    public void allFieldSaveState(int testint, short testshort, long testlong,
+        float testfloat, double testdouble, byte testbyte,
+        boolean testboolean, char testchar, Date testDate,
+        Serializable testObject, String testString,
+        BigInteger testBigInteger, BigDecimal testBigDecimal)
+        throws Exception {
+        try {
+            allFieldSaveStateInternal(testint, testshort, testlong,
+                testfloat, testdouble, testbyte,
+                testboolean, testchar, testDate,
+                testObject, testString, testBigInteger, testBigDecimal);
+        } finally {
+            try {
+                // make *sure* we do not leave a transaction open
+                rollbackTx(getPM(true, false));
+            } catch (Throwable t) {
+
+            }
+        }
+    }
+
+    public void allFieldSaveStateInternal(
+        int testint, short testshort, long testlong,
+        float testfloat, double testdouble, byte testbyte,
+        boolean testboolean, char testchar, Date testDate,
+        Serializable testObject, String testString,
+        BigInteger testBigInteger, BigDecimal testBigDecimal)
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+
+        AllFieldTypesTest test = new AllFieldTypesTest();
+        pm.persist(test);
+        Object testID = pm.getObjectId(test);
+
+        test.setTestint(testint);
+        test.setTestlong(testlong);
+        test.setTestdouble(testdouble);
+        test.setTestshort(testshort);
+        test.setTestfloat(testfloat);
+        test.setTestbyte(testbyte);
+        test.setTestboolean(testboolean);
+        test.setTestchar(testchar);
+        test.setTestString(testString);
+        test.setTestDate(testDate);
+        test.setTestObject(testObject);
+        test.setTestBigInteger(testBigInteger);
+        test.setTestBigDecimal(testBigDecimal);
+
+        try {
+            endTx(pm);
+        } catch (Exception e) {
+            if (e instanceof Exception &&
+                ((Exception) e).getMessage().indexOf
+                    ("Maximum length is 8000") != -1) {
+                bug(AbstractTestCase.Platform.SQLSERVER, 5, e,
+                    "SQLServer cannot deal"
+                        + " with numbers with more than 8000 digits");
+            } else {
+                throw e;
+            }
+        }
+
+        endEm(pm);
+
+        //assertPersistent (test, true, false, false, false);
+
+        pm = getPM(true, false);
+        startTx(pm);
+
+        AllFieldTypesTest retrievedObject =
+            (AllFieldTypesTest) pm.find(AllFieldTypesTest.class, testID);
+
+        assertEquals("Field type int", testint,
+            retrievedObject.getTestint());
+        assertEquals("Field type short", testshort,
+            retrievedObject.getTestshort());
+        assertEquals("Field type boolean", testboolean,
+            retrievedObject.getTestboolean());
+        assertEquals("Field type char", testchar,
+            retrievedObject.getTestchar());
+        assertEquals("Field type long", testlong,
+            retrievedObject.getTestlong());
+
+        assertEquals("Field type byte", testbyte,
+            retrievedObject.getTestbyte());
+        assertEquals("Field type String", testString,
+            retrievedObject.getTestString());
+
+        int i1 = (int) (testDate.getTime() / 1000);
+        int i2 = (int) (retrievedObject.getTestDate().getTime() / 1000);
+
+        int testDateDay = testDate.getDay();
+        int testDateMonth = testDate.getMonth();
+        int testDateYear = testDate.getYear();
+
+        int retrievedObjectDay = retrievedObject.getTestDate().getDay();
+        int retrievedObjectMonth = retrievedObject.getTestDate().getMonth();
+        int retrievedObjectYear = retrievedObject.getTestDate().getYear();
+
+        System.out.println("i1 : " + i1 + "\ni2 : " + i2);
+
+        //CR346162. In this CR, it was stated that @Temporal(DATE) fields will be equal for year, month, day but not for hours, 
+        //minutes, seconds. So, we removed the time check and checked only for the equality of day, month and year
+
+        /* assertEquals("Field type Date: "
+     + testDate.getTime() + "!="
+     + retrievedObject.getTestDate().getTime()
+     + "[" + new Date(testDate.getTime()) + " != "
+     + new Date(retrievedObject.getTestDate().getTime()) + "]",
+     (int) (testDate.getTime() / 1000),
+     (int) (retrievedObject.getTestDate().getTime() / 1000));*/
+
+        if ((testDateDay != retrievedObjectDay) ||
+            (testDateMonth != retrievedObjectMonth) ||
+            (testDateYear != retrievedObjectYear)) {
+            Assert.fail(
+                "Field type Date not stored properly. One or more of the components of the date (day, month or year) do not match. \n" +
+                    " Value that should be stored : " + testDate.toGMTString() +
+                    ". \nValue that is actually" +
+                    "stored : " + retrievedObject.getTestDate().toGMTString());
+        }
+        //assertEquals ("Field type Object", testObject,
+        //retrievedObject.getTestObject ());
+        assertEquals("Field type BigInteger", testBigInteger,
+            retrievedObject.getTestBigInteger());
+
+        try {
+            assertEquals("Field type BigDecimal (BigInteger part)",
+                testBigDecimal.toBigInteger(),
+                retrievedObject.getTestBigDecimal().toBigInteger());
+
+            assertEquals("Field type BigDecimal",
+                testBigDecimal,
+                retrievedObject.getTestBigDecimal());
+
+            assertEquals("Field type float", testfloat,
+                retrievedObject.getTestfloat(), 0.01f);
+            assertEquals("Field type double", testdouble,
+                retrievedObject.getTestdouble(), 0.01d);
+        } catch (AssertionFailedError afe) {
+            bug(3, afe,
+                "Doubles and Floats lose precision in some data stores");
+        }
+
+        rollbackTx(pm);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldRange2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldRange2.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldRange2.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldRange2.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,232 @@
+/*
+ * TestFieldRange.java
+ *
+ * Created on October 12, 2006, 10:14 AM
+ *
+ * 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.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.AllFieldTypesTest;
+import junit.framework.AssertionFailedError;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestFieldRange2 extends BaseKernelTest {
+
+    protected static String RANDOM_STRING =
+        "This is my test String with all "
+            + "kinds of wierd characters: "
+            + "!@@#$\\%^&\"*()-=\\|\"\"\"\"\"+_/?.>,<~`"
+            + "'''''''''''\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
+            + "''''''''''''\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
+            + "!@@#$\\%^&\"*()-=\\|+_/?.>,<~`";
+
+    /**
+     * Creates a new instance of TestFieldRange
+     */
+    public TestFieldRange2() {
+    }
+
+    public TestFieldRange2(String name) {
+        super(name);
+    }
+
+    public void setUp()
+        throws Exception {
+        super.setUp();
+        deleteAll(AllFieldTypesTest.class);
+    }
+
+    public void testSaveState()
+        throws Exception {
+        allFieldSaveState(
+            (int) 259645,
+            (short) 50849,
+            (long) 2349847982L,
+            (float) 43273423.0234723F,
+            (double) 34678.02384723D,
+            (byte) -120,
+            (boolean) true,
+            (char) '%',
+            (Date) new Date(),
+            (Serializable) new StringBuffer(5000),
+            (String) RANDOM_STRING,
+            randomBigInteger(),
+            randomBigDecimal());
+    }
+
+    private void dateTest(long l)
+        throws Exception {
+        Date d = new Date(l);
+
+        allFieldSaveState(
+            (int) 10,
+            (short) 10,
+            (long) 10,
+            (float) 0,
+            (double) 0,
+            (byte) 10,
+            (boolean) true,
+            (char) 'x',
+            (Date) d,
+            (Serializable) new StringBuffer(10),
+            (String) RANDOM_STRING,
+            new BigInteger("0"),
+            new BigDecimal("0"));
+    }
+
+    public void allFieldSaveState(int testint, short testshort, long testlong,
+        float testfloat, double testdouble, byte testbyte,
+        boolean testboolean, char testchar, Date testDate,
+        Serializable testObject, String testString,
+        BigInteger testBigInteger, BigDecimal testBigDecimal)
+        throws Exception {
+        try {
+            allFieldSaveStateInternal(testint, testshort, testlong,
+                testfloat, testdouble, testbyte,
+                testboolean, testchar, testDate,
+                testObject, testString, testBigInteger, testBigDecimal);
+        } finally {
+            try {
+                // make *sure* we do not leave a transaction open
+                rollbackTx(getPM(true, false));
+            } catch (Throwable t) {
+
+            }
+        }
+    }
+
+    public void allFieldSaveStateInternal(
+        int testint, short testshort, long testlong,
+        float testfloat, double testdouble, byte testbyte,
+        boolean testboolean, char testchar, Date testDate,
+        Serializable testObject, String testString,
+        BigInteger testBigInteger, BigDecimal testBigDecimal)
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+
+        AllFieldTypesTest test = new AllFieldTypesTest();
+        //pm.persist(test);
+        //Object testID = pm.getObjectId(test);
+
+        test.setTestint(testint);
+        test.setTestlong(testlong);
+        test.setTestdouble(testdouble);
+        test.setTestshort(testshort);
+        test.setTestfloat(testfloat);
+        test.setTestbyte(testbyte);
+        test.setTestboolean(testboolean);
+        test.setTestchar(testchar);
+        test.setTestString(testString);
+        test.setTestDate(testDate);
+        test.setTestObject(testObject);
+        test.setTestBigInteger(testBigInteger);
+        test.setTestBigDecimal(testBigDecimal);
+
+        pm.persist(test);
+        Object testID = pm.getObjectId(test);
+
+        try {
+            endTx(pm);
+        } catch (Exception e) {
+            if (e instanceof Exception &&
+                ((Exception) e).getMessage().indexOf
+                    ("Maximum length is 8000") != -1) {
+                bug(5, e, "SQLServer cannot deal"
+                        + " with numbers with more than 8000 digits");
+            } else {
+                throw e;
+            }
+        }
+
+        endEm(pm);
+
+        //assertPersistent (test, true, false, false, false);
+
+        pm = getPM(true, false);
+        startTx(pm);
+
+        AllFieldTypesTest retrievedObject =
+            (AllFieldTypesTest) pm.find(AllFieldTypesTest.class, testID);
+
+        assertEquals("Field type int", testint,
+            retrievedObject.getTestint());
+        assertEquals("Field type short", testshort,
+            retrievedObject.getTestshort());
+        assertEquals("Field type boolean", testboolean,
+            retrievedObject.getTestboolean());
+        assertEquals("Field type char", testchar,
+            retrievedObject.getTestchar());
+        assertEquals("Field type long", testlong,
+            retrievedObject.getTestlong());
+
+        assertEquals("Field type byte", testbyte,
+            retrievedObject.getTestbyte());
+        assertEquals("Field type String", testString,
+            retrievedObject.getTestString());
+
+        int i1 = (int) (testDate.getTime() / 1000);
+        int i2 = (int) (retrievedObject.getTestDate().getTime() / 1000);
+
+        System.out.println("i1 : " + i1 + "\ni2 : " + i2);
+        assertEquals("Field type Date: "
+            + testDate.getTime() + "!="
+            + retrievedObject.getTestDate().getTime()
+            + "[" + new Date(testDate.getTime()) + " != "
+            + new Date(retrievedObject.getTestDate().getTime()) + "]",
+            (int) (testDate.getTime() / 1000),
+            (int) (retrievedObject.getTestDate().getTime() / 1000));
+        //assertEquals ("Field type Object", testObject,
+        //retrievedObject.getTestObject ());
+        assertEquals("Field type BigInteger", testBigInteger,
+            retrievedObject.getTestBigInteger());
+
+        try {
+            assertEquals("Field type BigDecimal (BigInteger part)",
+                testBigDecimal.toBigInteger(),
+                retrievedObject.getTestBigDecimal().toBigInteger());
+
+            assertEquals("Field type BigDecimal",
+                testBigDecimal,
+                retrievedObject.getTestBigDecimal());
+
+            assertEquals("Field type float", testfloat,
+                retrievedObject.getTestfloat(), 0.01f);
+            assertEquals("Field type double", testdouble,
+                retrievedObject.getTestdouble(), 0.01d);
+        } catch (AssertionFailedError afe) {
+            bug(3, afe,
+                "Doubles and Floats lose precision in some data stores");
+        }
+
+        rollbackTx(pm);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldState.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldState.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldState.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFieldState.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,81 @@
+/*
+ * TestFieldState.java
+ *
+ * Created on October 12, 2006, 10:22 AM
+ *
+ * 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.persistence.kernel.common.apps.RuntimeTest1;
+
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestFieldState extends BaseKernelTest {
+
+    private Object oid;
+
+    /**
+     * Creates a new instance of TestFieldState
+     */
+    public TestFieldState() {
+    }
+
+    public TestFieldState(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest1.class);
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+
+        // create a test object
+        RuntimeTest1 a = new RuntimeTest1("foo", 3);
+        pm.persist(a);
+
+        endTx(pm);
+
+        oid = pm.getObjectId(a);
+        endEm(pm);
+    }
+
+    public void testNotDirtyAfterSameChange() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+
+        RuntimeTest1 a = (RuntimeTest1) pm.find(RuntimeTest1.class, oid);
+        a.setStringField(a.getStringField());
+        OpenJPAStateManager sm = getStateManager(a, pm);
+        FieldMetaData fmd = sm.getMetaData().getField("stringField");
+        assertTrue(sm.getDirty().get(fmd.getIndex()) == false);
+
+        endTx(pm);
+        endEm(pm);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestGetObjectsById.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestGetObjectsById.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestGetObjectsById.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestGetObjectsById.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,88 @@
+/*
+ * TestGetObjectsById.java
+ *
+ * Created on October 12, 2006, 10:49 AM
+ *
+ * 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.persistence.kernel.common.apps.RuntimeTest4;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest5;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestGetObjectsById extends BaseKernelTest {
+
+    private Object[] oids;
+
+    /**
+     * Creates a new instance of TestGetObjectsById
+     */
+    public TestGetObjectsById(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest5.class);
+        deleteAll(RuntimeTest4.class);
+
+        RuntimeTest4 rt4 = new RuntimeTest4("foo");
+
+        RuntimeTest5 related0 = new RuntimeTest5("bar");
+        related0.setRuntimeTest4(rt4);
+        rt4.getRuntimeTest5s().add(related0);
+
+        RuntimeTest5 related1 = new RuntimeTest5("baz");
+        related1.setRuntimeTest4(rt4);
+        rt4.getRuntimeTest5s().add(related1);
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        pm.persist(rt4);
+        endTx(pm);
+        oids = new Object[]
+            {
+                pm.getObjectId(rt4),
+                pm.getObjectId(related0),
+                pm.getObjectId(related1),
+            };
+        endEm(pm);
+    }
+
+    public void testGetObjectsByIdInvocation() {
+        OpenJPAEntityManager pm = getPM();
+        try {
+            Object[] pcs = pm.findAll(Object.class, oids);
+            assertEquals(oids.length, pcs.length);
+            for (int i = 0; i < oids.length; i++)
+                assertEquals(oids[i], pm.getObjectId(pcs[i]));
+        } catch (Exception e) {
+            bug(1017, e, "getObjectsById() bug");
+        } finally {
+            endEm(pm);
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestIncrementalFlushes.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestIncrementalFlushes.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestIncrementalFlushes.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestIncrementalFlushes.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,448 @@
+/*
+ * TestIncrementalFlushes.java
+ *
+ * Created on October 12, 2006, 11:24 AM
+ *
+ * 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.persistence.kernel.common.apps.ModInstanceCallbackTests;
+import org.apache.openjpa.persistence.kernel.common.apps.ModRuntimeTest1;
+
+import org.apache.openjpa.event.AbstractTransactionListener;
+import org.apache.openjpa.event.TransactionEvent;
+import org.apache.openjpa.kernel.PCState;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+
+public class TestIncrementalFlushes extends BaseKernelTest {
+
+    public TestIncrementalFlushes(String str) {
+        super(str);
+    }
+
+    /**
+     * Creates a new instance of TestIncrementalFlushes
+     */
+    public TestIncrementalFlushes() {
+    }
+
+    public void setUp() {
+        deleteAll(ModRuntimeTest1.class);
+//        deleteAll(ModInstanceCallbackTests.class);
+    }
+
+    public void testBasicJdoPreStore() {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+        ModInstanceCallbackTests a = new ModInstanceCallbackTests("foo", 10);
+        pm.persist(a);
+        pm.flush();
+        assertTrue(a.preStoreCalled);
+        endTx(pm);
+    }
+
+    public void testNoFlush() {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+        ModInstanceCallbackTests a = new ModInstanceCallbackTests("foo", 10);
+        pm.persist(a);
+        endTx(pm);
+        assertTrue(a.preStoreCalled);
+    }
+
+    public void testFlushNoChange() {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+        ModInstanceCallbackTests a = new ModInstanceCallbackTests("foo", 10);
+        pm.persist(a);
+        pm.flush();
+        endTx(pm);
+        assertTrue(a.preStoreCalled);
+        assertEquals(10, a.getIntField());
+    }
+
+    /**
+     * Helper method for some common test cases. See utilizations of
+     * this below.
+     */
+    private void basicHelper(boolean update, boolean multi, boolean dfg,
+        boolean nonDFG) {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+
+        ModInstanceCallbackTests a = new ModInstanceCallbackTests("foo", 10);
+        pm.persist(a);
+        if (update) {
+            endTx(pm);
+            Object oid = pm.getObjectId(a);
+            endEm(pm);
+            pm = getPM(true, false);
+            startTx(pm);
+            a = (ModInstanceCallbackTests) pm
+                .find(ModInstanceCallbackTests.class, oid);
+        } else {
+            pm.flush();
+        }
+
+        if (dfg)
+            a.setIntField(11);
+        if (nonDFG)
+            a.setNonDFGField(11);
+
+        if (multi) {
+            pm.flush();
+
+            if (dfg)
+                a.setIntField(12);
+            if (nonDFG)
+                a.setNonDFGField(12);
+        }
+
+        endTx(pm);
+
+        // if no changes were made and we're in update mode, then this
+        // object won't have had jdoPreStore() called.
+//        if (!(update && (!dfg && !nonDFG)))
+//            assertTrue("a.prestoreCalled is false", a.preStoreCalled);
+
+        if (multi) {
+            if (dfg)
+                assertEquals("a.getIntField is not 12", 12, a.getIntField());
+            if (nonDFG)
+                assertEquals("a.getNonDFGField is not 12", 12,
+                    a.getNonDFGField());
+        } else {
+            if (dfg)
+                assertEquals("a.getIntField is not 12", 11, a.getIntField());
+            if (nonDFG)
+                assertEquals("a.getNonDFGField is not 12", 11,
+                    a.getNonDFGField());
+        }
+    }
+
+    public void testFlushStorePrimaryDFGChange() {
+        basicHelper(false, false, true, false);
+        basicHelper(false, true, true, false);
+        basicHelper(true, false, true, false);
+        basicHelper(true, true, true, false);
+    }
+
+    public void testFlushStorePrimaryNonDFGChange() {
+        basicHelper(false, false, false, true);
+        basicHelper(false, true, false, true);
+        basicHelper(true, false, false, true);
+        basicHelper(true, true, false, true);
+    }
+
+    public void testFlushStorePrimaryNonDFGAndDFGChange() {
+        basicHelper(false, false, true, true);
+        basicHelper(false, true, true, true);
+        basicHelper(true, false, true, true);
+        basicHelper(true, true, true, true);
+    }
+
+    public void testFlushStorePrimaryNoChanges() {
+        basicHelper(false, false, false, false);
+        basicHelper(false, true, false, false);
+        basicHelper(true, false, false, false);
+        basicHelper(true, true, false, false);
+    }
+
+    public void testJdoPreStoreWithModificationBeforeFlush() {
+        tjpswmHelper(true);
+    }
+
+    public void testJdoPreStoreWithModificationAfterFlush() {
+        tjpswmHelper(false);
+    }
+
+    private void tjpswmHelper(boolean before) {
+        // set retainvalues to false so that we can ensure that the
+        // data in the database is correct, and that we're not just
+        // testing that the JVM data is correct.
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+        ModInstanceCallbackTests a = new ModInstanceCallbackTests("foo", 10);
+        pm.persist(a);
+
+        // by setting the name to 'bar', the jdoPreStore() invocation
+        // will set the parent to a new object. This ensures that new
+        // objects created in jdoPreStore() make their way into the DB
+        // during commit.
+        if (before) {
+            a.setStringField("bar");
+            pm.flush();
+        } else {
+            pm.flush();
+            a.setStringField("bar");
+        }
+        endTx(pm);
+        assertTrue("a.preStoreCalled is false", a.preStoreCalled);
+        assertNotNull("a.getOneOne is null", a.getOneOne());
+        assertTrue("getOneOne().getstrngfld.equals(jdoPrestore) is false",
+            a.getOneOne().getStringField().equals("jdoPreStore"));
+    }
+
+    public void testOneToOneBefore() {
+        totoHelper(true, true, false);
+        totoHelper(true, false, false);
+        totoHelper(true, true, true);
+        totoHelper(true, false, true);
+    }
+
+    public void testOneToOneAfter() {
+        totoHelper(false, true, false);
+        totoHelper(false, false, false);
+        totoHelper(false, true, true);
+        totoHelper(false, false, true);
+    }
+
+    private void totoHelper(boolean before, boolean persist,
+        boolean multi) {
+        // set retainvalues to false so that we can ensure that the
+        // data in the database is correct, and that we're not just
+        // testing that the JVM data is correct.
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+        ModInstanceCallbackTests a = new ModInstanceCallbackTests("foo", 10);
+        pm.persist(a);
+
+        ModRuntimeTest1 parent = new ModRuntimeTest1("baz", 11);
+        if (!before)
+            pm.flush();
+
+        if (persist)
+            pm.persist(parent);
+
+        a.setOneOne(parent);
+
+        if (before)
+            pm.flush();
+
+        ModRuntimeTest1 oldParent = null;
+        if (multi) {
+            oldParent = parent;
+            parent = new ModRuntimeTest1("newParent", 12);
+
+            if (!before)
+                pm.flush();
+
+            if (persist)
+                pm.persist(parent);
+
+            a.setOneOne(parent);
+
+            if (before)
+                pm.flush();
+        }
+
+        endTx(pm);
+        assertTrue("a.preStoreCalled is false", a.preStoreCalled);
+        assertNotNull("a.getOneOne is null", a.getOneOne());
+        if (!multi)
+            assertTrue("a.getOneOne().getStringField().equals(baz) is false",
+                a.getOneOne().getStringField().equals("baz"));
+        else {
+            assertTrue(
+                "a.getOneOne().getStringField().equals(newParent) is false",
+                a.getOneOne().getStringField().equals("newParent"));
+
+            // if multi, then we really should delete the baz
+            // parent. This isn't happening right now.
+            // ### should be a bug
+            //assertTrue (JDOHelper.isDeleted (oldParent));
+        }
+    }
+
+    private void assertState(Object o, PCState state, OpenJPAEntityManager pm) {
+        assertEquals(state, getStateManager(o, pm).getPCState());
+    }
+
+    private void commitAndTestDelete(OpenJPAEntityManager pm, Object o) {
+        Object oid = pm.getObjectId(o);
+        endTx(pm);
+
+        pm = getPM();
+        try {
+            pm.find(Object.class, oid);
+            fail("should not be able to load deleted object");
+        } catch (Exception e) {
+            // expected case
+        }
+    }
+
+    public void testDeleteNew() {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+        ModRuntimeTest1 a = new ModRuntimeTest1("foo", 10);
+        pm.persist(a);
+        pm.remove(a);
+        assertState(a, PCState.PNEWDELETED, pm);
+    }
+
+    public void testOptimisticLockGivesCorrectError() {
+        OpenJPAEntityManager pm1 = getPM(true, false);
+        OpenJPAEntityManager pm2 = getPM(true, false);
+
+        ModRuntimeTest1 a1 = new ModRuntimeTest1("foo", 10);
+        startTx(pm1);
+        pm1.persist(a1);
+        endTx(pm1);
+
+        ModRuntimeTest1 a2 = (ModRuntimeTest1)
+            pm2.find(ModRuntimeTest1.class, pm2.getObjectId(a1));
+        startTx(pm2);
+        a2.setStringField("foobar");
+        endTx(pm2);
+
+        startTx(pm1);
+        a1.setStringField("foobarbaz");
+        try {
+            endTx(pm1);
+        } catch (Exception ole) {
+            // expected case
+        } finally {
+            rollbackTx(pm1);
+
+            pm1.close();
+            pm2.close();
+        }
+    }
+
+    /**
+     * Verify that flushes to the datastore are isolated from other
+     * PersistenceManagers. This is mostly a test of the underlying
+     * datastore's transactional isolation capabilities.
+     * <p/>
+     * Disabled: this hangs on Sybase.
+     */
+    public void XXXtestFlushesAreIsolated() {
+        final String name = "testFlushesAreIsolated";
+
+        deleteAll(ModRuntimeTest1.class);
+
+        OpenJPAEntityManager flushPM = getPM(true, false);
+        startTx(flushPM);
+
+        OpenJPAEntityManager readPM = getPM(true, false);
+        startTx(readPM);
+
+        assertSize(0, flushPM.createNativeQuery("stringField == '" + name + "'",
+            ModRuntimeTest1.class));
+        assertSize(0, readPM.createNativeQuery("stringField == '" + name + "'",
+            ModRuntimeTest1.class));
+
+        ModRuntimeTest1 a = new ModRuntimeTest1(name, randomInt().intValue());
+
+        flushPM.persist(a);
+
+        assertSize(0, readPM.createNativeQuery("name == '" + name + "'",
+            ModRuntimeTest1.class));
+
+        flushPM.flush();
+
+        // make sure the other pm doesn't see the flushed object
+        assertSize(0, readPM.createNativeQuery("name == '" + name + "'",
+            ModRuntimeTest1.class));
+
+        flushPM.remove(a);
+
+        assertSize(0, flushPM.createNativeQuery("name == '" + name + "'",
+            ModRuntimeTest1.class));
+        assertSize(0, readPM.createNativeQuery("name == '" + name + "'",
+            ModRuntimeTest1.class));
+
+        endTx(flushPM);
+        endEm(flushPM);
+
+        endTx(readPM);
+        endEm(readPM);
+    }
+
+    public void testEmptyFlush() {
+        OpenJPAEntityManager pm = getPM();
+        TListener listener = new TListener();
+        ((OpenJPAEntityManagerSPI) pm).addTransactionListener(listener);
+        startTx(pm);
+        ModRuntimeTest1 pc = new ModRuntimeTest1();
+        pm.persist(pc);
+        pm.flush();
+        assertEquals(1, listener.flushes);
+        assertEquals(0, listener.commits);
+
+        pm.flush();
+        assertEquals(1, listener.flushes);
+        assertEquals(0, listener.commits);
+
+        pc.setIntField(3);
+        pm.flush();
+        assertEquals(2, listener.flushes);
+        assertEquals(0, listener.commits);
+
+        endTx(pm);
+        assertEquals(2, listener.flushes);
+        assertEquals(1, listener.commits);
+
+        endEm(pm);
+    }
+
+    public void testEmptyRollback() {
+        OpenJPAEntityManager pm = getPM();
+        TListener listener = new TListener();
+        ((OpenJPAEntityManagerSPI) pm).addTransactionListener(listener);
+        startTx(pm);
+        pm.flush();
+        rollbackTx(pm);
+        assertEquals(0, listener.flushes);
+        assertEquals(0, listener.commits);
+        endEm(pm);
+    }
+
+    public void testEmptyCommit() {
+        OpenJPAEntityManager pm = getPM();
+        TListener listener = new TListener();
+        ((OpenJPAEntityManagerSPI) pm).addTransactionListener(listener);
+        startTx(pm);
+        endTx(pm);
+        assertEquals(0, listener.flushes);
+        assertEquals(1, listener.commits);
+        endEm(pm);
+    }
+
+    private static class TListener
+        extends AbstractTransactionListener {
+
+        public int flushes = 0;
+        public int commits = 0;
+
+        protected void eventOccurred(TransactionEvent event) {
+            if (event.getType() == event.BEFORE_FLUSH)
+                flushes++;
+            else if (event.getType() == event.BEFORE_COMMIT)
+                commits++;
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestIncrementalFlushesDeletes.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestIncrementalFlushesDeletes.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestIncrementalFlushesDeletes.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestIncrementalFlushesDeletes.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,137 @@
+/*
+ * TestIncrementalFlushesDeletes.java
+ *
+ * Created on October 12, 2006, 11:38 AM
+ *
+ * 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.persistence.kernel.common.apps.RuntimeTest1;
+
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.kernel.PCState;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestIncrementalFlushesDeletes extends BaseKernelTest {
+
+    private OpenJPAEntityManager pm;
+    private Object oid;
+    private RuntimeTest1 a;
+
+    public TestIncrementalFlushesDeletes(String str) {
+        super(str);
+    }
+
+    /**
+     * Creates a new instance of TestIncrementalFlushesDeletes
+     */
+    public TestIncrementalFlushesDeletes() {
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest1.class);
+
+        pm = getPM(true, false);
+        startTx(pm);
+        a = new RuntimeTest1("foo", 10);
+        pm.persist(a);
+        oid = pm.getObjectId(a);
+    }
+
+    public void tearDown() throws Exception {
+        endTx(pm);
+
+        OpenJPAEntityManager newPm = getPM();
+        try {
+            Object o = newPm.find(RuntimeTest1.class, oid);
+            if (o != null) {
+                fail("should not be able to load deleted object");
+            }
+        } catch (Exception e) {
+            // expected case
+        }
+
+        endEm(newPm);
+        endEm(pm);
+
+        super.tearDown();
+    }
+
+    private void assertState(PCState state, boolean flushed) {
+        OpenJPAStateManager sm = getStateManager(a, pm);
+        assertNotNull(sm);
+        assertEquals(flushed, sm.isFlushed());
+        assertEquals(state, sm.getPCState());
+    }
+
+    /**
+     * PNew => PNewDeleted
+     */
+    public void testNewDeleted() {
+        pm.remove(a);
+        assertState(PCState.PNEWDELETED, false);
+    }
+
+    /**
+     * PNew => PNewDeleted => PNewDeletedFlushed
+     */
+    public void testNewDeletedFlushed() {
+        pm.remove(a);
+        assertState(PCState.PNEWDELETED, false);
+        pm.flush();
+        assertState(PCState.PNEWDELETED, true);
+    }
+
+    /**
+     * PNew => PNewFlushed => PNewFlushedDeleted
+     */
+    public void testNewFlushedDeleted() {
+        pm.flush();
+        assertState(PCState.PNEW, true);
+        pm.remove(a);
+        assertState(PCState.PNEWFLUSHEDDELETED, true);
+    }
+
+    /**
+     * PNew => PNewFlushed => PNewFlushedDeleted => PNewFlushedDeletedFlushed
+     */
+    public void testNewFlushedDeletedFlushed() {
+        pm.flush();
+        assertState(PCState.PNEW, true);
+        pm.remove(a);
+        assertState(PCState.PNEWFLUSHEDDELETED, true);
+        pm.flush();
+        assertState(PCState.PNEWFLUSHEDDELETEDFLUSHED, true);
+    }
+
+/*
+* 	### some remaining test deletes:
+*		PDirty => PDeleted => PDeletedFlushed
+*		PDirty => (change and flush) PDirty => PDeleted => PDeletedFlushed
+*		PClean => PDeleted => PDeletedFlushed
+*		Hollow => PDeleted => PDeletedFlushed
+*/
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInheritance.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInheritance.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInheritance.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInheritance.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,148 @@
+/*
+ * TestInheritance.java
+ *
+ * Created on October 12, 2006, 11:46 AM
+ *
+ * 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.Collection;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest2;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest3;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestInheritance extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestInheritance
+     */
+    public TestInheritance() {
+    }
+
+    public TestInheritance(String name) {
+        super(name);
+    }
+
+    public void setUp()
+        throws Exception {
+        deleteAll(RuntimeTest1.class);
+        deleteAll(RuntimeTest2.class);
+        deleteAll(RuntimeTest3.class);
+
+        // create some instances to query on
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        pm.persist(new RuntimeTest1("RuntimeTest1-instance", 2));
+        pm.persist(new RuntimeTest2("RuntimeTest2-instance", 3));
+        pm.persist(new RuntimeTest3("RuntimeTest3-instance", 4));
+        endTx(pm);
+        endEm(pm);
+    }
+
+    /**
+     * Tests that we can get all three objects via an extent.
+     */
+    public void testGetAllRuntimeTest1s() {
+        OpenJPAEntityManager pm = getPM();
+        OpenJPAQuery q = pm.createQuery("SELECT o FROM RuntimeTest1 o");
+        Collection c = (Collection) q.getResultList();
+        assertEquals(3, c.size());
+        endEm(pm);
+    }
+
+    /**
+     * Tests that we can get all RuntimeTest2 objects via an extent.
+     */
+    public void testGetAllRuntimeTest2s() {
+        OpenJPAEntityManager pm = getPM();
+        OpenJPAQuery q = pm.createQuery("SELECT o FROM RuntimeTest2 o");
+        Collection c = (Collection) q.getResultList();
+        assertEquals(2, c.size());
+        endEm(pm);
+    }
+
+    /**
+     * Tests that we can get all RuntimeTest3 objects via an extent.
+     */
+    public void testGetAllRuntimeTest3s() {
+        OpenJPAEntityManager pm = getPM();
+        OpenJPAQuery q = pm.createQuery("SELECT o FROM RuntimeTest3 o");
+        Collection c = (Collection) q.getResultList();
+        assertEquals(1, c.size());
+        endEm(pm);
+    }
+
+    /**
+     * Tests that we can get just RuntimeTest1s via an extent.
+     */
+    public void testGetJustRuntimeTest1s() {
+        OpenJPAEntityManager pm = getPM();
+        OpenJPAQuery q = pm.createQuery("SELECT o FROM RuntimeTest1 o");
+        q.setSubclasses(false);
+
+//        OpenJPAQuery q = pm.createNativeQuery("",RuntimeTest1.class);
+//        FIXME jthomas
+//        q.setCandidates(pm.getExtent(RuntimeTest1.class, false));
+        Collection c = (Collection) q.getResultList();
+        assertEquals(1, c.size());
+        endEm(pm);
+    }
+
+    /**
+     * Tests that we can get just RuntimeTest2s via an extent.
+     */
+    public void testGetJustRuntimeTest2s() {
+        OpenJPAEntityManager pm = getPM();
+        OpenJPAQuery q = pm.createQuery("SELECT o FROM RuntimeTest2 o");
+        q.setSubclasses(false);
+
+//        FIXME jthomas        
+//        OpenJPAQuery q = pm.createNativeQuery("",RuntimeTest2.class);
+//        q.setCandidates(pm.createExtent(RuntimeTest2.class, false));
+        Collection c = (Collection) q.getResultList();
+        assertEquals(1, c.size());
+        endEm(pm);
+    }
+
+    /**
+     * Tests that we can get just RuntimeTest3s via an extent.
+     */
+    public void testGetJustRuntimeTest3() {
+        OpenJPAEntityManager pm = getPM();
+        OpenJPAQuery q = pm.createQuery("SELECT o FROM RuntimeTest3 o");
+        q.setSubclasses(false);
+
+//      FIXME jthomas
+//        OpenJPAQuery q = pm.createNativeQuery("",RuntimeTest3.class);
+//        q.setCandidates(pm.getExtent(RuntimeTest3.class, false));
+        Collection c = (Collection) q.getResultList();
+        assertEquals(1, c.size());
+        endEm(pm);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitialValueFetching.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitialValueFetching.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitialValueFetching.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitialValueFetching.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,181 @@
+/*
+ * TestInitialValueFetching.java
+ *
+ * Created on October 12, 2006, 11:58 AM
+ *
+ * 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.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.apache.openjpa.persistence.RestoreStateType;
+
+public class TestInitialValueFetching extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestInitialValueFetching
+     */
+    public TestInitialValueFetching(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest1.class);
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        RuntimeTest1 rt1 = new RuntimeTest1("TestInitialValueFetching", 10);
+        pm.persist(rt1);
+
+        rt1.setDateField(new Date());
+        endTx(pm);
+        endEm(pm);
+    }
+
+    public void testInitialValueString() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        RuntimeTest1 rt1 = getObject(pm);
+        OpenJPAStateManager sm = getStateManager(rt1, pm);
+        FieldMetaData fmd = sm.getMetaData().getField("stringField");
+        assertEquals("TestInitialValueFetching",
+            sm.fetchInitialField(fmd.getIndex()));
+        rt1.setStringField("TestInitialValueFetching-2");
+        assertEquals("TestInitialValueFetching",
+            sm.fetchInitialField(fmd.getIndex()));
+        endTx(pm);
+        assertEquals("TestInitialValueFetching-2",
+            sm.fetchInitialField(fmd.getIndex()));
+        endEm(pm);
+    }
+
+    public void testInitialValueInt() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        RuntimeTest1 rt1 = getObject(pm);
+        OpenJPAStateManager sm = getStateManager(rt1, pm);
+        FieldMetaData fmd = sm.getMetaData().getField("intField1");
+        assertEquals(10,
+            ((Integer) sm.fetchInitialField(fmd.getIndex())).intValue());
+        rt1.setIntField1(11);
+        assertEquals(10,
+            ((Integer) sm.fetchInitialField(fmd.getIndex())).intValue());
+        endTx(pm);
+        assertEquals(11,
+            ((Integer) sm.fetchInitialField(fmd.getIndex())).intValue());
+        endEm(pm);
+    }
+
+    public void testInitialValueMutableValueFailures() {
+        Map props = new HashMap();
+        props.put("openjpa.RestoreMutableValues", "false");
+        OpenJPAEntityManagerFactory pmf = (OpenJPAEntityManagerFactory)
+            getEmf(props);
+
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)
+            pmf.createEntityManager();
+        RuntimeTest1 rt1 = getObject(pm);
+
+        Date d = rt1.getDateField();
+        OpenJPAStateManager sm = getStateManager(rt1, pm);
+        FieldMetaData fmd = sm.getMetaData().getField("dateField");
+        try {
+            sm.fetchInitialField(fmd.getIndex());
+            fail("should get an exception if RestoreMutableValues is false");
+        } catch (org.apache.openjpa.util.UserException e) {
+            // expected
+        }
+        endEm(pm);
+        pmf.close();
+    }
+
+    public void testInitialValueDate() {
+        Map props = new HashMap();
+        props.put("openjpa.RestoreState", "all");
+        OpenJPAEntityManagerFactory pmf = (OpenJPAEntityManagerFactory)
+            getEmf(props);
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)
+            pmf.createEntityManager();
+        startTx(pm);
+        RuntimeTest1 rt1 = getObject(pm);
+
+        Date d = rt1.getDateField();
+
+        OpenJPAStateManager sm = getStateManager(rt1, pm);
+        FieldMetaData fmd = sm.getMetaData().getField("dateField");
+        assertEquals(d, sm.fetchInitialField(fmd.getIndex()));
+
+        // == should pass here since we haven't made any modifications.
+        assertTrue("mutable object fails == test; should not",
+            d == sm.fetchInitialField(fmd.getIndex()));
+
+        Date d2 = new Date();
+        rt1.setDateField(d2);
+        assertEquals(d, sm.fetchInitialField(fmd.getIndex()));
+        endTx(pm);
+        assertEquals(d2, sm.fetchInitialField(fmd.getIndex()));
+        assertTrue("mutable object passes == test; should not",
+            d2 != sm.fetchInitialField(fmd.getIndex()));
+        endEm(pm);
+    }
+
+    public void testInitialValueExceptions() {
+        OpenJPAEntityManager pm = getPM();
+        pm.setRestoreState(RestoreStateType.NONE);
+        startTx(pm);
+        RuntimeTest1 rt1 = getObject(pm);
+        OpenJPAStateManager sm = getStateManager(rt1, pm);
+        FieldMetaData fmd = sm.getMetaData().getField("stringField");
+        try {
+            sm.fetchInitialField(fmd.getIndex());
+            fail("exception should be thrown by KodoSM.fetchInitialField");
+        } catch (org.apache.openjpa.util.UserException e) {
+            // expected case
+        }
+        endTx(pm);
+        endEm(pm);
+    }
+
+    private RuntimeTest1 getObject(OpenJPAEntityManager pm) {
+//        return (RuntimeTest1) ((Collection) 
+//        		pm.createNativeQuery( "stringField == \"TestInitialValueFetching\"",RuntimeTest1.class)
+//        .getResultList()).iterator().next();
+
+        OpenJPAQuery q = pm.createQuery(
+            "SELECT o FROM RuntimeTest1 o WHERE o.stringField = \'TestInitialValueFetching\'");
+        List l = q.getResultList();
+
+        return (RuntimeTest1) l.iterator().next();
+    }
+}



Mime
View raw message