Search in sources :

Example 6 with Condition

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

the class CndTest method test_segment.

@Test
public void test_segment() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("name", "比尔盖茨");
    map.put("age", 50);
    Condition c1 = Cnd.wrap("name='${name}' AND age>${age}", map);
    assertEquals("name='比尔盖茨' AND age>50", c1.toSql(en));
    Worker worker = new Worker();
    worker.name = "老板";
    worker.age = 30;
    Condition c2 = Cnd.wrap("name like'${name}%' AND age>${age}", worker);
    assertEquals("name like'老板%' AND age>30", c2.toSql(en));
}
Also used : Condition(org.nutz.dao.Condition) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with Condition

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

the class CndTest method test_gt_like.

@Test
public void test_gt_like() {
    Condition c = Cnd.where("id", ">", 45).and("name", "LIKE", "%ry%");
    String exp = "WHERE wid>45 AND wname LIKE '%ry%'";
    assertEquals(exp, c.toSql(en).trim());
}
Also used : Condition(org.nutz.dao.Condition) Test(org.junit.Test)

Example 8 with Condition

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

the class CndTest method test_bracket.

@Test
public void test_bracket() {
    Condition c = Cnd.where(Cnd.exps("id", ">", 45)).and("name", "LIKE", "%ry%");
    String exp = "WHERE (wid>45) AND wname LIKE '%ry%'";
    assertEquals(exp, c.toSql(en).trim());
}
Also used : Condition(org.nutz.dao.Condition) Test(org.junit.Test)

Example 9 with Condition

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

the class CndTest method test_equel.

@Test
public void test_equel() {
    Condition c = Cnd.where("ff", "=", true);
    String exp = "WHERE ff=true";
    assertEquals(exp, c.toSql(en).trim());
}
Also used : Condition(org.nutz.dao.Condition) Test(org.junit.Test)

Example 10 with Condition

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

the class SimpleDaoTest method test_count_with_entity.

@Test
public void test_count_with_entity() {
    insertRecords(8);
    int re = dao.count(Pet.class, new Condition() {

        /**
			 * 
			 */
        private static final long serialVersionUID = 6425274813857908874L;

        public String toSql(Entity<?> entity) {
            return entity.getField("nickName").getColumnName() + " IN ('alias_5','alias_6')";
        }
    });
    assertEquals(2, re);
}
Also used : Condition(org.nutz.dao.Condition) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 Condition (org.nutz.dao.Condition)16 SqlExpression (org.nutz.dao.util.cri.SqlExpression)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 Cnd (org.nutz.dao.Cnd)1