public void testMapAndObjectHolder() { // 清晰的sql语句,/~ ~/为一个语法块 String sql = "select * from user where 1=1 " + "/~ and title = {title} ~/" + "/~ and sex = {sex} ~/" + "/~ and salary = {salary} ~/" + "/~ and age = [age] ~/" + "/~ and mapKey = [mapKey] ~/"; // filters为参数 BlogInfo info = new BlogInfo(); info.setTitle("java"); Map hashMap = new HashMap(); hashMap.put("mapKey", "2009_mapKey"); XsqlFilterResult result = new XsqlBuilder().generateHql(sql, hashMap, info); assertEquals( "select * from user where 1=1 and title = :title and sex = :sex and age = 0 and mapKey = 2009_mapKey ", result.getXsql()); assertTrue(result.getAcceptedFilters().containsKey("sex")); assertTrue(result.getAcceptedFilters().containsKey("title")); assertFalse(result.getAcceptedFilters().containsKey("age")); }
public void testBean() { // 清晰的sql语句,/~ ~/为一个语法块 String sql = "select * from user where 1=1 " + "/~ and title = {title} ~/" + "/~ and sex = {sex} ~/" + "/~ and salary = {salary} ~/" + "/~ and age = [age] ~/"; // filters为参数 BlogInfo info = new BlogInfo(); info.setTitle("java"); XsqlFilterResult result = new XsqlBuilder().generateHql(sql, info); assertEquals( "select * from user where 1=1 and title = :title and sex = :sex and age = 0 ", result.getXsql()); assertTrue(result.getAcceptedFilters().containsKey("sex")); assertTrue(result.getAcceptedFilters().containsKey("title")); assertFalse(result.getAcceptedFilters().containsKey("age")); }