@Test public void testGetByCondition() throws Exception { CmdletInfo command1 = new CmdletInfo(0, 1, CmdletState.EXECUTING, "test", 123123333L, 232444444L); CmdletInfo command2 = new CmdletInfo(1, 78, CmdletState.PAUSED, "tt", 123178333L, 232444994L); cmdletDao.insert(new CmdletInfo[]{command1, command2}); List<CmdletInfo> commandInfos = cmdletDao .getByCondition(null, null, null); Assert.assertTrue(commandInfos.size() == 2); commandInfos = cmdletDao .getByCondition(null, null, CmdletState.PAUSED); Assert.assertTrue(commandInfos.size() == 1); }
public List<CmdletInfo> getByCondition( String cidCondition, String ridCondition, CmdletState state) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sqlPrefix = "SELECT * FROM " + TABLE_NAME + " WHERE "; String sqlCid = (cidCondition == null) ? "" : "AND cid " + cidCondition; String sqlRid = (ridCondition == null) ? "" : "AND rid " + ridCondition; String sqlState = (state == null) ? "" : "AND state = " + state.getValue(); String sqlFinal = ""; if (cidCondition != null || ridCondition != null || state != null) { sqlFinal = sqlPrefix + sqlCid + sqlRid + sqlState; sqlFinal = sqlFinal.replaceFirst("AND ", ""); } else { sqlFinal = sqlPrefix.replaceFirst("WHERE ", ""); } return jdbcTemplate.query(sqlFinal, new CmdletRowMapper()); }
CmdletDao { public List<CmdletInfo> getByCondition( String cidCondition, String ridCondition, CmdletState state) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sqlPrefix = "SELECT * FROM " + TABLE_NAME + " WHERE "; String sqlCid = (cidCondition == null) ? "" : "AND cid " + cidCondition; String sqlRid = (ridCondition == null) ? "" : "AND rid " + ridCondition; String sqlState = (state == null) ? "" : "AND state = " + state.getValue(); String sqlFinal = ""; if (cidCondition != null || ridCondition != null || state != null) { sqlFinal = sqlPrefix + sqlCid + sqlRid + sqlState; sqlFinal = sqlFinal.replaceFirst("AND ", ""); } else { sqlFinal = sqlPrefix.replaceFirst("WHERE ", ""); } return jdbcTemplate.query(sqlFinal, new CmdletRowMapper()); } }
CmdletDao { public List<CmdletInfo> getByCondition( String cidCondition, String ridCondition, CmdletState state) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sqlPrefix = "SELECT * FROM " + TABLE_NAME + " WHERE "; String sqlCid = (cidCondition == null) ? "" : "AND cid " + cidCondition; String sqlRid = (ridCondition == null) ? "" : "AND rid " + ridCondition; String sqlState = (state == null) ? "" : "AND state = " + state.getValue(); String sqlFinal = ""; if (cidCondition != null || ridCondition != null || state != null) { sqlFinal = sqlPrefix + sqlCid + sqlRid + sqlState; sqlFinal = sqlFinal.replaceFirst("AND ", ""); } else { sqlFinal = sqlPrefix.replaceFirst("WHERE ", ""); } return jdbcTemplate.query(sqlFinal, new CmdletRowMapper()); } CmdletDao(DataSource dataSource); }
CmdletDao { public List<CmdletInfo> getByCondition( String cidCondition, String ridCondition, CmdletState state) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sqlPrefix = "SELECT * FROM " + TABLE_NAME + " WHERE "; String sqlCid = (cidCondition == null) ? "" : "AND cid " + cidCondition; String sqlRid = (ridCondition == null) ? "" : "AND rid " + ridCondition; String sqlState = (state == null) ? "" : "AND state = " + state.getValue(); String sqlFinal = ""; if (cidCondition != null || ridCondition != null || state != null) { sqlFinal = sqlPrefix + sqlCid + sqlRid + sqlState; sqlFinal = sqlFinal.replaceFirst("AND ", ""); } else { sqlFinal = sqlPrefix.replaceFirst("WHERE ", ""); } return jdbcTemplate.query(sqlFinal, new CmdletRowMapper()); } CmdletDao(DataSource dataSource); void setDataSource(DataSource dataSource); List<CmdletInfo> getAll(); List<CmdletInfo> getAPageOfCmdlet(long start, long offset,
      List<String> orderBy, List<Boolean> isDesc); List<CmdletInfo> getAPageOfCmdlet(long start, long offset); List<CmdletInfo> getByIds(List<Long> aids); CmdletInfo getById(long cid); List<CmdletInfo> getByRid(long rid); long getNumByRid(long rid); List<CmdletInfo> getByRid(long rid, long start, long offset); List<CmdletInfo> getByRid(long rid, long start, long offset,
      List<String> orderBy, List<Boolean> isDesc); List<CmdletInfo> getByState(CmdletState state); int getNumCmdletsInTerminiatedStates(); List<CmdletInfo> getByCondition(
      String cidCondition, String ridCondition, CmdletState state); void delete(long cid); int[] batchDelete(final List<Long> cids); int deleteBeforeTime(long timestamp); int deleteKeepNewCmd(long num); void deleteAll(); void insert(CmdletInfo cmdletInfo); void insert(CmdletInfo[] cmdletInfos); int[] replace(final CmdletInfo[] cmdletInfos); int update(long cid, int state); int update(long cid, String parameters, int state); int update(final CmdletInfo cmdletInfo); int[] update(final List<CmdletInfo> cmdletInfos); long getMaxId(); }
CmdletDao { public List<CmdletInfo> getByCondition( String cidCondition, String ridCondition, CmdletState state) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sqlPrefix = "SELECT * FROM " + TABLE_NAME + " WHERE "; String sqlCid = (cidCondition == null) ? "" : "AND cid " + cidCondition; String sqlRid = (ridCondition == null) ? "" : "AND rid " + ridCondition; String sqlState = (state == null) ? "" : "AND state = " + state.getValue(); String sqlFinal = ""; if (cidCondition != null || ridCondition != null || state != null) { sqlFinal = sqlPrefix + sqlCid + sqlRid + sqlState; sqlFinal = sqlFinal.replaceFirst("AND ", ""); } else { sqlFinal = sqlPrefix.replaceFirst("WHERE ", ""); } return jdbcTemplate.query(sqlFinal, new CmdletRowMapper()); } CmdletDao(DataSource dataSource); void setDataSource(DataSource dataSource); List<CmdletInfo> getAll(); List<CmdletInfo> getAPageOfCmdlet(long start, long offset,
      List<String> orderBy, List<Boolean> isDesc); List<CmdletInfo> getAPageOfCmdlet(long start, long offset); List<CmdletInfo> getByIds(List<Long> aids); CmdletInfo getById(long cid); List<CmdletInfo> getByRid(long rid); long getNumByRid(long rid); List<CmdletInfo> getByRid(long rid, long start, long offset); List<CmdletInfo> getByRid(long rid, long start, long offset,
      List<String> orderBy, List<Boolean> isDesc); List<CmdletInfo> getByState(CmdletState state); int getNumCmdletsInTerminiatedStates(); List<CmdletInfo> getByCondition(
      String cidCondition, String ridCondition, CmdletState state); void delete(long cid); int[] batchDelete(final List<Long> cids); int deleteBeforeTime(long timestamp); int deleteKeepNewCmd(long num); void deleteAll(); void insert(CmdletInfo cmdletInfo); void insert(CmdletInfo[] cmdletInfos); int[] replace(final CmdletInfo[] cmdletInfos); int update(long cid, int state); int update(long cid, String parameters, int state); int update(final CmdletInfo cmdletInfo); int[] update(final List<CmdletInfo> cmdletInfos); long getMaxId();  }