@Test public void testInsertUpdate() throws Exception { CompressionFileState compressionInfo = new CompressionFileState( "/test", 131072, compressionImpl, originalPos.toArray(new Long[0]), compressedPos.toArray(new Long[0])); compressionFileDao.insertUpdate(compressionInfo); Assert.assertTrue(compressionFileDao.getInfoByPath("/test"). getOriginalPos()[0].equals(9000L)); compressionInfo.setOriginalLength(1000); compressionInfo.setCompressedLength(100); compressionFileDao.insertUpdate(compressionInfo); CompressionFileState newCompressionInfo = compressionFileDao.getInfoByPath("/test"); Assert.assertEquals(compressionInfo.getOriginalLength(), newCompressionInfo.getOriginalLength()); Assert.assertEquals(compressionInfo.getCompressedLength(), newCompressionInfo.getCompressedLength()); }
public void insertUpdate(CompressionFileState compressionInfo) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); Gson gson = new Gson(); String sql = "REPLACE INTO " + TABLE_NAME + "(path, buffer_size, compression_impl, " + "original_length, compressed_length, originalPos, compressedPos)" + " VALUES(?,?,?,?,?,?,?);"; jdbcTemplate.update(sql, compressionInfo.getPath(), compressionInfo.getBufferSize(), compressionInfo.getCompressionImpl(), compressionInfo.getOriginalLength(), compressionInfo.getCompressedLength(), gson.toJson(compressionInfo.getOriginalPos()), gson.toJson(compressionInfo.getCompressedPos())); }
CompressionFileDao { public void insertUpdate(CompressionFileState compressionInfo) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); Gson gson = new Gson(); String sql = "REPLACE INTO " + TABLE_NAME + "(path, buffer_size, compression_impl, " + "original_length, compressed_length, originalPos, compressedPos)" + " VALUES(?,?,?,?,?,?,?);"; jdbcTemplate.update(sql, compressionInfo.getPath(), compressionInfo.getBufferSize(), compressionInfo.getCompressionImpl(), compressionInfo.getOriginalLength(), compressionInfo.getCompressedLength(), gson.toJson(compressionInfo.getOriginalPos()), gson.toJson(compressionInfo.getCompressedPos())); } }
CompressionFileDao { public void insertUpdate(CompressionFileState compressionInfo) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); Gson gson = new Gson(); String sql = "REPLACE INTO " + TABLE_NAME + "(path, buffer_size, compression_impl, " + "original_length, compressed_length, originalPos, compressedPos)" + " VALUES(?,?,?,?,?,?,?);"; jdbcTemplate.update(sql, compressionInfo.getPath(), compressionInfo.getBufferSize(), compressionInfo.getCompressionImpl(), compressionInfo.getOriginalLength(), compressionInfo.getCompressedLength(), gson.toJson(compressionInfo.getOriginalPos()), gson.toJson(compressionInfo.getCompressedPos())); } CompressionFileDao(DataSource dataSource); }
CompressionFileDao { public void insertUpdate(CompressionFileState compressionInfo) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); Gson gson = new Gson(); String sql = "REPLACE INTO " + TABLE_NAME + "(path, buffer_size, compression_impl, " + "original_length, compressed_length, originalPos, compressedPos)" + " VALUES(?,?,?,?,?,?,?);"; jdbcTemplate.update(sql, compressionInfo.getPath(), compressionInfo.getBufferSize(), compressionInfo.getCompressionImpl(), compressionInfo.getOriginalLength(), compressionInfo.getCompressedLength(), gson.toJson(compressionInfo.getOriginalPos()), gson.toJson(compressionInfo.getCompressedPos())); } CompressionFileDao(DataSource dataSource); void setDataSource(DataSource dataSource); void insert(CompressionFileState compressionInfo); void insertUpdate(CompressionFileState compressionInfo); void deleteByPath(String filePath); void deleteAll(); List<CompressionFileState> getAll(); CompressionFileState getInfoByPath(String filePath); }
CompressionFileDao { public void insertUpdate(CompressionFileState compressionInfo) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); Gson gson = new Gson(); String sql = "REPLACE INTO " + TABLE_NAME + "(path, buffer_size, compression_impl, " + "original_length, compressed_length, originalPos, compressedPos)" + " VALUES(?,?,?,?,?,?,?);"; jdbcTemplate.update(sql, compressionInfo.getPath(), compressionInfo.getBufferSize(), compressionInfo.getCompressionImpl(), compressionInfo.getOriginalLength(), compressionInfo.getCompressedLength(), gson.toJson(compressionInfo.getOriginalPos()), gson.toJson(compressionInfo.getCompressedPos())); } CompressionFileDao(DataSource dataSource); void setDataSource(DataSource dataSource); void insert(CompressionFileState compressionInfo); void insertUpdate(CompressionFileState compressionInfo); void deleteByPath(String filePath); void deleteAll(); List<CompressionFileState> getAll(); CompressionFileState getInfoByPath(String filePath);  }