Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.entity.condition. (OFBIZ-9713) Thanks Dennis Balkir for reporting and providing the patch. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1813633 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -139,9 +139,9 @@ public class EntityClause {
|
||||
outputBuffer.append("[secondField,").append(secondField == null ? "null" : secondField).append("]");
|
||||
outputBuffer.append("[firstModelEntity,").append(firstModelEntity == null ? "null" : (firstModelEntity.getEntityName() == null ? "null" : firstModelEntity.getEntityName())).append("]");
|
||||
outputBuffer.append("[secondModelEntity,").append(secondModelEntity == null ? "null" : (secondModelEntity.getEntityName() == null ? "null" : secondModelEntity.getEntityName())).append("]");
|
||||
outputBuffer.append("[interFieldOperation,").append(interFieldOperation == null ? "null" : (interFieldOperation.getCode() == null ? "null" : interFieldOperation.getCode())).append("]");
|
||||
outputBuffer.append("[interFieldOperation,").append(interFieldOperation == null ? "null" : (interFieldOperation.getCode())).append("]");
|
||||
outputBuffer.append("[intraFieldOperation,").append(intraFieldOperation == null ? "null" : (intraFieldOperation.getCode() == null ? "null" : intraFieldOperation.getCode())).append("]");
|
||||
outputBuffer.append("[value,").append(getValue().toString() == null ? "null" : getValue().toString()).append("]");
|
||||
outputBuffer.append("[value,").append(getValue().toString()).append("]");
|
||||
return outputBuffer.toString();
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -22,6 +22,7 @@ package org.apache.ofbiz.entity.condition;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
@@ -87,9 +88,9 @@ public class EntityConditionBuilder extends BuilderSupport {
|
||||
|
||||
@Override
|
||||
protected Object createNode(Object methodName) {
|
||||
String operatorName = ((String)methodName).toLowerCase();
|
||||
String operatorName = ((String)methodName).toLowerCase(Locale.getDefault());
|
||||
EntityJoinOperator operator = EntityOperator.lookupJoin(operatorName);
|
||||
List<EntityCondition> condList = new LinkedList<EntityCondition>();
|
||||
List<EntityCondition> condList = new LinkedList<>();
|
||||
return new ConditionHolder(EntityCondition.makeCondition(condList, operator));
|
||||
}
|
||||
|
||||
@@ -103,17 +104,16 @@ public class EntityConditionBuilder extends BuilderSupport {
|
||||
@Override
|
||||
protected Object createNode(Object methodName, Map mapArg) {
|
||||
Map<String, Object> fieldValueMap = UtilGenerics.checkMap(mapArg);
|
||||
String operatorName = ((String)methodName).toLowerCase();
|
||||
String operatorName = ((String)methodName).toLowerCase(Locale.getDefault());
|
||||
EntityComparisonOperator<String, Object> operator = EntityOperator.lookupComparison(operatorName);
|
||||
List<EntityCondition> conditionList = new LinkedList<EntityCondition>();
|
||||
List<EntityCondition> conditionList = new LinkedList<>();
|
||||
for (Map.Entry<String, Object> entry : fieldValueMap.entrySet()) {
|
||||
conditionList.add(EntityCondition.makeCondition(entry.getKey(), operator, entry.getValue()));
|
||||
}
|
||||
if (conditionList.size() == 1) {
|
||||
return new ConditionHolder(conditionList.get(0));
|
||||
} else {
|
||||
return new ConditionHolder(EntityCondition.makeCondition(conditionList));
|
||||
}
|
||||
return new ConditionHolder(EntityCondition.makeCondition(conditionList));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,7 +126,7 @@ public class EntityConditionBuilder extends BuilderSupport {
|
||||
ConditionHolder holder = (ConditionHolder) parent;
|
||||
EntityConditionList<EntityCondition> parentConList = UtilGenerics.cast(holder.condition);
|
||||
Iterator<EntityCondition> iterator = parentConList.getConditionIterator();
|
||||
List<EntityCondition> tempList = new LinkedList<EntityCondition>();
|
||||
List<EntityCondition> tempList = new LinkedList<>();
|
||||
while (iterator.hasNext()) {
|
||||
tempList.add(iterator.next());
|
||||
}
|
||||
|
||||
+2
-3
@@ -71,8 +71,7 @@ public abstract class EntityConditionFunction extends EntityCondition {
|
||||
public String getCode() {
|
||||
if (codeString == null)
|
||||
return "null";
|
||||
else
|
||||
return codeString;
|
||||
return codeString;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@@ -88,7 +87,7 @@ public abstract class EntityConditionFunction extends EntityCondition {
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof EntityConditionFunction)) return false;
|
||||
EntityConditionFunction otherFunc = (EntityConditionFunction) obj;
|
||||
return this.idInt == otherFunc.idInt && (this.condition != null ? condition.equals(otherFunc.condition) : otherFunc.condition != null);
|
||||
return this.idInt.equals(otherFunc.idInt) && (this.condition != null ? condition.equals(otherFunc.condition) : otherFunc.condition != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -36,8 +36,8 @@ import org.apache.ofbiz.entity.model.ModelEntity;
|
||||
@SuppressWarnings("serial")
|
||||
public final class EntityDateFilterCondition extends EntityCondition {
|
||||
|
||||
protected final String fromDateName;
|
||||
protected final String thruDateName;
|
||||
private final String fromDateName;
|
||||
private final String thruDateName;
|
||||
|
||||
public EntityDateFilterCondition(String fromDateName, String thruDateName) {
|
||||
this.fromDateName = fromDateName;
|
||||
@@ -131,7 +131,7 @@ public final class EntityDateFilterCondition extends EntityCondition {
|
||||
* @return EntityCondition representing the date range filter
|
||||
*/
|
||||
public static EntityCondition makeRangeCondition(Timestamp rangeStart, Timestamp rangeEnd, String fromDateName, String thruDateName) {
|
||||
List<EntityCondition> criteria = new LinkedList<EntityCondition>();
|
||||
List<EntityCondition> criteria = new LinkedList<>();
|
||||
// fromDate is equal to or after rangeStart but before rangeEnd
|
||||
criteria.add(
|
||||
EntityCondition.makeCondition(
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.apache.ofbiz.entity.condition;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
@@ -140,7 +141,7 @@ public final class EntityExpr extends EntityCondition {
|
||||
protected void addValue(StringBuilder buffer, ModelField field, Object value, List<EntityConditionParam> params) {
|
||||
if (rhs instanceof EntityFunction.UPPER) {
|
||||
if (value instanceof String) {
|
||||
value = ((String) value).toUpperCase();
|
||||
value = ((String) value).toUpperCase(Locale.getDefault());
|
||||
}
|
||||
}
|
||||
super.addValue(buffer, field, value, params);
|
||||
@@ -215,6 +216,9 @@ public final class EntityExpr extends EntityCondition {
|
||||
} catch (GenericEntityException e) {
|
||||
Debug.logWarning(e, module);
|
||||
}
|
||||
if (valueType == null) {
|
||||
throw new IllegalArgumentException("Type " + curField.getType() + " not found for entity [" + modelEntity.getEntityName() + "]; probably because there is no datasource (helper) setup for the entity group that this entity is in: [" + delegator.getEntityGroupName(modelEntity.getEntityName()) + "]");
|
||||
}
|
||||
// make sure the type of keyFieldName of EntityConditionSubSelect matches the field Java type
|
||||
try {
|
||||
if (!ObjectType.instanceOf(ObjectType.loadClass(valueType.getJavaType()), type.getJavaType())) {
|
||||
|
||||
+2
-2
@@ -34,13 +34,13 @@ import org.apache.ofbiz.entity.util.EntityUtil;
|
||||
@SuppressWarnings("serial")
|
||||
public final class EntityFieldMap extends EntityConditionListBase<EntityExpr> {
|
||||
|
||||
protected final Map<String, ? extends Object> fieldMap;
|
||||
private final Map<String, ? extends Object> fieldMap;
|
||||
|
||||
public static <V> List<EntityExpr> makeConditionList(Map<String, V> fieldMap, EntityComparisonOperator<?,V> op) {
|
||||
if (fieldMap == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<EntityExpr> list = new ArrayList<EntityExpr>(fieldMap.size());
|
||||
List<EntityExpr> list = new ArrayList<>(fieldMap.size());
|
||||
for (Map.Entry<String, ? extends Object> entry: fieldMap.entrySet()) {
|
||||
list.add(EntityCondition.makeCondition(entry.getKey(), op, entry.getValue()));
|
||||
}
|
||||
|
||||
+3
-5
@@ -64,7 +64,7 @@ public class EntityFieldValue extends EntityConditionValue {
|
||||
this.fieldName = fieldName;
|
||||
this.entityAlias = entityAlias;
|
||||
if (UtilValidate.isNotEmpty(entityAliasStack)) {
|
||||
this.entityAliasStack = new LinkedList<String>();
|
||||
this.entityAliasStack = new LinkedList<>();
|
||||
this.entityAliasStack.addAll(entityAliasStack);
|
||||
}
|
||||
this.modelViewEntity = modelViewEntity;
|
||||
@@ -115,9 +115,8 @@ public class EntityFieldValue extends EntityConditionValue {
|
||||
if (this.entityAlias != null) {
|
||||
ModelEntity memberModelEntity = modelViewEntity.getMemberModelEntity(entityAlias);
|
||||
return getField(memberModelEntity, fieldName);
|
||||
} else {
|
||||
return getField(modelViewEntity, fieldName);
|
||||
}
|
||||
return getField(modelViewEntity, fieldName);
|
||||
}
|
||||
return getField(modelEntity, fieldName);
|
||||
}
|
||||
@@ -181,9 +180,8 @@ public class EntityFieldValue extends EntityConditionValue {
|
||||
}
|
||||
if (map instanceof GenericEntity.NULL) {
|
||||
return null;
|
||||
} else {
|
||||
return map.get(fieldName);
|
||||
}
|
||||
return map.get(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+8
-8
@@ -20,6 +20,7 @@
|
||||
package org.apache.ofbiz.entity.condition;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ofbiz.base.util.UtilGenerics;
|
||||
@@ -64,7 +65,7 @@ public abstract class EntityFunction<T extends Comparable<?>> extends EntityCond
|
||||
*
|
||||
*/
|
||||
public static class LENGTH extends EntityFunctionSingle<Integer> {
|
||||
public static Fetcher<Integer> FETCHER = new Fetcher<Integer>() {
|
||||
public static final Fetcher<Integer> FETCHER = new Fetcher<Integer>() {
|
||||
public Integer getValue(Object value) { return value.toString().length(); }
|
||||
};
|
||||
|
||||
@@ -78,7 +79,7 @@ public abstract class EntityFunction<T extends Comparable<?>> extends EntityCond
|
||||
*
|
||||
*/
|
||||
public static class TRIM extends EntityFunctionSingle<String> {
|
||||
public static Fetcher<String> FETCHER = new Fetcher<String>() {
|
||||
public static final Fetcher<String> FETCHER = new Fetcher<String>() {
|
||||
public String getValue(Object value) { return value.toString().trim(); }
|
||||
};
|
||||
|
||||
@@ -92,8 +93,8 @@ public abstract class EntityFunction<T extends Comparable<?>> extends EntityCond
|
||||
*
|
||||
*/
|
||||
public static class UPPER extends EntityFunctionSingle<String> {
|
||||
public static Fetcher<String> FETCHER = new Fetcher<String>() {
|
||||
public String getValue(Object value) { return value.toString().toUpperCase(); }
|
||||
public static final Fetcher<String> FETCHER = new Fetcher<String>() {
|
||||
public String getValue(Object value) { return value.toString().toUpperCase(Locale.getDefault()); }
|
||||
};
|
||||
|
||||
private UPPER(Object value) {
|
||||
@@ -106,8 +107,8 @@ public abstract class EntityFunction<T extends Comparable<?>> extends EntityCond
|
||||
*
|
||||
*/
|
||||
public static class LOWER extends EntityFunctionSingle<String> {
|
||||
public static Fetcher<String> FETCHER = new Fetcher<String>() {
|
||||
public String getValue(Object value) { return value.toString().toLowerCase(); }
|
||||
public static final Fetcher<String> FETCHER = new Fetcher<String>() {
|
||||
public String getValue(Object value) { return value.toString().toLowerCase(Locale.getDefault()); }
|
||||
};
|
||||
|
||||
private LOWER(Object value) {
|
||||
@@ -156,9 +157,8 @@ public abstract class EntityFunction<T extends Comparable<?>> extends EntityCond
|
||||
public EntityConditionValue freeze() {
|
||||
if (nested != null) {
|
||||
return new EntityFunctionNested<T>(fetcher, function, nested.freeze()) {};
|
||||
} else {
|
||||
return new EntityFunctionSingle<T>(fetcher, function, value) {};
|
||||
}
|
||||
return new EntityFunctionSingle<T>(fetcher, function, value) {};
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ public class EntityJoinOperator extends EntityOperator<EntityCondition, EntityCo
|
||||
|
||||
@Override
|
||||
public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean compat, EntityCondition lhs, EntityCondition rhs, Datasource datasourceInfo) {
|
||||
List<EntityCondition> conditions = new LinkedList<EntityCondition>();
|
||||
List<EntityCondition> conditions = new LinkedList<>();
|
||||
conditions.add(lhs);
|
||||
conditions.add(rhs);
|
||||
addSqlValue(sql, modelEntity, entityConditionParams, conditions, datasourceInfo);
|
||||
@@ -89,7 +89,7 @@ public class EntityJoinOperator extends EntityOperator<EntityCondition, EntityCo
|
||||
}
|
||||
|
||||
public EntityCondition freeze(List<? extends EntityCondition> conditionList) {
|
||||
List<EntityCondition> newList = new ArrayList<EntityCondition>(conditionList.size());
|
||||
List<EntityCondition> newList = new ArrayList<>(conditionList.size());
|
||||
for (EntityCondition condition: conditionList) {
|
||||
newList.add(condition.freeze());
|
||||
}
|
||||
|
||||
+4
-4
@@ -23,6 +23,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -60,8 +61,8 @@ public abstract class EntityOperator<L, R, T> extends EntityConditionBase {
|
||||
private static HashMap<String, EntityOperator<?,?,?>> registry = new HashMap<String, EntityOperator<?,?,?>>();
|
||||
|
||||
private static <L,R,T> void registerCase(String name, EntityOperator<L,R,T> operator) {
|
||||
registry.put(name.toLowerCase(), operator);
|
||||
registry.put(name.toUpperCase(), operator);
|
||||
registry.put(name.toLowerCase(Locale.getDefault()), operator);
|
||||
registry.put(name.toUpperCase(Locale.getDefault()), operator);
|
||||
}
|
||||
|
||||
public static <L,R,T> void register(String name, EntityOperator<L,R,T> operator) {
|
||||
@@ -209,9 +210,8 @@ public abstract class EntityOperator<L, R, T> extends EntityConditionBase {
|
||||
public String getCode() {
|
||||
if (codeString == null) {
|
||||
return "null";
|
||||
} else {
|
||||
return codeString;
|
||||
}
|
||||
return codeString;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ import org.apache.ofbiz.entity.model.ModelEntity;
|
||||
@SuppressWarnings("serial")
|
||||
public final class EntityWhereString extends EntityCondition {
|
||||
|
||||
protected final String sqlString;
|
||||
private final String sqlString;
|
||||
|
||||
public EntityWhereString(String sqlString) {
|
||||
this.sqlString = sqlString;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package org.apache.ofbiz.entity.condition;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.ofbiz.base.util.UtilGenerics;
|
||||
import org.apache.ofbiz.entity.GenericEntity;
|
||||
@@ -34,6 +35,7 @@ public class OrderByItem implements Comparator<GenericEntity> {
|
||||
|
||||
public static final String NULLS_FIRST = "NULLS FIRST";
|
||||
public static final String NULLS_LAST = "NULLS LAST";
|
||||
public static final String module = OrderByItem.class.getName();
|
||||
|
||||
protected boolean descending;
|
||||
protected Boolean nullsFirst;
|
||||
@@ -78,12 +80,12 @@ public class OrderByItem implements Comparator<GenericEntity> {
|
||||
|
||||
// handle nulls first/last
|
||||
Boolean nullsFirst = null;
|
||||
if (text.toUpperCase().endsWith(NULLS_FIRST)) {
|
||||
if (text.toUpperCase(Locale.getDefault()).endsWith(NULLS_FIRST)) {
|
||||
nullsFirst = true;
|
||||
text = text.substring(0, text.length() - NULLS_FIRST.length()).trim();
|
||||
}
|
||||
|
||||
if (text.toUpperCase().endsWith(NULLS_LAST)) {
|
||||
if (text.toUpperCase(Locale.getDefault()).endsWith(NULLS_LAST)) {
|
||||
nullsFirst = false;
|
||||
text = text.substring(0, text.length() - NULLS_LAST.length()).trim();
|
||||
}
|
||||
@@ -114,7 +116,7 @@ public class OrderByItem implements Comparator<GenericEntity> {
|
||||
}
|
||||
|
||||
if (text.endsWith(")")) {
|
||||
String upperText = text.toUpperCase();
|
||||
String upperText = text.toUpperCase(Locale.getDefault());
|
||||
endIndex--;
|
||||
if (upperText.startsWith("UPPER(")) {
|
||||
caseSensitivity = UPPER;
|
||||
@@ -132,7 +134,6 @@ public class OrderByItem implements Comparator<GenericEntity> {
|
||||
if (startIndex != 0 || endIndex != text.length()) {
|
||||
text = text.substring(startIndex, endIndex);
|
||||
startIndex = 0;
|
||||
endIndex = text.length();
|
||||
}
|
||||
EntityConditionValue value = EntityFieldValue.makeFieldValue(text);
|
||||
switch (caseSensitivity) {
|
||||
@@ -142,6 +143,8 @@ public class OrderByItem implements Comparator<GenericEntity> {
|
||||
case LOWER:
|
||||
value = EntityFunction.LOWER(value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new OrderByItem(value, descending, nullsFirst);
|
||||
}
|
||||
@@ -191,6 +194,16 @@ public class OrderByItem implements Comparator<GenericEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (descending ? 1231 : 1237);
|
||||
result = prime * result + ((nullsFirst == null) ? 0 : nullsFirst.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object obj) {
|
||||
if (!(obj instanceof OrderByItem)) return false;
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.apache.ofbiz.entity.config.model.Datasource;
|
||||
import org.apache.ofbiz.entity.model.ModelEntity;
|
||||
|
||||
public class OrderByList implements Comparator<GenericEntity> {
|
||||
protected List<OrderByItem> orderByList = new ArrayList<OrderByItem>();
|
||||
protected List<OrderByItem> orderByList = new ArrayList<>();
|
||||
|
||||
public OrderByList() {
|
||||
}
|
||||
@@ -103,6 +103,14 @@ public class OrderByList implements Comparator<GenericEntity> {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((orderByList == null) ? 0 : orderByList.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object obj) {
|
||||
if (!(obj instanceof OrderByList)) return false;
|
||||
|
||||
Reference in New Issue
Block a user