@Test public void testDelete() throws Exception { GroupTagModel groupTag = newGroupTag(); groupTagDao.insertOrUpdate(groupTag); assertGroupOperation(groupTag, query(groupTag)); groupTagDao.delete(groupTag); Assert.assertNull(query(groupTag)); }
public void delete(GroupTagModel filter) { ValueCheckers.notNull(filter, "filter"); final Map<String, String> conditions = Maps.newHashMap(); conditions.put("group_id=?", filter.getGroupId() == null ? null : Long.toString(filter.getGroupId())); conditions.put("tag=?", filter.getTag()); conditions.put("value=?", filter.getValue()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); if (conditions.size() == 0) { throw new IllegalStateException("forbidden operation."); } String sql = "delete from service_group_tag where " + Joiner.on(" and ").join(conditions.keySet()); DataConfig.jdbcTemplate().update(sql, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { List<String> args = Lists.newArrayList(conditions.values()); for (int i = 0; i < args.size(); i++) { ps.setString(i + 1, args.get(i)); } } }); }
GroupTagDao { public void delete(GroupTagModel filter) { ValueCheckers.notNull(filter, "filter"); final Map<String, String> conditions = Maps.newHashMap(); conditions.put("group_id=?", filter.getGroupId() == null ? null : Long.toString(filter.getGroupId())); conditions.put("tag=?", filter.getTag()); conditions.put("value=?", filter.getValue()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); if (conditions.size() == 0) { throw new IllegalStateException("forbidden operation."); } String sql = "delete from service_group_tag where " + Joiner.on(" and ").join(conditions.keySet()); DataConfig.jdbcTemplate().update(sql, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { List<String> args = Lists.newArrayList(conditions.values()); for (int i = 0; i < args.size(); i++) { ps.setString(i + 1, args.get(i)); } } }); } }
GroupTagDao { public void delete(GroupTagModel filter) { ValueCheckers.notNull(filter, "filter"); final Map<String, String> conditions = Maps.newHashMap(); conditions.put("group_id=?", filter.getGroupId() == null ? null : Long.toString(filter.getGroupId())); conditions.put("tag=?", filter.getTag()); conditions.put("value=?", filter.getValue()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); if (conditions.size() == 0) { throw new IllegalStateException("forbidden operation."); } String sql = "delete from service_group_tag where " + Joiner.on(" and ").join(conditions.keySet()); DataConfig.jdbcTemplate().update(sql, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { List<String> args = Lists.newArrayList(conditions.values()); for (int i = 0; i < args.size(); i++) { ps.setString(i + 1, args.get(i)); } } }); } private  GroupTagDao(); }
GroupTagDao { public void delete(GroupTagModel filter) { ValueCheckers.notNull(filter, "filter"); final Map<String, String> conditions = Maps.newHashMap(); conditions.put("group_id=?", filter.getGroupId() == null ? null : Long.toString(filter.getGroupId())); conditions.put("tag=?", filter.getTag()); conditions.put("value=?", filter.getValue()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); if (conditions.size() == 0) { throw new IllegalStateException("forbidden operation."); } String sql = "delete from service_group_tag where " + Joiner.on(" and ").join(conditions.keySet()); DataConfig.jdbcTemplate().update(sql, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { List<String> args = Lists.newArrayList(conditions.values()); for (int i = 0; i < args.size(); i++) { ps.setString(i + 1, args.get(i)); } } }); } private  GroupTagDao(); List<GroupTagModel> query(); void delete(GroupTagModel filter); void insertOrUpdate(GroupTagModel... models); void insertOrUpdate(final List<GroupTagModel> models); }
GroupTagDao { public void delete(GroupTagModel filter) { ValueCheckers.notNull(filter, "filter"); final Map<String, String> conditions = Maps.newHashMap(); conditions.put("group_id=?", filter.getGroupId() == null ? null : Long.toString(filter.getGroupId())); conditions.put("tag=?", filter.getTag()); conditions.put("value=?", filter.getValue()); Set<String> removed = Sets.newHashSet(); for (String key : conditions.keySet()) { if (StringValues.isNullOrWhitespace(conditions.get(key))) { removed.add(key); } } conditions.keySet().removeAll(removed); if (conditions.size() == 0) { throw new IllegalStateException("forbidden operation."); } String sql = "delete from service_group_tag where " + Joiner.on(" and ").join(conditions.keySet()); DataConfig.jdbcTemplate().update(sql, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { List<String> args = Lists.newArrayList(conditions.values()); for (int i = 0; i < args.size(); i++) { ps.setString(i + 1, args.get(i)); } } }); } private  GroupTagDao(); List<GroupTagModel> query(); void delete(GroupTagModel filter); void insertOrUpdate(GroupTagModel... models); void insertOrUpdate(final List<GroupTagModel> models); static final GroupTagDao INSTANCE; }