openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r747081 - in /openjpa/branches/1.2.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/ ...
Date Mon, 23 Feb 2009 16:59:22 GMT
Author: mikedd
Date: Mon Feb 23 16:59:22 2009
New Revision: 747081

URL: http://svn.apache.org/viewvc?rev=747081&view=rev
Log:
OPENJPA-838 re-committing Fay's changes. 

Added:
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNativeQueryProcedures.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java
Modified:
    openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
    openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java

Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java?rev=747081&r1=747080&r2=747081&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
(original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
Mon Feb 23 16:59:22 2009
@@ -26,11 +26,8 @@
 import java.util.Map;
 
 import org.apache.openjpa.enhance.PersistenceCapable;
-import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfigurationImpl;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.kernel.JDBCStoreManager;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.meta.FieldStrategy;
@@ -38,14 +35,11 @@
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.sql.Joins;
-import org.apache.openjpa.jdbc.sql.LogicalUnion;
 import org.apache.openjpa.jdbc.sql.Result;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.jdbc.sql.SelectExecutor;
-import org.apache.openjpa.jdbc.sql.SelectImpl;
 import org.apache.openjpa.jdbc.sql.Union;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
-import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.JavaTypes;
@@ -526,86 +520,19 @@
             return;
         }
 
-        //cache union for field here
         // select data for this sm
-        boolean found = true;
         final ClassMapping[] elems = getIndependentElementMappings(true);
         final Joins[] resJoins = new Joins[Math.max(1, elems.length)];
-        List parmList = null;
-        Union union = null;
-        SelectImpl sel = null;
-        Map<JDBCStoreManager.SelectKey, Object[]> storeCollectionUnionCache = null;
-        JDBCStoreManager.SelectKey selKey = null;
-        if (!((JDBCStoreManager)store).isQuerySQLCacheOn() || elems.length > 1)
-            union = newUnion(sm, store, fetch, elems, resJoins);
-        else {
-            parmList = new ArrayList();
-            JDBCFetchConfiguration fetchClone = new JDBCFetchConfigurationImpl();
-            fetchClone.copy(fetch);
-           
-            // to specify the type so that no cast is needed
-            storeCollectionUnionCache = ((JDBCStoreManager)store).
-                getCacheMapFromQuerySQLCache(StoreCollectionFieldStrategy.class);
-            selKey = 
-                new JDBCStoreManager.SelectKey(null, field, fetchClone);
-            Object[] objs = storeCollectionUnionCache.get(selKey);
-            if (objs != null) {
-                union = (Union) objs[0];
-                resJoins[0] = (Joins) objs[1];
-            }
-            else {
-                synchronized(storeCollectionUnionCache) {
-                    objs = storeCollectionUnionCache.get(selKey);
-                    if (objs == null) {
-                        // select data for this sm
-                        union = newUnion(sm, store, fetch, elems, resJoins);
-                        found = false;
-                    } else {
-                        union = (Union) objs[0];
-                        resJoins[0] = (Joins) objs[1];
-                    }
-
-                    sel = ((LogicalUnion.UnionSelect)union.getSelects()[0]).
-                        getDelegate();
-                    if (sel.getSQL() == null) {
-                    	((SelectImpl)sel).setSQL(store, fetch);
-                        found = false;
-                    }
-
-                    // only cache the union when elems length is 1 for now
-                    if (!found) { 
-                        Object[] objs1 = new Object[2];
-                        objs1[0] = union;
-                        objs1[1] = resJoins[0];
-                        ((JDBCStoreManager)store).addToSqlCache(
-                            storeCollectionUnionCache, selKey, objs1);
-                     }
-                }
-            }
-            
-            Log log = store.getConfiguration().
-                getLog(JDBCConfiguration.LOG_JDBC);
-            if (log.isTraceEnabled()) {
-                if (found)
-                    log.trace(_loc.get("cache-hit", field, this.getClass()));
-                else
-                    log.trace(_loc.get("cache-missed", field, this.getClass())); 
+        Union union = store.getSQLFactory().newUnion
+            (Math.max(1, elems.length));
+        union.select(new Union.Selector() {
+            public void select(Select sel, int idx) {
+                ClassMapping elem = (elems.length == 0) ? null : elems[idx];
+                resJoins[idx] = selectAll(sel, elem, sm, store, fetch,
+                    JDBCFetchConfiguration.EAGER_PARALLEL);
             }
-            
-            ClassMapping mapping = field.getDefiningMapping();
-            Object oid = sm.getObjectId();
-            Column[] cols = mapping.getPrimaryKeyColumns();
-            if (sel == null)
-                sel = ((LogicalUnion.UnionSelect)union.getSelects()[0]).
-                getDelegate();
-
-            sel.wherePrimaryKey(mapping, cols, cols, oid, store, 
-                	null, null, parmList);
-            List nonFKParams = sel.getSQL().getNonFKParameters();
-            if (nonFKParams != null && nonFKParams.size() > 0) 
-                parmList.addAll(nonFKParams);
-        }
-        
+        });
+
         // create proxy
         Object coll;
         ChangeTracker ct = null;
@@ -618,7 +545,7 @@
         }
 
         // load values
-        Result res = union.execute(store, fetch, parmList);
+        Result res = union.execute(store, fetch);
         try {
             int seq = -1;
             while (res.next()) {
@@ -642,21 +569,6 @@
             sm.storeObject(field.getIndex(), coll);
     }
 
-    protected Union newUnion(final OpenJPAStateManager sm, final JDBCStore store,
-        final JDBCFetchConfiguration fetch, final ClassMapping[] elems,
-        final Joins[] resJoins) {
-        Union union = store.getSQLFactory().newUnion
-        (Math.max(1, elems.length));
-        union.select(new Union.Selector() {
-            public void select(Select sel, int idx) {
-                ClassMapping elem = (elems.length == 0) ? null : elems[idx];
-                resJoins[idx] = selectAll(sel, elem, sm, store, fetch,
-                        JDBCFetchConfiguration.EAGER_PARALLEL);
-            }
-        });
-        return union;
-    }
-    
     /**
      * Select data for loading, starting in field table.
      */

Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java?rev=747081&r1=747080&r2=747081&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
(original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
Mon Feb 23 16:59:22 2009
@@ -56,7 +56,6 @@
     private List _subsels = null;
     private List _params = null;
     private List _cols = null;
-    private List _nonFKParams = null;
 
     /**
      * Default constructor.
@@ -147,11 +146,6 @@
                         _cols.add(paramIndex, null);
             }
         }
-        if (buf._nonFKParams != null) {
-            if (_nonFKParams == null)
-                _nonFKParams = new ArrayList();
-            _nonFKParams.addAll(buf._nonFKParams);
-        }
     }
 
     public SQLBuffer append(Table table) {
@@ -271,11 +265,6 @@
                 if (isFK)
                     break;
             }
-            if (!isFK) {
-                if (_nonFKParams == null)
-                    _nonFKParams = new ArrayList();
-                _nonFKParams.add(o);                
-            }
         }
         return this;
     }
@@ -399,9 +388,6 @@
         return (_params == null) ? Collections.EMPTY_LIST : _params;
     }
 
-    public List getNonFKParameters() {
-        return (_nonFKParams == null) ? Collections.EMPTY_LIST : _nonFKParams;
-    }
     /**
      * Return the SQL for this buffer.
      */

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNativeQueryProcedures.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNativeQueryProcedures.java?rev=747081&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNativeQueryProcedures.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNativeQueryProcedures.java
Mon Feb 23 16:59:22 2009
@@ -0,0 +1,168 @@
+/*
+ * 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.jdbc.query;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DerbyDictionary;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.jdbc.query.domain.Applicant;
+import org.apache.openjpa.persistence.jdbc.query.procedure.DerbyProcedureList;
+import org.apache.openjpa.persistence.jdbc.query.procedure.ProcedureList;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Tests that Native queries use only 1-based positional parameters and 
+ * disallows named parameters.
+ * 
+ * Originally reported in 
+ * <A HRE="http://issues.apache.org/jira/browse/OPENJPA-112>OPENJPA-112</A>
+ *  
+ * @author B.J. Reed
+ *
+ */
+public class TestNativeQueryProcedures extends SingleEMFTestCase {
+    ProcedureList procedureList = null;
+    
+    @Override
+    public void setUp() throws Exception {
+        super.setUp(Applicant.class, CLEAR_TABLES);
+
+        // Figure out which DB we have and get the proper DB Procedure List
+        OpenJPAEntityManagerFactorySPI ojpaEmf = 
+            (OpenJPAEntityManagerFactorySPI) emf;
+        JDBCConfiguration conf = (JDBCConfiguration) ojpaEmf.getConfiguration();
+        
+        if (conf.getDBDictionaryInstance() instanceof DerbyDictionary) {
+            procedureList = new DerbyProcedureList();
+        }
+
+        if (procedureList != null) {
+            EntityManager em = emf.createEntityManager();
+            List<String> createList = procedureList.getCreateProcedureList();
+            try {
+                for (String createProcedure : createList) {
+                    em.getTransaction().begin();
+                    Query query = em.createNativeQuery(createProcedure);
+                    query.executeUpdate();
+                    em.getTransaction().commit();
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                em.getTransaction().commit();
+            }
+            em.clear();
+            em.close();
+        }
+    }
+
+    public void tearDown() throws Exception {
+        if (procedureList != null) {
+            EntityManager em = emf.createEntityManager();
+            List<String> dropList = procedureList.getDropProcedureList();
+            try {
+                for (String dropProcedure : dropList) {
+                    em.getTransaction().begin();
+                    Query query = em.createNativeQuery(dropProcedure);
+                    query.executeUpdate();
+                    em.getTransaction().commit();
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                em.getTransaction().commit();
+            }
+            em.clear();
+            em.close();
+        }
+        super.tearDown();
+    }
+    
+    public void testNoReturnNoParamProcedure() {
+        if (procedureList != null) {
+            EntityManager em = emf.createEntityManager();
+
+            Applicant applicant1 = new Applicant();
+            applicant1.setName("Charlie");
+            Applicant applicant2 = new Applicant();
+            applicant2.setName("Snoopy");
+
+            em.getTransaction().begin();
+            em.persist(applicant1);
+            em.persist(applicant2);
+            em.getTransaction().commit();
+
+            String sql = procedureList.callAddXToCharlie();
+
+            // query.getSingleResult() and query.getResultList() both throw an
+            // exception: Statement.executeQuery() cannot be called with a
+            // statement that returns a row count
+            try {
+                em.getTransaction().begin();
+                Query query = em.createNativeQuery(sql);
+                query.getSingleResult();
+                em.getTransaction().commit();
+                fail("Expected exception. getSingleResult() with no returns "+ 
+                    "should fail.");
+            } catch (Exception e) {
+                //Expected exception
+                em.getTransaction().rollback();
+            }
+            try {
+                em.getTransaction().begin();
+                Query query = em.createNativeQuery(sql);
+                query.getResultList();
+                em.getTransaction().commit();
+                fail("Expected exception. getResultList() with no returns " + 
+                    "should fail.");
+            } catch (Exception e) {
+                //Expected exception
+                em.getTransaction().rollback();
+            }
+
+            // This one should work properly
+            try {
+                em.getTransaction().begin();
+                Query query = em.createNativeQuery(sql);
+                query.executeUpdate();
+                em.getTransaction().commit();
+            } catch (Exception e) {
+                fail("Caught unexpected exception executing stored procedure: "
+                    + e.getMessage());
+                em.getTransaction().commit();
+            }
+        
+            em.clear();
+            em.close();
+            em = emf.createEntityManager();
+            applicant1 = em.find(Applicant.class, applicant1.getId());
+            applicant2 = em.find(Applicant.class, applicant2.getId());
+
+            // verify one changed and one didn't
+            assertEquals("Charliex", applicant1.getName());
+            assertEquals("Snoopy", applicant2.getName());
+        
+            em.clear();
+            em.close();
+        }
+    }
+}
\ No newline at end of file

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java?rev=747081&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java
Mon Feb 23 16:59:22 2009
@@ -0,0 +1,80 @@
+/*
+ * 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.jdbc.query.cache;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.*;
+/**
+ * @version $Revision$ $Date$
+ */
+@Entity
+@IdClass(InvoiceKey.class)
+public class Invoice {
+
+    @Id
+    private int id;
+    @Id
+    private String brandName;
+    
+    private double price;
+
+    @OneToMany(cascade={CascadeType.ALL})
+    private List<LineItem> lineItems = new ArrayList<LineItem>();
+
+    public Invoice() {
+    }
+
+    public Invoice(int id, String brandName, double price) {
+        this.id = id;
+        this.brandName = brandName;
+        this.price = price;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getBrandName() {
+        return brandName;
+    }
+
+    public void setBrandName(String brandName) {
+        this.brandName = brandName;
+    }
+
+    public double getPrice() {
+        return price;
+    }
+
+    public void setPrice(double price) {
+        this.price = price;
+    }
+
+    public List<LineItem> getLineItems() {
+        return lineItems;
+    }
+
+    public void setLineItems(List<LineItem> lineItems) {
+        this.lineItems = lineItems;
+    }
+}

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java?rev=747081&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java
Mon Feb 23 16:59:22 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.jdbc.query.cache;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class InvoiceKey {
+
+    private int id;
+    private String brandName;
+
+    public InvoiceKey() {
+    }
+
+    public InvoiceKey(int id, String brandName) {
+        this.id = id;
+        this.brandName = brandName;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        InvoiceKey invoiceKey = (InvoiceKey) o;
+
+        if (id != invoiceKey.id) return false;
+        if (!brandName.equals(invoiceKey.brandName)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = id;
+        result = 31 * result + brandName.hashCode();
+        return result;
+    }
+}

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java?rev=747081&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java
Mon Feb 23 16:59:22 2009
@@ -0,0 +1,65 @@
+/*
+ * 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.jdbc.query.cache;
+import javax.persistence.*;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@Entity
+public class LineItem {
+
+    @Id
+    private String id;
+    private int quantity;
+    
+    @ManyToOne
+    private Invoice invoice;
+
+    public LineItem() {
+    }
+
+    public LineItem(String id, int quantity) {
+        this.id = id;
+        this.quantity = quantity;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public int getQuantity() {
+        return quantity;
+    }
+
+    public void setQuantity(int quantity) {
+        this.quantity = quantity;
+    }
+
+    public Invoice getInvoice() {
+        return invoice;
+    }
+
+    public void setInvoice(Invoice invoice) {
+        this.invoice = invoice;
+    }
+}
+

Modified: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java?rev=747081&r1=747080&r2=747081&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java
(original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java
Mon Feb 23 16:59:22 2009
@@ -18,10 +18,10 @@
  */
 package org.apache.openjpa.persistence.jdbc.query.cache;
 
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.List;
 
 import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
 import javax.persistence.Query;
 
 import org.apache.openjpa.persistence.test.SQLListenerTestCase;
@@ -45,18 +45,21 @@
  * 
  * @author Pinaki Poddar
  * @author Vikram Bhatia
- * 
+ * @author David Blevins
  */
 public class TestNonPrimaryKeyQueryParameters extends SQLListenerTestCase {
 	private static final int FULLTIME_EMPLOYEE_COUNT = 3;
 	private static final int PARTTIME_EMPLOYEE_COUNT = 2;
+    private static final int LINEITEM_PER_INVOICE = 1;
 	private static final String DEPT_NAME = "ENGINEERING";
 
 	public void setUp() {
 		super.setUp(CLEAR_TABLES, Department.class, Employee.class,
 				FullTimeEmployee.class, PartTimeEmployee.class,
+				Invoice.class, LineItem.class,
 				"openjpa.jdbc.QuerySQLCache", "true");
 		createDepartment(DEPT_NAME);
+		createInvoice();
 		sql.clear();
 	}
 
@@ -103,6 +106,10 @@
 				.size());
 
 		assertSQL(".* AND t0.TYPE = .*");
+		
+        Invoice invoice = em.find(Invoice.class, new InvoiceKey(1, "Red"));
+        List<LineItem> list = invoice.getLineItems();
+        assertEquals(LINEITEM_PER_INVOICE, list.size());
 		em.close();
 	}
 
@@ -154,4 +161,20 @@
 		em.close();
 
 	}
+	
+    private void createInvoice() {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Invoice invoice = new Invoice(1, "Red", 1.30);
+        for (int i = 1;  i <= LINEITEM_PER_INVOICE; i++) {
+            LineItem item = new LineItem(String.valueOf(i), 10);
+            item.setInvoice(invoice);
+            invoice.getLineItems().add(item);
+            em.persist(invoice);
+        }
+        em.flush();
+        tran.commit();
+        em.close();        
+    }	
 }



Mime
View raw message