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 2024/05/17 09:55:00 UTC

(empire-db) branch master updated: EMPIREDB-425 added funciton getEntityType() to the Column interface

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 818b6637 EMPIREDB-425 added funciton getEntityType() to the Column interface
818b6637 is described below

commit 818b6637fe55497a223a0f4658b88d60d371945d
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Fri May 17 11:54:56 2024 +0200

    EMPIREDB-425
    added funciton getEntityType() to the Column interface
---
 .../org/apache/empire/commons/StringUtils.java     | 42 ++++++++++++++++++++++
 .../main/java/org/apache/empire/data/Column.java   |  6 ++++
 .../org/apache/empire/data/bean/BeanProperty.java  |  7 ++++
 .../main/java/org/apache/empire/db/DBColumn.java   | 13 ++++++-
 4 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java b/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
index c1268eb5..4602ee23 100644
--- a/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
@@ -186,6 +186,48 @@ public class StringUtils
         return ((value.indexOf(substring))<0);
     }
 
+    /**
+     * Returns the first index of any of the given characters in value starting from the beginning 
+     * 
+     * @param value the value to check
+     * @param chars the characters to search
+     * @return the index 
+     */
+    public static int indexOfAny(String value, char... chars)
+    {
+        if (value==null || chars.length==0)
+            return -1;
+        // search
+        for (int i=0; i<value.length(); i++) {
+            char c = value.charAt(i);
+            for (int j=0; j<chars.length; j++)
+                if (c==chars[j])
+                    return i;
+        }
+        return -1; // Not found
+    }
+
+    /**
+     * Returns the first index of any of the given characters in value starting from the end 
+     * 
+     * @param value the value to check
+     * @param chars the characters to search
+     * @return the index 
+     */
+    public static int lastIndexOfAny(String value, char... chars)
+    {
+        if (value==null || chars.length==0)
+            return -1;
+        // search
+        for (int i=value.length(); i>=0; i--) {
+            char c = value.charAt(i);
+            for (int j=0; j<chars.length; j++)
+                if (c==chars[j])
+                    return i;
+        }
+        return -1; // Not found
+    }
+
     /**
      * Converts an array of objects to a string.
      * 
diff --git a/empire-db/src/main/java/org/apache/empire/data/Column.java b/empire-db/src/main/java/org/apache/empire/data/Column.java
index 8e14431b..625f8920 100644
--- a/empire-db/src/main/java/org/apache/empire/data/Column.java
+++ b/empire-db/src/main/java/org/apache/empire/data/Column.java
@@ -52,6 +52,12 @@ public interface Column extends ColumnExpr
     public static final String COLATTR_CURRENCY_CODE    = "currencyCode";           // "ISO 4217 code of the currency"
     public static final String COLATTR_DATETIMEPATTERN  = "dateTimePattern";        // default is yyyy-MM-dd HH:mm:ss
 
+    /**
+     * Returns the EntityType that this Column belongs to
+     * @return the EntityType if any
+     */
+    EntityType getEntityType();    
+    
     /**
      * Returns the maximum size a value for this column is allowed to have.
      * <P>
diff --git a/empire-db/src/main/java/org/apache/empire/data/bean/BeanProperty.java b/empire-db/src/main/java/org/apache/empire/data/bean/BeanProperty.java
index 243462d9..569e8286 100644
--- a/empire-db/src/main/java/org/apache/empire/data/bean/BeanProperty.java
+++ b/empire-db/src/main/java/org/apache/empire/data/bean/BeanProperty.java
@@ -26,6 +26,7 @@ import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.Options;
 import org.apache.empire.data.Column;
 import org.apache.empire.data.DataType;
+import org.apache.empire.data.EntityType;
 import org.apache.empire.db.exceptions.FieldNotNullException;
 
 /**
@@ -94,6 +95,12 @@ public class BeanProperty implements Column
         this(name, dataType, size, required, "text", false);
     }
 
+    @Override
+    public EntityType getEntityType()
+    {
+        return beanClass;
+    }
+    
     /**
      * Returns the name of the property.
      * @return the property name
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBColumn.java b/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
index 903181e6..1ad9dd42 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
@@ -26,6 +26,7 @@ import org.apache.empire.commons.Options;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.Column;
 import org.apache.empire.data.DataType;
+import org.apache.empire.data.EntityType;
 import org.apache.empire.db.exceptions.DatabaseNotOpenException;
 import org.apache.empire.db.expr.column.DBValueExpr;
 import org.apache.empire.db.expr.set.DBSetExpr;
@@ -271,7 +272,17 @@ public abstract class DBColumn extends DBColumnExpr
     {
         return rowset;
     }
-
+    
+    /**
+     * Returns the Entity Type
+     * Same as getRowSet()
+     */
+    @Override
+    public EntityType getEntityType()
+    {
+        return rowset;
+    }
+    
     /**
      * Returns itself as the underlying column.
      */