openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dez...@apache.org
Subject svn commit: r890402 [3/3] - in /openjpa/branches/1.1.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/ openjpa-persistence-jdbc/src/test/java/org/apache/open...
Date Mon, 14 Dec 2009 16:55:05 GMT
Propchange: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java?rev=890402&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
Mon Dec 14 16:55:04 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.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java?rev=890402&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
Mon Dec 14 16:55:04 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.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java?rev=890402&r1=890401&r2=890402&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
Mon Dec 14 16:55:04 2009
@@ -57,6 +57,12 @@
     protected static final Object CLEAR_TABLES = new Object();
 
     /**
+     * Marker object you pass to {@link #setUp} to indicate that the
+     * database table should be dropped and then recreated.
+     */
+    protected static final Object DROP_TABLES = new Object();
+
+    /**
      * The {@link TestResult} instance for the current test run.
      */
     protected TestResult testResult;
@@ -107,6 +113,10 @@
                 map.put("openjpa.jdbc.SynchronizeMappings",
                     "buildSchema(ForeignKeys=true," 
                     + "SchemaAction='add,deleteTableContents')");
+            } else if (props[i] == DROP_TABLES) {
+                map.put("openjpa.jdbc.SynchronizeMappings",
+                    "buildSchema(ForeignKeys=true,"
+                    + "SchemaAction='drop,add')");
             } else if (props[i] instanceof Class)
                 types.add((Class) props[i]);
             else if (props[i] != null)



Mime
View raw message