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 2021/10/31 16:27:04 UTC

[empire-db] branch master updated: EMPIREDB-354 Added DBCommand methods for convenience

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 37f71f1  EMPIREDB-354 Added DBCommand methods for convenience
37f71f1 is described below

commit 37f71f149064e69597d74c5f9a2c9f46ddded97d
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Sun Oct 31 17:27:01 2021 +0100

    EMPIREDB-354
    Added DBCommand methods for convenience
---
 .../main/java/org/apache/empire/db/DBCommand.java  | 33 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
index 5311311..d8a7932 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
@@ -359,9 +359,9 @@ public abstract class DBCommand extends DBCommandExpr
     /**
      * replaces a select expression with another or removes a select expression
      * In order to remove the expression, set the replWith parameter to null
+     * If the replace expression is not found, an ItemNotFoundException is thrown 
      * @param replExpr
      * @param replWith
-     * @return true if the expression could be replaced or false otherwise
      */
     public void replaceSelect(DBColumnExpr replExpr, DBColumnExpr replWith)
     {
@@ -374,6 +374,22 @@ public abstract class DBCommand extends DBCommandExpr
         else
             select.remove(idx);
     }
+
+    /**
+     * removes one or more expressions from the Select expression list
+     * @param exprs the expression(s) to be removed
+     */
+    public void removeSelect(DBColumnExpr... exprs)
+    {
+        if (select==null)
+            return;
+        for (int i=0; i<exprs.length; i++)
+        {
+            int idx = select.indexOf(exprs[i]);
+            if (idx>=0)
+                select.remove(idx);
+        }
+    }
     
     /**
      * returns true if prepared statements are enabled for this database
@@ -913,9 +929,22 @@ public abstract class DBCommand extends DBCommandExpr
         }
     }
     
+    /**
+     * returns whether or not the command has any select expression 
+     * @return true if the command has any select expression of false otherwise
+     */
     public boolean hasSelectExpr()
     {
-        return (select!=null && select.size()>0);
+        return (select!=null && !select.isEmpty());
+    }
+
+    /**
+     * returns whether or not the command has a specific select expression 
+     * @return true if the command contains the given select expression of false otherwise
+     */
+    public boolean hasSelectExpr(DBColumnExpr expr)
+    {
+        return (select!=null ? (select.indexOf(expr)>=0) : false);
     }
     
     @Override