You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2019/07/09 16:09:34 UTC

[empire-db] branch master updated: EMPIREDB-292: new overloads for DBTable.addColumn

This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 80e34b5  EMPIREDB-292: new overloads for DBTable.addColumn
80e34b5 is described below

commit 80e34b5157148d44415dd73cc629c9586855ae48
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Tue Jul 9 18:09:30 2019 +0200

    EMPIREDB-292: new overloads for DBTable.addColumn
---
 .../main/java/org/apache/empire/db/DBTable.java    | 46 +++++++++++++++++++++-
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/db/DBTable.java b/empire-db/src/main/java/org/apache/empire/db/DBTable.java
index b09d463..ad40e0d 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBTable.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBTable.java
@@ -26,6 +26,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.empire.commons.Options;
 import org.apache.empire.data.DataMode;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBRelation.DBCascadeAction;
@@ -305,7 +306,48 @@ public class DBTable extends DBRowSet implements Cloneable
     }
 
     /**
-     * Creates a new table column and adds it to the table's column list
+     * Creates a new table column with options and adds it to the table's column list
+     * This overload should be used for column containing enum values which have no default value.
+     * 
+     * @param columnName the column name
+     * @param type the type of the column e.g. integer, text, date
+     * @param size the column width
+     * @param required true if not null column
+     * @param options this list of options
+     * @return the new column object 
+     */
+    public final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required, Options options)
+    {
+        DBTableColumn col = this.crateAndAppendColumn(columnName, type, size, required, null);
+        col.setOptions(options);
+        return col;
+    }
+
+    /**
+     * Creates a new table column with options and adds it to the table's column list
+     * This overload should be used for column containing enum values which have a default value.
+     * 
+     * @param columnName the column name
+     * @param type the type of the column e.g. integer, text, date
+     * @param size the column width
+     * @param required true if not null column
+     * @param options this list of options
+     * @param defValue the default value
+     * @return the new column object 
+     */
+    public final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required, Options options, Object defValue)
+    { 
+        // defValue must be part of options
+        if (defValue!=null && !options.contains(defValue))
+            throw new InvalidArgumentException("devValue", defValue);
+        // add
+        DBTableColumn col = this.crateAndAppendColumn(columnName, type, size, required, defValue);
+        col.setOptions(options);
+        return col;
+    }
+
+    /**
+     * Creates a new table column with Enum-Options and adds it to the table's column list
      * This overload should be used for column containing enum values which have no default value.
      * 
      * @param columnName the column name
@@ -327,7 +369,7 @@ public class DBTable extends DBRowSet implements Cloneable
     }
 
     /**
-     * Creates a new table column and adds it to the table's column list
+     * Creates a new table column with Enum-Options and adds it to the table's column list
      * This overload should be used for column containing enum values which have a default value.
      * 
      * @param columnName the column name