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 50ed9c2 EMPIREDB-344 new method "replaceSelect" in DBCommand
50ed9c2 is described below
commit 50ed9c2a4071f9ad601529c56d3f19a79034b505
Author: Rainer Döbele <[email protected]>
AuthorDate: Tue Apr 20 11:59:45 2021 +0200
EMPIREDB-344
new method "replaceSelect" in DBCommand
---
.../main/java/org/apache/empire/db/DBCommand.java | 30 ++++++++++++++++++++++
.../java/org/apache/empire/db/DBRecordData.java | 19 ++++++++++++++
2 files changed, 49 insertions(+)
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 b2aea65..96feebe 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
@@ -42,6 +42,7 @@ import org.apache.empire.db.expr.join.DBJoinExpr;
import org.apache.empire.db.expr.set.DBSetExpr;
import org.apache.empire.exceptions.InternalException;
import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.ItemNotFoundException;
import org.apache.empire.exceptions.MiscellaneousErrorException;
import org.apache.empire.exceptions.ObjectNotValidException;
import org.slf4j.Logger;
@@ -344,6 +345,35 @@ public abstract class DBCommand extends DBCommandExpr
select(col.qualified());
}
}
+
+ /**
+ * returns whether or not a command contains a select expression
+ * @return true if the expression is contained in the select
+ */
+ public boolean containsSelect(DBColumnExpr selExpr)
+ {
+ int idx = (select != null ? select.indexOf(selExpr) : -1);
+ return (idx<0);
+ }
+
+ /**
+ * replaces a select expression with another or removes a select expression
+ * In order to remove the expression, set the replWith parameter to null
+ * @param replExpr
+ * @param replWith
+ * @return true if the expression could be replaced or false otherwise
+ */
+ public void replaceSelect(DBColumnExpr replExpr, DBColumnExpr replWith)
+ {
+ int idx = (select != null ? select.indexOf(replExpr) : -1);
+ if (idx < 0)
+ throw new ItemNotFoundException(replExpr);
+ // replace now
+ if (replWith!=null)
+ select.set(idx, replWith);
+ else
+ select.remove(idx);
+ }
/**
* returns true if prepared statements are enabled for this database
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 f9b8d38..61e08b1 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
@@ -93,6 +93,25 @@ public abstract class DBRecordData extends DBObject
}
/**
+ * Returns an array of values for the given column expressions
+ *
+ * @param column the column expressions
+ * @return the corresponding record values
+ */
+ public final Object[] getValues(ColumnExpr[] columns)
+ {
+ Object[] values = new Object[columns.length];
+ for (int i=0; i<columns.length; i++)
+ {
+ int index = getFieldIndex(columns[i]);
+ if (index<0)
+ throw new ItemNotFoundException(columns[i].getName());
+ values[i] = getValue(index);
+ }
+ return values;
+ }
+
+ /**
* Returns a data value identified by the column index.
* The value is converted to integer if necessary .
*