cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r905191 - in /cayenne/main/branches/STABLE-3.0: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/types/ ...
Date Mon, 01 Feb 2010 06:52:31 GMT
Author: aadamchik
Date: Mon Feb  1 06:52:30 2010
New Revision: 905191

URL: http://svn.apache.org/viewvc?rev=905191&view=rev
Log:
CAY-1382 org.apache.cayenne.reflect.EnumConverter not handling null values for ExtendedEnumerations

Added:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/types/MockEnum4.java
      - copied, changed from r904804, cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/EnumConverterTest.java
Modified:
    cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java

Modified: cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=905191&r1=905190&r2=905191&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt Mon Feb
 1 06:52:30 2010
@@ -8,6 +8,15 @@
 http://issues.apache.org/cayenne/
 
 ----------------------------------
+Release: 3.0 RC 3
+Date: 
+----------------------------------
+
+Bug Fixes Since 3.0RC2:
+
+CAY-1382 org.apache.cayenne.reflect.EnumConverter not handling null values for ExtendedEnumerations
+
+----------------------------------
 Release: 3.0 RC 2
 Date: 
 ----------------------------------

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java?rev=905191&r1=905190&r2=905191&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java
Mon Feb  1 06:52:30 2010
@@ -19,7 +19,9 @@
 
 package org.apache.cayenne.reflect;
 
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ExtendedEnumeration;
+import org.apache.cayenne.util.Util;
 
 /**
  * @since 1.2
@@ -30,21 +32,27 @@
     @SuppressWarnings("unchecked")
     Object convert(Object object, Class type) {
 
-        if (object == null) {
-            return null;
-        }
+        if (ExtendedEnumeration.class.isAssignableFrom(type)) {
+            ExtendedEnumeration[] values;
+
+            try {
+                values = (ExtendedEnumeration[]) type.getMethod("values").invoke(null);
+            }
+            catch (Exception e) {
+                // unexpected, all enums should have values
+                throw new CayenneRuntimeException(e);
+            }
 
-        try {
-            if (ExtendedEnumeration.class.isAssignableFrom(type)) {
-                for (ExtendedEnumeration en : (ExtendedEnumeration[]) type.getMethod(
-                        "values").invoke(null)) {
-                    if (en.getDatabaseValue().equals(object))
-                        return en;
+            for (ExtendedEnumeration en : values) {
+                if (Util.nullSafeEquals(en.getDatabaseValue(), object)) {
+                    return en;
                 }
-                return null;
             }
+
+            return null;
         }
-        catch (Exception e1) {
+
+        if (object == null) {
             return null;
         }
 

Copied: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/types/MockEnum4.java
(from r904804, cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java)
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/types/MockEnum4.java?p2=cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/types/MockEnum4.java&p1=cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java&r1=904804&r2=905191&rev=905191&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/EnumConverter.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/types/MockEnum4.java
Mon Feb  1 06:52:30 2010
@@ -16,38 +16,21 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-
-package org.apache.cayenne.reflect;
+package org.apache.cayenne.access.types;
 
 import org.apache.cayenne.ExtendedEnumeration;
 
-/**
- * @since 1.2
- */
-class EnumConverter extends Converter {
-
-    @Override
-    @SuppressWarnings("unchecked")
-    Object convert(Object object, Class type) {
-
-        if (object == null) {
-            return null;
-        }
-
-        try {
-            if (ExtendedEnumeration.class.isAssignableFrom(type)) {
-                for (ExtendedEnumeration en : (ExtendedEnumeration[]) type.getMethod(
-                        "values").invoke(null)) {
-                    if (en.getDatabaseValue().equals(object))
-                        return en;
-                }
-                return null;
-            }
-        }
-        catch (Exception e1) {
-            return null;
-        }
+public enum MockEnum4 implements ExtendedEnumeration {
+
+    A("1"), B(null), C("3");
+
+    private String databaseValue;
+
+    private MockEnum4(String databaseValue) {
+        this.databaseValue = databaseValue;
+    }
 
-        return Enum.valueOf(type, object.toString());
+    public Object getDatabaseValue() {
+        return this.databaseValue;
     }
 }

Added: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/EnumConverterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/EnumConverterTest.java?rev=905191&view=auto
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/EnumConverterTest.java
(added)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/EnumConverterTest.java
Mon Feb  1 06:52:30 2010
@@ -0,0 +1,49 @@
+/*****************************************************************
+ *   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.cayenne.reflect;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.access.types.MockEnum2;
+import org.apache.cayenne.access.types.MockEnum3;
+import org.apache.cayenne.access.types.MockEnum4;
+
+public class EnumConverterTest extends TestCase {
+    
+    public void testConvert() {
+        EnumConverter converter = new EnumConverter();
+
+        assertSame(MockEnum2.x, converter.convert("x", MockEnum2.class));
+        assertSame(MockEnum2.z, converter.convert("z", MockEnum2.class));
+    }
+
+    public void testConvertExtendedEnumeration() {
+        EnumConverter converter = new EnumConverter();
+
+        assertSame(MockEnum3.B, converter.convert(2, MockEnum3.class));
+        assertSame(MockEnum3.C, converter.convert(3, MockEnum3.class));
+    }
+    
+    public void testConvertExtendedEnumerationWithNull() {
+        EnumConverter converter = new EnumConverter();
+
+        assertSame(MockEnum4.B, converter.convert(null, MockEnum4.class));
+        assertSame(MockEnum4.C, converter.convert("3", MockEnum4.class));
+    }
+}



Mime
View raw message