@Test public void testInsertUpdate() throws Exception { FileState fileState1 = new FileState("/file1", FileState.FileType.COMPACT, FileState.FileStage.PROCESSING); FileState fileState2 = new FileState("/file2", FileState.FileType.COMPRESSION, FileState.FileStage.DONE); fileStateDao.insertUpdate(fileState1); fileStateDao.insertUpdate(fileState2); List<FileState> fileStates = fileStateDao.getAll(); Assert.assertEquals(2, fileStates.size()); Assert.assertEquals(fileState1, fileStateDao.getByPath("/file1")); Assert.assertEquals(fileState2, fileStateDao.getByPath("/file2")); fileState1 = new FileState("/file1", FileState.FileType.COMPACT, FileState.FileStage.DONE); fileStateDao.insertUpdate(fileState1); fileStates = fileStateDao.getAll(); Assert.assertEquals(2, fileStates.size()); Assert.assertEquals(fileState1, fileStateDao.getByPath("/file1")); Assert.assertEquals(fileState2, fileStateDao.getByPath("/file2")); }
public void insertUpdate(FileState fileState) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "REPLACE INTO " + TABLE_NAME + " (path, type, stage) VALUES (?,?,?)"; jdbcTemplate.update(sql, fileState.getPath(), fileState.getFileType().getValue(), fileState.getFileStage().getValue()); }
FileStateDao { public void insertUpdate(FileState fileState) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "REPLACE INTO " + TABLE_NAME + " (path, type, stage) VALUES (?,?,?)"; jdbcTemplate.update(sql, fileState.getPath(), fileState.getFileType().getValue(), fileState.getFileStage().getValue()); } }
FileStateDao { public void insertUpdate(FileState fileState) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "REPLACE INTO " + TABLE_NAME + " (path, type, stage) VALUES (?,?,?)"; jdbcTemplate.update(sql, fileState.getPath(), fileState.getFileType().getValue(), fileState.getFileStage().getValue()); } FileStateDao(DataSource dataSource); }
FileStateDao { public void insertUpdate(FileState fileState) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "REPLACE INTO " + TABLE_NAME + " (path, type, stage) VALUES (?,?,?)"; jdbcTemplate.update(sql, fileState.getPath(), fileState.getFileType().getValue(), fileState.getFileStage().getValue()); } FileStateDao(DataSource dataSource); void setDataSource(DataSource dataSource); void insertUpdate(FileState fileState); int[] batchInsertUpdate(final FileState[] fileStates); FileState getByPath(String path); Map<String, FileState> getByPaths(List<String> paths); List<FileState> getAll(); void deleteByPath(String path, boolean recursive); int[] batchDelete(final List<String> paths); void deleteAll(); }
FileStateDao { public void insertUpdate(FileState fileState) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "REPLACE INTO " + TABLE_NAME + " (path, type, stage) VALUES (?,?,?)"; jdbcTemplate.update(sql, fileState.getPath(), fileState.getFileType().getValue(), fileState.getFileStage().getValue()); } FileStateDao(DataSource dataSource); void setDataSource(DataSource dataSource); void insertUpdate(FileState fileState); int[] batchInsertUpdate(final FileState[] fileStates); FileState getByPath(String path); Map<String, FileState> getByPaths(List<String> paths); List<FileState> getAll(); void deleteByPath(String path, boolean recursive); int[] batchDelete(final List<String> paths); void deleteAll();  }