All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.redis.riot.db.DatabaseWriterArgs Maven / Gradle / Ivy

The newest version!
package com.redis.riot.db;

import java.util.Map;

import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder;

import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

public class DatabaseWriterArgs {

	public static final boolean DEFAULT_ASSERT_UPDATES = true;

	@ArgGroup(exclusive = false)
	private DataSourceArgs dataSourceArgs = new DataSourceArgs();

	@Parameters(arity = "1", description = "SQL INSERT statement.", paramLabel = "SQL")
	private String sql;

	@Option(names = "--assert-updates", description = "Confirm every insert results in update of at least one row. True by default.", negatable = true, defaultValue = "true", fallbackValue = "true")
	private boolean assertUpdates = DEFAULT_ASSERT_UPDATES;

	public JdbcBatchItemWriter> writer() {
		JdbcBatchItemWriterBuilder> builder = new JdbcBatchItemWriterBuilder<>();
		builder.itemSqlParameterSourceProvider(NullableSqlParameterSource::new);
		builder.dataSource(dataSourceArgs.dataSource());
		builder.sql(sql);
		builder.assertUpdates(assertUpdates);
		JdbcBatchItemWriter> writer = builder.build();
		writer.afterPropertiesSet();
		return writer;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public boolean isAssertUpdates() {
		return assertUpdates;
	}

	public void setAssertUpdates(boolean assertUpdates) {
		this.assertUpdates = assertUpdates;
	}

	public DataSourceArgs getDataSourceArgs() {
		return dataSourceArgs;
	}

	public void setDataSourceArgs(DataSourceArgs dataSourceArgs) {
		this.dataSourceArgs = dataSourceArgs;
	}

	@Override
	public String toString() {
		return "DatabaseWriterArgs [dataSourceArgs=" + dataSourceArgs + ", sql=" + sql + ", assertUpdates="
				+ assertUpdates + "]";
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy