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 b3c7be00 EMPIREDB-460 BeanPropertyUtils as replacement for direct
calls to org.apache.commons.beanutils
b3c7be00 is described below
commit b3c7be0005074b8742bb497ceb294358a9438545
Author: Rainer Döbele <[email protected]>
AuthorDate: Sat Mar 22 23:21:46 2025 +0100
EMPIREDB-460
BeanPropertyUtils as replacement for direct calls to
org.apache.commons.beanutils
---
.../websample/web/pages/EmployeeListPage.java | 56 ++--
.../jsf2/websample/web/pages/EmployeeListPage.java | 53 ++--
.../empire/samples/springboot/SampleApp.java | 22 +-
.../jakarta/pageelements/BeanListPageElement.java | 4 +-
.../empire/jakarta/pages/PagePhaseListener.java | 7 +-
.../empire/jakarta/utils/TagEncodingHelper.java | 78 +-----
.../jsf2/pageelements/BeanListPageElement.java | 4 +-
.../empire/jsf2/pages/PagePhaseListener.java | 7 +-
.../empire/jsf2/utils/TagEncodingHelper.java | 78 +-----
.../apache/empire/commons/BeanPropertyUtils.java | 286 +++++++++++++++++++++
.../java/org/apache/empire/commons/ClassUtils.java | 59 -----
.../apache/empire/data/bean/BeanRecordProxy.java | 76 ++----
.../org/apache/empire/data/list/DataListEntry.java | 11 +-
.../java/org/apache/empire/db/DBRecordBase.java | 41 +--
.../java/org/apache/empire/db/DBRecordData.java | 11 +-
15 files changed, 414 insertions(+), 379 deletions(-)
diff --git
a/empire-db-examples/empire-db-example-jakarta-faces/src/main/java/org/apache/empire/jakarta/websample/web/pages/EmployeeListPage.java
b/empire-db-examples/empire-db-example-jakarta-faces/src/main/java/org/apache/empire/jakarta/websample/web/pages/EmployeeListPage.java
index 643c33e1..ee622905 100644
---
a/empire-db-examples/empire-db-example-jakarta-faces/src/main/java/org/apache/empire/jakarta/websample/web/pages/EmployeeListPage.java
+++
b/empire-db-examples/empire-db-example-jakarta-faces/src/main/java/org/apache/empire/jakarta/websample/web/pages/EmployeeListPage.java
@@ -19,17 +19,15 @@
*/
package org.apache.empire.jakarta.websample.web.pages;
-import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Date;
-import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.Options;
import org.apache.empire.db.DBColumn;
import org.apache.empire.db.DBColumnExpr;
import org.apache.empire.db.DBCommand;
-import org.apache.empire.exceptions.BeanPropertyGetException;
import org.apache.empire.jakarta.pageelements.BeanListPageElement;
import org.apache.empire.jakarta.pageelements.ListPageElement;
import
org.apache.empire.jakarta.pageelements.ListPageElement.ParameterizedItem;
@@ -223,45 +221,27 @@ public class EmployeeListPage extends SamplePage
private void addSearchConstraint(DBCommand cmd, DBColumn col, Object bean)
{
- Object value;
- try
- {
- value = PropertyUtils.getProperty(bean, col.getBeanPropertyName());
- if (ObjectUtils.isEmpty(value))
- return;
- // is it an array
- if (value instanceof Collection<?> || value.getClass().isArray())
- {
- cmd.where(col.in(value));
- return;
- }
- // text
- if (col.getOptions() == null && col.getDataType().isText())
- {
- StringBuilder b = new StringBuilder();
- b.append("%");
- b.append(((String) value).toUpperCase());
- b.append("%");
- cmd.where(col.upper().like(b.toString()));
- return;
- }
- // value
- cmd.where(col.is(value));
+ Object value = BeanPropertyUtils.getProperty(bean,
col.getBeanPropertyName());
+ if (ObjectUtils.isEmpty(value))
return;
- }
- catch (IllegalAccessException e)
- {
- throw new BeanPropertyGetException(bean,
col.getBeanPropertyName(), e);
- }
- catch (InvocationTargetException e)
+ // is it an array
+ if (value instanceof Collection<?> || value.getClass().isArray())
{
- throw new BeanPropertyGetException(bean,
col.getBeanPropertyName(), e);
+ cmd.where(col.in(value));
+ return;
}
- catch (NoSuchMethodException e)
+ // text
+ if (col.getOptions() == null && col.getDataType().isText())
{
- throw new BeanPropertyGetException(bean,
col.getBeanPropertyName(), e);
+ StringBuilder b = new StringBuilder();
+ b.append("%");
+ b.append(((String) value).toUpperCase());
+ b.append("%");
+ cmd.where(col.upper().like(b.toString()));
+ return;
}
+ // value
+ cmd.where(col.is(value));
+ return;
}
-
-
}
diff --git
a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeListPage.java
b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeListPage.java
index 032c1dc4..a8254556 100644
---
a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeListPage.java
+++
b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeListPage.java
@@ -23,7 +23,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Date;
-import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.Options;
import org.apache.empire.db.DBColumn;
@@ -223,45 +223,28 @@ public class EmployeeListPage extends SamplePage
private void addSearchConstraint(DBCommand cmd, DBColumn col, Object bean)
{
- Object value;
- try
- {
- value = PropertyUtils.getProperty(bean, col.getBeanPropertyName());
- if (ObjectUtils.isEmpty(value))
- return;
- // is it an array
- if (value instanceof Collection<?> || value.getClass().isArray())
- {
- cmd.where(col.in(value));
- return;
- }
- // text
- if (col.getOptions() == null && col.getDataType().isText())
- {
- StringBuilder b = new StringBuilder();
- b.append("%");
- b.append(((String) value).toUpperCase());
- b.append("%");
- cmd.where(col.upper().like(b.toString()));
- return;
- }
- // value
- cmd.where(col.is(value));
+ Object value = BeanPropertyUtils.getProperty(bean,
col.getBeanPropertyName());
+ if (ObjectUtils.isEmpty(value))
return;
- }
- catch (IllegalAccessException e)
- {
- throw new BeanPropertyGetException(bean,
col.getBeanPropertyName(), e);
- }
- catch (InvocationTargetException e)
+ // is it an array
+ if (value instanceof Collection<?> || value.getClass().isArray())
{
- throw new BeanPropertyGetException(bean,
col.getBeanPropertyName(), e);
+ cmd.where(col.in(value));
+ return;
}
- catch (NoSuchMethodException e)
+ // text
+ if (col.getOptions() == null && col.getDataType().isText())
{
- throw new BeanPropertyGetException(bean,
col.getBeanPropertyName(), e);
+ StringBuilder b = new StringBuilder();
+ b.append("%");
+ b.append(((String) value).toUpperCase());
+ b.append("%");
+ cmd.where(col.upper().like(b.toString()));
+ return;
}
+ // value
+ cmd.where(col.is(value));
+ return;
}
-
}
diff --git
a/empire-db-examples/empire-db-example-spring-boot/src/main/java/org/apache/empire/samples/springboot/SampleApp.java
b/empire-db-examples/empire-db-example-spring-boot/src/main/java/org/apache/empire/samples/springboot/SampleApp.java
index 6c6ccb16..b5a6986b 100644
---
a/empire-db-examples/empire-db-example-spring-boot/src/main/java/org/apache/empire/samples/springboot/SampleApp.java
+++
b/empire-db-examples/empire-db-example-spring-boot/src/main/java/org/apache/empire/samples/springboot/SampleApp.java
@@ -18,7 +18,6 @@
*/
package org.apache.empire.samples.springboot;
-import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Connection;
@@ -29,7 +28,7 @@ import java.util.Map;
import javax.sql.DataSource;
-import org.apache.commons.beanutils.BeanUtils;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.Record;
@@ -555,21 +554,14 @@ public class SampleApp implements ApplicationRunner {
for (Map.Entry<String, String> entry : dbmsHandlerProperties.entrySet())
{
String name = entry.getKey();
String newValue = entry.getValue();
- try {
- BeanUtils.setProperty(bean, name, newValue);
-
- Object value = BeanUtils.getProperty(bean, name);
- if (ObjectUtils.compareEqual(newValue, value)) {
+ // set property
+ BeanPropertyUtils.setProperty(bean, name, newValue);
+ // Check
+ Object value = BeanPropertyUtils.getProperty(bean, name);
+ if (ObjectUtils.compareEqual(newValue, value)) {
LOGGER.info("Configuration property '{}' set to \"{}\"", name,
newValue);
- } else {
+ } else {
LOGGER.error("Failed to set property '{}'. Value is \"{}\"", name,
value);
- }
- } catch (IllegalAccessException ex) {
- LOGGER.error(null, ex);
- } catch (InvocationTargetException ex) {
- LOGGER.error(null, ex);
- } catch (NoSuchMethodException ex) {
- LOGGER.error("Property '{}' not found in {}", name,
bean.getClass().getName());
}
}
}
diff --git
a/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/pageelements/BeanListPageElement.java
b/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/pageelements/BeanListPageElement.java
index 83c28a77..1fdc35c6 100644
---
a/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/pageelements/BeanListPageElement.java
+++
b/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/pageelements/BeanListPageElement.java
@@ -23,7 +23,7 @@ import java.util.Set;
import jakarta.faces.event.ValueChangeEvent;
-import org.apache.commons.beanutils.BeanUtils;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.Column;
@@ -589,7 +589,7 @@ public class BeanListPageElement<T> extends
ListPageElement<T> implements ListIt
// Get Property value
try
{
- key[i] = BeanUtils.getSimpleProperty(item, propName);
+ key[i] = BeanPropertyUtils.getProperty(item, propName);
}
catch (Exception e)
{
diff --git
a/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/pages/PagePhaseListener.java
b/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/pages/PagePhaseListener.java
index bf916ce6..1a64191a 100644
---
a/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/pages/PagePhaseListener.java
+++
b/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/pages/PagePhaseListener.java
@@ -26,7 +26,7 @@ import jakarta.faces.event.PhaseEvent;
import jakarta.faces.event.PhaseId;
import jakarta.faces.event.PhaseListener;
-import org.apache.commons.beanutils.BeanUtils;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.exceptions.InternalException;
import org.apache.empire.exceptions.ObjectNotValidException;
import org.apache.empire.jakarta.app.FacesUtils;
@@ -200,11 +200,12 @@ public class PagePhaseListener implements PhaseListener
String value = pageParams.get(name);
try
{
- BeanUtils.setProperty(pageBean, name, value);
+ if (!BeanPropertyUtils.setProperty(pageBean, name, value))
+ log.error("Unable to set PageParam \"{}\" on {}", name,
pageBean.getClass().getName());
}
catch (Exception e)
{
- log.error("Unable to set PageParam " + name + " on " +
pageBean.getClass().getName() + ".", e);
+ log.error("Unable to set PageParam \"{}\" on {}", name,
pageBean.getClass().getName(), e);
}
}
}
diff --git
a/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/utils/TagEncodingHelper.java
b/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/utils/TagEncodingHelper.java
index 52291829..23d0c691 100644
---
a/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/utils/TagEncodingHelper.java
+++
b/empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/utils/TagEncodingHelper.java
@@ -19,17 +19,13 @@
package org.apache.empire.jakarta.utils;
import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.BeanUtilsBean;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.beanutils.PropertyUtilsBean;
import org.apache.empire.commons.Attributes;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.Options;
import org.apache.empire.commons.StringUtils;
@@ -45,11 +41,10 @@ import org.apache.empire.db.DBRecordBase;
import org.apache.empire.db.DBRowSet;
import org.apache.empire.db.exceptions.FieldIllegalValueException;
import org.apache.empire.db.exceptions.FieldNotNullException;
-import org.apache.empire.exceptions.BeanPropertyGetException;
-import org.apache.empire.exceptions.BeanPropertySetException;
import org.apache.empire.exceptions.EmpireException;
import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.InvalidPropertyException;
+import org.apache.empire.exceptions.ItemNotFoundException;
import org.apache.empire.exceptions.NotSupportedException;
import org.apache.empire.exceptions.PropertyReadOnlyException;
import org.apache.empire.jakarta.app.FacesUtils;
@@ -1404,65 +1399,21 @@ public class TagEncodingHelper implements
NamingContainer
protected Object getBeanPropertyValue(Object bean, String property)
{
- try
- { // Get Property Value
- PropertyUtilsBean pub =
BeanUtilsBean.getInstance().getPropertyUtils();
- return pub.getSimpleProperty(bean, property);
-
- }
- catch (IllegalAccessException e)
- {
- log.error(bean.getClass().getName() + ": unable to get property '"
+ property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- }
- catch (InvocationTargetException e)
- {
- log.error(bean.getClass().getName() + ": unable to get property '"
+ property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- }
- catch (NoSuchMethodException e)
- {
- log.warn(bean.getClass().getName() + ": no getter available for
property '" + property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- }
+ return BeanPropertyUtils.getProperty(bean, property);
}
protected void setBeanPropertyValue(Object bean, String property, Object
value)
{
- // Get Property Name
- try
- { // Get Property Value
- if (ObjectUtils.isEmpty(value))
- value = null;
- // Set Property Value
- if (value != null)
- { // Bean utils will convert if necessary
- BeanUtils.setProperty(bean, property, value);
- }
+ // set Property
+ if (ObjectUtils.isEmpty(value))
+ value = null;
+ // Set Property Value
+ if (!BeanPropertyUtils.setProperty(bean, property, value))
+ { // Property has not been set
+ if (BeanPropertyUtils.hasProperty(bean, property, true)==0)
+ throw new PropertyReadOnlyException(property);
else
- { // Don't convert, just set
- PropertyUtils.setProperty(bean, property, null);
- }
- }
- catch (IllegalArgumentException e)
- {
- log.error(bean.getClass().getName() + ": invalid argument for
property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- catch (IllegalAccessException e)
- {
- log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- catch (InvocationTargetException e)
- {
- log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- catch (NoSuchMethodException e)
- {
- log.error(bean.getClass().getName() + ": no setter available for
property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
+ throw new ItemNotFoundException(property);
}
}
@@ -2162,11 +2113,10 @@ public class TagEncodingHelper implements
NamingContainer
String property = col.getBeanPropertyName();
try
{ // Use Beanutils to get Property
- PropertyUtilsBean pub =
BeanUtilsBean.getInstance().getPropertyUtils();
- return pub.getSimpleProperty(rec, property);
+ return BeanPropertyUtils.getProperty(rec, property);
}
catch (Exception e)
- { log.error("BeanUtils.getSimpleProperty failed for
"+property, e);
+ { log.error("BeanUtils.getProperty failed for property {} on
{} ", property, rec.getClass().getName(), e);
return null;
}
}
diff --git
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
index 550c65de..899c9668 100644
---
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
+++
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
@@ -23,7 +23,7 @@ import java.util.Set;
import javax.faces.event.ValueChangeEvent;
-import org.apache.commons.beanutils.BeanUtils;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.Column;
@@ -589,7 +589,7 @@ public class BeanListPageElement<T> extends
ListPageElement<T> implements ListIt
// Get Property value
try
{
- key[i] = BeanUtils.getSimpleProperty(item, propName);
+ key[i] = BeanPropertyUtils.getProperty(item, propName);
}
catch (Exception e)
{
diff --git
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
index c899126b..79fccff9 100644
---
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
+++
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
@@ -26,7 +26,7 @@ import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
-import org.apache.commons.beanutils.BeanUtils;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.exceptions.InternalException;
import org.apache.empire.exceptions.ObjectNotValidException;
import org.apache.empire.jsf2.app.FacesUtils;
@@ -200,11 +200,12 @@ public class PagePhaseListener implements PhaseListener
String value = pageParams.get(name);
try
{
- BeanUtils.setProperty(pageBean, name, value);
+ if (!BeanPropertyUtils.setProperty(pageBean, name, value))
+ log.error("Unable to set PageParam \"{}\" on {}", name,
pageBean.getClass().getName());
}
catch (Exception e)
{
- log.error("Unable to set PageParam " + name + " on " +
pageBean.getClass().getName() + ".", e);
+ log.error("Unable to set PageParam \"{}\" on {}", name,
pageBean.getClass().getName(), e);
}
}
}
diff --git
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
index 4b008e2e..8d82126d 100644
---
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
+++
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
@@ -19,7 +19,6 @@
package org.apache.empire.jsf2.utils;
import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
@@ -38,11 +37,8 @@ import javax.faces.component.html.HtmlPanelGroup;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.BeanUtilsBean;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.beanutils.PropertyUtilsBean;
import org.apache.empire.commons.Attributes;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.Options;
import org.apache.empire.commons.StringUtils;
@@ -58,11 +54,10 @@ import org.apache.empire.db.DBRecordBase;
import org.apache.empire.db.DBRowSet;
import org.apache.empire.db.exceptions.FieldIllegalValueException;
import org.apache.empire.db.exceptions.FieldNotNullException;
-import org.apache.empire.exceptions.BeanPropertyGetException;
-import org.apache.empire.exceptions.BeanPropertySetException;
import org.apache.empire.exceptions.EmpireException;
import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.InvalidPropertyException;
+import org.apache.empire.exceptions.ItemNotFoundException;
import org.apache.empire.exceptions.NotSupportedException;
import org.apache.empire.exceptions.PropertyReadOnlyException;
import org.apache.empire.jsf2.app.FacesUtils;
@@ -1404,65 +1399,21 @@ public class TagEncodingHelper implements
NamingContainer
protected Object getBeanPropertyValue(Object bean, String property)
{
- try
- { // Get Property Value
- PropertyUtilsBean pub =
BeanUtilsBean.getInstance().getPropertyUtils();
- return pub.getSimpleProperty(bean, property);
-
- }
- catch (IllegalAccessException e)
- {
- log.error(bean.getClass().getName() + ": unable to get property '"
+ property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- }
- catch (InvocationTargetException e)
- {
- log.error(bean.getClass().getName() + ": unable to get property '"
+ property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- }
- catch (NoSuchMethodException e)
- {
- log.warn(bean.getClass().getName() + ": no getter available for
property '" + property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- }
+ return BeanPropertyUtils.getProperty(bean, property);
}
protected void setBeanPropertyValue(Object bean, String property, Object
value)
{
- // Get Property Name
- try
- { // Get Property Value
- if (ObjectUtils.isEmpty(value))
- value = null;
- // Set Property Value
- if (value != null)
- { // Bean utils will convert if necessary
- BeanUtils.setProperty(bean, property, value);
- }
+ // set Property
+ if (ObjectUtils.isEmpty(value))
+ value = null;
+ // Set Property Value
+ if (!BeanPropertyUtils.setProperty(bean, property, value))
+ { // Property has not been set
+ if (BeanPropertyUtils.hasProperty(bean, property, true)==0)
+ throw new PropertyReadOnlyException(property);
else
- { // Don't convert, just set
- PropertyUtils.setProperty(bean, property, null);
- }
- }
- catch (IllegalArgumentException e)
- {
- log.error(bean.getClass().getName() + ": invalid argument for
property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- catch (IllegalAccessException e)
- {
- log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- catch (InvocationTargetException e)
- {
- log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- catch (NoSuchMethodException e)
- {
- log.error(bean.getClass().getName() + ": no setter available for
property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
+ throw new ItemNotFoundException(property);
}
}
@@ -2162,11 +2113,10 @@ public class TagEncodingHelper implements
NamingContainer
String property = col.getBeanPropertyName();
try
{ // Use Beanutils to get Property
- PropertyUtilsBean pub =
BeanUtilsBean.getInstance().getPropertyUtils();
- return pub.getSimpleProperty(rec, property);
+ return BeanPropertyUtils.getProperty(rec, property);
}
catch (Exception e)
- { log.error("BeanUtils.getSimpleProperty failed for
"+property, e);
+ { log.error("BeanUtils.getProperty failed for property {} on
{} ", property, rec.getClass().getName(), e);
return null;
}
}
diff --git
a/empire-db/src/main/java/org/apache/empire/commons/BeanPropertyUtils.java
b/empire-db/src/main/java/org/apache/empire/commons/BeanPropertyUtils.java
new file mode 100644
index 00000000..c7dff721
--- /dev/null
+++ b/empire-db/src/main/java/org/apache/empire/commons/BeanPropertyUtils.java
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.commons;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.beanutils.ConvertUtilsBean;
+import org.apache.commons.beanutils.PropertyUtilsBean;
+import org.apache.empire.exceptions.BeanPropertyGetException;
+import org.apache.empire.exceptions.BeanPropertySetException;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * BeanPropertyUtils provides methods for getting and setting bean property
values
+ * It is a replacement for org.apache.commons.beanutils.BeanUtils
+ * @author rainer
+ */
+public final class BeanPropertyUtils
+{
+ // Logger
+ private static final Logger log =
LoggerFactory.getLogger(ClassUtils.class);
+
+ static private BeanPropertyUtilsImpl instance = new
BeanPropertyUtilsImpl();
+
+ /**
+ * Returns the BeanUtils implementation
+ * @return the new BeanUtils implementation
+ */
+ public static BeanPropertyUtilsImpl getImplementation()
+ {
+ return instance;
+ }
+
+ /**
+ * Allows to override the implementation
+ * @param utils the new BeanUtils implementation
+ */
+ public static void setImplementation(BeanPropertyUtilsImpl utils)
+ {
+ instance = utils;
+ }
+
+ /**
+ * Checks if a bean has a particular property and a corresponding
getter/setter method exists
+ * @param bean the bean to check
+ * @param property the property to check
+ * @param writeAccess flag whether to check for the getter method (false)
or the setter method (true)
+ * @return 1 if the getter/setter exists, 0 if the getter/setter does not
exist, and -1 if the property does not exist at all
+ */
+ public static int hasProperty(Object bean, String property, boolean
writeAccess)
+ {
+ return instance.hasProperty(bean, property, writeAccess);
+ }
+
+ /**
+ * Returns the property of a bean by calling the correponding getter
function
+ * @param bean the bean
+ * @param property the property name
+ * @return the property value
+ */
+ public static Object getProperty(Object bean, String property)
+ {
+ return instance.getProperty(bean, property);
+ }
+
+ /**
+ * Set a single property value of a java bean object used by
readProperties.
+ * Return false if the property does not exist or if no setter method
exists (read only)
+ * throws BeanPropertySetException if an error occurs in the setter method
+ *
+ * @param column the column expression
+ * @param bean the bean
+ * @param property the property
+ * @param value the value
+ * @return true if the property has been set or false if the property does
not exist or if no setter method exists
+ */
+ public static boolean setProperty(Object bean, String property, Object
value)
+ {
+ return instance.setProperty(bean, property, value);
+ }
+
+ /**
+ * Converts a bean property value to a specific Java type
+ * @param value the value to convert
+ * @param type the type
+ * @return the converted value
+ */
+ public static Object convertPropertyValue(Object value, Class<?> type)
+ {
+ return instance.convertPropertyValue(value, type);
+ }
+
+ /**
+ * Provided the implementation for the BeanUtils methods
+ * @author rainer
+ */
+ public static class BeanPropertyUtilsImpl
+ {
+ /**
+ * @see org.apache.empire.commons.BeanPropertyUtils#hasProperty(Object
bean, String property, boolean writeAccess)
+ */
+ public int hasProperty(Object bean, String property, boolean
writeAccess)
+ {
+ // Check Params
+ if (bean==null)
+ throw new InvalidArgumentException("bean", bean);
+ if (property==null)
+ throw new InvalidArgumentException("property", property);
+ try
+ { // Get Property Value
+ PropertyUtilsBean propUtils =
BeanUtilsBean.getInstance().getPropertyUtils();
+ PropertyDescriptor pd;
+ pd = propUtils.getPropertyDescriptor(bean, property);
+ if (pd==null) {
+ return -1; // No such property
+ }
+ // check methods
+ final Method method;
+ if (writeAccess)
+ { // find setter
+ method = propUtils.getWriteMethod(pd);
+ }
+ else
+ { // find getter
+ method = propUtils.getReadMethod(pd);
+ }
+ return (method!=null ? 1 : 0);
+ } catch (IllegalAccessException | InvocationTargetException |
NoSuchMethodException e)
+ { log.warn("Property access not available for {} on {}",
property, bean.getClass().getName());
+ return 0;
+ }
+ }
+
+ /**
+ * @see org.apache.empire.commons.BeanPropertyUtils#getProperty(Object
bean, String property)
+ */
+ public Object getProperty(Object bean, String property)
+ {
+ // Check Params
+ if (bean==null)
+ throw new InvalidArgumentException("bean", bean);
+ if (property==null)
+ throw new InvalidArgumentException("property", property);
+ try
+ { // Get Property Value
+ PropertyUtilsBean pub =
BeanUtilsBean.getInstance().getPropertyUtils();
+ return pub.getSimpleProperty(bean, property);
+
+ } catch (IllegalAccessException e)
+ { log.error(bean.getClass().getName() + ": unable to get
property '" + property + "'");
+ throw new BeanPropertyGetException(bean, property, e);
+ } catch (InvocationTargetException e)
+ { log.error(bean.getClass().getName() + ": unable to get
property '" + property + "'");
+ throw new BeanPropertyGetException(bean, property, e);
+ } catch (NoSuchMethodException e)
+ { log.warn(bean.getClass().getName() + ": no getter available
for property '" + property + "'");
+ throw new BeanPropertyGetException(bean, property, e);
+ }
+ }
+
+ /**
+ * @see org.apache.empire.commons.BeanPropertyUtils#setProperty(Object
bean, String property, Object value)
+ */
+ public boolean setProperty(Object bean, String property, Object value)
+ {
+ try
+ {
+ if (bean==null)
+ throw new InvalidArgumentException("bean", bean);
+ if (StringUtils.isEmpty(property))
+ throw new InvalidArgumentException("property", property);
+ if (log.isTraceEnabled())
+ log.trace("{}: setting property '{}' to {}",
bean.getClass().getName(), property, value);
+ // Set Property Value
+ /**
+ * replacement for BeanUtils.setProperty(bean, property,
value);
+ */
+ PropertyUtilsBean propUtils =
BeanUtilsBean.getInstance().getPropertyUtils();
+ PropertyDescriptor pd = propUtils.getPropertyDescriptor(bean,
property);
+ if (pd==null) {
+ if (log.isDebugEnabled())
+ log.debug("{}: property '{}' does not exist!",
bean.getClass().getName(), property);
+ return false; // No such property
+ }
+ // get the write method
+ // final Method method = propUtils.getWriteMethod(pd);
+ final Method method =
propUtils.getWriteMethod(bean.getClass(), pd);
+ if (method == null) {
+ if (log.isDebugEnabled())
+ log.debug("{}: property '{}' has no write method!",
bean.getClass().getName(), property);
+ return false; // Read-only
+ }
+ // convert type
+ Class<?> propType = pd.getPropertyType();
+ value = convertPropertyValue(value, propType);
+ // invoke setter
+ // propUtils.setSimpleProperty(bean, property, convertedValue);
+ if (propType.isArray())
+ method.invoke(bean, new Object[] { value });
+ else
+ method.invoke(bean, value);
+ return true;
+ // IllegalAccessException
+ } catch (IllegalAccessException e)
+ { log.error(bean.getClass().getName() + ": unable to set
property '" + property + "'");
+ throw new BeanPropertySetException(bean, property, e);
+ // InvocationTargetException
+ } catch (InvocationTargetException e)
+ { log.error(bean.getClass().getName() + ": unable to set
property '" + property + "'");
+ throw new BeanPropertySetException(bean, property, e);
+ // NoSuchMethodException
+ } catch (NoSuchMethodException e)
+ { log.error(bean.getClass().getName() + ": unable to set
property '" + property + "'");
+ throw new BeanPropertySetException(bean, property, e);
+ } catch (NullPointerException e)
+ { log.error(bean.getClass().getName() + ": unable to set
property '" + property + "'");
+ throw new BeanPropertySetException(bean, property, e);
+ }
+ }
+
+ /**
+ * @see
org.apache.empire.commons.BeanPropertyUtils#convertPropertyValue(Object value,
Class<?> type)
+ */
+ public Object convertPropertyValue(Object value, Class<?> type)
+ {
+ ConvertUtilsBean convertUtils =
BeanUtilsBean.getInstance().getConvertUtils();
+ // Convert the specified value to the required type
+ if (type.isArray()) {
+ // Scalar value into array
+ if (value == null) {
+ final String[] values = new String[0];
+ return convertUtils.convert(values, type);
+ } else if (value instanceof String) {
+ return convertUtils.convert(value, type);
+ } else if (value instanceof String[]) {
+ return convertUtils.convert((String[]) value, type);
+ } else {
+ /* old implementation from BeanUtilsBean
+ final Converter converter = convertUtils.lookup(type);
+ return (converter != null) ? converter.convert(type,
value) : value;
+ */
+ // see org.apache.commons.beanutils.BeanUtilsBean2
+ return convertUtils.convert(value, type);
+ }
+ } else {
+ // Value into scalar
+ if (value==null)
+ return null;
+ else if (value instanceof String) {
+ return convertUtils.convert((String) value, type);
+ } else if (value instanceof String[]) {
+ return convertUtils.convert(((String[]) value)[0], type);
+ } else {
+ /* old implementation from BeanUtilsBean
+ final Converter converter = convertUtils.lookup(type);
+ return (converter != null) ? converter.convert(type,
value) : value;
+ */
+ // see org.apache.commons.beanutils.BeanUtilsBean2
+ return convertUtils.convert(value, type);
+ }
+ }
+ }
+ }
+
+}
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 8a10f6cb..d540822c 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
@@ -18,7 +18,6 @@
*/
package org.apache.empire.commons;
-import java.beans.PropertyDescriptor;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -32,17 +31,13 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URISyntaxException;
-import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConstructorUtils;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.empire.exceptions.BeanPropertySetException;
import org.apache.empire.exceptions.EmpireException;
import org.apache.empire.exceptions.InternalException;
import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.InvalidOperationException;
import org.apache.empire.exceptions.NotImplementedException;
import org.apache.empire.exceptions.NotSupportedException;
-import org.apache.empire.exceptions.PropertyReadOnlyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -807,58 +802,4 @@ public final class ClassUtils
return "[ClassNotFoundException]";
}
}
-
- /**
- * Set a single property value of a java bean object used by
readProperties.
- *
- * @param column the column expression
- * @param bean the bean
- * @param property the property
- * @param value the value
- */
- public static void setBeanProperty(Object bean, String property, Object
value)
- {
- try
- {
- if (bean==null)
- throw new InvalidArgumentException("bean", bean);
- if (StringUtils.isEmpty(property))
- throw new InvalidArgumentException("property", property);
- if (log.isTraceEnabled())
- log.trace("{}: setting property '{}' to {}",
bean.getClass().getName(), property, value);
- // Set Property Value
- if (value!=null)
- { // Bean utils will convert if necessary
- BeanUtils.setProperty(bean, property, value);
- }
- else
- { // Don't convert, just set
- PropertyDescriptor pd =
PropertyUtils.getPropertyDescriptor(bean, property);
- if (pd==null)
- return; // No such property
- // get the write method
- final Method method = PropertyUtils.getWriteMethod(pd);
- if (method == null)
- throw new PropertyReadOnlyException(property);
- // invoke
- method.invoke(bean, value);
- }
- // IllegalAccessException
- } catch (IllegalAccessException e)
- { log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- // InvocationTargetException
- } catch (InvocationTargetException e)
- { log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- // NoSuchMethodException
- } catch (NoSuchMethodException e)
- { log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- } catch (NullPointerException e)
- { log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- }
-
}
diff --git
a/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
b/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
index 94adadaf..520e6ea2 100644
--- a/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
+++ b/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
@@ -18,25 +18,20 @@
*/
package org.apache.empire.data.bean;
-import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.List;
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.BeanUtilsBean;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.beanutils.PropertyUtilsBean;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.Options;
import org.apache.empire.data.Column;
import org.apache.empire.data.ColumnExpr;
import org.apache.empire.data.EntityType;
import org.apache.empire.data.Record;
-import org.apache.empire.exceptions.BeanPropertyGetException;
-import org.apache.empire.exceptions.BeanPropertySetException;
import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.ItemNotFoundException;
import org.apache.empire.exceptions.ObjectNotValidException;
+import org.apache.empire.exceptions.PropertyReadOnlyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -380,63 +375,26 @@ public class BeanRecordProxy<T> implements Record
protected Object getBeanProperty(Object bean, String property)
{
- // Check Params
- if (bean==null)
- throw new InvalidArgumentException("bean", bean);
- if (property==null)
- throw new InvalidArgumentException("property", property);
- try
- { // Get Property Value
- PropertyUtilsBean pub =
BeanUtilsBean.getInstance().getPropertyUtils();
- return pub.getSimpleProperty(bean, property);
-
- } catch (IllegalAccessException e)
- { log.error(bean.getClass().getName() + ": unable to get property '"
+ property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- } catch (InvocationTargetException e)
- { log.error(bean.getClass().getName() + ": unable to get property '"
+ property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- } catch (NoSuchMethodException e)
- { log.warn(bean.getClass().getName() + ": no getter available for
property '" + property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- }
+ return BeanPropertyUtils.getProperty(bean, property);
}
protected void setBeanProperty(Object bean, Column column, Object value)
{
- // Check Params
- if (bean==null)
- throw new InvalidArgumentException("bean", bean);
- if (column==null)
- throw new InvalidArgumentException("column", column);
- // Get Property Name
- String property = column.getBeanPropertyName();
- try
- { // Get Property Value
- if (ObjectUtils.isEmpty(value))
- value = null;
- // Set Property Value
- if (value!=null)
- { // Bean utils will convert if necessary
- BeanUtils.setProperty(bean, property, value);
- }
+ if (value!=null)
+ { // Convert to enum
+ Class<Enum<?>> enumType = column.getEnumType();
+ if (enumType!=null)
+ value = ObjectUtils.getEnum(enumType, value);
+ }
+ // set property
+ String property = column.getBeanPropertyName();
+ if (!BeanPropertyUtils.setProperty(bean, property, value))
+ { // Property has not been set
+ if (BeanPropertyUtils.hasProperty(bean, property, true)==0)
+ throw new PropertyReadOnlyException(property);
else
- { // Don't convert, just set
- PropertyUtils.setProperty(bean, property, null);
- }
- } catch (IllegalArgumentException e) {
- log.error(bean.getClass().getName() + ": invalid argument for
property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
- } catch (IllegalAccessException e)
- { log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- } catch (InvocationTargetException e)
- { log.error(bean.getClass().getName() + ": unable to set property '"
+ property + "'");
- throw new BeanPropertySetException(bean, property, e);
- } catch (NoSuchMethodException e) {
- log.error(bean.getClass().getName() + ": no setter available for
property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
+ log.info("The bean property \"{}\" does not exist on {} and
will be ignored!", property, bean.getClass().getName());
+ }
}
}
diff --git
a/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
b/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
index b28ba7be..55f9e86c 100644
--- a/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
+++ b/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
@@ -26,7 +26,7 @@ import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Date;
-import org.apache.empire.commons.ClassUtils;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.Column;
@@ -662,8 +662,6 @@ public class DataListEntry implements RecordData,
Serializable
for (int i = 0; i < getFieldCount(); i++)
{ // Check Property
ColumnExpr column = getColumn(i);
- if ((column instanceof Column) && ((Column)column).isReadOnly())
- continue;
if (ignoreList != null && ignoreList.contains(column))
continue; // ignore this property
// Get Property Name
@@ -699,8 +697,13 @@ public class DataListEntry implements RecordData,
Serializable
if (enumType!=null)
value = ObjectUtils.getEnum(enumType, value);
}
+ // set property
String property = column.getBeanPropertyName();
- ClassUtils.setBeanProperty(bean, property, value);
+ if (!BeanPropertyUtils.setProperty(bean, property, value))
+ { // Property has not been set
+ if (log.isDebugEnabled())
+ log.debug("The bean property \"{}\" coult not be set on {} and
will be ignored!", property, bean.getClass().getName());
+ }
}
/*
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
b/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
index 39a99a48..5fdd5e59 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
@@ -19,15 +19,13 @@
package org.apache.empire.db;
import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.beanutils.BeanUtilsBean;
-import org.apache.commons.beanutils.PropertyUtilsBean;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ClassUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.Options;
@@ -41,7 +39,6 @@ import org.apache.empire.db.exceptions.FieldReadOnlyException;
import org.apache.empire.db.exceptions.FieldValueNotFetchedException;
import org.apache.empire.db.exceptions.NoPrimaryKeyException;
import org.apache.empire.db.exceptions.RecordReadOnlyException;
-import org.apache.empire.exceptions.BeanPropertyGetException;
import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.NotSupportedException;
import org.apache.empire.exceptions.ObjectNotValidException;
@@ -805,8 +802,7 @@ public abstract class DBRecordBase extends DBRecordData
implements Record, Clone
if (ignoreList != null && ignoreList.contains(column))
continue; // ignore this property
// Get Property Name
- String property = column.getBeanPropertyName();
- setRecordValue(column, bean, property);
+ setRecordValue(column, bean);
count++;
}
return count;
@@ -1157,30 +1153,21 @@ public abstract class DBRecordBase extends DBRecordData
implements Record, Clone
* setValue(column, bean.getFOO())
* <P>
* @param bean the Java Bean from which to read the value from
- * @param property the name of the property
* @param column the column for which to set the record value
*/
- protected void setRecordValue(Column column, Object bean, String property)
+ protected void setRecordValue(Column column, Object bean)
{
- if (StringUtils.isEmpty(property))
- property = column.getBeanPropertyName();
- try
- { // Get Property Value
- PropertyUtilsBean pub =
BeanUtilsBean.getInstance().getPropertyUtils();
- Object value = pub.getSimpleProperty(bean, property);
- // Now, set the record value
- set( column, value );
- // done
- } catch (IllegalAccessException e)
- { log.error(bean.getClass().getName() + ": unable to get property '"
+ property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- } catch (InvocationTargetException e)
- { log.error(bean.getClass().getName() + ": unable to get property '"
+ property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- } catch (NoSuchMethodException e)
- { log.warn(bean.getClass().getName() + ": no getter available for
property '" + property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- }
+ // check
+ if (column==null)
+ throw new InvalidArgumentException("column", column);
+ if (bean==null)
+ throw new InvalidArgumentException("bean", column);
+ // the property name
+ String property = column.getBeanPropertyName();
+ // Get Property Value
+ Object value = BeanPropertyUtils.getProperty(bean, property);
+ // Now, set the record value
+ set( column, value );
}
/**
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
b/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
index ad769810..f0629ef1 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
@@ -24,7 +24,7 @@ import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Date;
-import org.apache.empire.commons.ClassUtils;
+import org.apache.empire.commons.BeanPropertyUtils;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.Options;
import org.apache.empire.commons.StringUtils;
@@ -555,8 +555,6 @@ public abstract class DBRecordData extends DBObject
for (int i = 0; i < getFieldCount(); i++)
{ // Check Property
ColumnExpr column = getColumn(i);
- if ((column instanceof Column) && ((Column)column).isReadOnly())
- continue;
if (ignoreList != null && ignoreList.contains(column))
continue; // ignore this property
// Get Property Name
@@ -592,8 +590,13 @@ public abstract class DBRecordData extends DBObject
if (enumType!=null)
value = ObjectUtils.getEnum(enumType, value);
}
+ // set property
String property = column.getBeanPropertyName();
- ClassUtils.setBeanProperty(bean, property, value);
+ if (!BeanPropertyUtils.setProperty(bean, property, value))
+ { // Property has not been set
+ if (log.isDebugEnabled())
+ log.debug("The bean property \"{}\" coult not be set on {} and
will be ignored!", property, bean.getClass().getName());
+ }
}
/*