[BATCH-496] Added more descriptive error messages
This commit is contained in:
@@ -31,11 +31,11 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A {@link FactoryBean} that automates the creation of a
|
||||
* {@link SimpleJobRepository}. Requires the user to describe what kind of
|
||||
* database they are using.
|
||||
* A {@link FactoryBean} that automates the creation of a {@link SimpleJobRepository}. Requires the
|
||||
* user to describe what kind of database they are using.
|
||||
*
|
||||
* @author Ben Hale
|
||||
* @author Lucas Ward
|
||||
@@ -73,7 +73,9 @@ public class JobRepositoryFactoryBean implements FactoryBean, InitializingBean {
|
||||
incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
|
||||
}
|
||||
|
||||
Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "Unsupported database type");
|
||||
Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType
|
||||
+ "' is an unsupported database type. The supported database types are "
|
||||
+ StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes()));
|
||||
}
|
||||
|
||||
public Object getObject() throws Exception {
|
||||
|
||||
@@ -41,7 +41,12 @@ public interface DataFieldMaxValueIncrementerFactory {
|
||||
/**
|
||||
* Returns boolean indicated whether or not the provided string is supported by this
|
||||
* factory.
|
||||
*
|
||||
*/
|
||||
public boolean isSupportedIncrementerType(String databaseType);
|
||||
|
||||
/**
|
||||
* Returns the list of supported database incrementer types
|
||||
* @return
|
||||
*/
|
||||
public String[] getSupportedIncrementerTypes();
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrem
|
||||
import org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link DataFieldMaxValueIncrementerFactory}
|
||||
* interface. Valid types are:
|
||||
* Default implementation of the {@link DataFieldMaxValueIncrementerFactory} interface. Valid types
|
||||
* are:
|
||||
*
|
||||
* Valid values are:
|
||||
*
|
||||
@@ -41,29 +41,28 @@ import org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIn
|
||||
* </ul>
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DefaultDataFieldMaxValueIncrementerFactory implements
|
||||
DataFieldMaxValueIncrementerFactory {
|
||||
|
||||
private static final String DB_TYPE_DB2 = "db2";
|
||||
public class DefaultDataFieldMaxValueIncrementerFactory implements DataFieldMaxValueIncrementerFactory {
|
||||
|
||||
private static final String DB_TYPE_DERBY = "derby";
|
||||
static final String DB_TYPE_DB2 = "db2";
|
||||
|
||||
private static final String DB_TYPE_HSQL = "hsql";
|
||||
static final String DB_TYPE_DERBY = "derby";
|
||||
|
||||
private static final String DB_TYPE_MYSQL = "mysql";
|
||||
static final String DB_TYPE_HSQL = "hsql";
|
||||
|
||||
private static final String DB_TYPE_ORACLE = "oracle";
|
||||
static final String DB_TYPE_MYSQL = "mysql";
|
||||
|
||||
static final String DB_TYPE_ORACLE = "oracle";
|
||||
|
||||
static final String DB_TYPE_POSTGRES = "postgres";
|
||||
|
||||
private static final String DB_TYPE_POSTGRES = "postgres";
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
|
||||
public DefaultDataFieldMaxValueIncrementerFactory(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
|
||||
public DataFieldMaxValueIncrementer getIncrementer(String incrementerType, String incrementerName) {
|
||||
if (DB_TYPE_DB2.equals(incrementerType)) {
|
||||
return new DB2SequenceMaxValueIncrementer(dataSource, incrementerName);
|
||||
@@ -79,18 +78,21 @@ public class DefaultDataFieldMaxValueIncrementerFactory implements
|
||||
return new PostgreSQLSequenceMaxValueIncrementer(dataSource, incrementerName);
|
||||
}
|
||||
throw new IllegalArgumentException("databaseType argument was not on the approved list");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean isSupportedIncrementerType(String incrementerType) {
|
||||
if (!DB_TYPE_DB2.equals(incrementerType) && !DB_TYPE_DERBY.equals(incrementerType)
|
||||
&& !DB_TYPE_HSQL.equals(incrementerType) && !DB_TYPE_MYSQL.equals(incrementerType)
|
||||
&& !DB_TYPE_ORACLE.equals(incrementerType) && !DB_TYPE_POSTGRES.equals(incrementerType)) {
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getSupportedIncrementerTypes() {
|
||||
return new String[] { DB_TYPE_DB2, DB_TYPE_DERBY, DB_TYPE_HSQL, DB_TYPE_MYSQL, DB_TYPE_ORACLE, DB_TYPE_POSTGRES };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIn
|
||||
*/
|
||||
public class DefaultDataFieldMaxValueIncrementerFactoryTests extends TestCase {
|
||||
|
||||
DefaultDataFieldMaxValueIncrementerFactory factory;
|
||||
DataFieldMaxValueIncrementerFactory factory;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
|
||||
Reference in New Issue
Block a user