RESOLVED - issue BATCH-980: Add SystemPropertyInitializer

This commit is contained in:
dsyer
2008-12-30 09:23:27 +00:00
parent c9d7b45f14
commit e4ca63a927
9 changed files with 190 additions and 51 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.batch.core.repository.dao.JobInstanceDao;
import org.springframework.batch.core.repository.dao.StepExecutionDao;
import org.springframework.batch.item.database.support.DataFieldMaxValueIncrementerFactory;
import org.springframework.batch.item.database.support.DefaultDataFieldMaxValueIncrementerFactory;
import org.springframework.batch.support.DatabaseType;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
@@ -92,6 +93,10 @@ public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean imple
incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
}
if (databaseType == null) {
databaseType = DatabaseType.fromMetaData(dataSource).name();
}
Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType
+ "' is an unsupported database type. The supported database types are "
+ StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes()));

View File

@@ -22,6 +22,9 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import javax.sql.DataSource;
import org.junit.Before;
@@ -57,20 +60,45 @@ public class JobExplorerFactoryBeanTests {
}
@Test
public void testDetectDatabaseType() throws Exception {
DatabaseMetaData dmd = createMock(DatabaseMetaData.class);
Connection con = createMock(Connection.class);
expect(dataSource.getConnection()).andReturn(con);
expect(con.getMetaData()).andReturn(dmd);
expect(dmd.getDatabaseProductName()).andReturn("Oracle");
expect(incrementerFactory.isSupportedIncrementerType("ORACLE")).andReturn(true);
expect(incrementerFactory.getSupportedIncrementerTypes()).andReturn(new String[0]);
expect(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).andReturn(new StubIncrementer());
expect(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).andReturn(
new StubIncrementer());
expect(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).andReturn(
new StubIncrementer());
replay(dataSource, con, dmd, incrementerFactory);
factory.afterPropertiesSet();
}
@Test
public void testNoDatabaseType() throws Exception {
DatabaseMetaData dmd = createMock(DatabaseMetaData.class);
Connection con = createMock(Connection.class);
expect(dataSource.getConnection()).andReturn(con);
expect(con.getMetaData()).andReturn(dmd);
expect(dmd.getDatabaseProductName()).andReturn("foo");
try {
expect(incrementerFactory.isSupportedIncrementerType(null)).andReturn(false);
expect(incrementerFactory.getSupportedIncrementerTypes()).andReturn(new String[0]);
replay(incrementerFactory);
replay(dataSource, con, dmd, incrementerFactory);
factory.afterPropertiesSet();
fail();
}
catch (IllegalArgumentException ex) {
// expected
String message = ex.getMessage();
assertTrue("Wrong message: " + message, message.indexOf("unsupported database type") >= 0);
assertTrue("Wrong message: " + message, message.indexOf("DatabaseType") >= 0);
}
}
@@ -117,9 +145,12 @@ public class JobExplorerFactoryBeanTests {
expect(incrementerFactory.isSupportedIncrementerType("foo")).andReturn(true);
expect(incrementerFactory.getSupportedIncrementerTypes()).andReturn(new String[0]);
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ")).andReturn(new StubIncrementer());
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ")).andReturn(new StubIncrementer());
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ")).andReturn(new StubIncrementer());
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ")).andReturn(
new StubIncrementer());
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ")).andReturn(
new StubIncrementer());
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ")).andReturn(
new StubIncrementer());
replay(incrementerFactory);
factory.afterPropertiesSet();