private BasicDataSource newDbcpConfiguration(Map map) { BasicDataSource basicDataSource = new BasicDataSource(); Iterator props = map.keySet().iterator(); while (props.hasNext()) { String propertyName = (String) props.next(); if (propertyName.startsWith(ADD_DRIVER_PROPS_PREFIX)) { String value = (String) map.get(propertyName); basicDataSource.addConnectionProperty( propertyName.substring(ADD_DRIVER_PROPS_PREFIX_LENGTH), value); } else if (PROBE.hasWritableProperty(basicDataSource, propertyName)) { String value = (String) map.get(propertyName); Object convertedValue = convertValue(basicDataSource, propertyName, value); PROBE.setObject(basicDataSource, propertyName, convertedValue); } } return basicDataSource; }
private Object convertValue(Object object, String propertyName, String value) { Object convertedValue = value; Class targetType = PROBE.getPropertyTypeForSetter(object, propertyName); if (targetType == Integer.class || targetType == int.class) { convertedValue = Integer.valueOf(value); } else if (targetType == Long.class || targetType == long.class) { convertedValue = Long.valueOf(value); } else if (targetType == Boolean.class || targetType == boolean.class) { convertedValue = Boolean.valueOf(value); } return convertedValue; }