@Test public void testDestroyServers() { final ServerModel server1 = ServerModels.newServerModel(); final ServerModel server2 = ServerModels.newServerModel(); serverDao.insert(server1, server2); Assert.assertTrue(query(server1).size() == 1); Assert.assertTrue(query(server2).size() == 1); List<ServerKey> serverKeys = Lists.newArrayList(new ServerKey(server1.getRegionId(), server1.getServerId()), new ServerKey(server2.getRegionId(), server2.getServerId())); serverDao.destroyServers(serverKeys); Assert.assertTrue(query(server1).size() == 0); Assert.assertTrue(query(server2).size() == 0); }
public void destroyServers(final List<ServerKey> serverKeys) { if (CollectionUtils.isEmpty(serverKeys)) { return; } DataConfig.jdbcTemplate().batchUpdate("delete from server where region_id=? and server_id=?", new BatchPreparedStatementSetter() { @Override public int getBatchSize() { return serverKeys.size(); } @Override public void setValues(final PreparedStatement ps, final int index) throws SQLException { ServerKey serverKey = serverKeys.get(index); ps.setString(1, serverKey.getRegionId()); ps.setString(2, serverKey.getServerId()); } }); }
ServerDao { public void destroyServers(final List<ServerKey> serverKeys) { if (CollectionUtils.isEmpty(serverKeys)) { return; } DataConfig.jdbcTemplate().batchUpdate("delete from server where region_id=? and server_id=?", new BatchPreparedStatementSetter() { @Override public int getBatchSize() { return serverKeys.size(); } @Override public void setValues(final PreparedStatement ps, final int index) throws SQLException { ServerKey serverKey = serverKeys.get(index); ps.setString(1, serverKey.getRegionId()); ps.setString(2, serverKey.getServerId()); } }); } }
ServerDao { public void destroyServers(final List<ServerKey> serverKeys) { if (CollectionUtils.isEmpty(serverKeys)) { return; } DataConfig.jdbcTemplate().batchUpdate("delete from server where region_id=? and server_id=?", new BatchPreparedStatementSetter() { @Override public int getBatchSize() { return serverKeys.size(); } @Override public void setValues(final PreparedStatement ps, final int index) throws SQLException { ServerKey serverKey = serverKeys.get(index); ps.setString(1, serverKey.getRegionId()); ps.setString(2, serverKey.getServerId()); } }); } private  ServerDao(); }
ServerDao { public void destroyServers(final List<ServerKey> serverKeys) { if (CollectionUtils.isEmpty(serverKeys)) { return; } DataConfig.jdbcTemplate().batchUpdate("delete from server where region_id=? and server_id=?", new BatchPreparedStatementSetter() { @Override public int getBatchSize() { return serverKeys.size(); } @Override public void setValues(final PreparedStatement ps, final int index) throws SQLException { ServerKey serverKey = serverKeys.get(index); ps.setString(1, serverKey.getRegionId()); ps.setString(2, serverKey.getServerId()); } }); } private  ServerDao(); List<ServerModel> queryServer(final String regionId, final String serverId); List<ServerModel> queryServers(final String regionId); List<ServerModel> queryServers(); List<ServerModel> query(final String condition, final String... args); void delete(final Long... ids); void delete(final ServerModel... servers); void delete(final List<ServerModel> serverList); void destroyServers(final List<ServerKey> serverKeys); void insert(final ServerModel... servers); void insert(final List<ServerModel> serverList); }
ServerDao { public void destroyServers(final List<ServerKey> serverKeys) { if (CollectionUtils.isEmpty(serverKeys)) { return; } DataConfig.jdbcTemplate().batchUpdate("delete from server where region_id=? and server_id=?", new BatchPreparedStatementSetter() { @Override public int getBatchSize() { return serverKeys.size(); } @Override public void setValues(final PreparedStatement ps, final int index) throws SQLException { ServerKey serverKey = serverKeys.get(index); ps.setString(1, serverKey.getRegionId()); ps.setString(2, serverKey.getServerId()); } }); } private  ServerDao(); List<ServerModel> queryServer(final String regionId, final String serverId); List<ServerModel> queryServers(final String regionId); List<ServerModel> queryServers(); List<ServerModel> query(final String condition, final String... args); void delete(final Long... ids); void delete(final ServerModel... servers); void delete(final List<ServerModel> serverList); void destroyServers(final List<ServerKey> serverKeys); void insert(final ServerModel... servers); void insert(final List<ServerModel> serverList); static final ServerDao INSTANCE; }