2323import java .util .ArrayList ;
2424import java .util .Date ;
2525import java .util .HashMap ;
26+ import java .util .List ;
2627import java .util .Map ;
2728import java .util .TimeZone ;
29+ import java .util .concurrent .ConcurrentHashMap ;
30+ import java .util .stream .Stream ;
2831
2932import org .apache .xmlrpc .XmlRpcException ;
3033
@@ -50,17 +53,17 @@ public class ObjectAdapter {
5053 // the database for every new object.
5154 // Bulk loads/reads can become very slow if every adapter requires a call
5255 // back to the server
53- private static ArrayList <String > objectNameCache = new ArrayList <>();
56+ private static final List <String > objectNameCache = new ArrayList <>();
5457
5558 // Object workflow signal cache so the adapter doesn't have to reread signal
5659 // names from the database for every workflow call.
57- private static ArrayList <String > signalCache = new ArrayList <>();
60+ private static final List <String > signalCache = new ArrayList <>();
5861
5962 // Cache used to store the name_get result of an model to cater for
6063 // many2many relations in the import function
6164 // It is cleared every time the import function is called for a specific
6265 // object
63- private HashMap <String , HashMap <String , String >> modelNameCache = new HashMap <>();
66+ private final Map <String , Map <String , String >> modelNameCache = new ConcurrentHashMap <>();
6467
6568 /**
6669 * Default constructor
@@ -238,9 +241,7 @@ public RowCollection readObject(Object[] ids, String[] fields) throws XmlRpcExce
238241 * sortedResults[idList.indexOf(id)] = result; }
239242 ****/
240243
241- RowCollection rows = new RowCollection (results , fieldCol );
242-
243- return rows ;
244+ return new RowCollection (results , fieldCol );
244245 }
245246
246247 /***
@@ -487,9 +488,9 @@ private Object[] fixImportData(Row inputRow) throws OpeneERPApiException, XmlRpc
487488 * import. Replace the ID list passed in with a Name list for
488489 * the import_data function that we are about to call
489490 */
490- HashMap <String , String > idToName = null ;
491+ Map <String , String > idToName ;
491492 if (!modelNameCache .containsKey (fld .getRelation ())) {
492- idToName = new HashMap <String , String >();
493+ idToName = new HashMap <>();
493494 Object [] ids = command .searchObject (fld .getRelation (), new Object [] {});
494495 Object [] names = command .nameGet (fld .getRelation (), ids );
495496 for (int j = 0 ; j < ids .length ; j ++) {
@@ -533,19 +534,17 @@ private Object[] fixImportData(Row inputRow) throws OpeneERPApiException, XmlRpc
533534 }
534535
535536 private String [] getFieldListForImport (FieldCollection currentFields ) {
537+ return Stream
538+ .concat (Stream .of (".id" ),
539+ currentFields .stream ().map (ObjectAdapter ::getFieldNameForImport ))
540+ .toArray (String []::new );
536541
537- ArrayList <String > fieldList = new ArrayList <String >();
538- fieldList .add (".id" );
539-
540- for (Field field : currentFields ) {
541- if (field .getType () == FieldType .MANY2ONE )
542- fieldList .add (field .getName () + ".id" );
543- else
544- fieldList .add (field .getName ());
545- }
546-
547- return fieldList .toArray (new String [fieldList .size ()]);
542+ }
548543
544+ private static String getFieldNameForImport (Field field ) {
545+ // Return field name, adding ".id" if type is MANY2ONE
546+ return field .getType () == FieldType .MANY2ONE ? field .getName () + ".id"
547+ : field .getName ();
549548 }
550549
551550 /**
@@ -723,7 +722,7 @@ public RowCollection searchAndReadObject(FilterCollection filter, String[] field
723722 public RowCollection searchAndReadObject (final FilterCollection filter , final String [] fields , int offset ,
724723 int limit , String order ) throws XmlRpcException , OpeneERPApiException {
725724
726- String [] fieldArray = ( fields == null ? new String [] {} : fields ) ;
725+ String [] fieldArray = fields == null ? new String [] {} : fields ;
727726 Object [] preparedFilters = validateFilters (filter );
728727 Object [] idList = (Object []) command .searchObject (modelName , preparedFilters , offset , limit , order , false );
729728
@@ -938,7 +937,7 @@ public FieldCollection callFieldsFunction(String functionName, Object[] paramete
938937 }
939938
940939 if (fldDetails == null )
941- fldDetails = new HashMap <String , Object >();
940+ fldDetails = new HashMap <>();
942941
943942 if (!fldDetails .containsKey ("name" ))
944943 fldDetails .put ("name" , field );
@@ -991,9 +990,7 @@ public RowCollection callFunction(String functionName, Object[] parameters, Fiel
991990 if (fieldCol == null )
992991 fieldCol = callFieldsFunction (functionName , parameters );
993992
994- RowCollection rows = new RowCollection (results , fieldCol );
995-
996- return rows ;
993+ return new RowCollection (results , fieldCol );
997994 }
998995
999996 /**
0 commit comments