You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2007/07/20 21:17:21 UTC
svn commit: r558097 - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/
Author: mikedd
Date: Fri Jul 20 12:17:19 2007
New Revision: 558097
URL: http://svn.apache.org/viewvc?view=rev&rev=558097
Log:
OPENJPA-284 committing on behalf of Teresa
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestTableGenerator.java (with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java?view=diff&rev=558097&r1=558096&r2=558097
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java Fri Jul 20 12:17:19 2007
@@ -76,6 +76,7 @@
private transient JDBCConfiguration _conf = null;
private transient Log _log = null;
private int _alloc = 50;
+ private int _intValue = 1;
private final Status _stat = new Status();
private String _table = "OPENJPA_SEQUENCE_TABLE";
@@ -168,6 +169,24 @@
public void setAllocate(int alloc) {
_alloc = alloc;
}
+
+ /**
+ * Return the number as the initial number for the
+ * GeneratedValue.TABLE strategy to start with.
+ * @return an initial number
+ */
+ public int getInitialValue() {
+ return _intValue;
+ }
+
+ /**
+ * Set the initial number in the table for the GeneratedValue.TABLE
+ * strategy to use as initial number.
+ * @param intValue. The initial number
+ */
+ public void setInitialValue(int intValue) {
+ _intValue = intValue;
+ }
/**
* @deprecated Use {@link #setAllocate}. Retained for backwards
@@ -378,8 +397,8 @@
append(_pkColumn).append(", ").append(_seqColumn).
append(") VALUES (").
appendValue(pk, _pkColumn).append(", ").
- appendValue(Numbers.valueOf(1), _seqColumn).append(")");
-
+ appendValue(_intValue, _seqColumn).append(")");
+
boolean wasAuto = conn.getAutoCommit();
if (!wasAuto && !suspendInJTA())
conn.setAutoCommit(true);
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog.java?view=auto&rev=558097
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog.java Fri Jul 20 12:17:19 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.TableGenerator;
+
+@Entity
+public class Dog {
+ @Id
+ @TableGenerator(name = "Dog_Gen", table = "ID_Gen",
+ pkColumnName = "GEN_NAME", valueColumnName = "GEN_VAL",
+ pkColumnValue = "ID2", initialValue = 20, allocationSize = 10)
+ @GeneratedValue(strategy = GenerationType.TABLE, generator = "Dog_Gen")
+ private int id;
+
+ private String name;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestTableGenerator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestTableGenerator.java?view=auto&rev=558097
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestTableGenerator.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestTableGenerator.java Fri Jul 20 12:17:19 2007
@@ -0,0 +1,47 @@
+/*
+ * 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.EntityManager;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestTableGenerator extends SingleEMFTestCase {
+
+ public void setUp() {
+ setUp(Dog.class);
+ }
+
+ public void testInitialValue() {
+ EntityManager em = emf.createEntityManager();
+
+ Dog dog = new Dog();
+ dog.setName("Fido");
+
+ em.getTransaction().begin();
+
+ em.persist(dog);
+
+ em.getTransaction().commit();
+
+ em.refresh(dog);
+
+ assertEquals(20, dog.getId());
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestTableGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native