Search in sources :

Example 1 with SqlPagingQueryProviderFactoryBean

use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.

the class CosmotronHarvestJobConfig method upate996Reader.

@Bean(name = Constants.JOB_ID_HARVEST_COSMOTRON + ":update996reader")
@StepScope
public ItemReader<HarvestedRecordUniqueId> upate996Reader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId, @Value("#{stepExecutionContext[" + Constants.JOB_PARAM_FROM_DATE + "] " + "?:jobParameters[ " + Constants.JOB_PARAM_FROM_DATE + "]}") Date from) throws Exception {
    SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
    JdbcPagingItemReader<HarvestedRecordUniqueId> reader = new JdbcPagingItemReader<>();
    Map<String, Object> parameterValues = new HashMap<>();
    pqpf.setDataSource(dataSource);
    pqpf.setSelectClause("SELECT harvested_record_id, import_conf_id, record_id");
    pqpf.setFromClause("FROM cosmotron_periodicals_last_update");
    String where = "WHERE import_conf_id = :conf_id";
    parameterValues.put("conf_id", configId);
    if (from != null) {
        where += " AND last_update > :from";
        parameterValues.put("from", from);
    }
    pqpf.setWhereClause(where);
    pqpf.setSortKey("harvested_record_id");
    reader.setParameterValues(parameterValues);
    reader.setRowMapper(new HarvestedRecordIdRowMapper());
    reader.setPageSize(PAGE_SIZE);
    reader.setQueryProvider(pqpf.getObject());
    reader.setDataSource(dataSource);
    reader.setSaveState(true);
    reader.afterPropertiesSet();
    return reader;
}
Also used : SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) 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 2 with SqlPagingQueryProviderFactoryBean

use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.

the class ExportRecordsJobConfig method exportRecordsReader.

@Bean(name = "exportRecordsJob:exportRecordsReader")
@StepScope
public ItemReader<HarvestedRecordUniqueId> exportRecordsReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId, @Value("#{jobParameters[" + Constants.JOB_PARAM_DELETED + "]}") Long deleted) 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" + (deleted == null ? " AND deleted IS NULL" : ""));
    pqpf.setSortKey("record_id");
    Map<String, Object> parameterValues = new HashMap<String, Object>();
    parameterValues.put("conf_id", configId);
    reader.setParameterValues(parameterValues);
    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) 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 3 with SqlPagingQueryProviderFactoryBean

use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.

the class ManuscriptoriumFulltextJobConfig method manuscriptoriumFulltextReader.

@Bean(name = Constants.JOB_ID_FULLTEXT_MANUSCRIPTORIUM + ":reader")
@StepScope
public ItemReader<HarvestedRecordUniqueId> manuscriptoriumFulltextReader(@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.ASCENDING));
    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 4 with SqlPagingQueryProviderFactoryBean

use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.

the class IndexHarvestedRecordsToSolrJobConfig method deletedHarvestedRecordsReader.

@Bean(name = "indexHarvestedRecordsToSolrJob:deletedHarvestedRecordsReader")
@StepScope
public JdbcPagingItemReader<HarvestedRecord> deletedHarvestedRecordsReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_FROM_DATE + "]}") Date from, @Value("#{jobParameters[" + Constants.JOB_PARAM_UNTIL_DATE + "]}") Date to, @Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long importConfId) throws Exception {
    JdbcPagingItemReader<HarvestedRecord> reader = new JdbcPagingItemReader<HarvestedRecord>();
    SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
    pqpf.setDataSource(dataSource);
    pqpf.setSelectClause("SELECT id, import_conf_id, record_id, updated, deleted, raw_record, format");
    pqpf.setFromClause("FROM harvested_record");
    init(reader, pqpf, from, to, importConfId, true);
    pqpf.setSortKeys(ImmutableMap.of("import_conf_id", Order.ASCENDING, "record_id", Order.ASCENDING));
    reader.setRowMapper(harvestedRecordRowMapper());
    reader.setPageSize(PAGE_SIZE);
    reader.setQueryProvider(pqpf.getObject());
    reader.setDataSource(dataSource);
    reader.setSaveState(true);
    reader.afterPropertiesSet();
    return reader;
}
Also used : SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) 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 5 with SqlPagingQueryProviderFactoryBean

use of org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean in project RecordManager2 by moravianlibrary.

the class IndexHarvestedRecordsToSolrJobConfig method updatedRecordsReader.

@Bean(name = "indexHarvestedRecordsToSolrJob:updatedRecordsReader")
@StepScope
public JdbcPagingItemReader<HarvestedRecord> updatedRecordsReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_FROM_DATE + "]}") Date from, @Value("#{jobParameters[" + Constants.JOB_PARAM_UNTIL_DATE + "]}") Date to, @Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long importConfId) throws Exception {
    JdbcPagingItemReader<HarvestedRecord> reader = new JdbcPagingItemReader<>();
    SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
    pqpf.setDataSource(dataSource);
    pqpf.setSelectClause("SELECT id, import_conf_id, record_id, updated, deleted, raw_record, format");
    pqpf.setFromClause("FROM harvested_record");
    init(reader, pqpf, from, to, importConfId, false);
    if (from != null && to != null) {
        pqpf.setSortKeys(ImmutableMap.of("updated", Order.ASCENDING, "id", Order.ASCENDING));
    } else {
        pqpf.setSortKeys(ImmutableMap.of("id", Order.ASCENDING));
    }
    reader.setRowMapper(harvestedRecordRowMapper());
    reader.setPageSize(PAGE_SIZE);
    reader.setQueryProvider(pqpf.getObject());
    reader.setDataSource(dataSource);
    reader.setSaveState(true);
    reader.afterPropertiesSet();
    return reader;
}
Also used : SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) 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)

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