openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r813868 - in /openjpa/branches/1.3.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/
Date Fri, 11 Sep 2009 15:04:02 GMT
Author: dwoods
Date: Fri Sep 11 15:04:01 2009
New Revision: 813868

URL: http://svn.apache.org/viewvc?rev=813868&view=rev
Log:
OPENJPA-1260 ported updates by Kevin Sutter from trunk r813597.  Based on patch contributed
by Ravi Palacherla.

Added:
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
  (with props)
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
  (with props)
Modified:
    openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java

Modified: openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?rev=813868&r1=813867&r2=813868&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
(original)
+++ openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
Fri Sep 11 15:04:01 2009
@@ -3563,9 +3563,25 @@
             default:
                 // use store manager for native sequence
                 if (fmd == null) {
-                    // this will return a sequence even for app id classes,
-                    // which is what we want for backwards-compatibility
-                    return _store.getDataStoreIdSequence(meta);
+                    // This will return a sequence even for app id classes,
+                    // which is what we want for backwards-compatibility.
+                    // Even if user uses Application Identity,
+                    // user might use custom sequence information.
+                    // So, first, the sequence should be checked.
+                    // Trying to get primary key field if it has
+                    // sequence meta data.
+                    FieldMetaData[] pks = meta.getPrimaryKeyFields();
+                    if (pks != null && pks.length == 1) {
+                        smd = pks[0].getValueSequenceMetaData();
+                    } else {
+                        smd = meta.getIdentitySequenceMetaData();
+                    }
+
+                    if (smd != null) {
+                        return smd.getInstance(_loader);
+                    } else {
+                        return _store.getDataStoreIdSequence(meta);
+                    }
                 }
                 return _store.getValueSequence(fmd);
         }

Added: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java?rev=813868&view=auto
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
(added)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
Fri Sep 11 15:04:01 2009
@@ -0,0 +1,69 @@
+/*
+ * 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.generationtype;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="primary_entityE2")
+public class EntityE2 {
+    @Id
+    @SequenceGenerator(name="entityE2_seq_gen_name", 
+                       sequenceName="entityE2_seq_gen")
+    @GeneratedValue(strategy=GenerationType.SEQUENCE, 
+        generator="entityE2_seq_gen_name")
+    private int id;
+    @Column(name="e_name")
+    private String name;
+    
+    public EntityE2(String name) {
+        this.name = name;
+    }
+    
+    /**
+     * @return the id
+     */
+    public int getId() {
+        return id;
+    }
+    /**
+     * @param id the id to set
+     */
+    public void setId(int id) {
+        this.id = id;
+    }
+    /**
+     * @return the name
+     */
+    public String getName() {
+        return name;
+    }
+    /**
+     * @param name the name to set
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+}

Propchange: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java?rev=813868&view=auto
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
(added)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
Fri Sep 11 15:04:01 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.generationtype;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestNativeSeqGenerator extends SQLListenerTestCase {
+    OpenJPAEntityManager em;
+    JDBCConfiguration conf;
+    DBDictionary dict;
+    boolean supportsNativeSequence = false;
+    
+    EntityE2 entityE2;
+    
+    @Override
+    public void setUp() throws Exception {
+        super.setUp(EntityE2.class,DROP_TABLES);
+        assertNotNull(emf);
+        conf = (JDBCConfiguration) emf.getConfiguration();
+        dict = conf.getDBDictionaryInstance();
+        supportsNativeSequence = dict.nextSequenceQuery != null;       
+        if (supportsNativeSequence) {
+            em = emf.createEntityManager();
+            assertNotNull(em);
+        }
+    }
+    
+    public void createEntityE2() {
+        entityE2 = new EntityE2("e name");
+    }
+    
+    public void testGetIdGeneratorSeqGen() {
+        if (!supportsNativeSequence) {
+            System.out.println("Does not support native sequence");
+            return;
+        }
+        createEntityE2();
+        em.getTransaction().begin();
+        em.persist(entityE2);
+        em.getTransaction().commit();
+        int genId = entityE2.getId();        
+        int nextId = (int)((Long)em.getIdGenerator(EntityE2.class).next()).longValue();
+        assertTrue("Next value should depend on previous genid", nextId == genId + 1);
+        em.close();
+    }
+}

Propchange: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message