empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject empire-db git commit: EMPIREDB-239 special enum treatment
Date Sat, 20 Feb 2016 12:20:10 GMT
Repository: empire-db
Updated Branches:
  refs/heads/master 5e314f54c -> 4182161bb


EMPIREDB-239
special enum treatment

Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/4182161b
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/4182161b
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/4182161b

Branch: refs/heads/master
Commit: 4182161bb761668ccb1f9e83e24848720040ffa8
Parents: 5e314f5
Author: Rainer Döbele <doebele@esteam.de>
Authored: Sat Feb 20 13:20:06 2016 +0100
Committer: Rainer Döbele <doebele@esteam.de>
Committed: Sat Feb 20 13:20:06 2016 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/empire/db/DBExpr.java  |  7 +++++++
 .../java/org/apache/empire/db/DBTableColumn.java    | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/empire-db/blob/4182161b/empire-db/src/main/java/org/apache/empire/db/DBExpr.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBExpr.java b/empire-db/src/main/java/org/apache/empire/db/DBExpr.java
index 48d8f16..f0c573d 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBExpr.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBExpr.java
@@ -82,6 +82,13 @@ public abstract class DBExpr extends DBObject
             ((DBExpr) value).addSQL(buf, context);
             return buf.toString();
         } 
+        else if (value!=null && value.getClass().isEnum())
+        {   // check enum
+            if (dataType.isNumeric())
+                value = ((Enum<?>)value).ordinal();
+            else
+                value = ((Enum<?>)value).name();
+        }
         else if (value instanceof Collection<?>)
         {
         	value = ((Collection<?>)value).toArray();

http://git-wip-us.apache.org/repos/asf/empire-db/blob/4182161b/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java b/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
index 593e790..d23c9ad 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
@@ -402,6 +402,12 @@ public class DBTableColumn extends DBColumn
             case DECIMAL:
                 if (value==null)
                     break;
+                // check enum
+                if (value!=null && value.getClass().isEnum())
+                {   
+                    value = ((Enum<?>)value).ordinal();
+                }
+                // check number
                 if (!(value instanceof java.lang.Number))
                 {   try
                     {   // Convert to String and check
@@ -438,6 +444,12 @@ public class DBTableColumn extends DBColumn
             case INTEGER:
                 if (value==null)
                     break;
+                // check enum
+                if (value!=null && value.getClass().isEnum())
+                {   
+                    value = ((Enum<?>)value).ordinal();
+                }
+                // check number
                 if (!(value instanceof java.lang.Number))
                 {   try
                     {   // Convert to String and check
@@ -455,6 +467,10 @@ public class DBTableColumn extends DBColumn
 
             case TEXT:
             case CHAR:
+                if (value!=null && value.getClass().isEnum())
+                {   // check enum
+                    value = ((Enum<?>)value).name();
+                }
                 if (value!=null && value.toString().length() > size)
                     throw new FieldValueTooLongException(this);
                 break;


Mime
View raw message