use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.
the class KrameriusFulltextJobConfig method missingReader.
@Bean(name = Constants.JOB_ID_MISSING_FULLTEXT_KRAMERIUS + ":reader")
@StepScope
public ItemReader<HarvestedRecord> missingReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId, @Value("#{jobParameters[" + Constants.JOB_PARAM_FULLTEXT_FIRST + "]}") String firstId, @Value("#{jobParameters[" + Constants.JOB_PARAM_FULLTEXT_LAST + "]}") String lastId, @Value("#{stepExecutionContext[" + Constants.JOB_PARAM_FROM_DATE + "] " + "?:jobParameters[ " + Constants.JOB_PARAM_FROM_DATE + "]}") Date from, @Value("#{stepExecutionContext[" + Constants.JOB_PARAM_UNTIL_DATE + "]" + "?:jobParameters[" + Constants.JOB_PARAM_UNTIL_DATE + "]}") Date to) throws Exception {
JdbcPagingItemReader<HarvestedRecord> reader = new JdbcPagingItemReader<HarvestedRecord>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT *");
pqpf.setFromClause("FROM harvested_record hr");
String whereClause = "WHERE hr.import_conf_id = :configId AND NOT EXISTS (" + "SELECT 1 FROM fulltext_kramerius fk WHERE hr.id = fk.harvested_record_id)";
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("configId", configId);
if (from != null) {
whereClause += " AND hr.updated >= :from";
parameterValues.put("from", new Timestamp(from.getTime()));
}
if (to != null) {
Date toStamp = new Timestamp(to.getTime());
whereClause += " AND hr.updated <= :to";
parameterValues.put("to", toStamp);
}
if (firstId != null) {
whereClause += " AND hr.record_id >= :firstId";
parameterValues.put("firstId", firstId);
}
if (lastId != null) {
whereClause += " AND hr.record_id <= :lastId";
parameterValues.put("lastId", lastId);
}
pqpf.setWhereClause(whereClause);
pqpf.setSortKey("record_id");
reader.setParameterValues(parameterValues);
reader.setRowMapper(harvestedRecordRowMapper);
reader.setPageSize(PAGE_SIZE);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.
the class MiscellaneousJobsConfig method generateSkatKeysReader.
@Bean(name = Constants.JOB_ID_GENERATE_SKAT_DEDUP_KEYS + ":generateSkatKeysReader")
@StepScope
public ItemReader<Long> generateSkatKeysReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_FROM_DATE + "]}") Date fromDate, @Value("#{jobParameters[" + Constants.JOB_PARAM_UNTIL_DATE + "]}") Date toDate) throws Exception {
Date from = fromDate == null ? new Date(0) : fromDate;
Date to = toDate == null ? new Date() : toDate;
JdbcPagingItemReader<Long> reader = new JdbcPagingItemReader<>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT id");
pqpf.setFromClause("FROM harvested_record");
pqpf.setWhereClause("WHERE import_conf_id = :conf_id AND updated > :updated_from AND updated < :updated_to");
pqpf.setSortKey("id");
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("conf_id", Constants.IMPORT_CONF_ID_CASLIN);
parameterValues.put("updated_from", from);
parameterValues.put("updated_to", to);
reader.setParameterValues(parameterValues);
reader.setRowMapper(new LongValueRowMapper());
reader.setPageSize(100);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.
the class MiscellaneousJobsConfig method generateItemIdReader.
@Bean(name = Constants.JOB_ID_GENERATE_ITEM_ID + ":generateItemIdReader")
@StepScope
public synchronized ItemReader<HarvestedRecordUniqueId> generateItemIdReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long confId) throws Exception {
JdbcPagingItemReader<HarvestedRecordUniqueId> reader = new JdbcPagingItemReader<HarvestedRecordUniqueId>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT id, import_conf_id, record_id");
pqpf.setFromClause("FROM harvested_record");
String where = "WHERE deleted is null";
if (confId != null) {
where += " AND import_conf_id=:conf_id";
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("conf_id", confId);
reader.setParameterValues(parameterValues);
}
pqpf.setWhereClause(where);
pqpf.setSortKey("id");
reader.setRowMapper(new HarvestedRecordIdRowMapper());
reader.setPageSize(20);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.
the class ZakonyProLidiHarvestJobConfig method zakonyProLidiFulltextReader.
@Bean(name = Constants.JOB_ID_FULLTEXT_ZAKONYPROLIDI + ":reader")
@StepScope
public ItemReader<HarvestedRecordUniqueId> zakonyProLidiFulltextReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId) throws Exception {
JdbcPagingItemReader<HarvestedRecordUniqueId> reader = new JdbcPagingItemReader<HarvestedRecordUniqueId>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT import_conf_id, record_id");
pqpf.setFromClause("FROM harvested_record");
pqpf.setWhereClause("WHERE import_conf_id = :conf_id and deleted is null");
pqpf.setSortKeys(ImmutableMap.of("record_id", Order.DESCENDING));
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("conf_id", configId);
reader.setParameterValues(parameterValues);
reader.setRowMapper(new HarvestedRecordIdRowMapper());
reader.setPageSize(1);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.
the class ExportRecordsJobConfig method exportCosmotron996Reader.
@Bean(name = Constants.JOB_ID_EXPORT_COSMOTRON_996 + ":exportCosmotron996Reader")
@StepScope
public ItemReader<Cosmotron996> exportCosmotron996Reader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId) throws Exception {
JdbcPagingItemReader<Cosmotron996> reader = new JdbcPagingItemReader<Cosmotron996>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT *");
pqpf.setFromClause("FROM cosmotron_996");
pqpf.setWhereClause("WHERE import_conf_id = :conf_id");
pqpf.setSortKey("record_id");
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("conf_id", configId);
reader.setParameterValues(parameterValues);
reader.setRowMapper(new Cosmotron996RowMapper());
reader.setPageSize(20);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
Aggregations