ISE-ComProg-After-Midterm/screwdriver-3.5.6/box/snippets/java/jpa2/SearchParameterBuilder.java

72 lines
1.4 KiB
Java
Raw Permalink Normal View History

2020-10-29 09:38:56 +00:00
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;
}
};
}
}