use of org.nutz.dao.DaoInterceptor in project nutz by nutzam.
the class DaoSupport method setInterceptors.
public void setInterceptors(List<Object> interceptors) {
List<DaoInterceptor> list = new LinkedList<DaoInterceptor>();
for (Object it : interceptors) {
DaoInterceptor d = makeInterceptor(it);
if (d != null)
list.add(d);
}
this._interceptors = list;
}
use of org.nutz.dao.DaoInterceptor in project nutz by nutzam.
the class DaoSupport method addInterceptor.
public void addInterceptor(Object it) {
DaoInterceptor d = makeInterceptor(it);
if (d != null) {
List<DaoInterceptor> list = new LinkedList<DaoInterceptor>(this._interceptors);
list.add(d);
this._interceptors = list;
}
}
use of org.nutz.dao.DaoInterceptor in project nutz by nutzam.
the class SimpleDaoInterceptorTest method issue_1325.
/**
* 测试的内容: 在DaoInterceptor内设置字段过滤,看看能不能起作用
*/
@Test
public void issue_1325() {
// 现有默认dao创建记录
this.dao.create(Pet.class, true);
Pet pet = Pet.create("wendal");
pet.setAge(30);
this.dao.insert(pet);
// 然后构建一个临时用的Dao实例, 拦截器顺序: 设置FieldFilter, log
DataSource ds = ioc.get(DataSource.class);
NutDao dao = new NutDao(ds);
dao.setInterceptors(Arrays.asList(new DaoInterceptor() {
public void filter(DaoInterceptorChain chain) throws DaoException {
chain.getDaoStatement().getContext().setFieldMatcher(FieldMatcher.make(null, "age", false));
chain.doChain();
}
}, "log"));
// 用临时dao,应该是没有age数据
pet = dao.fetch(Pet.class, Cnd.where("name", "=", "wendal"));
Assert.assertEquals(0, pet.getAge());
// 用默认dao, 应该有age数据
pet = this.dao.fetch(Pet.class, Cnd.where("name", "=", "wendal"));
Assert.assertEquals(30, pet.getAge());
}
Aggregations