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 1fae785 EMPIREDB-362 DataListHead getDatabase() helper function
1fae785 is described below
commit 1fae785f4d18b18c45e06a25b448f50df0119d8a
Author: Rainer Döbele <[email protected]>
AuthorDate: Tue Feb 22 09:42:30 2022 +0100
EMPIREDB-362 DataListHead getDatabase() helper function
---
.../org/apache/empire/data/list/DataListHead.java | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git
a/empire-db/src/main/java/org/apache/empire/data/list/DataListHead.java
b/empire-db/src/main/java/org/apache/empire/data/list/DataListHead.java
index 6ff041b..40a917f 100644
--- a/empire-db/src/main/java/org/apache/empire/data/list/DataListHead.java
+++ b/empire-db/src/main/java/org/apache/empire/data/list/DataListHead.java
@@ -24,6 +24,8 @@ import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.Options;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.ColumnExpr;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBObject;
public class DataListHead implements Serializable
{
@@ -69,6 +71,27 @@ public class DataListHead implements Serializable
}
/**
+ * Returns the database instance associated with this DataList (if any)
+ * The database is extracted from the column list
+ * @param dbClass the desired subclass of DBDatabase
+ * @return the database instance or null if no Database instance of this
type could be found
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends DBDatabase> T getDatabase(Class<T> dbClass)
+ {
+ for (int i=0; i<columns.length; i++)
+ {
+ if (columns[i] instanceof DBObject)
+ {
+ DBDatabase db = ((DBObject)columns[i]).getDatabase();
+ if (db!=null && dbClass.isAssignableFrom(db.getClass()))
+ return (T)db;
+ }
+ }
+ return null;
+ }
+
+ /**
* Custom value formatting
* Default is to convert to a String and calls escape()
* @param idx the field index