IN PROGRESS - issue BATCH-792: Automatically detect database type in JobRepositoryFactoryBean

http://jira.springframework.org/browse/BATCH-792

JobRepositoryFactoryBean now detects the database type by the meta data.  There is also now an enum representing the DatabaseType.
This commit is contained in:
lucasward
2008-09-05 23:25:12 +00:00
parent fc2de248f6
commit 85fceaff47
3 changed files with 56 additions and 12 deletions

View File

@@ -17,6 +17,7 @@ package org.springframework.batch.core.repository.support;
import static junit.framework.Assert.*;
import static org.easymock.EasyMock.*;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.item.database.support.DataFieldMaxValueIncrementerFactory;
@@ -29,6 +30,7 @@ import org.junit.Test;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
/**
* @author Lucas Ward
@@ -63,19 +65,24 @@ public class JobRepositoryFactoryBeanTests {
@Test
public void testNoDatabaseType() throws Exception {
try {
expect(incrementerFactory.isSupportedIncrementerType(null)).andReturn(false);
expect(incrementerFactory.getSupportedIncrementerTypes()).andReturn(new String[0]);
replay(incrementerFactory);
factory.afterPropertiesSet();
fail();
}
catch (IllegalArgumentException ex) {
// expected
String message = ex.getMessage();
assertTrue("Wrong message: " + message, message.indexOf("unsupported database type") >= 0);
}
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();
factory.getObject();
verify(incrementerFactory);
}
@Test

View File

@@ -102,6 +102,33 @@ public class StepExecutionResourceProxyTests extends TestCase {
resource.beforeStep(jobExecution.createStepExecution(step.getName()));
doTestPathName("spam-foo", "foo" + pathsep + "data" + pathsep);
}
// public void testNonExistentJobParameter() throws Exception{
//
// resource.setFilePattern("foo/data/%JOB_NAME%/%non.key%-foo");
// jobInstance = new JobInstance(new Long(0), new JobParametersBuilder().addString("job.key", "spam")
// .toJobParameters(), "testJob");
// JobExecution jobExecution = new JobExecution(jobInstance);
// Step step = new StepSupport("bar");
// try{
// resource.beforeStep(jobExecution.createStepExecution(step.getName()));
// fail();
// }
// catch(Exception ex){
// //expected, if there isn't a JobParameter for that key, it should throw an exception
// }
// }
public void testLongJobParameter() throws Exception {
resource.setFilePattern("foo/data/%JOB_NAME%/%job.key(long)%-foo");
jobInstance = new JobInstance(new Long(0), new JobParametersBuilder().addLong("job.key", 123L)
.toJobParameters(), "testJob");
JobExecution jobExecution = new JobExecution(jobInstance);
Step step = new StepSupport("bar");
resource.beforeStep(jobExecution.createStepExecution(step.getName()));
doTestPathName("123-foo", "foo" + pathsep + "data" + pathsep);
}
public void testResoureLoaderAware() throws Exception {
resource = new StepExecutionResourceProxy();