@Test public void testSelect() { RouteRuleModel routeRule = newRouteRule(); routeRuleDao.insertOrUpdate(routeRule); RouteRuleModel filter = new RouteRuleModel(); filter.setName(routeRule.getName()); filter.setServiceId(routeRule.getServiceId()); Assert.assertEquals(1, routeRuleDao.select(filter).size()); Assert.assertEquals(1, routeRuleDao.select(Lists.newArrayList(routeRuleDao.select(filter).get(0).getId())).size()); }
public List<RouteRuleModel> select(RouteRuleModel filter) { ValueCheckers.notNull(filter, "filter"); Map<String, String> conditions = Maps.newHashMap(); conditions.put("id=?", filter.getId() == null ? null : Long.toString(filter.getId())); conditions.put("service_id=?", filter.getServiceId()); conditions.put("name=?", filter.getName()); conditions.put("status=?", filter.getStatus()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); return query(Joiner.on(" and ").join(conditions.keySet()), Lists.newArrayList(conditions.values())); }
RouteRuleDao { public List<RouteRuleModel> select(RouteRuleModel filter) { ValueCheckers.notNull(filter, "filter"); Map<String, String> conditions = Maps.newHashMap(); conditions.put("id=?", filter.getId() == null ? null : Long.toString(filter.getId())); conditions.put("service_id=?", filter.getServiceId()); conditions.put("name=?", filter.getName()); conditions.put("status=?", filter.getStatus()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); return query(Joiner.on(" and ").join(conditions.keySet()), Lists.newArrayList(conditions.values())); } }
RouteRuleDao { public List<RouteRuleModel> select(RouteRuleModel filter) { ValueCheckers.notNull(filter, "filter"); Map<String, String> conditions = Maps.newHashMap(); conditions.put("id=?", filter.getId() == null ? null : Long.toString(filter.getId())); conditions.put("service_id=?", filter.getServiceId()); conditions.put("name=?", filter.getName()); conditions.put("status=?", filter.getStatus()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); return query(Joiner.on(" and ").join(conditions.keySet()), Lists.newArrayList(conditions.values())); }  }
RouteRuleDao { public List<RouteRuleModel> select(RouteRuleModel filter) { ValueCheckers.notNull(filter, "filter"); Map<String, String> conditions = Maps.newHashMap(); conditions.put("id=?", filter.getId() == null ? null : Long.toString(filter.getId())); conditions.put("service_id=?", filter.getServiceId()); conditions.put("name=?", filter.getName()); conditions.put("status=?", filter.getStatus()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); return query(Joiner.on(" and ").join(conditions.keySet()), Lists.newArrayList(conditions.values())); }  List<RouteRuleModel> query(); List<RouteRuleModel> select(RouteRuleModel filter); List<RouteRuleModel> select(List<Long> groupIds); }
RouteRuleDao { public List<RouteRuleModel> select(RouteRuleModel filter) { ValueCheckers.notNull(filter, "filter"); Map<String, String> conditions = Maps.newHashMap(); conditions.put("id=?", filter.getId() == null ? null : Long.toString(filter.getId())); conditions.put("service_id=?", filter.getServiceId()); conditions.put("name=?", filter.getName()); conditions.put("status=?", filter.getStatus()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); return query(Joiner.on(" and ").join(conditions.keySet()), Lists.newArrayList(conditions.values())); }  List<RouteRuleModel> query(); List<RouteRuleModel> select(RouteRuleModel filter); List<RouteRuleModel> select(List<Long> groupIds); static final RouteRuleDao INSTANCE; }