@Test public void testUpdateConfiguration() { final ScopePathBuilderFactory factory = getConfigService().getScopePathBuilderFactory(TestConfiguration.class); final ComplexConfigDTO configuration = createTestConfigDTO(factory.annotatedPath().create()); persister.saveConfiguration(configuration); final ConfigSimpleValueDTO simpleValueProperty = configuration.getSimpleValueProperty("field2"); simpleValueProperty.setValue("23423"); final long version = configuration.getVersion(); configuration.setVersion(version + 1); configuration.addSimpleValueProperty(simpleValueProperty); persister.updateConfiguration(configuration); final ComplexConfigDTO result = persister.loadConfiguration(factory.annotatedPath().create()); Assert.assertEquals(configuration, result); }
@Override public void updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement updateStmt = null; final Statement stmt = null; ByteArrayOutputStream out = null; try { updateStmt = con.prepareStatement(queryGen.createUpdateQuery( configTableName, configColumnName, scopePathColumnName, configVersionColumnName)); out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); updateStmt.setBinaryStream( 1, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); updateStmt.setString(2, gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + SCOPE_PATH_SEPARATOR + gen.createName(configDTO.getDefiningScopePath())); updateStmt.setLong(3, configDTO.getVersion()); final int countRowsUpdated = updateStmt.executeUpdate(); if (countRowsUpdated < 1) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "' or it has been updated meanwhile!"); } return null; } finally { dbUtils.closeQuietly(stmt); dbUtils.closeQuietly(updateStmt); dbUtils.closeQuietly(out); } } }); }
DbConfigPersister implements ConfigPersister { @Override public void updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement updateStmt = null; final Statement stmt = null; ByteArrayOutputStream out = null; try { updateStmt = con.prepareStatement(queryGen.createUpdateQuery( configTableName, configColumnName, scopePathColumnName, configVersionColumnName)); out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); updateStmt.setBinaryStream( 1, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); updateStmt.setString(2, gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + SCOPE_PATH_SEPARATOR + gen.createName(configDTO.getDefiningScopePath())); updateStmt.setLong(3, configDTO.getVersion()); final int countRowsUpdated = updateStmt.executeUpdate(); if (countRowsUpdated < 1) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "' or it has been updated meanwhile!"); } return null; } finally { dbUtils.closeQuietly(stmt); dbUtils.closeQuietly(updateStmt); dbUtils.closeQuietly(out); } } }); } }
DbConfigPersister implements ConfigPersister { @Override public void updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement updateStmt = null; final Statement stmt = null; ByteArrayOutputStream out = null; try { updateStmt = con.prepareStatement(queryGen.createUpdateQuery( configTableName, configColumnName, scopePathColumnName, configVersionColumnName)); out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); updateStmt.setBinaryStream( 1, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); updateStmt.setString(2, gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + SCOPE_PATH_SEPARATOR + gen.createName(configDTO.getDefiningScopePath())); updateStmt.setLong(3, configDTO.getVersion()); final int countRowsUpdated = updateStmt.executeUpdate(); if (countRowsUpdated < 1) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "' or it has been updated meanwhile!"); } return null; } finally { dbUtils.closeQuietly(stmt); dbUtils.closeQuietly(updateStmt); dbUtils.closeQuietly(out); } } }); } DbConfigPersister(
		final String configTableName,
		final String scopePathColumnName,
		final String configVersionColumnName,
		final String configColumnName,
		final ConfigMarshaller marshaller,
		final DataSource dataSource); }
DbConfigPersister implements ConfigPersister { @Override public void updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement updateStmt = null; final Statement stmt = null; ByteArrayOutputStream out = null; try { updateStmt = con.prepareStatement(queryGen.createUpdateQuery( configTableName, configColumnName, scopePathColumnName, configVersionColumnName)); out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); updateStmt.setBinaryStream( 1, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); updateStmt.setString(2, gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + SCOPE_PATH_SEPARATOR + gen.createName(configDTO.getDefiningScopePath())); updateStmt.setLong(3, configDTO.getVersion()); final int countRowsUpdated = updateStmt.executeUpdate(); if (countRowsUpdated < 1) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "' or it has been updated meanwhile!"); } return null; } finally { dbUtils.closeQuietly(stmt); dbUtils.closeQuietly(updateStmt); dbUtils.closeQuietly(out); } } }); } DbConfigPersister(
		final String configTableName,
		final String scopePathColumnName,
		final String configVersionColumnName,
		final String configColumnName,
		final ConfigMarshaller marshaller,
		final DataSource dataSource); @Override String getId(); @Override ComplexConfigDTO loadConfiguration(final ScopePath scopePath); @Override void saveConfiguration(final ComplexConfigDTO configDTO); @Override void updateConfiguration(final ComplexConfigDTO configDTO); @Override void delete(final ScopePath scope, final boolean deleteChildren); @Override void deleteAllOccurences(final String scopeName, final Map<String, String> properties); @Override Collection<ScopePath> listScopes(final String scopeName, final Map<String, String> properties); }
DbConfigPersister implements ConfigPersister { @Override public void updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement updateStmt = null; final Statement stmt = null; ByteArrayOutputStream out = null; try { updateStmt = con.prepareStatement(queryGen.createUpdateQuery( configTableName, configColumnName, scopePathColumnName, configVersionColumnName)); out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); updateStmt.setBinaryStream( 1, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); updateStmt.setString(2, gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + SCOPE_PATH_SEPARATOR + gen.createName(configDTO.getDefiningScopePath())); updateStmt.setLong(3, configDTO.getVersion()); final int countRowsUpdated = updateStmt.executeUpdate(); if (countRowsUpdated < 1) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "' or it has been updated meanwhile!"); } return null; } finally { dbUtils.closeQuietly(stmt); dbUtils.closeQuietly(updateStmt); dbUtils.closeQuietly(out); } } }); } DbConfigPersister(
		final String configTableName,
		final String scopePathColumnName,
		final String configVersionColumnName,
		final String configColumnName,
		final ConfigMarshaller marshaller,
		final DataSource dataSource); @Override String getId(); @Override ComplexConfigDTO loadConfiguration(final ScopePath scopePath); @Override void saveConfiguration(final ComplexConfigDTO configDTO); @Override void updateConfiguration(final ComplexConfigDTO configDTO); @Override void delete(final ScopePath scope, final boolean deleteChildren); @Override void deleteAllOccurences(final String scopeName, final Map<String, String> properties); @Override Collection<ScopePath> listScopes(final String scopeName, final Map<String, String> properties); static final String ID; }