BATCH-407:Added repository factory to samples and created a factory for incrementers for that logic to obtain them could be unit tested. Also renamed SimpelJobRepositoryFactoryBean to just JobRepositoryFactoryBean

This commit is contained in:
lucasward
2008-03-03 20:23:14 +00:00
parent a4cb024882
commit 93760bd298
3 changed files with 249 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2006-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.support;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
/**
* Factory for creating {@link DataFieldMaxValueIncrementer} implementations
* based upon a provided string.
*
* @author Lucas Ward
*
*/
public interface DataFieldMaxValueIncrementerFactory {
/**
* Return the {@link DataFieldMaxValueIncrementer} for the provided database type.
*
* @param databaseType string represented database type
* @param incrementerName incrementer name to create. In many cases this may be the
* sequence name
* @return incrementer
* @throws IllegalArgumentException if databaseType is invalid type, or incrementerName
* is null.
*/
public DataFieldMaxValueIncrementer getIncrementer(String databaseType, String incrementerName);
/**
* Returns boolean indicated whether or not the provided string is supported by this
* factory.
*
*/
public boolean isSupportedIncrementerType(String databaseType);
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright 2006-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.support;
import javax.sql.DataSource;
import org.springframework.jdbc.support.incrementer.DB2SequenceMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer;
/**
* Default implementation of the {@link DataFieldMaxValueIncrementerFactory}
* interface. Valid types are:
*
* Valid values are:
*
* <ul>
* <li>db2</li>
* <li>derby</li>
* <li>hsql</li>
* <li>mysql</li>
* <li>oracle</li>
* <li>postgres</li>
* </ul>
*
* @author Lucas Ward
*
*/
public class DefaultDataFieldMaxValueIncrementerFactory implements
DataFieldMaxValueIncrementerFactory {
private static final String DB_TYPE_DB2 = "db2";
private static final String DB_TYPE_DERBY = "derby";
private static final String DB_TYPE_HSQL = "hsql";
private static final String DB_TYPE_MYSQL = "mysql";
private static final String DB_TYPE_ORACLE = "oracle";
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);
} else if (DB_TYPE_DERBY.equals(incrementerType)) {
return new DerbyMaxValueIncrementer(dataSource, incrementerName, "id");
} else if (DB_TYPE_HSQL.equals(incrementerType)) {
return new HsqlMaxValueIncrementer(dataSource, incrementerName, "id");
} else if (DB_TYPE_MYSQL.equals(incrementerType)) {
return new MySQLMaxValueIncrementer(dataSource, incrementerName, "id");
} else if (DB_TYPE_ORACLE.equals(incrementerType)) {
return new OracleSequenceMaxValueIncrementer(dataSource, incrementerName);
} else if (DB_TYPE_POSTGRES.equals(incrementerType)) {
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{
return true;
}
}
}