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 support enum types in bean properties
Date Tue, 22 Mar 2016 18:17:46 GMT
Repository: empire-db
Updated Branches:
  refs/heads/master 6580f386e -> 527dac43c


EMPIREDB-239
support enum types in bean properties


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

Branch: refs/heads/master
Commit: 527dac43cd92b767fc8bf164e7b63c9e9d846611
Parents: 6580f38
Author: Rainer Döbele <doebele@apache.org>
Authored: Tue Mar 22 19:17:38 2016 +0100
Committer: Rainer Döbele <doebele@apache.org>
Committed: Tue Mar 22 19:17:38 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/empire/data/Record.java     |  4 +--
 .../java/org/apache/empire/data/RecordData.java |  4 +--
 .../empire/data/bean/BeanRecordProxy.java       | 16 ++++++------
 .../java/org/apache/empire/db/DBReader.java     |  2 +-
 .../java/org/apache/empire/db/DBRecord.java     | 19 +++++++-------
 .../java/org/apache/empire/db/DBRecordData.java | 27 ++++++++++++++++----
 6 files changed, 44 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/empire-db/blob/527dac43/empire-db/src/main/java/org/apache/empire/data/Record.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/data/Record.java b/empire-db/src/main/java/org/apache/empire/data/Record.java
index 362dac1..470d0df 100644
--- a/empire-db/src/main/java/org/apache/empire/data/Record.java
+++ b/empire-db/src/main/java/org/apache/empire/data/Record.java
@@ -146,7 +146,7 @@ public interface Record extends RecordData
      * @param ignoreList list of column to ignore
      * @return the number of fields that have been set    
      */
-    int setBeanValues(Object bean, Collection<Column> ignoreList);
+    int setRecordValues(Object bean, Collection<Column> ignoreList);
 
     /**
      * sets all record values from a particular bean.
@@ -156,6 +156,6 @@ public interface Record extends RecordData
      * @param bean the Java Bean from which to read the value from
      * @return the number of fields that have been set    
      */
-    int setBeanValues(Object bean);
+    int setRecordValues(Object bean);
 
 }

http://git-wip-us.apache.org/repos/asf/empire-db/blob/527dac43/empire-db/src/main/java/org/apache/empire/data/RecordData.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/data/RecordData.java b/empire-db/src/main/java/org/apache/empire/data/RecordData.java
index 101b049..19da930 100644
--- a/empire-db/src/main/java/org/apache/empire/data/RecordData.java
+++ b/empire-db/src/main/java/org/apache/empire/data/RecordData.java
@@ -98,7 +98,7 @@ public interface RecordData
      * @param bean the Java Bean for which to set the properties
      * @param ignoreList list of columns to skip (optional)
      */
-    int getBeanProperties(Object bean, Collection<ColumnExpr> ignoreList);
+    int setBeanProperties(Object bean, Collection<ColumnExpr> ignoreList);
 
     /**
      * copies all field values into a static Java Bean.
@@ -107,6 +107,6 @@ public interface RecordData
      * the property name is detected by ColumnExpr.getBeanPropertyName()     
      * @param bean the Java Bean for which to set the properties
      */
-    int getBeanProperties(Object bean);
+    int setBeanProperties(Object bean);
 
 }

http://git-wip-us.apache.org/repos/asf/empire-db/blob/527dac43/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java b/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
index 6cd0b7e..f481f68 100644
--- a/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
+++ b/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
@@ -313,13 +313,13 @@ public class BeanRecordProxy<T> implements Record
     // --------------- Bean support ------------------
 
     @Override
-    public int getBeanProperties(Object bean)
+    public int setBeanProperties(Object bean)
     {
-        return getBeanProperties(bean, null);
+        return setBeanProperties(bean, null);
     }
 
     @Override
-    public int getBeanProperties(Object bean, Collection<ColumnExpr> ignoreList)
+    public int setBeanProperties(Object bean, Collection<ColumnExpr> ignoreList)
     {
         // Add all Columns
         int count = 0;
@@ -337,7 +337,7 @@ public class BeanRecordProxy<T> implements Record
     }
 
     @Override
-    public int setBeanValues(Object bean, Collection<Column> ignoreList)
+    public int setRecordValues(Object bean, Collection<Column> ignoreList)
     {
         // Add all Columns
         int count = 0;
@@ -356,15 +356,15 @@ public class BeanRecordProxy<T> implements Record
         }
         return count;
     }
-
+    
     @Override
-    public int setBeanValues(Object bean)
+    public int setRecordValues(Object bean)
     {
-        return setBeanValues(bean, null);
+        return setRecordValues(bean, null);
     }
 
     // --------------- protected ------------------
-    
+
     protected Object getBeanPropertyValue(Object bean, ColumnExpr column)
     {
         // Check Params

http://git-wip-us.apache.org/repos/asf/empire-db/blob/527dac43/empire-db/src/main/java/org/apache/empire/db/DBReader.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBReader.java b/empire-db/src/main/java/org/apache/empire/db/DBReader.java
index ec899bc..91f5902 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBReader.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBReader.java
@@ -675,7 +675,7 @@ public class DBReader extends DBRecordData
                 else
                 {   // Use Property Setters
                     T bean = t.newInstance();
-                    getBeanProperties(bean);
+                    setBeanProperties(bean);
                     c.add(bean);
                 }
                 // Decrease count

http://git-wip-us.apache.org/repos/asf/empire-db/blob/527dac43/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecord.java b/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
index ec13ced..942f01e 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
@@ -27,6 +27,7 @@ import org.apache.commons.beanutils.BeanUtilsBean;
 import org.apache.commons.beanutils.PropertyUtilsBean;
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.Options;
+import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.Column;
 import org.apache.empire.data.ColumnExpr;
 import org.apache.empire.data.Record;
@@ -1022,14 +1023,12 @@ public class DBRecord extends DBRecordData implements Record, Cloneable
      * @param property the name of the property
      * @param column the column for which to set the record value
      */
-    protected void setBeanValue(Object bean, String property, Column column)
+    protected void setRecordValue(Column column, Object bean, String property)
     {
+        if (StringUtils.isEmpty(property))
+            property = column.getBeanPropertyName();
         try
-        {   /*
-            if (log.isTraceEnabled())
-                log.trace(bean.getClass().getName() + ": getting property '" + property +
"' for column " + column.getName());
-            */
-            
+        {
             // Get Property Value
             PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
             Object value = pub.getSimpleProperty(bean, property);
@@ -1055,7 +1054,7 @@ public class DBRecord extends DBRecordData implements Record, Cloneable
      * @return true if at least one value has been set successfully 
      */
     @Override
-    public int setBeanValues(Object bean, Collection<Column> ignoreList)
+    public int setRecordValues(Object bean, Collection<Column> ignoreList)
     {
         // Add all Columns
         int count = 0;
@@ -1068,7 +1067,7 @@ public class DBRecord extends DBRecordData implements Record, Cloneable
                 continue; // ignore this property
             // Get Property Name
             String property = column.getBeanPropertyName();
-            setBeanValue(bean, property, column);
+            setRecordValue(column, bean, property);
             count++;
         }
         return count;
@@ -1079,9 +1078,9 @@ public class DBRecord extends DBRecordData implements Record, Cloneable
      * @return true if at least one value has been set sucessfully
      */
     @Override
-    public final int setBeanValues(Object bean)
+    public final int setRecordValues(Object bean)
     {
-        return setBeanValues(bean, null);
+        return setRecordValues(bean, null);
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/empire-db/blob/527dac43/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java b/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
index 704ff14..173505b 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
@@ -27,6 +27,7 @@ import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.StringUtils;
+import org.apache.empire.data.Column;
 import org.apache.empire.data.ColumnExpr;
 import org.apache.empire.data.RecordData;
 import org.apache.empire.exceptions.BeanPropertySetException;
@@ -297,8 +298,11 @@ public abstract class DBRecordData extends DBObject
     /**
      * Set a single property value of a java bean object used by readProperties.
      */
-    protected void getBeanProperty(Object bean, String property, Object value)
+    @SuppressWarnings("rawtypes")
+    protected void setBeanProperty(ColumnExpr column, Object bean, String property, Object
value)
     {
+        if (StringUtils.isEmpty(property))
+            property = column.getBeanPropertyName();
         try
         {
             if (bean==null)
@@ -315,6 +319,19 @@ public abstract class DBRecordData extends DBObject
                 value = DateUtils.addDate((Date)value, 0, 0, 0);
             }
             */
+            Object type = column.getAttribute(Column.COLATTR_ENUMTYPE);
+            if (type!=null && value!=null)
+            {
+                String name = value.toString();
+                @SuppressWarnings("unchecked")
+                Class<Enum> enumType = (Class<Enum>)type;
+                for (Enum e : enumType.getEnumConstants())
+                    if (e.name().equals(name))
+                    {
+                        value = e;
+                        break;
+                    }
+            }
             // Set Property Value
             if (value!=null)
             {   // Bean utils will convert if necessary
@@ -348,7 +365,7 @@ public abstract class DBRecordData extends DBObject
      * @return the number of bean properties set on the supplied bean
      */
     @Override
-    public int getBeanProperties(Object bean, Collection<ColumnExpr> ignoreList)
+    public int setBeanProperties(Object bean, Collection<ColumnExpr> ignoreList)
     {
         // Add all Columns
         int count = 0;
@@ -360,7 +377,7 @@ public abstract class DBRecordData extends DBObject
             // Get Property Name
             String property = column.getBeanPropertyName();
             if (property!=null)
-                getBeanProperty(bean, property, this.getValue(i));
+                setBeanProperty(column, bean, property, this.getValue(i));
             count++;
         }
         return count;
@@ -372,9 +389,9 @@ public abstract class DBRecordData extends DBObject
      * @return the number of bean properties set on the supplied bean
      */
     @Override
-    public final int getBeanProperties(Object bean)
+    public final int setBeanProperties(Object bean)
     {
-        return getBeanProperties(bean, null);
+        return setBeanProperties(bean, null);
     }
     
 }


Mime
View raw message