Search in sources :

Example 6 with JdbcPagingItemReader

use of org.springframework.batch.item.database.JdbcPagingItemReader 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;
}
Also used : SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HashMap(java.util.HashMap) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) Timestamp(java.sql.Timestamp) Date(java.util.Date) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with JdbcPagingItemReader

use of org.springframework.batch.item.database.JdbcPagingItemReader 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;
}
Also used : LongValueRowMapper(cz.mzk.recordmanager.server.jdbc.LongValueRowMapper) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HashMap(java.util.HashMap) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) Date(java.util.Date) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 8 with JdbcPagingItemReader

use of org.springframework.batch.item.database.JdbcPagingItemReader 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;
}
Also used : HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HashMap(java.util.HashMap) HarvestedRecordIdRowMapper(cz.mzk.recordmanager.server.export.HarvestedRecordIdRowMapper) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 9 with JdbcPagingItemReader

use of org.springframework.batch.item.database.JdbcPagingItemReader 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;
}
Also used : HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HashMap(java.util.HashMap) HarvestedRecordIdRowMapper(cz.mzk.recordmanager.server.export.HarvestedRecordIdRowMapper) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 10 with JdbcPagingItemReader

use of org.springframework.batch.item.database.JdbcPagingItemReader 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;
}
Also used : SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) HashMap(java.util.HashMap) Cosmotron996RowMapper(cz.mzk.recordmanager.server.jdbc.Cosmotron996RowMapper) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

JdbcPagingItemReader (org.springframework.batch.item.database.JdbcPagingItemReader)18 SqlPagingQueryProviderFactoryBean (org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean)18 StepScope (org.springframework.batch.core.configuration.annotation.StepScope)17 Bean (org.springframework.context.annotation.Bean)17 HashMap (java.util.HashMap)14 HarvestedRecordUniqueId (cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId)7 HarvestedRecordIdRowMapper (cz.mzk.recordmanager.server.export.HarvestedRecordIdRowMapper)5 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)4 Date (java.util.Date)4 LongValueRowMapper (cz.mzk.recordmanager.server.jdbc.LongValueRowMapper)3 Timestamp (java.sql.Timestamp)2 Cosmotron996RowMapper (cz.mzk.recordmanager.server.jdbc.Cosmotron996RowMapper)1 DedupRecordRowMapper (cz.mzk.recordmanager.server.jdbc.DedupRecordRowMapper)1 Cosmotron996 (cz.mzk.recordmanager.server.model.Cosmotron996)1 DedupRecord (cz.mzk.recordmanager.server.model.DedupRecord)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1