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 54c36423 EMPIREDB-431 DBColumnExpr: added method to prepend a value
54c36423 is described below
commit 54c3642364bb92c3add1c3f6ea936025e317bfaf
Author: Rainer Döbele <[email protected]>
AuthorDate: Wed Oct 23 20:09:30 2024 +0200
EMPIREDB-431
DBColumnExpr: added method to prepend a value
---
.../src/main/java/org/apache/empire/db/DBColumnExpr.java | 16 +++++++++++++++-
.../empire/exceptions/InvalidOperationException.java | 7 ++++++-
.../empire/exceptions/OperationFailedException.java | 5 +++++
3 files changed, 26 insertions(+), 2 deletions(-)
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 71d8655d..25dade4f 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
@@ -928,7 +928,7 @@ public abstract class DBColumnExpr extends DBExpr
{
return new DBConcatFuncExpr(this, concatExprs);
}
-
+
/**
* concatenates a list of expressions to the current column
* @param separator a string to insert between each of the expressions
@@ -939,6 +939,20 @@ public abstract class DBColumnExpr extends DBExpr
{
return new DBConcatFuncExpr(this, separator, concatExprs);
}
+
+ /**
+ * Puts a value or expression before the current expression
+ * @param value the expressions to prepend
+ * @return the combined value
+ */
+ public DBColumnExpr prepend(Object value)
+ {
+ String opertor = (getDataType()==DataType.UNKNOWN ? ""
+ : (getDataType().isText() ?
getDatabase().getDbms().getSQLPhrase(DBSqlPhrase.SQL_CONCAT_EXPR)
+ : "+"));
+ String template = StringUtils.concat("{0}",opertor,"?");
+ return new DBFuncExpr(this, template, new Object[] { value }, false,
getDataType());
+ }
/*
* Numeric functions
diff --git
a/empire-db/src/main/java/org/apache/empire/exceptions/InvalidOperationException.java
b/empire-db/src/main/java/org/apache/empire/exceptions/InvalidOperationException.java
index 907c89f5..fb6374c9 100644
---
a/empire-db/src/main/java/org/apache/empire/exceptions/InvalidOperationException.java
+++
b/empire-db/src/main/java/org/apache/empire/exceptions/InvalidOperationException.java
@@ -37,9 +37,14 @@ public class InvalidOperationException extends
EmpireException
super(errorType, new String[] { errorMessage });
}
+ public InvalidOperationException(String errorMessage, Throwable cause)
+ {
+ super(errorType, new String[] { errorMessage }, cause);
+ }
+
public InvalidOperationException(String msgTemplate, Object... msgArgs)
{
- super(errorType, new String[] { MessageFormat.format(msgTemplate,
msgArgs) });
+ super(errorType, new String[] { MessageFormat.format(msgTemplate,
msgArgs) }, (msgArgs.length>0 && (msgArgs[msgArgs.length-1] instanceof
Exception)) ? (Exception)msgArgs[msgArgs.length-1] : null );
}
}
diff --git
a/empire-db/src/main/java/org/apache/empire/exceptions/OperationFailedException.java
b/empire-db/src/main/java/org/apache/empire/exceptions/OperationFailedException.java
index d1eb85a1..727a28b5 100644
---
a/empire-db/src/main/java/org/apache/empire/exceptions/OperationFailedException.java
+++
b/empire-db/src/main/java/org/apache/empire/exceptions/OperationFailedException.java
@@ -29,6 +29,11 @@ public class OperationFailedException extends EmpireException
private static final long serialVersionUID = 1L;
public static final ErrorType errorType = new
ErrorType("error.operationFailed", "The operation {0} has failed. Reason given
is: {1}") ;
+
+ public OperationFailedException(String operation, String reason, Throwable
cause)
+ {
+ super(errorType, new String[] { operation, reason }, cause);
+ }
public OperationFailedException(String operation, String reason)
{