@Override public void afterPropertiesSet() throws Exception { DataFieldMaxValueIncrementerFactory factory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); this.incrementer = factory.getIncrementer(DatabaseType.fromMetaData(dataSource).name(), tablePrefix + "JOB_SEQ"); }
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(dataSource, "DataSource must not be null."); if (jdbcOperations == null) { jdbcOperations = new JdbcTemplate(dataSource); } 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(); }
@Test public void testCreateRepository() throws Exception { String databaseType = "HSQL"; factory.setDatabaseType(databaseType); when(incrementerFactory.isSupportedIncrementerType("HSQL")).thenReturn(true); when(incrementerFactory.getSupportedIncrementerTypes()).thenReturn(new String[0]); when(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); factory.afterPropertiesSet(); factory.getObject(); }
@Test public void testDefaultJdbcOperations() throws Exception { factory.setDatabaseType("ORACLE"); incrementerFactory = mock(DataFieldMaxValueIncrementerFactory.class); when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); factory.setIncrementerFactory(incrementerFactory); factory.afterPropertiesSet(); JdbcOperations jdbcOperations = (JdbcOperations) ReflectionTestUtils.getField(factory, "jdbcOperations"); assertTrue(jdbcOperations instanceof JdbcTemplate); }
@Test public void testOracleLobHandler() throws Exception { factory.setDatabaseType("ORACLE"); incrementerFactory = mock(DataFieldMaxValueIncrementerFactory.class); when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); factory.setIncrementerFactory(incrementerFactory); factory.afterPropertiesSet(); LobHandler lobHandler = (LobHandler) ReflectionTestUtils.getField(factory, "lobHandler"); assertTrue(lobHandler instanceof DefaultLobHandler); }
@Test public void testNoDatabaseType() throws Exception { DatabaseMetaData dmd = mock(DatabaseMetaData.class); Connection con = mock(Connection.class); when(dataSource.getConnection()).thenReturn(con); when(con.getMetaData()).thenReturn(dmd); when(dmd.getDatabaseProductName()).thenReturn("Oracle"); when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true); when(incrementerFactory.getSupportedIncrementerTypes()).thenReturn(new String[0]); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); factory.afterPropertiesSet(); factory.getObject(); }
@Test public void testInvalidDatabaseType() throws Exception { factory.setDatabaseType("foo"); try { when(incrementerFactory.isSupportedIncrementerType("foo")).thenReturn(false); when(incrementerFactory.getSupportedIncrementerTypes()).thenReturn(new String[0]); factory.afterPropertiesSet(); fail(); } catch (IllegalArgumentException ex) { // expected String message = ex.getMessage(); assertTrue("Wrong message: " + message, message.contains("foo")); } }
@Override protected JobInstanceDao createJobInstanceDao() throws Exception { JdbcJobInstanceDao dao = new JdbcJobInstanceDao(); dao.setJdbcTemplate(jdbcOperations); dao.setJobIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ")); dao.setTablePrefix(tablePrefix); dao.afterPropertiesSet(); return dao; }
@Test @SuppressWarnings("unchecked") public void tesDefaultSerializer() throws Exception { factory.setDatabaseType("ORACLE"); incrementerFactory = mock(DataFieldMaxValueIncrementerFactory.class); when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); factory.setIncrementerFactory(incrementerFactory); factory.afterPropertiesSet(); Serializer<Map<String, Object>> serializer = (Serializer<Map<String,Object>>) ReflectionTestUtils.getField(factory, "serializer"); assertTrue(serializer instanceof Jackson2ExecutionContextStringSerializer); }
@Test public void testMissingTransactionManager() throws Exception { factory.setDatabaseType("mockDb"); factory.setTransactionManager(null); try { when(incrementerFactory.isSupportedIncrementerType("mockDb")).thenReturn(true); when(incrementerFactory.getSupportedIncrementerTypes()).thenReturn(new String[0]); factory.afterPropertiesSet(); fail(); } catch (IllegalArgumentException ex) { // expected String message = ex.getMessage(); assertTrue("Wrong message: " + message, message.contains("TransactionManager")); } }
@Override protected JobExecutionDao createJobExecutionDao() throws Exception { JdbcJobExecutionDao dao = new JdbcJobExecutionDao(); dao.setJdbcTemplate(jdbcOperations); dao.setJobExecutionIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ")); dao.setTablePrefix(tablePrefix); dao.setClobTypeToUse(determineClobTypeToUse(this.databaseType)); dao.setExitMessageLength(maxVarCharLength); dao.afterPropertiesSet(); return dao; }
@Test public void testCustomJdbcOperations() throws Exception { factory.setDatabaseType("ORACLE"); incrementerFactory = mock(DataFieldMaxValueIncrementerFactory.class); when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); factory.setIncrementerFactory(incrementerFactory); JdbcOperations customJdbcOperations = mock(JdbcOperations.class); factory.setJdbcOperations(customJdbcOperations); factory.afterPropertiesSet(); assertEquals(customJdbcOperations, ReflectionTestUtils.getField(factory, "jdbcOperations")); }
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(dataSource, "DataSource must not be null."); Assert.notNull(jobRepository, "JobRepository must not be null."); Assert.notNull(jobLocator, "JobLocator must not be null."); Assert.notNull(jobLauncher, "JobLauncher must not be null."); Assert.notNull(jobExplorer, "JobExplorer must not be null."); jdbcTemplate = new JdbcTemplate(dataSource); 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) { lobHandler = new DefaultLobHandler(); } if (serializer == null) { this.serializer = new Jackson2ExecutionContextStringSerializer(); } Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType + "' is an unsupported database type. The supported database types are " + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes())); }
@Override protected StepExecutionDao createStepExecutionDao() throws Exception { JdbcStepExecutionDao dao = new JdbcStepExecutionDao(); dao.setJdbcTemplate(jdbcOperations); dao.setStepExecutionIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ")); dao.setTablePrefix(tablePrefix); dao.setClobTypeToUse(determineClobTypeToUse(this.databaseType)); dao.setExitMessageLength(maxVarCharLength); dao.afterPropertiesSet(); return dao; }
@Test public void testCustomLobHandler() throws Exception { factory.setDatabaseType("ORACLE"); incrementerFactory = mock(DataFieldMaxValueIncrementerFactory.class); when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); factory.setIncrementerFactory(incrementerFactory); LobHandler lobHandler = new DefaultLobHandler(); factory.setLobHandler(lobHandler); factory.afterPropertiesSet(); assertEquals(lobHandler, ReflectionTestUtils.getField(factory, "lobHandler")); }
public void afterPropertiesSet() throws Exception { Assert.notNull(dataSource, "DataSource must not be null."); Assert.notNull(jobRepository, "JobRepository must not be null."); Assert.notNull(jobLocator, "JobLocator must not be null."); Assert.notNull(jobLauncher, "JobLauncher must not be null."); Assert.notNull(jobExplorer, "JobExplorer must not be null."); jdbcTemplate = new JdbcTemplate(dataSource); 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) { lobHandler = new DefaultLobHandler(); } if (serializer == null) { XStreamExecutionContextStringSerializer defaultSerializer = new XStreamExecutionContextStringSerializer(); defaultSerializer.afterPropertiesSet(); serializer = defaultSerializer; } Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType + "' is an unsupported database type. The supported database types are " + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes())); }
@Override public void afterPropertiesSet() throws Exception { DataFieldMaxValueIncrementerFactory factory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); this.incrementer = factory.getIncrementer(DatabaseType.fromMetaData(dataSource).name(), tablePrefix + "JOB_SEQ"); }
@Test public void testCustomSerializer() throws Exception { factory.setDatabaseType("ORACLE"); incrementerFactory = mock(DataFieldMaxValueIncrementerFactory.class); when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).thenReturn(new StubIncrementer()); factory.setIncrementerFactory(incrementerFactory); ExecutionContextSerializer customSerializer = new DefaultExecutionContextSerializer(); factory.setSerializer(customSerializer); factory.afterPropertiesSet(); assertEquals(customSerializer, ReflectionTestUtils.getField(factory, "serializer")); }
public void afterPropertiesSet() throws Exception { Assert.notNull(dataSource, "DataSource must not be null."); jdbcTemplate = new SimpleJdbcTemplate(dataSource); 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 OracleLobHandler(); } Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType + "' is an unsupported database type. The supported database types are " + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes())); super.afterPropertiesSet(); }
@Override public void afterPropertiesSet() throws Exception { DataFieldMaxValueIncrementerFactory factory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); this.incremeter = factory.getIncrementer(DatabaseType.fromMetaData(dataSource).name(), tablePrefix + "JOB_SEQ"); }