OPENJPA-470. Added test case for custom sequence implementations, and updated docs with the current parentheses limitation.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@605679 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2007-12-19 20:19:49 +00:00
parent 84205d6d50
commit ab88266f2a
5 changed files with 105 additions and 4 deletions

View File

@ -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.Constructor;
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 @@ public class ConfigurationImpl
_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 @@ public class ConfigurationImpl
// <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;

View File

@ -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() {
}
}

View File

@ -20,7 +20,9 @@ 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.SequenceGenerator;
@Entity
public class GeneratedValues {
@ -31,6 +33,16 @@ public class GeneratedValues {
@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 @@ public class GeneratedValues {
this.field = field;
}
// public int getCustomSeqField() {
// return customSeqField;
// }
public int getCustomSeqWithIndirectionField() {
return customSeqWithIndirectionField;
}
}

View File

@ -102,4 +102,28 @@ public class TestGeneratedValues extends SingleEMFTestCase {
// 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());
}
}

View File

@ -1649,7 +1649,10 @@ suitable for single-JVM environments.
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>