Example usage for org.springframework.batch.support DatabaseType ORACLE

List of usage examples for org.springframework.batch.support DatabaseType ORACLE

Introduction

In this page you can find the example usage for org.springframework.batch.support DatabaseType ORACLE.

Prototype

DatabaseType ORACLE

To view the source code for org.springframework.batch.support DatabaseType ORACLE.

Click Source Link

Usage

From source file:org.springframework.batch.core.repository.support.JobRepositoryFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {

    Assert.notNull(dataSource, "DataSource must not be null.");

    if (jdbcOperations == null) {
        jdbcOperations = new JdbcTemplate(dataSource);
    }//from  w ww. j  av  a  2  s . co m

    if (incrementerFactory == null) {
        incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
    }

    if (databaseType == null) {
        databaseType = DatabaseType.fromMetaData(dataSource).name();
        logger.info("No database type set, using meta data indicating: " + databaseType);
    }

    if (lobHandler == null && databaseType.equalsIgnoreCase(DatabaseType.ORACLE.toString())) {
        lobHandler = new DefaultLobHandler();
    }

    if (serializer == null) {
        Jackson2ExecutionContextStringSerializer defaultSerializer = new Jackson2ExecutionContextStringSerializer();

        serializer = defaultSerializer;
    }

    Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType
            + "' is an unsupported database type.  The supported database types are "
            + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes()));

    if (lobType != null) {
        Assert.isTrue(isValidTypes(lobType), "lobType must be a value from the java.sql.Types class");
    }

    super.afterPropertiesSet();
}

From source file:org.springframework.batch.core.test.football.FootballJobSkipIntegrationTests.java

@Test
public void testLaunchJob() throws Exception {
    try {/*w  w w  .j a v a  2  s  . c  o  m*/
        if (databaseType == DatabaseType.POSTGRES || databaseType == DatabaseType.ORACLE) {
            // Extra special test for these platforms (would have failed
            // the job with UNKNOWN status in Batch 2.0):
            jdbcTemplate.update("SET CONSTRAINTS ALL DEFERRED");
        }
    } catch (Exception e) {
        // Ignore (wrong platform)
    }
    JobExecution execution = jobLauncher.run(job,
            new JobParametersBuilder().addLong("skip.limit", 0L).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, execution.getStatus());
    for (StepExecution stepExecution : execution.getStepExecutions()) {
        logger.info("Processed: " + stepExecution);
    }
    // They all skip on the second execution because of a primary key
    // violation
    long retryLimit = 2L;
    execution = jobLauncher.run(job, new JobParametersBuilder().addLong("skip.limit", 100000L)
            .addLong("retry.limit", retryLimit).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, execution.getStatus());
    for (StepExecution stepExecution : execution.getStepExecutions()) {
        logger.info("Processed: " + stepExecution);
        if (stepExecution.getStepName().equals("playerload")) {
            // The effect of the retries is to increase the number of
            // rollbacks
            int commitInterval = stepExecution.getReadCount() / (stepExecution.getCommitCount() - 1);
            // Account for the extra empty commit if the read count is
            // commensurate with the commit interval
            int effectiveCommitCount = stepExecution.getReadCount() % commitInterval == 0
                    ? stepExecution.getCommitCount() - 1
                    : stepExecution.getCommitCount();
            long expectedRollbacks = Math.max(1, retryLimit) * effectiveCommitCount
                    + stepExecution.getReadCount();
            assertEquals(expectedRollbacks, stepExecution.getRollbackCount());
            assertEquals(stepExecution.getReadCount(), stepExecution.getWriteSkipCount());
        }
    }

}