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 ef066cd EMPIREDB-323 DBCommand constaints dectect mutually-exclusive
for function expressions.
ef066cd is described below
commit ef066cddd9c760b42045b8cfa114546c3923c174
Author: Rainer Döbele <[email protected]>
AuthorDate: Tue Jan 7 13:16:30 2020 +0100
EMPIREDB-323
DBCommand constaints dectect mutually-exclusive for function expressions.
---
.../src/main/java/org/apache/empire/db/DBExpr.java | 19 ++++++++-----
.../empire/db/expr/column/DBAbstractFuncExpr.java | 17 ++++++++++++
.../empire/db/expr/compare/DBCompareColExpr.java | 31 +++++++++++++++++++---
3 files changed, 57 insertions(+), 10 deletions(-)
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 56c5c65..4ee04a6 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
@@ -18,15 +18,16 @@
*/
package org.apache.empire.db;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Set;
+
+import org.apache.empire.commons.OptionEntry;
// java
import org.apache.empire.data.DataType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Set;
-
/**
* This abstract class is the base class for all database expression classes
(e.g. DBAliasExpr or DBCalsExpr)
@@ -82,7 +83,13 @@ public abstract class DBExpr extends DBObject
((DBExpr) value).addSQL(buf, context);
return buf.toString();
}
- else if (value!=null && value.getClass().isEnum())
+ // check option entry
+ if (value instanceof OptionEntry)
+ {
+ value = ((OptionEntry)value).getValue();
+ }
+ // check enum
+ if (value!=null && value.getClass().isEnum())
{ // check enum
if (dataType.isNumeric())
value = ((Enum<?>)value).ordinal();
@@ -90,7 +97,7 @@ public abstract class DBExpr extends DBObject
value = ((Enum<?>)value).name();
}
else if (value instanceof Collection<?>)
- {
+ { // collection 2 array
value = ((Collection<?>)value).toArray();
}
// Check whether it is an array
diff --git
a/empire-db/src/main/java/org/apache/empire/db/expr/column/DBAbstractFuncExpr.java
b/empire-db/src/main/java/org/apache/empire/db/expr/column/DBAbstractFuncExpr.java
index d89fd3d..1a2e7f8 100644
---
a/empire-db/src/main/java/org/apache/empire/db/expr/column/DBAbstractFuncExpr.java
+++
b/empire-db/src/main/java/org/apache/empire/db/expr/column/DBAbstractFuncExpr.java
@@ -146,6 +146,23 @@ public abstract class DBAbstractFuncExpr extends
DBColumnExpr
}
/**
+ * check if other function is the same and applies to the same column
+ * @param other
+ * @return true if both functions are the same and on the same column or
false otherwise
+ */
+ public boolean isMutuallyExclusive(DBAbstractFuncExpr other)
+ {
+ String tname = getFunctionName();
+ String oname = other.getFunctionName();
+ if (StringUtils.compareNotEqual(tname, oname))
+ return false;
+ // check update columns
+ DBColumn tcol = getUpdateColumn();
+ DBColumn ocol = other.getUpdateColumn();
+ return (tcol!=null) ? (tcol.equals(ocol)) : false;
+ }
+
+ /**
* Creates the SQL-Command adds a function to the SQL-Command.
*
* The sql function string is built from a string template.
diff --git
a/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBCompareColExpr.java
b/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBCompareColExpr.java
index 700b2b5..1612030 100644
---
a/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBCompareColExpr.java
+++
b/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBCompareColExpr.java
@@ -18,14 +18,16 @@
*/
package org.apache.empire.db.expr.compare;
+import java.util.Set;
+
// java
import org.apache.empire.db.DBCmpType;
import org.apache.empire.db.DBColumn;
import org.apache.empire.db.DBColumnExpr;
import org.apache.empire.db.DBDatabase;
import org.apache.empire.db.DBExpr;
-
-import java.util.Set;
+import org.apache.empire.db.expr.column.DBAbstractFuncExpr;
+import org.apache.empire.db.expr.column.DBAliasExpr;
/**
@@ -253,9 +255,30 @@ public class DBCompareColExpr extends DBCompareExpr
DBColumnExpr oexpr = o.getColumnExpr();
if (expr.equals(oexpr))
return true;
- DBColumn col = expr.getUpdateColumn();
+ // unwrap
+ DBColumnExpr texpr = expr;
+ if (texpr instanceof DBAliasExpr)
+ texpr = ((DBAliasExpr) texpr).getExpr();
+ if (oexpr instanceof DBAliasExpr)
+ oexpr = ((DBAliasExpr) oexpr).getExpr();
+ // check function expression
+ boolean tfunc = (texpr instanceof DBAbstractFuncExpr);
+ boolean ofunc = (oexpr instanceof DBAbstractFuncExpr);
+ if (tfunc || ofunc)
+ { // check if both are the same
+ if (tfunc && ofunc)
+ { // both are functions
+ return
((DBAbstractFuncExpr)texpr).isMutuallyExclusive((DBAbstractFuncExpr)oexpr);
+ }
+ else
+ { // not the same
+ return false;
+ }
+ }
+ // finally check update columns
+ DBColumn tcol = texpr.getUpdateColumn();
DBColumn ocol = oexpr.getUpdateColumn();
- return (col!=null) ? (col.equals(ocol)) : false;
+ return (tcol!=null) ? (tcol.equals(ocol)) : false;
}
return false;
}