Refactoring classes in the com.ibatis.common.jdbc package
---------------------------------------------------------
Key: IBATIS-57
URL: http://issues.apache.org/jira/browse/IBATIS-57
Project: iBatis for Java
Type: Improvement
Versions: 2.0.9
Environment: 2.0.9
Reporter: Siveton Vincent
In the current release, each class in com.ibatis.common.jdbc package has a
public constructor with a given map as parameter.
Using maps implies that the developer should know exactly the needed keys to
construct a valid object. Actually, the developer need to read the
implementaion to know which are the needed properties (the needed properties
are not the same between constructor, checks SimpleDataSource and ScriptRunner
classes...)
Moreover, no validation of keys exists or throws conventional errors between
these classes. Maybe, we can have something like:
if (props.get(PROP_JDBC_DRIVER) == null) {
throw new NestedRuntimeException("The property '" + PROP_JDBC_DRIVER + "' is
required.");
} else {
jdbcDriver = (String) props.get(PROP_JDBC_DRIVER);
}
PROP_JDBC_DRIVER is a public static field in an interface or an abstract class
because all classes use it.
Like SimpleDataSource class contains only getter, I propose to use an immutable
object to instanciate this object and maybe the same pattern for all classes in
this package.
The main idea of this code refactoring is to configure more easily theses
objects like:
Properties props = new Properties();
URL url = new URL(MyTest.class.getResource("/").toString()+ myPropertiesConf);
props.load(url.openStream());
DataSource ds = new SimpleDataSource(props);
OR
ScriptRunner sr = new ScriptRunner(props);
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira