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-237 added DBColumnExpr:modulo()
Date Thu, 11 Feb 2016 16:21:11 GMT
Repository: empire-db
Updated Branches:
  refs/heads/master 873f699f8 -> f57f8a57f


EMPIREDB-237
added DBColumnExpr:modulo()


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

Branch: refs/heads/master
Commit: f57f8a57f6d3f99f455576e514ea7eac7d044f33
Parents: 873f699
Author: Rainer Döbele <doebele@apache.org>
Authored: Thu Feb 11 17:21:07 2016 +0100
Committer: Rainer Döbele <doebele@apache.org>
Committed: Thu Feb 11 17:21:07 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/empire/db/DBColumnExpr.java | 19 +++++++++++++----
 .../org/apache/empire/db/DBDatabaseDriver.java  |  1 +
 .../main/java/org/apache/empire/db/DBTable.java | 22 ++++++++++++++++----
 .../apache/empire/db/h2/DBDatabaseDriverH2.java |  1 +
 .../empire/db/hsql/DBDatabaseDriverHSql.java    |  1 +
 .../empire/db/mysql/DBDatabaseDriverMySQL.java  |  1 +
 .../db/oracle/DBDatabaseDriverOracle.java       |  1 +
 .../postgresql/DBDatabaseDriverPostgreSQL.java  |  1 +
 .../db/sqlite/DBDatabaseDriverSQLite.java       |  2 ++
 .../db/sqlserver/DBDatabaseDriverMSSQL.java     |  1 +
 10 files changed, 42 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java b/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
index ab97fc1..79593de 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
@@ -19,6 +19,10 @@
 package org.apache.empire.db;
 
 // java
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.empire.commons.Attributes;
 import org.apache.empire.commons.OptionEntry;
 import org.apache.empire.commons.Options;
@@ -40,10 +44,6 @@ import org.apache.empire.db.expr.compare.DBCompareExpr;
 import org.apache.empire.db.expr.order.DBOrderByExpr;
 import org.w3c.dom.Element;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
 
 /**
  * This class is the base class for all expressions that represent a single value.
@@ -627,6 +627,17 @@ public abstract class DBColumnExpr extends DBExpr
     }
 
     /**
+     * Creates a sql-expression for the modulo or mod() function.
+     * 
+     * @param divisor the Object value
+     * @return the new DBFuncExpr object
+     */
+    public DBColumnExpr modulo(Object divisor)
+    {
+        return getExprFromPhrase(DBDatabaseDriver.SQL_FUNC_MODULO, new Object[] { divisor
}, getUpdateColumn(), false);
+    }
+
+    /**
      * Creates a sql-expression for the nvl() or coalesce() function.
      * 
      * @param nullValue the int value

http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java b/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
index 0995c55..3fd8bef 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
@@ -92,6 +92,7 @@ public abstract class DBDatabaseDriver implements Serializable
     public static final int SQL_FUNC_TRUNC       = 122; // Oracle: trunc(?, {0})
     public static final int SQL_FUNC_FLOOR       = 123; // Oracle: floor(?)
     public static final int SQL_FUNC_CEILING     = 124; // Oracle: ceil(?)
+    public static final int SQL_FUNC_MODULO      = 125; // Oracle: mod(?)
     // Date
     public static final int SQL_FUNC_DAY         = 132; // MSSQL: month(?)
     public static final int SQL_FUNC_MONTH       = 133; // MSSQL: month(?)

http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/DBTable.java
----------------------------------------------------------------------
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 25708bc..c9d0923 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
@@ -58,7 +58,6 @@ public class DBTable extends DBRowSet implements Cloneable
     private Boolean              quoteName           = null;
     private DBCascadeAction      cascadeDeleteAction = DBCascadeAction.NONE;
     
-
     /**
      * Construct a new DBTable object set the specified parameters
      * to this object and add this object to the current database.
@@ -66,18 +65,33 @@ public class DBTable extends DBRowSet implements Cloneable
      * @param name the table name
      * @param db the valid database object
      */
-    public DBTable(String name, DBDatabase db)
+    public DBTable(String name, DBDatabase db, String alias)
     { 
         super(db);
+        // generate alias
+        if (alias==null)
+            alias = "t" + String.valueOf(tableCount.incrementAndGet());
         // init
         this.name = name;
-        this.alias = "t" + String.valueOf(tableCount.incrementAndGet());
+        this.alias = alias;
         // Add Table to Database
         if (db != null)
             db.addTable(this);
     }
 
     /**
+     * Construct a new DBTable object set the specified parameters
+     * to this object and add this object to the current database.
+     * 
+     * @param name the table name
+     * @param db the valid database object
+     */
+    public DBTable(String name, DBDatabase db)
+    { 
+        this(name, db, null);
+    }
+
+    /**
      * Returns the table name of this object.
      * 
      * @return the table name of this object
@@ -378,7 +392,7 @@ public class DBTable extends DBRowSet implements Cloneable
         if ((context & CTX_ALIAS)!=0 && alias!=null)
         {    // append alias
              buf.append(getRenameTablePhrase());
-             buf.append(alias);
+             buf.append(getAlias());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java b/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
index 6d31f44..48a541f 100644
--- a/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
+++ b/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
@@ -262,6 +262,7 @@ public class DBDatabaseDriverH2 extends DBDatabaseDriver
             case SQL_FUNC_TRUNC:              return "truncate(?,{0})";
             case SQL_FUNC_CEILING:            return "ceiling(?)";
             case SQL_FUNC_FLOOR:              return "floor(?)";
+            case SQL_FUNC_MODULO:             return "mod(?,{0})";
             // Date
             case SQL_FUNC_DAY:                return "day(?)";
             case SQL_FUNC_MONTH:              return "month(?)";

http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java b/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
index 823a6a9..060cbb4 100644
--- a/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
+++ b/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
@@ -154,6 +154,7 @@ public class DBDatabaseDriverHSql extends DBDatabaseDriver
             case SQL_FUNC_TRUNC:        return "truncate(?,{0})";
             case SQL_FUNC_CEILING:      return "ceiling(?)";
             case SQL_FUNC_FLOOR:        return "floor(?)";
+            case SQL_FUNC_MODULO:       return "mod(?,{0})";
             // Date
             case SQL_FUNC_DAY:          return "day(?)";
             case SQL_FUNC_MONTH:        return "month(?)";

http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
b/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
index f802b3e..5da5611 100644
--- a/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
+++ b/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
@@ -604,6 +604,7 @@ public class DBDatabaseDriverMySQL extends DBDatabaseDriver
             case SQL_FUNC_TRUNC:              return "truncate(?,{0})";
             case SQL_FUNC_CEILING:            return "ceiling(?)";
             case SQL_FUNC_FLOOR:              return "floor(?)";
+            case SQL_FUNC_MODULO:             return "mod(?,{0})";
             // Date
             case SQL_FUNC_DAY:                return "day(?)";
             case SQL_FUNC_MONTH:              return "month(?)";

http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
b/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
index 2d9dc06..bc6d248 100644
--- a/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
+++ b/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
@@ -180,6 +180,7 @@ public class DBDatabaseDriverOracle extends DBDatabaseDriver
             case SQL_FUNC_TRUNC:                return "trunc(?,{0})";
             case SQL_FUNC_CEILING:              return "ceil(?)";
             case SQL_FUNC_FLOOR:                return "floor(?)";
+            case SQL_FUNC_MODULO:               return "mod(?,{0})";
             // Date
             case SQL_FUNC_DAY:                  return oracle8Compatibilty ? "to_number(to_char(?,'DD'))"
  : "extract(day from ?)";
             case SQL_FUNC_MONTH:                return oracle8Compatibilty ? "to_number(to_char(?,'MM'))"
  : "extract(month from ?)";

http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
b/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
index 0b82a41..0c30891 100644
--- a/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
+++ b/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
@@ -359,6 +359,7 @@ public class DBDatabaseDriverPostgreSQL extends DBDatabaseDriver
             case SQL_FUNC_TRUNC:              return "truncate(?,{0})";
             case SQL_FUNC_CEILING:            return "ceiling(?)";
             case SQL_FUNC_FLOOR:              return "floor(?)";
+            case SQL_FUNC_MODULO:             return "mod(?,{0})";
             // Date
             case SQL_FUNC_DAY:                return "day(?)";
             case SQL_FUNC_MONTH:              return "month(?)";

http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/sqlite/DBDatabaseDriverSQLite.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/sqlite/DBDatabaseDriverSQLite.java
b/empire-db/src/main/java/org/apache/empire/db/sqlite/DBDatabaseDriverSQLite.java
index 75968db..24e345e 100644
--- a/empire-db/src/main/java/org/apache/empire/db/sqlite/DBDatabaseDriverSQLite.java
+++ b/empire-db/src/main/java/org/apache/empire/db/sqlite/DBDatabaseDriverSQLite.java
@@ -374,6 +374,8 @@ public class DBDatabaseDriverSQLite extends DBDatabaseDriver
                 return "ceiling(?)";
             case SQL_FUNC_FLOOR:
                 return "floor(?)";
+            case SQL_FUNC_MODULO:               
+                return "mod(?,{0})";
                 // Date
             case SQL_FUNC_DAY:
                 return "day(?)";

http://git-wip-us.apache.org/repos/asf/empire-db/blob/f57f8a57/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
b/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
index 66645e0..1d53257 100644
--- a/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
+++ b/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
@@ -305,6 +305,7 @@ public class DBDatabaseDriverMSSQL extends DBDatabaseDriver
             case SQL_FUNC_TRUNC:              return "trunc(?,{0})";
             case SQL_FUNC_CEILING:            return "ceiling(?)";
             case SQL_FUNC_FLOOR:              return "floor(?)";
+            case SQL_FUNC_MODULO:             return "mod(?,{0})";
             // Date
             case SQL_FUNC_DAY:                return "day(?)";
             case SQL_FUNC_MONTH:              return "month(?)";


Mime
View raw message