mirror of https://github.com/apache/openjpa.git
OPENJPA-1050: Use generic types where applicable
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@773179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f6f99775bf
commit
23bd8aa147
|
@ -22,7 +22,6 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -56,12 +55,12 @@ public abstract class AbstractExpressionBuilder {
|
|||
protected static final int EX_UNSUPPORTED = 2;
|
||||
|
||||
// common implicit type settings
|
||||
protected static final Class TYPE_OBJECT = Object.class;
|
||||
protected static final Class TYPE_STRING = String.class;
|
||||
protected static final Class TYPE_CHAR_OBJ = Character.class;
|
||||
protected static final Class TYPE_NUMBER = Number.class;
|
||||
protected static final Class TYPE_COLLECTION = Collection.class;
|
||||
protected static final Class TYPE_MAP = Map.class;
|
||||
protected static final Class<Object> TYPE_OBJECT = Object.class;
|
||||
protected static final Class<String> TYPE_STRING = String.class;
|
||||
protected static final Class<Character> TYPE_CHAR_OBJ = Character.class;
|
||||
protected static final Class<Number> TYPE_NUMBER = Number.class;
|
||||
protected static final Class<Collection> TYPE_COLLECTION = Collection.class;
|
||||
protected static final Class<Map> TYPE_MAP = Map.class;
|
||||
|
||||
// contains types for setImplicitTypes
|
||||
protected static final int CONTAINS_TYPE_ELEMENT = 1;
|
||||
|
@ -74,9 +73,9 @@ public abstract class AbstractExpressionBuilder {
|
|||
protected final Resolver resolver;
|
||||
protected ExpressionFactory factory;
|
||||
|
||||
private final Set _accessPath = new HashSet();
|
||||
private Map _seenVars = null;
|
||||
private Set _boundVars = null;
|
||||
private final Set<ClassMetaData> _accessPath = new HashSet<ClassMetaData>();
|
||||
private Map<String,Value> _seenVars = null;
|
||||
private Set<Value> _boundVars = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -149,7 +148,7 @@ public abstract class AbstractExpressionBuilder {
|
|||
*/
|
||||
protected void bind(Value var) {
|
||||
if (_boundVars == null)
|
||||
_boundVars = new HashSet();
|
||||
_boundVars = new HashSet<Value>();
|
||||
_boundVars.add(var);
|
||||
}
|
||||
|
||||
|
@ -162,7 +161,7 @@ public abstract class AbstractExpressionBuilder {
|
|||
return (Value) _seenVars.get(id);
|
||||
|
||||
// create and cache var
|
||||
Class type = getDeclaredVariableType(id);
|
||||
Class<?> type = getDeclaredVariableType(id);
|
||||
|
||||
// add this type to the set of classes in the filter's access path
|
||||
ClassMetaData meta = null;
|
||||
|
@ -181,7 +180,7 @@ public abstract class AbstractExpressionBuilder {
|
|||
var.setMetaData(meta);
|
||||
|
||||
if (_seenVars == null)
|
||||
_seenVars = new HashMap();
|
||||
_seenVars = new HashMap<String,Value>();
|
||||
_seenVars.put(id, var);
|
||||
return var;
|
||||
}
|
||||
|
@ -195,13 +194,11 @@ public abstract class AbstractExpressionBuilder {
|
|||
if (_seenVars == null)
|
||||
return;
|
||||
|
||||
Map.Entry entry;
|
||||
Value var;
|
||||
for (Iterator itr = _seenVars.entrySet().iterator(); itr.hasNext();) {
|
||||
entry = (Map.Entry) itr.next();
|
||||
var = (Value) entry.getValue();
|
||||
for (Map.Entry<String,Value> entry : _seenVars.entrySet()) {
|
||||
var = entry.getValue();
|
||||
if (var.getMetaData() == null && !isBound(var)
|
||||
&& !isDeclaredVariable((String) entry.getKey())) {
|
||||
&& !isDeclaredVariable(entry.getKey())) {
|
||||
throw parseException(EX_USER, "not-unbound-var",
|
||||
new Object[]{ entry.getKey() }, null);
|
||||
}
|
||||
|
@ -228,14 +225,14 @@ public abstract class AbstractExpressionBuilder {
|
|||
/**
|
||||
* Convenience method to get metadata for the given type.
|
||||
*/
|
||||
protected ClassMetaData getMetaData(Class c, boolean required) {
|
||||
protected ClassMetaData getMetaData(Class<?> c, boolean required) {
|
||||
return getMetaData(c, required, getClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get metadata for the given type.
|
||||
*/
|
||||
protected ClassMetaData getMetaData(Class c, boolean required,
|
||||
protected ClassMetaData getMetaData(Class<?> c, boolean required,
|
||||
ClassLoader loader) {
|
||||
return resolver.getConfiguration().getMetaDataRepositoryInstance().
|
||||
getMetaData(c, loader, required);
|
||||
|
@ -284,7 +281,7 @@ public abstract class AbstractExpressionBuilder {
|
|||
Object val = traverseStaticField(meta.getDescribedType(), field);
|
||||
if (val == null) {
|
||||
String[] all = meta.getFieldNames();
|
||||
Class cls = meta.getDescribedType();
|
||||
Class<?> cls = meta.getDescribedType();
|
||||
throw parseException(EX_USER, "no-field",
|
||||
new Object[] {field, cls.getSimpleName(),
|
||||
StringDistance.getClosestLevenshteinDistance(field, all),
|
||||
|
@ -320,7 +317,7 @@ public abstract class AbstractExpressionBuilder {
|
|||
/**
|
||||
* Return a constant containing the value of the given static field.
|
||||
*/
|
||||
protected Object traverseStaticField(Class cls, String field) {
|
||||
protected Object traverseStaticField(Class<?> cls, String field) {
|
||||
try {
|
||||
return cls.getField(field).get(null);
|
||||
} catch (Exception e) {
|
||||
|
@ -330,18 +327,18 @@ public abstract class AbstractExpressionBuilder {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the named variabe if it has been declared.
|
||||
* Returns the type of the named variable if it has been declared.
|
||||
*/
|
||||
protected abstract Class getDeclaredVariableType(String name);
|
||||
protected abstract Class<?> getDeclaredVariableType(String name);
|
||||
|
||||
/**
|
||||
* Set the implicit types of the given values based on the fact that
|
||||
* they're used together, and based on the operator type.
|
||||
*/
|
||||
protected void setImplicitTypes(Value val1, Value val2,
|
||||
Class expected) {
|
||||
Class c1 = val1.getType();
|
||||
Class c2 = val2.getType();
|
||||
Class<?> expected) {
|
||||
Class<?> c1 = val1.getType();
|
||||
Class<?> c2 = val2.getType();
|
||||
boolean o1 = c1 == TYPE_OBJECT;
|
||||
boolean o2 = c2 == TYPE_OBJECT;
|
||||
|
||||
|
@ -370,8 +367,8 @@ public abstract class AbstractExpressionBuilder {
|
|||
* Perform conversions to make values compatible.
|
||||
*/
|
||||
private void convertTypes(Value val1, Value val2) {
|
||||
Class t1 = val1.getType();
|
||||
Class t2 = val2.getType();
|
||||
Class<?> t1 = val1.getType();
|
||||
Class<?> t2 = val2.getType();
|
||||
|
||||
// allow string-to-char conversions
|
||||
if (t1 == TYPE_STRING && (Filters.wrap(t2) == TYPE_CHAR_OBJ
|
||||
|
@ -419,8 +416,8 @@ public abstract class AbstractExpressionBuilder {
|
|||
* Perform conversions to make values compatible.
|
||||
*/
|
||||
private void convertTypesQuotedNumbers(Value val1, Value val2) {
|
||||
Class t1 = val1.getType();
|
||||
Class t2 = val2.getType();
|
||||
Class<?> t1 = val1.getType();
|
||||
Class<?> t2 = val2.getType();
|
||||
|
||||
// if we're comparing to a single-quoted string, convert
|
||||
// the value according to the 3.1 rules.
|
||||
|
@ -460,7 +457,7 @@ public abstract class AbstractExpressionBuilder {
|
|||
/**
|
||||
* Return true if given class can be used as a number.
|
||||
*/
|
||||
private static boolean isNumeric(Class type) {
|
||||
private static boolean isNumeric(Class<?> type) {
|
||||
type = Filters.wrap(type);
|
||||
return Number.class.isAssignableFrom(type)
|
||||
|| type == Character.TYPE || type == TYPE_CHAR_OBJ;
|
||||
|
@ -504,7 +501,7 @@ public abstract class AbstractExpressionBuilder {
|
|||
/**
|
||||
* Set the implicit type of the given value to the given class.
|
||||
*/
|
||||
protected static void setImplicitType(Value val, Class expected) {
|
||||
protected static void setImplicitType(Value val, Class<?> expected) {
|
||||
// we never expect a pc type, so no need to worry about metadata
|
||||
if (val.getType() == TYPE_OBJECT)
|
||||
val.setImplicitType(expected);
|
||||
|
|
Loading…
Reference in New Issue