Search in sources :

Example 1 with FieldFilter

use of org.nutz.dao.FieldFilter in project nutz by nutzam.

the class NutDao method query.

public <T> List<T> query(final Class<T> classOfT, final Condition cnd, final Pager pager, String regex) {
    if (regex == null)
        return query(classOfT, cnd, pager);
    FieldFilter ff = FieldFilter.create(classOfT, FieldMatcher.make(regex, null, false));
    Molecule<List<T>> m = new Molecule<List<T>>() {

        public void run() {
            setObj(query(classOfT, cnd, pager));
        }
    };
    return ff.run(m);
}
Also used : FieldFilter(org.nutz.dao.FieldFilter) Molecule(org.nutz.trans.Molecule) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with FieldFilter

use of org.nutz.dao.FieldFilter in project nutz by nutzam.

the class NutDao method insert.

public <T> T insert(final T t, boolean ignoreNull, boolean ignoreZero, boolean ignoreBlankStr) {
    Object obj = Lang.first(t);
    Entity<?> en = getEntity(obj.getClass());
    List<String> names = new ArrayList<String>();
    for (MappingField mf : en.getMappingFields()) {
        Object tmp = mf.getValue(obj);
        if (ignoreNull && tmp == null) {
            continue;
        }
        if (ignoreZero && (tmp == null || (tmp instanceof Number && ((Number) tmp).intValue() == 0))) {
            continue;
        }
        if (ignoreBlankStr && (tmp instanceof CharSequence && Strings.isBlank((CharSequence) tmp)))
            continue;
        names.add(mf.getName());
    }
    FieldFilter ff = FieldFilter.create(obj.getClass(), "^(" + Strings.join("|", names.toArray()) + ")$");
    Molecule<T> m = new Molecule<T>() {

        public void run() {
            insert(t);
            setObj(t);
        }
    };
    return ff.run(m);
}
Also used : FieldFilter(org.nutz.dao.FieldFilter) Molecule(org.nutz.trans.Molecule) ArrayList(java.util.ArrayList) MappingField(org.nutz.dao.entity.MappingField)

Example 3 with FieldFilter

use of org.nutz.dao.FieldFilter in project nutz by nutzam.

the class NutDao method query.

public <T> List<T> query(final Class<T> classOfT, final Condition cnd, final Pager pager, FieldMatcher matcher) {
    if (matcher == null)
        return query(classOfT, cnd, pager);
    FieldFilter ff = FieldFilter.create(classOfT, matcher);
    Molecule<List<T>> m = new Molecule<List<T>>() {

        public void run() {
            setObj(query(classOfT, cnd, pager));
        }
    };
    return ff.run(m);
}
Also used : FieldFilter(org.nutz.dao.FieldFilter) Molecule(org.nutz.trans.Molecule) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)3 FieldFilter (org.nutz.dao.FieldFilter)3 Molecule (org.nutz.trans.Molecule)3 List (java.util.List)2 MappingField (org.nutz.dao.entity.MappingField)1