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 ecd3e469 EMPIREDB-431 DBColumnExpr: move beanPropertyName generation
to StringUtils
ecd3e469 is described below
commit ecd3e469d99317c76215b7430aa67cb69d2f50e4
Author: Rainer Döbele <[email protected]>
AuthorDate: Mon Oct 14 00:13:43 2024 +0200
EMPIREDB-431
DBColumnExpr: move beanPropertyName generation to StringUtils
---
.../org/apache/empire/commons/StringUtils.java | 43 ++++++++++++++++++++
.../java/org/apache/empire/db/DBColumnExpr.java | 46 +++-------------------
2 files changed, 49 insertions(+), 40 deletions(-)
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 6d7e13d2..37448422 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
@@ -926,5 +926,48 @@ public class StringUtils
b.append(padChar);
return b.toString();
}
+
+ /**
+ * Converts a String to camel case
+ * Words must be separated by underscore
+ * @param text the string to convert
+ * @param firstCharUpper flag wether the first character should be upper
case (true) or lower case (false)
+ * @return the camel case string
+ */
+ public static String toCamelCase(String text, boolean firstCharUpper)
+ {
+ // remove spaces
+ if (text.indexOf(' ')>=0)
+ text = text.trim().replace(' ', '_');
+ // begin
+ StringBuilder b = new StringBuilder(text.length());
+ int beg=0;
+ while (beg<text.length())
+ {
+ int end = text.indexOf('_', beg);
+ if (end<0)
+ end = text.length();
+ // assemble
+ if (end>beg)
+ {
+ if (beg==0 && !firstCharUpper)
+ { // begin with all lower cases
+ b.append(text.substring(beg, end).toLowerCase());
+ }
+ else
+ { // add word where first letter is upper case
+ b.append(text.substring(beg, beg+1).toUpperCase());
+ if (end-beg>1)
+ {
+ b.append(text.substring(beg+1, end).toLowerCase());
+ }
+ }
+ }
+ // next
+ beg = end + 1;
+ }
+ // Result
+ return b.toString();
+ }
}
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 f33edf3e..71d8655d 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
@@ -147,7 +147,7 @@ public abstract class DBColumnExpr extends DBExpr
* @return value of the attribute if it exists or null otherwise
*/
@Override
- public synchronized Object getAttribute(String name)
+ public Object getAttribute(String name)
{
if (attributes != null && attributes.indexOf(name)>=0)
return attributes.get(name);
@@ -180,7 +180,7 @@ public abstract class DBColumnExpr extends DBExpr
* @return the list of options
*/
@Override
- public synchronized Options getOptions()
+ public Options getOptions()
{
if (options != null)
return options;
@@ -197,7 +197,7 @@ public abstract class DBColumnExpr extends DBExpr
* @param options the list of options
*/
@SuppressWarnings("unchecked")
- public synchronized <T extends DBColumnExpr> T setOptions(Options options)
+ public <T extends DBColumnExpr> T setOptions(Options options)
{
this.options = options;
return (T)this;
@@ -257,44 +257,10 @@ public abstract class DBColumnExpr extends DBExpr
* @return the name of the bean property used to get and set values
*/
@Override
- public synchronized String getBeanPropertyName()
+ public String getBeanPropertyName()
{
if (beanPropertyName==null)
- { // Compute bean property name
- String name = getName();
- if (name==null)
- return null; // no name provided!
- // compute name
- name = name.toLowerCase();
- String res = "";
- int beg=0;
- while (beg<name.length())
- {
- int end = name.indexOf('_', beg);
- if (end<0)
- end = name.length();
- // assemble
- if (end>beg)
- {
- if (beg==0)
- { // begin with all lower cases
- res = name.substring(beg, end);
- }
- else
- { // add word where first letter is upper case
- res += name.substring(beg, beg+1).toUpperCase();
- if (end-beg>1)
- {
- res += name.substring(beg+1, end);
- }
- }
- }
- // next
- beg = end + 1;
- }
- // Result
- beanPropertyName = res;
- }
+ beanPropertyName = StringUtils.toCamelCase(getName(), false); //
Compute bean property name
return beanPropertyName;
}
@@ -304,7 +270,7 @@ public abstract class DBColumnExpr extends DBExpr
* @param propertyName
*/
@SuppressWarnings("unchecked")
- public synchronized <T extends DBColumnExpr> T setBeanPropertyName(String
propertyName)
+ public <T extends DBColumnExpr> T setBeanPropertyName(String propertyName)
{
this.beanPropertyName = propertyName;
return (T)this;