Author: pcl
Date: Wed Dec 19 12:19:49 2007
New Revision: 605679
URL: http://svn.apache.org/viewvc?rev=605679&view=rev
Log:
OPENJPA-470. Added test case for custom sequence implementations, and updated
docs with the current parentheses limitation.
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/CustomSeq.java
Modified:
openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/GeneratedValues.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGeneratedValues.java
openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_runtime.xml
Modified:
openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java?rev=605679&r1=605678&r2=605679&view=diff
==============================================================================
---
openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
(original)
+++
openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
Wed Dec 19 12:19:49 2007
@@ -18,7 +18,7 @@
*/
package org.apache.openjpa.lib.conf;
-import java.awt.Image;
+import java.awt.*;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
@@ -40,13 +40,13 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
@@ -622,6 +622,14 @@
_globals = false;
}
+ // copy the input to avoid mutation issues
+ if (map instanceof HashMap)
+ map = (Map) ((HashMap) map).clone();
+ else if (map instanceof Properties)
+ map = (Map) ((Properties) map).clone();
+ else
+ map = new LinkedHashMap(map);
+
Map remaining = new HashMap(map);
boolean ser = true;
Value val;
@@ -646,7 +654,7 @@
// <prefix>.properties System property; remove that property so we
// we don't warn about it
Configurations.removeProperty("properties", remaining);
-
+
// now warn if there are any remaining properties that there
// is an unhandled prop, and remove the unknown properties
Map.Entry entry;
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/CustomSeq.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/CustomSeq.java?rev=605679&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/CustomSeq.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/CustomSeq.java
Wed Dec 19 12:19:49 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 org.apache.openjpa.kernel.Seq;
+import org.apache.openjpa.kernel.StoreContext;
+import org.apache.openjpa.meta.ClassMetaData;
+
+public class CustomSeq implements Seq {
+
+ private int i = 1;
+
+ public void setType(int type) {
+ if (type == Seq.TYPE_TRANSACTIONAL)
+ throw new UnsupportedOperationException();
+ }
+
+ public Object next(StoreContext ctx, ClassMetaData cls) {
+ return i++;
+ }
+
+ public Object current(StoreContext ctx, ClassMetaData cls) {
+ return i;
+ }
+
+ public void allocate(int additional, StoreContext ctx, ClassMetaData cls) {
+ }
+
+ public void close() {
+ }
+}
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/GeneratedValues.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/GeneratedValues.java?rev=605679&r1=605678&r2=605679&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/GeneratedValues.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/GeneratedValues.java
Wed Dec 19 12:19:49 2007
@@ -20,7 +20,9 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
@Entity
public class GeneratedValues {
@@ -31,6 +33,16 @@
@GeneratedValue
private long field;
+// @GeneratedValue(strategy= GenerationType.SEQUENCE,
+// generator="org.apache.openjpa.persistence.generationtype.CustomSeq")
+// private int customSeqField;
+
+ @GeneratedValue(strategy= GenerationType.SEQUENCE,
+ generator="GeneratedValues.SequenceGeneratorCustomSeq")
+ @SequenceGenerator(name="GeneratedValues.SequenceGeneratorCustomSeq",
+
sequenceName="org.apache.openjpa.persistence.generationtype.CustomSeq()")
+ private int customSeqWithIndirectionField;
+
public GeneratedValues() {
super();
}
@@ -57,4 +69,11 @@
this.field = field;
}
+// public int getCustomSeqField() {
+// return customSeqField;
+// }
+
+ public int getCustomSeqWithIndirectionField() {
+ return customSeqWithIndirectionField;
+ }
}
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGeneratedValues.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGeneratedValues.java?rev=605679&r1=605678&r2=605679&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGeneratedValues.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGeneratedValues.java
Wed Dec 19 12:19:49 2007
@@ -102,4 +102,28 @@
// should not get here...
fail();
}
+
+// public void testCustomSequenceGenerator() {
+// EntityManager em = emf.createEntityManager();
+//
+// GeneratedValues gv = new GeneratedValues();
+//
+// em.getTransaction().begin();
+// em.persist(gv);
+// em.getTransaction().commit();
+//
+// assertNotEquals(0, gv.getCustomSeqField());
+// }
+
+ public void testCustomSequenceGeneratorWithIndirection() {
+ EntityManager em = emf.createEntityManager();
+
+ GeneratedValues gv = new GeneratedValues();
+
+ em.getTransaction().begin();
+ em.persist(gv);
+ em.getTransaction().commit();
+
+ assertNotEquals(0, gv.getCustomSeqWithIndirectionField());
+ }
}
Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_runtime.xml
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_runtime.xml?rev=605679&r1=605678&r2=605679&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_runtime.xml
(original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_runtime.xml Wed Dec
19 12:19:49 2007
@@ -1649,7 +1649,10 @@
You can use JPA <literal>SequenceGenerator</literal>s to describe any built-in
<classname>Seq</classname>s or your own <classname>Seq</classname>
implementation. Set the <literal>sequenceName</literal> attribute to a plugin
-string describing your choice. See
+string describing your choice. If specifying your own class name, you must
+include parentheses at the end of the class name, even if you have no plugin
+properties to configure.
+(E.g., <literal>sequenceName="com.example.SeqImpl()"</literal>. See
<xref linkend="jpa_overview_mapping_sequence"/> in the JPA Overview for
details on defining <literal>SequenceGenerator</literal>s.
</para>