OPENJPA-1868: Miscellaneous FindBugs suggested performance improvements for openjpa-kernel.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1030139 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard G. Curtis 2010-11-02 17:33:41 +00:00
parent 05d19a0672
commit 66ce36c0ad
16 changed files with 48 additions and 49 deletions

View File

@ -492,9 +492,9 @@ public class DataCacheStoreManager
unloaded = addUnloaded(sm, null, unloaded);
}
for (Iterator<DataCache> itr = caches.keySet().iterator(); itr.hasNext();) {
cache = itr.next();
smList = caches.get(cache);
for(Entry<DataCache,List<OpenJPAStateManager>> entry : caches.entrySet()){
cache = entry.getKey();
smList = entry.getValue();
List<Object> oidList = new ArrayList<Object>(smList.size());
for (OpenJPAStateManager sm : smList) {

View File

@ -199,7 +199,7 @@ public abstract class AbstractQueryCacheInstrument extends AbstractInstrument
private QueryKey findKey(String key) {
QueryStatistics<QueryKey> stats = getStatistics();
for (QueryKey qk : stats.keys()) {
if (qk.toString().equals(key.toString())) {
if (qk.toString().equals(key)) {
return qk;
}
}

View File

@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.apache.commons.lang.ObjectUtils;
import org.apache.openjpa.enhance.PersistenceCapable;
@ -379,10 +380,11 @@ abstract class AttachStrategy
try {
return manager.getProxyManager().copyMap(orig);
} catch (Exception e) {
Map map = (Map) sm.newFieldProxy(fmd.getIndex());
Set keys = orig.keySet();
for (Object key : keys)
map.put(key, orig.get(key));
Map<Object, Object> map = (Map<Object, Object>) sm.newFieldProxy(fmd.getIndex());
for (Entry<Object, Object> entry : ((Map<Object, Object>) orig).entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return map;
}
}

View File

@ -316,9 +316,9 @@ public class DetachedValueStateManager
case JavaTypes.CHAR:
return Character.valueOf(fm.fetchCharField(field));
case JavaTypes.DOUBLE:
return new Double(fm.fetchDoubleField(field));
return Double.valueOf(fm.fetchDoubleField(field));
case JavaTypes.FLOAT:
return new Float(fm.fetchFloatField(field));
return Float.valueOf(fm.fetchFloatField(field));
case JavaTypes.INT:
return fm.fetchIntField(field);
case JavaTypes.LONG:

View File

@ -28,11 +28,10 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.apache.commons.collections.map.LinkedMap;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.datacache.DataCache;
import org.apache.openjpa.kernel.exps.Subquery;
import org.apache.openjpa.kernel.exps.AbstractExpressionVisitor;
import org.apache.openjpa.kernel.exps.AggregateListener;
import org.apache.openjpa.kernel.exps.Constant;
@ -44,6 +43,7 @@ import org.apache.openjpa.kernel.exps.Path;
import org.apache.openjpa.kernel.exps.QueryExpressions;
import org.apache.openjpa.kernel.exps.Resolver;
import org.apache.openjpa.kernel.exps.StringContains;
import org.apache.openjpa.kernel.exps.Subquery;
import org.apache.openjpa.kernel.exps.Val;
import org.apache.openjpa.kernel.exps.Value;
import org.apache.openjpa.kernel.exps.WildcardMatch;
@ -409,7 +409,8 @@ public class ExpressionStoreQuery
OrderedMap<?,Class<?>> paramTypes = getOrderedParameterTypes(q);
Object[] arr = new Object[userParams.size()];
int base = positionalParameterBase(userParams.keySet());
for (Object key : paramTypes.keySet()) {
for(Entry<?, Class<?>> entry : paramTypes.entrySet()){
Object key = entry.getKey();
int idx = (key instanceof Integer)
? ((Integer)key).intValue() - base
: paramTypes.indexOf(key);
@ -418,7 +419,7 @@ public class ExpressionStoreQuery
new Object[]{q.getContext().getQueryString(), key,
userParams.size(), userParams}));
Object value = userParams.get(key);
validateParameterValue(key, value, (Class)paramTypes.get(key));
validateParameterValue(key, value, (Class)entry.getValue());
arr[idx] = value;
}
return arr;

View File

@ -337,9 +337,9 @@ public class Filters {
if (type == Integer.class && allowNumericConversion(o.getClass(), type, strictNumericConversion)) {
return ((Number) o).intValue();
} else if (type == Float.class && allowNumericConversion(o.getClass(), type, strictNumericConversion)) {
return new Float(((Number) o).floatValue());
return Float.valueOf(((Number) o).floatValue());
} else if (type == Double.class) {
return new Double(((Number) o).doubleValue());
return Double.valueOf(((Number) o).doubleValue());
} else if (type == Long.class && allowNumericConversion(o.getClass(), type, strictNumericConversion)) {
return ((Number) o).longValue();
} else if (type == BigDecimal.class) {
@ -349,11 +349,11 @@ public class Filters {
// and Float versions, despite wanting to cast it to BigDecimal
double dval = ((Number) o).doubleValue();
if (Double.isNaN(dval) || Double.isInfinite(dval))
return new Double(dval);
return Double.valueOf(dval);
float fval = ((Number) o).floatValue();
if (Float.isNaN(fval) || Float.isInfinite(fval))
return new Float(fval);
return Float.valueOf(fval);
return new BigDecimal(o.toString());
} else if (type == BigInteger.class) {
@ -512,7 +512,7 @@ public class Filters {
default:
throw new InternalException();
}
return new Float(tot);
return Float.valueOf(tot);
}
/**
@ -539,7 +539,7 @@ public class Filters {
default:
throw new InternalException();
}
return new Double(tot);
return Double.valueOf(tot);
}
/**
@ -1021,7 +1021,7 @@ public class Filters {
if (nType == Integer.class)
return Integer.valueOf(0);
if (nType == Double.class)
return new Double(0.0);
return Double.valueOf(0.0);
if (nType == Float.class)
return new Float(0.0);
if (nType == Short.class)

View File

@ -49,8 +49,8 @@ public class ObjectIdStateManager
private static final Byte ZERO_BYTE = Byte.valueOf((byte)0);
private static final Character ZERO_CHAR = Character.valueOf((char)0);
private static final Double ZERO_DOUBLE = new Double(0);
private static final Float ZERO_FLOAT = new Float(0);
private static final Double ZERO_DOUBLE = Double.valueOf(0);
private static final Float ZERO_FLOAT = Float.valueOf(0);
private static final Short ZERO_SHORT = Short.valueOf((short)0);
private Object _oid;
@ -483,11 +483,11 @@ public class ObjectIdStateManager
}
public void storeFloat(int field, float extVal) {
setValue(field, new Float(extVal), true);
setValue(field, Float.valueOf(extVal), true);
}
public void storeDouble(int field, double extVal) {
setValue(field, new Double(extVal), true);
setValue(field, Double.valueOf(extVal), true);
}
public void storeString(int field, String extVal) {

View File

@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.collections.map.LinkedMap;
@ -1769,10 +1770,7 @@ public class QueryImpl
expected, paramTypes.keySet()));
}
Iterator<Map.Entry<Object, Class<?>>> itr = paramTypes.entrySet().iterator();
Map.Entry<Object, Class<?>> entry;
for (int i = 0; itr.hasNext(); i++) {
entry = itr.next();
for (Entry<Object, Class<?>> entry : paramTypes.entrySet()) {
if (entry.getValue().isPrimitive()
&& params.get(entry.getKey()) == null)
throw new UserException(_loc.get("null-primitive-param", entry.getKey()));

View File

@ -852,9 +852,9 @@ public class StateManagerImpl
case JavaTypes.CHAR:
return Character.valueOf(fetchCharField(field));
case JavaTypes.DOUBLE:
return new Double(fetchDoubleField(field));
return Double.valueOf(fetchDoubleField(field));
case JavaTypes.FLOAT:
return new Float(fetchFloatField(field));
return Float.valueOf(fetchFloatField(field));
case JavaTypes.INT:
return fetchIntField(field);
case JavaTypes.LONG:
@ -983,9 +983,9 @@ public class StateManagerImpl
case JavaTypes.CHAR:
return Character.valueOf(fm.fetchCharField(field));
case JavaTypes.DOUBLE:
return new Double(fm.fetchDoubleField(field));
return Double.valueOf(fm.fetchDoubleField(field));
case JavaTypes.FLOAT:
return new Float(fm.fetchFloatField(field));
return Float.valueOf(fm.fetchFloatField(field));
case JavaTypes.INT:
return fm.fetchIntField(field);
case JavaTypes.LONG:
@ -2486,8 +2486,7 @@ public class StateManagerImpl
if (!fmd.isExternalized())
storeDoubleField(field, externalVal);
else
storeField(field, fmd.getFieldValue(new Double(externalVal),
_broker));
storeField(field, fmd.getFieldValue(Double.valueOf(externalVal), _broker));
}
public void storeDoubleField(int field, double curVal) {
@ -2507,8 +2506,7 @@ public class StateManagerImpl
if (!fmd.isExternalized())
storeFloatField(field, externalVal);
else
storeField(field, fmd.getFieldValue(new Float(externalVal),
_broker));
storeField(field, fmd.getFieldValue(Float.valueOf(externalVal), _broker));
}
public void storeFloatField(int field, float curVal) {

View File

@ -53,9 +53,9 @@ class Abs
if (c == Integer.class)
return Math.abs(((Number) o).intValue());
if (c == Float.class)
return new Float(Math.abs(((Number) o).floatValue()));
return Float.valueOf(Math.abs(((Number) o).floatValue()));
if (c == Double.class)
return new Double(Math.abs(((Number) o).doubleValue()));
return Double.valueOf(Math.abs(((Number) o).doubleValue()));
if (c == Long.class)
return Math.abs(((Number) o).longValue());
if (c == BigDecimal.class)

View File

@ -38,6 +38,6 @@ class Sqrt
}
protected Object operate(Object o, Class c) {
return new Double(Math.sqrt(((Number) o).doubleValue()));
return Double.valueOf(Math.sqrt(((Number) o).doubleValue()));
}
}

View File

@ -295,21 +295,21 @@ public class JavaTypes {
if (val instanceof Double)
return val;
if (val instanceof Number)
return new Double(((Number) val).doubleValue());
return Double.valueOf(((Number) val).doubleValue());
// no break
case DOUBLE:
if (val instanceof String)
return new Double(val.toString());
return Double.valueOf(val.toString());
return val;
case FLOAT_OBJ:
if (val instanceof Float)
return val;
if (val instanceof Number)
return new Float(((Number) val).floatValue());
return Float.valueOf(((Number) val).floatValue());
// no break
case FLOAT:
if (val instanceof String)
return new Float(val.toString());
return Float.valueOf(val.toString());
return val;
case INT_OBJ:
if (val instanceof Integer)

View File

@ -1268,7 +1268,7 @@ public class MetaDataRepository implements PCRegistry.RegisterClassListener, Con
mapped.add(meta);
}
}
return mapped.toArray(new ClassMetaData[]{});
return mapped.toArray(new ClassMetaData[mapped.size()]);
}
/**
* Gets the metadata corresponding to the given persistence-aware class. Returns null, if the

View File

@ -622,11 +622,11 @@ public class ApplicationIds {
}
public void storeFloatField(int field, float val) {
store(new Float(val));
store(Float.valueOf(val));
}
public void storeDoubleField(int field, double val) {
store(new Double(val));
store(Double.valueOf(val));
}
public void storeStringField(int field, String val) {

View File

@ -51,7 +51,7 @@ public final class DoubleId
}
public Object getIdObject() {
return new Double(key);
return Double.valueOf(key);
}
public String toString() {

View File

@ -51,7 +51,7 @@ public final class FloatId
}
public Object getIdObject() {
return new Float(key);
return Float.valueOf(key);
}
public String toString() {