@Test public void testSelect() { ZoneOperationModel zone = newZoneOperation(); zoneOperationDao.insertOrUpdate(zone); ZoneOperationModel filter = new ZoneOperationModel(); filter.setServiceId(zone.getServiceId()); filter.setZoneId(zone.getZoneId()); assertZoneOperation(zone, zoneOperationDao.select(filter).get(0)); }
public List<ZoneOperationModel> select(ZoneOperationModel 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("region_id=?", filter.getRegionId()); conditions.put("zone_id=?", filter.getZoneId()); conditions.put("operation=?", filter.getOperation()); 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())); }
ZoneOperationDao { public List<ZoneOperationModel> select(ZoneOperationModel 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("region_id=?", filter.getRegionId()); conditions.put("zone_id=?", filter.getZoneId()); conditions.put("operation=?", filter.getOperation()); 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())); } }
ZoneOperationDao { public List<ZoneOperationModel> select(ZoneOperationModel 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("region_id=?", filter.getRegionId()); conditions.put("zone_id=?", filter.getZoneId()); conditions.put("operation=?", filter.getOperation()); 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())); } private  ZoneOperationDao(); }
ZoneOperationDao { public List<ZoneOperationModel> select(ZoneOperationModel 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("region_id=?", filter.getRegionId()); conditions.put("zone_id=?", filter.getZoneId()); conditions.put("operation=?", filter.getOperation()); 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())); } private  ZoneOperationDao(); List<ZoneOperationModel> query(); void delete(final ZoneOperationModel... zoneOperations); void delete(final List<ZoneOperationModel> zoneOperations); void insertOrUpdate(ZoneOperationModel... operationModels); void insertOrUpdate(final List<ZoneOperationModel> models); List<ZoneOperationModel> select(ZoneOperationModel filter); }
ZoneOperationDao { public List<ZoneOperationModel> select(ZoneOperationModel 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("region_id=?", filter.getRegionId()); conditions.put("zone_id=?", filter.getZoneId()); conditions.put("operation=?", filter.getOperation()); 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())); } private  ZoneOperationDao(); List<ZoneOperationModel> query(); void delete(final ZoneOperationModel... zoneOperations); void delete(final List<ZoneOperationModel> zoneOperations); void insertOrUpdate(ZoneOperationModel... operationModels); void insertOrUpdate(final List<ZoneOperationModel> models); List<ZoneOperationModel> select(ZoneOperationModel filter); static final ZoneOperationDao INSTANCE; }