Package org.nutz.dao

Examples of org.nutz.dao.Condition


    assertEquals(exp, c.toSql(null).trim());
  }

  @Test
  public void test_is_null() {
    Condition c = Cnd.where("nm", " is ", null);
    String exp = "WHERE nm IS NULL";
    assertEquals(exp, c.toSql(null).trim());
  }
View Full Code Here


    assertEquals(exp, c.toSql(null).trim());
  }

  @Test
  public void test_is_not_null() {
    Condition c = Cnd.where("nm", " is nOT ", null);
    String exp = "WHERE nm IS NOT NULL";
    assertEquals(exp, c.toSql(null).trim());
  }
View Full Code Here

    assertEquals(exp, c.toSql(null).trim());
  }

  @Test
  public void test_not_in() {
    Condition c = Cnd.where("nm", " Not iN ", new int[]{1, 2, 3});
    String exp = "WHERE nm NOT IN (1,2,3)";
    assertEquals(exp, c.toSql(null).trim());
  }
View Full Code Here

  }

  @Test
  public void test_count_with_entity() {
    insertRecords(8);
    int re = dao.count(Pet.class, new Condition() {
      public String toSql(Entity<?> entity) {
        return entity.getField("nickName").getColumnName() + " IN ('alias_5','alias_6')";
      }
    });
    assertEquals(2, re);
View Full Code Here

    @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));
    }
View Full Code Here

        assertEquals("name like'老板%' AND age>30", c2.toSql(en));
    }

    @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());
    }
View Full Code Here

        assertEquals(exp, c.toSql(en).trim());
    }

    @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());
    }
View Full Code Here

        assertEquals(exp, c.toSql(en).trim());
    }

    @Test
    public void test_order() {
        Condition c = Cnd.orderBy().asc("id").desc("name").asc("age").desc("workingDay");
        String exp = "ORDER BY wid ASC, wname DESC, age ASC, days DESC";
        assertEquals(exp, c.toSql(en).trim());
    }
View Full Code Here

    @Test
    public void test_like_in() {
        int[] ages = {4, 7, 9};
        SqlExpression e = Cnd.exps("age", ">", 35).and("id", "<", 47);
        SqlExpression e2 = Cnd.exps("name", "\tLIKE ", "%t%").and("age", "IN  \n\r", ages).or(e);
        Condition c = Cnd.where("id", "=", 37).and(e).or(e2).asc("age").desc("id");
        String exp = "WHERE wid=37 AND (age>35 AND wid<47) OR (wname LIKE '%t%' AND age IN (4,7,9) OR (age>35 AND wid<47)) ORDER BY age ASC, wid DESC";
        assertEquals(exp, c.toSql(en).trim());
    }
View Full Code Here

        assertEquals(exp, c.toSql(en).trim());
    }

    @Test
    public void test_equel() {
        Condition c = Cnd.where("ff", "=", true);
        String exp = "WHERE ff=true";
        assertEquals(exp, c.toSql(en).trim());
    }
View Full Code Here

TOP

Related Classes of org.nutz.dao.Condition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.