读书人

BoneCP源码从Manual configuratio

发布时间: 2013-03-16 11:51:46 作者: rapoo

BoneCP源码——从Manual configuration说起

BoneCP官网上有其配置的使用文档,看最基本的Manual configuration:

?

if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(int.class)){String val = props.getProperty(tmp);if (val == null){val = props.getProperty("bonecp."+tmp); // hibernate provider style}if (val != null) {try{method.invoke(this, Integer.parseInt(val));} catch (NumberFormatException e){// do nothing, use the default value}}} else if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(long.class)){String val = props.getProperty(tmp);if (val == null){val = props.getProperty("bonecp."+tmp); // hibernate provider style}if (val != null) {try{method.invoke(this, Long.parseLong(val));} catch (NumberFormatException e){// do nothing, use the default value}}} else if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(String.class)){String val = props.getProperty(tmp);if (val == null){val = props.getProperty("bonecp."+tmp); // hibernate provider style}if (val != null) {method.invoke(this, val);}} if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(boolean.class)){String val = props.getProperty(tmp);if (val == null){val = props.getProperty("bonecp."+tmp); // hibernate provider style}if (val != null) {method.invoke(this, Boolean.parseBoolean(val));}}

个人认为这段代码写得不够优雅,至少相同部分可以提取出来,从设计的角度说这里也最好采用工厂方式便于多种实现。

?

读书人网 >开源软件

热点推荐