@Test public void testSaveConfiguration() { final ScopePathBuilderFactory factory = getConfigService().getScopePathBuilderFactory(TestConfiguration.class); final ComplexConfigDTO configuration = createTestConfigDTO(factory.annotatedPath().create()); persister.saveConfiguration(configuration); }
@Override public void saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement existsStmt = null; PreparedStatement saveStmt = null; ByteArrayOutputStream out = null; try { existsStmt = con.prepareStatement(queryGen.createSelectEqualsItemQuery( configColumnName, configTableName, scopePathColumnName)); existsStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); existsStmt.executeQuery(); final ResultSet resultSet = existsStmt.getResultSet(); if (resultSet.next()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); saveStmt = con.prepareStatement(queryGen.createInsertItemQuery( configTableName, scopePathColumnName, configVersionColumnName, configColumnName)); saveStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); saveStmt.setLong(2, configDTO.getVersion()); saveStmt.setBinaryStream( 3, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); saveStmt.executeUpdate(); return null; } finally { dbUtils.closeQuietly(out); dbUtils.closeQuietly(existsStmt); dbUtils.closeQuietly(saveStmt); } } }); }
DbConfigPersister implements ConfigPersister { @Override public void saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement existsStmt = null; PreparedStatement saveStmt = null; ByteArrayOutputStream out = null; try { existsStmt = con.prepareStatement(queryGen.createSelectEqualsItemQuery( configColumnName, configTableName, scopePathColumnName)); existsStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); existsStmt.executeQuery(); final ResultSet resultSet = existsStmt.getResultSet(); if (resultSet.next()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); saveStmt = con.prepareStatement(queryGen.createInsertItemQuery( configTableName, scopePathColumnName, configVersionColumnName, configColumnName)); saveStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); saveStmt.setLong(2, configDTO.getVersion()); saveStmt.setBinaryStream( 3, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); saveStmt.executeUpdate(); return null; } finally { dbUtils.closeQuietly(out); dbUtils.closeQuietly(existsStmt); dbUtils.closeQuietly(saveStmt); } } }); } }
DbConfigPersister implements ConfigPersister { @Override public void saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement existsStmt = null; PreparedStatement saveStmt = null; ByteArrayOutputStream out = null; try { existsStmt = con.prepareStatement(queryGen.createSelectEqualsItemQuery( configColumnName, configTableName, scopePathColumnName)); existsStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); existsStmt.executeQuery(); final ResultSet resultSet = existsStmt.getResultSet(); if (resultSet.next()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); saveStmt = con.prepareStatement(queryGen.createInsertItemQuery( configTableName, scopePathColumnName, configVersionColumnName, configColumnName)); saveStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); saveStmt.setLong(2, configDTO.getVersion()); saveStmt.setBinaryStream( 3, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); saveStmt.executeUpdate(); return null; } finally { dbUtils.closeQuietly(out); dbUtils.closeQuietly(existsStmt); dbUtils.closeQuietly(saveStmt); } } }); } 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 saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement existsStmt = null; PreparedStatement saveStmt = null; ByteArrayOutputStream out = null; try { existsStmt = con.prepareStatement(queryGen.createSelectEqualsItemQuery( configColumnName, configTableName, scopePathColumnName)); existsStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); existsStmt.executeQuery(); final ResultSet resultSet = existsStmt.getResultSet(); if (resultSet.next()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); saveStmt = con.prepareStatement(queryGen.createInsertItemQuery( configTableName, scopePathColumnName, configVersionColumnName, configColumnName)); saveStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); saveStmt.setLong(2, configDTO.getVersion()); saveStmt.setBinaryStream( 3, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); saveStmt.executeUpdate(); return null; } finally { dbUtils.closeQuietly(out); dbUtils.closeQuietly(existsStmt); dbUtils.closeQuietly(saveStmt); } } }); } 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 saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configDTO"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } new JdbcTemplate<ResultSet>(dataSource).perform(new DbCallable() { @Override public Object execute(final Connection con) throws Exception { PreparedStatement existsStmt = null; PreparedStatement saveStmt = null; ByteArrayOutputStream out = null; try { existsStmt = con.prepareStatement(queryGen.createSelectEqualsItemQuery( configColumnName, configTableName, scopePathColumnName)); existsStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); existsStmt.executeQuery(); final ResultSet resultSet = existsStmt.getResultSet(); if (resultSet.next()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } out = new ByteArrayOutputStream(); marshaller.marshal(out, configDTO); final byte[] serializedConfigAsByteArray = out.toByteArray(); saveStmt = con.prepareStatement(queryGen.createInsertItemQuery( configTableName, scopePathColumnName, configVersionColumnName, configColumnName)); saveStmt.setString(1, createColumnPath(configDTO.getDefiningScopePath())); saveStmt.setLong(2, configDTO.getVersion()); saveStmt.setBinaryStream( 3, new ByteArrayInputStream(serializedConfigAsByteArray), serializedConfigAsByteArray.length); saveStmt.executeUpdate(); return null; } finally { dbUtils.closeQuietly(out); dbUtils.closeQuietly(existsStmt); dbUtils.closeQuietly(saveStmt); } } }); } 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; }