You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/10/22 10:43:29 UTC

svn commit: r1187674 - in /camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy: BindyCsvFactory.java BindyFixedLengthFactory.java

Author: davsclaus
Date: Sat Oct 22 08:43:28 2011
New Revision: 1187674

URL: http://svn.apache.org/viewvc?rev=1187674&view=rev
Log:
CAMEL-4573: Fixed thread safety issues in bindy fixed and CSV marshaller. Thanks to Surya for patch.

Modified:
    camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
    camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java

Modified: camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java?rev=1187674&r1=1187673&r2=1187674&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java (original)
+++ camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java Sat Oct 22 08:43:28 2011
@@ -55,8 +55,6 @@ public class BindyCsvFactory extends Bin
     private Map<Integer, Field> annotatedFields = new LinkedHashMap<Integer, Field>();
     private Map<String, Integer> sections = new HashMap<String, Integer>();
 
-    private Map<Integer, List> results;
-
     private int numberOptionalFields;
     private int numberMandatoryFields;
     private int totalFields;
@@ -226,7 +224,7 @@ public class BindyCsvFactory extends Bin
     public String unbind(Map<String, Object> model) throws Exception {
 
         StringBuilder buffer = new StringBuilder();
-        results = new HashMap<Integer, List>();
+        Map<Integer, List> results = new HashMap<Integer, List>();
 
         // Check if separator exists
         ObjectHelper.notNull(this.separator, "The separator has not been instantiated or property not defined in the @CsvRecord annotation");
@@ -247,7 +245,7 @@ public class BindyCsvFactory extends Bin
                 if (obj != null) {
 
                     // Generate Csv table
-                    generateCsvPositionMap(clazz, obj);
+                    generateCsvPositionMap(clazz, obj, results);
 
                 }
             }
@@ -360,7 +358,7 @@ public class BindyCsvFactory extends Bin
      * If a relation @OneToMany is defined, than we iterate recursively through this function
      * The result is placed in the Map<Integer, List> results
      */
-    private void generateCsvPositionMap(Class clazz, Object obj) throws Exception {
+    private void generateCsvPositionMap(Class clazz, Object obj, Map<Integer, List> results) throws Exception {
 
         String result = "";
 
@@ -448,14 +446,14 @@ public class BindyCsvFactory extends Bin
                     Iterator it = list.iterator();
                     while (it.hasNext()) {
                         Object target = it.next();
-                        generateCsvPositionMap(target.getClass(), target);
+                        generateCsvPositionMap(target.getClass(), target, results);
                     }
 
                 } else {
 
                     // Call this function to add empty value
                     // in the table
-                    generateCsvPositionMap(field.getClass(), null);
+                    generateCsvPositionMap(field.getClass(), null, results);
                 }
 
             }

Modified: camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java?rev=1187674&r1=1187673&r2=1187674&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java (original)
+++ camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java Sat Oct 22 08:43:28 2011
@@ -52,8 +52,6 @@ public class BindyFixedLengthFactory ext
     private Map<Integer, DataField> dataFields = new LinkedHashMap<Integer, DataField>();
     private Map<Integer, Field> annotatedFields = new LinkedHashMap<Integer, Field>();
 
-    private Map<Integer, List> results;
-
     private int numberOptionalFields;
     private int numberMandatoryFields;
     private int totalFields;
@@ -251,7 +249,8 @@ public class BindyFixedLengthFactory ext
     public String unbind(Map<String, Object> model) throws Exception {
 
         StringBuilder buffer = new StringBuilder();
-        results = new HashMap<Integer, List>();
+
+        Map<Integer, List> results = new HashMap<Integer, List>();
 
         for (Class clazz : models) {
 
@@ -267,7 +266,7 @@ public class BindyFixedLengthFactory ext
 
                     // Generate Fixed Length table
                     // containing the positions of the fields
-                    generateFixedLengthPositionMap(clazz, obj);
+                    generateFixedLengthPositionMap(clazz, obj, results);
 
                 }
             }
@@ -292,8 +291,7 @@ public class BindyFixedLengthFactory ext
      * Generate a table containing the data formatted and sorted with their position/offset
      * The result is placed in the Map<Integer, List> results
      */
-
-    private void generateFixedLengthPositionMap(Class clazz, Object obj) throws Exception {
+    private void generateFixedLengthPositionMap(Class clazz, Object obj, Map<Integer, List> results) throws Exception {
 
         String result = "";