OPENJPA-1700 FindBugs - Inefficient use of keySet iterator instead of entrySet iterator

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@956939 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald Woods 2010-06-22 16:13:27 +00:00
parent 2747862d5f
commit d5fc007b70
3 changed files with 18 additions and 9 deletions

View File

@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.openjpa.jdbc.meta.ClassMapping; import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.meta.FieldMapping; import org.apache.openjpa.jdbc.meta.FieldMapping;
@ -318,11 +319,13 @@ public class PreparedQueryImpl implements PreparedQuery {
} }
Map<Integer, Object> result = new HashMap<Integer, Object>(_template); Map<Integer, Object> result = new HashMap<Integer, Object>(_template);
for (Object key : user.keySet()) { Set<Map.Entry<Object,Object>> userSet = user.entrySet();
for (Map.Entry<Object,Object> userEntry : userSet) {
Object key = userEntry.getKey();
int[] indices = _userParamPositions.get(key); int[] indices = _userParamPositions.get(key);
if (indices == null || indices.length == 0) if (indices == null || indices.length == 0)
throw new UserException(_loc.get("uparam-no-pos", key, this)); throw new UserException(_loc.get("uparam-no-pos", key, this));
Object val = user.get(key); Object val = userEntry.getValue();
if (ImplHelper.isManageable(val)) { if (ImplHelper.isManageable(val)) {
setPersistenceCapableParameter(result, val, indices, broker); setPersistenceCapableParameter(result, val, indices, broker);
} else if (val instanceof Collection) { } else if (val instanceof Collection) {

View File

@ -23,6 +23,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.openjpa.jdbc.kernel.exps.ExpContext; import org.apache.openjpa.jdbc.kernel.exps.ExpContext;
import org.apache.openjpa.jdbc.kernel.exps.QueryExpressionsState; import org.apache.openjpa.jdbc.kernel.exps.QueryExpressionsState;
@ -153,9 +154,11 @@ public class PreparedSQLStoreQuery extends SQLStoreQuery {
*/ */
public Object[] toParameterArray(StoreQuery q, Map userParams) { public Object[] toParameterArray(StoreQuery q, Map userParams) {
Object[] array = new Object[userParams.size()]; Object[] array = new Object[userParams.size()];
for (Object key : userParams.keySet()) {
int idx = ((Integer)key).intValue(); Set<Map.Entry<Object,Object>> userSet = userParams.entrySet();
array[idx] = userParams.get(key); for (Map.Entry<Object,Object> userEntry : userSet) {
int idx = ((Integer)userEntry.getKey()).intValue();
array[idx] = userEntry.getValue();
} }
return array; return array;
} }

View File

@ -91,8 +91,11 @@ public class VersionMappingInfo
} }
MappingDefaults def = vers.getMappingRepository().getMappingDefaults(); MappingDefaults def = vers.getMappingRepository().getMappingDefaults();
List<Column> result = new ArrayList<Column>(); List<Column> result = new ArrayList<Column>();
for (Table table : assign.keySet()) {
List<Column> cols = assign.get(table); Set<Map.Entry<Table,List<Column>>> assignSet = assign.entrySet();
for (Map.Entry<Table,List<Column>> assignEntry : assignSet) {
Table table = assignEntry.getKey();
List<Column> cols = assignEntry.getValue();
Column[] partTemplates = cols.toArray(new Column[cols.size()]); Column[] partTemplates = cols.toArray(new Column[cols.size()]);
def.populateColumns(vers, table, partTemplates); def.populateColumns(vers, table, partTemplates);
result.addAll(Arrays.asList(createColumns(vers, null, partTemplates, result.addAll(Arrays.asList(createColumns(vers, null, partTemplates,