Repository: commons-dbutils Updated Branches: refs/heads/master ea94faec8 -> 0e6405a12
[DBUTILS-135] BeanProcessor is not thread safe since [DBUTILS-124]. Project: http://git-wip-us.apache.org/repos/asf/commons-dbutils/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-dbutils/commit/0e6405a1 Tree: http://git-wip-us.apache.org/repos/asf/commons-dbutils/tree/0e6405a1 Diff: http://git-wip-us.apache.org/repos/asf/commons-dbutils/diff/0e6405a1 Branch: refs/heads/master Commit: 0e6405a12f74d6622e1d2e05bb649560da13669f Parents: ea94fae Author: hdevalke <notificati...@github.com> Authored: Tue Oct 10 16:43:04 2017 -0600 Committer: Gary Gregory <ggreg...@apache.org> Committed: Tue Oct 10 16:43:04 2017 -0600 ---------------------------------------------------------------------- src/changes/changes.xml | 3 +++ .../apache/commons/dbutils/BeanProcessor.java | 24 ++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/0e6405a1/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 76d46bd..4d2283d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -74,6 +74,9 @@ The <action> type attribute can be add,update,fix,remove. <action dev="thecarlhall" type="update" issue="PR/1" due-to="Michael Hausegger"> Created some Unit Tests to increase code coverage. </action> + <action dev="ggregory" type="update" issue="DBUTILS-135" due-to="hdevalke"> + BeanProcessor is not thread safe since [DBUTILS-124]. + </action> </release> <release version="1.6" date="2014-07-20" description="Bugfixes and addition of insert methods"> http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/0e6405a1/src/main/java/org/apache/commons/dbutils/BeanProcessor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/BeanProcessor.java b/src/main/java/org/apache/commons/dbutils/BeanProcessor.java index 74de18a..e18dc01 100644 --- a/src/main/java/org/apache/commons/dbutils/BeanProcessor.java +++ b/src/main/java/org/apache/commons/dbutils/BeanProcessor.java @@ -65,19 +65,9 @@ public class BeanProcessor { */ private static final Map<Class<?>, Object> primitiveDefaults = new HashMap<Class<?>, Object>(); - /** - * ServiceLoader to find <code>ColumnHandler</code> implementations on the classpath. The iterator for this is - * lazy and each time <code>iterator()</code> is called. - */ - // FIXME: I think this instantiates new handlers on each iterator() call. This might be worth caching upfront. - private static final ServiceLoader<ColumnHandler> columnHandlers = ServiceLoader.load(ColumnHandler.class); + private static final List<ColumnHandler> columnHandlers = new ArrayList<ColumnHandler>(); - /** - * ServiceLoader to find <code>PropertyHandler</code> implementations on the classpath. The iterator for this is - * lazy and each time <code>iterator()</code> is called. - */ - // FIXME: I think this instantiates new handlers on each iterator() call. This might be worth caching upfront. - private static final ServiceLoader<PropertyHandler> propertyHandlers = ServiceLoader.load(PropertyHandler.class); + private static final List<PropertyHandler> propertyHandlers = new ArrayList<PropertyHandler>(); /** * ResultSet column to bean property name overrides. @@ -93,6 +83,16 @@ public class BeanProcessor { primitiveDefaults.put(Long.TYPE, Long.valueOf(0L)); primitiveDefaults.put(Boolean.TYPE, Boolean.FALSE); primitiveDefaults.put(Character.TYPE, Character.valueOf((char) 0)); + + // Use a ServiceLoader to find implementations + for (ColumnHandler handler : ServiceLoader.load(ColumnHandler.class)) { + columnHandlers.add(handler); + } + + // Use a ServiceLoader to find implementations + for (PropertyHandler handler : ServiceLoader.load(PropertyHandler.class)) { + propertyHandlers.add(handler); + } } /**