openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r587943 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-kernel/src/main/resources/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/
Date Wed, 24 Oct 2007 18:09:02 GMT
Author: mikedd
Date: Wed Oct 24 11:09:01 2007
New Revision: 587943

URL: http://svn.apache.org/viewvc?rev=587943&view=rev
Log:
OPENJPA-416

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/EntityA.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/TestExternalValues.java
  (with props)
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
    openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?rev=587943&r1=587942&r2=587943&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
Wed Oct 24 11:09:01 2007
@@ -63,6 +63,8 @@
 import org.apache.openjpa.util.OpenJPAException;
 import org.apache.openjpa.util.UnsupportedException;
 import org.apache.openjpa.util.ImplHelper;
+import org.apache.openjpa.util.UserException;
+
 import serp.util.Strings;
 
 /**
@@ -1232,8 +1234,16 @@
      */
     public Object getExternalValue(Object val, StoreContext ctx) {
         Map extValues = getExternalValueMap();
-        if (extValues != null)
-            return extValues.get(val);
+        if (extValues != null) {
+            Object foundVal = extValues.get(val);
+            if (foundVal == null) {
+                throw new UserException(_loc.get("bad-externalized-value",
+                        new Object[] { val, extValues.keySet(), this }))
+                        .setFatal(true).setFailedObject(val);
+            } else {
+                return foundVal;
+            }
+        }
 
         Method externalizer = getExternalizerMethod();
         if (externalizer == null)

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties?rev=587943&r1=587942&r2=587943&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
Wed Oct 24 11:09:01 2007
@@ -310,3 +310,5 @@
 interface-load2: Enhanced dynamic implementaion of managed "{0}" can not be \
 	defined using classloader "{1}". See nested exception for details.
 interface-badenhance: Dynamic implementaion of "{0}" can not be enhanced.
+bad-externalized-value: Value "{0}" was not found in the list of \
+	ExternalValues for field "{2}". Valid values are {1}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/EntityA.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/EntityA.java?rev=587943&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/EntityA.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/EntityA.java
Wed Oct 24 11:09:01 2007
@@ -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.external;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.ExternalValues;
+import org.apache.openjpa.persistence.Type;
+
+@Entity
+@Table(name = "ExternalizationEntityA")
+public class EntityA implements java.io.Serializable {
+	private static final long serialVersionUID = 1L;
+
+	@Id
+	@GeneratedValue
+	private int id;
+
+	@ExternalValues( { "SMALL=SML", "MEDIUM=MID", "LARGE=LRG" })
+	@Column(length = 3)
+	private String s1;
+
+	@ExternalValues( { "SMALL=5", "MEDIUM=8", "LARGE=15" })
+	@Type(int.class)
+	private String s2;
+
+	public EntityA() {
+	}
+
+	public int getId() {
+		return id;
+	}
+
+	public String getS1() {
+		return s1;
+	}
+
+	public void setS1(String s1) {
+		this.s1 = s1;
+	}
+
+	public String getS2() {
+		return s2;
+	}
+
+	public void setS2(String s2) {
+		this.s2 = s2;
+	}
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/EntityA.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/TestExternalValues.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/TestExternalValues.java?rev=587943&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/TestExternalValues.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/TestExternalValues.java
Wed Oct 24 11:09:01 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.external;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.PersistenceException;
+import org.apache.openjpa.persistence.RollbackException;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestExternalValues extends SingleEMFTestCase {
+
+    public void setUp() {
+        super.setUp(EntityA.class);
+    }
+
+    public void testUnrecognizedExternalValue() {
+        EntityManager em = emf.createEntityManager();
+
+        em.getTransaction().begin();
+
+        EntityA entity = new EntityA();
+
+        entity.setS1("ABDEF");
+        entity.setS2("NOT_VALID");
+
+        em.persist(entity);
+
+        try {
+            em.getTransaction().commit();
+            fail("Expected an exception at commit time");
+        } catch (RollbackException e) {
+            Throwable t = e;
+            while (t.getCause() != null) {
+                t = t.getCause();
+            }
+            assertTrue(t.getMessage().contains(
+                    "was not found in the list of ExternalValues"));
+        } finally {
+            if (em.getTransaction().isActive()) {
+                em.getTransaction().rollback();
+            }
+        }
+        em.close();
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/external/TestExternalValues.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message