72 lines
1.4 KiB
Java
72 lines
1.4 KiB
Java
|
package +zoccolo+.jpa;
|
||
|
|
||
|
import javax.persistence.metamodel.SingularAttribute;
|
||
|
|
||
|
public class SearchParameterBuilder {
|
||
|
|
||
|
public static SearchParameter<String> getStringParam(String name, String value) {
|
||
|
return new StringParameter(name, value);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Per parametri anonimi.
|
||
|
*/
|
||
|
public static SearchParameter<String> getStringParam(String value) {
|
||
|
return getStringParam("", value);
|
||
|
}
|
||
|
|
||
|
public static <D, T> SearchParameter<T> getParam(SingularAttribute<D, T> sa, final T value) {
|
||
|
return new SingularParameter<D, T>(sa, value);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Il value non deve essere null.
|
||
|
*/
|
||
|
public static <T> SearchParameter<T> getParam(final String name, final T value) {
|
||
|
return new SearchParameter<T>() {
|
||
|
@Override
|
||
|
public String getName() {
|
||
|
return name;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public T getValue() {
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
@SuppressWarnings("unchecked")
|
||
|
@Override
|
||
|
public Class<T> getType() {
|
||
|
return (Class<T>) value.getClass();
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Per parametri anonimi.
|
||
|
*/
|
||
|
public static SearchParameter<String> getParam(String value) {
|
||
|
return getParam("", value);
|
||
|
}
|
||
|
|
||
|
public static <T> SearchParameter<T> getParam(final String name, final T value, final Class<T> clazz) {
|
||
|
return new SearchParameter<T>() {
|
||
|
@Override
|
||
|
public String getName() {
|
||
|
return name;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public T getValue() {
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Class<T> getType() {
|
||
|
return clazz;
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
}
|