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 af59f111 EMPIREDB-431 DBRowSet: allow custom attributes ClassUtils:
Unwrap all InvocationTargetExceptions
af59f111 is described below
commit af59f111c9ae677195018a19ba412975abaad7be
Author: Rainer Döbele <[email protected]>
AuthorDate: Mon Jan 13 15:33:59 2025 +0100
EMPIREDB-431
DBRowSet: allow custom attributes
ClassUtils: Unwrap all InvocationTargetExceptions
---
.../java/org/apache/empire/commons/ClassUtils.java | 40 +++++++++++++++++++---
.../main/java/org/apache/empire/db/DBRowSet.java | 37 +++++++++++++++++++-
.../{db => }/exceptions/UserLevelException.java | 0
3 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/empire-db/src/main/java/org/apache/empire/commons/ClassUtils.java
b/empire-db/src/main/java/org/apache/empire/commons/ClassUtils.java
index 921e4a0b..ad302614 100644
--- a/empire-db/src/main/java/org/apache/empire/commons/ClassUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/commons/ClassUtils.java
@@ -393,7 +393,15 @@ public final class ClassUtils
{
throw new InvalidOperationException(typeClass.getName()+" has no
default constructor.");
}
- catch (InstantiationException | IllegalAccessException |
IllegalArgumentException | SecurityException | InvocationTargetException e)
+ catch (InvocationTargetException e)
+ { // Unwrap exception and re-throw the cause exception
+ Throwable cause = e.getCause();
+ if (cause instanceof EmpireException)
+ throw (EmpireException)cause;
+ // wrap
+ throw new InternalException(cause);
+ }
+ catch (InstantiationException | IllegalAccessException |
IllegalArgumentException | SecurityException e)
{
throw new InternalException(e);
}
@@ -426,7 +434,15 @@ public final class ClassUtils
// create
return typeConstructor.newInstance(params);
}
- catch (InstantiationException | IllegalAccessException |
IllegalArgumentException | InvocationTargetException e)
+ catch (InvocationTargetException e)
+ { // Unwrap exception and re-throw the cause exception
+ Throwable cause = e.getCause();
+ if (cause instanceof EmpireException)
+ throw (EmpireException)cause;
+ // wrap
+ throw new InternalException(cause);
+ }
+ catch (InstantiationException | IllegalAccessException |
IllegalArgumentException e)
{
throw new InternalException(e);
}
@@ -687,7 +703,15 @@ public final class ClassUtils
// invoke
return method.invoke(object, EMPTY_ARGS);
}
- catch (IllegalAccessException | IllegalArgumentException |
InvocationTargetException e)
+ catch (InvocationTargetException e)
+ { // Unwrap exception and re-throw the cause exception
+ Throwable cause = e.getCause();
+ if (cause instanceof EmpireException)
+ throw (EmpireException)cause;
+ // wrap
+ throw new InternalException(cause);
+ }
+ catch (IllegalAccessException | IllegalArgumentException e)
{
throw new NotSupportedException(object, method.getName(), e);
}
@@ -710,7 +734,15 @@ public final class ClassUtils
// invoke
return method.invoke(object, params);
}
- catch (IllegalAccessException | IllegalArgumentException |
InvocationTargetException e)
+ catch (InvocationTargetException e)
+ { // Unwrap exception and re-throw the cause exception
+ Throwable cause = e.getCause();
+ if (cause instanceof EmpireException)
+ throw (EmpireException)cause;
+ // wrap
+ throw new InternalException(cause);
+ }
+ catch (IllegalAccessException | IllegalArgumentException e)
{
throw new NotSupportedException(object, method.getName(), e);
}
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
b/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
index b87cb26d..bf666315 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
@@ -29,6 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.empire.commons.Attributes;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.Column;
@@ -151,6 +152,7 @@ public abstract class DBRowSet extends DBExpr implements
EntityType
protected DBColumn timestampColumn = null;
protected Map<DBColumn, DBColumn> columnReferences = null;
protected List<DBColumn> columns = new
ArrayList<DBColumn>();
+ protected Attributes attributes = null;
// associated Entity Bean Class (optional)
protected Class<?> beanType = null;
@@ -200,7 +202,40 @@ public abstract class DBRowSet extends DBExpr implements
EntityType
*/
public String getIdentifier()
{
- return db.getIdentifier()+"."+getName();
+ return StringUtils.concat(db.getIdentifier(), ".", getName());
+ }
+
+ /**
+ * Returns a named attribute for this table
+ */
+ public Object getAttribute(String name)
+ {
+ return (attributes != null ? attributes.get(name) : null);
+ }
+
+ /**
+ * Returns all metadata attributes.
+ * @return set of metadata attributes
+ */
+ @SuppressWarnings("unchecked")
+ public Set<Attributes.Attribute> getAttributes()
+ {
+ return (attributes!=null ? Collections.unmodifiableSet(attributes)
+ : Collections.EMPTY_SET);
+ }
+
+ /**
+ * Sets the value of a attribute.
+ * @param name the attribute name
+ * @param value the value of the attribute
+ */
+ @SuppressWarnings("unchecked")
+ public synchronized <T extends DBTable> T setAttribute(String name, Object
value)
+ {
+ if (attributes== null)
+ attributes = new Attributes();
+ attributes.set(name, value);
+ return (T)this;
}
/**
diff --git
a/empire-db/src/main/java/org/apache/empire/db/exceptions/UserLevelException.java
b/empire-db/src/main/java/org/apache/empire/exceptions/UserLevelException.java
similarity index 100%
rename from
empire-db/src/main/java/org/apache/empire/db/exceptions/UserLevelException.java
rename to
empire-db/src/main/java/org/apache/empire/exceptions/UserLevelException.java