gu.sql2java.StringFieldSearcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sql2java-manager Show documentation
Show all versions of sql2java-manager Show documentation
sql2java manager class package for accessing database
package gu.sql2java;
import static com.google.common.base.Preconditions.checkNotNull;
import static gu.sql2java.Managers.baseManagerOf;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import com.google.common.collect.Multimap;
public class StringFieldSearcher extends BaseFieldSearcher {
private Function funKeyGetter;
public StringFieldSearcher(RowMetaData metaData, int... effectColumnIds) {
super(metaData, effectColumnIds);
setDefaultMatchFilter(StringMatchType.REGEX_MATCH);
}
public StringFieldSearcher(RowMetaData metaData, String... effectColumnNames) {
this(metaData, checkNotNull(metaData,"metaData is null").columnIDsOf(effectColumnNames));
}
public > StringFieldSearcher(Class interfaceClass, int[] effectColumnId) {
this(baseManagerOf(interfaceClass).metaData, effectColumnId);
}
public > StringFieldSearcher(Class interfaceClass, String... effectColumnNames) {
this(baseManagerOf(interfaceClass).metaData, effectColumnNames);
}
@Override
protected String keyOf(B bean) {
// 返回空则视为null
return Strings.emptyToNull(checkNotNull(funKeyGetter,"funKeyGetter is uninitialized").apply(bean));
}
public Function getFunKeyGetter() {
return funKeyGetter;
}
public StringFieldSearcher setFunKeyGetter(Function funKeyGetter) {
this.funKeyGetter = funKeyGetter;
return this;
}
public StringFieldSearcher setDefaultMatchFilter(StringMatchType defaultMatchType){
if(defaultMatchType != null){
setDefaultMatchFilter(defaultMatchType.createMatchFilter());
}
return this;
}
public final Multimap search(String key, int matchFlags, StringMatchType matchType, Predicate pkFilter){
return search(key,matchFlags, matchType == null ? null : matchType.createMatchFilter(), pkFilter);
}
}