use of org.nutz.dao.Cnd in project nutz by nutzam.
the class SimpleDaoTest method test_cnd_clone2.
@Test
public void test_cnd_clone2() {
// 序列化的方式, 不要考究SQL条件的合理性
dao.insert(Pet.create(30));
Cnd cnd = Cnd.where("age", ">", 15).and(Cnd.exps("age", ">", 0).and("age", "<", 16));
cnd.asc("age");
int t = dao.count(Pet.class, cnd);
assertNotNull(Lang.toBytes(cnd));
Stopwatch sw = Stopwatch.begin();
cnd.clone();
sw.stop();
System.out.println(sw);
assertEquals(t, dao.count(Pet.class, cnd.clone()));
// 仅拷贝where条件
Cnd cndCloned = cnd.cloneWhere();
assertEquals(t, dao.count(Pet.class, cndCloned));
// 修改原来的cnd条件, 使其互相矛盾,结果肯定是0
cnd.and("age", "<", 0);
assertEquals(0, dao.count(Pet.class, cnd));
// 克隆的cndCloned应该不受影响
assertEquals(t, dao.count(Pet.class, cndCloned));
}
use of org.nutz.dao.Cnd in project nutz by nutzam.
the class SimpleDaoTest method test_cnd_clone.
@Test
public void test_cnd_clone() throws IOException {
try {
Cnd cnd = Cnd.NEW().and("abc", "=", 123);
Cnd.byCri(cnd.getCri());
Cnd.byCri(cnd.getCri());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.nutz.dao.Cnd in project nutz by nutzam.
the class QueryTest method queryByJoin_with_cnd.
@Test
public void queryByJoin_with_cnd() {
dao.create(Pet.class, true);
dao.create(Master.class, true);
Master master = new Master();
master.setName("zozoh");
Pet petA = new Pet();
petA.setName("wendal");
petA.setAge(31);
Pet petB = new Pet();
petB.setName("pangwu");
petB.setAge(30);
master.setPets(Arrays.asList(petA, petB));
dao.insertWith(master, null);
Cnd cnd = Cnd.NEW();
cnd.asc("name");
List<Master> list = dao.queryByJoin(Master.class, "pets", cnd);
assertEquals(1, list.size());
assertEquals(2, list.get(0).getPets().size());
}
use of org.nutz.dao.Cnd in project nutz by nutzam.
the class CustomizedSqlsTest method test_issue_1281.
@Test
public void test_issue_1281() {
SqlExpression sqle = Exps.inSql2("id", "select user_id from role where id in (%s)", Arrays.asList(1, 2, 3));
Cnd cnd = Cnd.where(sqle);
System.out.println(cnd.toString());
StringBuilder sb = new StringBuilder();
// 取出带问号的SQL
sqle.joinSql(null, sb);
System.out.println(sb);
assertEquals("id IN (select user_id from role where id in (?,?,?))", sb.toString());
}
use of org.nutz.dao.Cnd in project nutz by nutzam.
the class UpdateTest method test_update_self_plus.
@Test
public void test_update_self_plus() {
dao.create(Pet.class, true);
Pet pet = Pet.create("Xy");
pet.setAge(98);
dao.insert(pet);
pet = dao.fetch(Pet.class, (Cnd) null);
dao.update(Pet.class, Chain.makeSpecial("age", "+1"), null);
assertEquals(pet.getAge() + 1, dao.fetch(Pet.class, pet.getId()).getAge());
}
Aggregations