Example usage for org.apache.ibatis.datasource DataSourceException DataSourceException

List of usage examples for org.apache.ibatis.datasource DataSourceException DataSourceException

Introduction

In this page you can find the example usage for org.apache.ibatis.datasource DataSourceException DataSourceException.

Prototype

public DataSourceException(Throwable cause) 

Source Link

Usage

From source file:org.nanoframework.orm.mybatis.plugin.AbstractDataSourceFactory.java

License:Apache License

@Override
public void setProperties(Properties properties) {
    Properties driverProperties = new Properties();
    MetaObject metaDataSource = SystemMetaObject.forObject(dataSource);
    for (Object key : properties.keySet()) {
        String propertyName = (String) key;
        if (metaDataSource.hasSetter(propertyName)) {
            String value = (String) properties.get(propertyName);
            /** */
            if (StringUtils.isNotEmpty(value) && value.startsWith("${") && value.endsWith("}")) {
                continue;
            }/*from  w  w w . j av a 2s . c o m*/

            Object convertedValue = convertValue(metaDataSource, propertyName, value);
            metaDataSource.setValue(propertyName, convertedValue);
        } else {
            throw new DataSourceException("Unknown DataSource property: " + propertyName);
        }
    }

    if (driverProperties.size() > 0) {
        metaDataSource.setValue("driverProperties", driverProperties);
    }
}

From source file:org.nanoframework.orm.mybatis.plugin.TomcatJdbcPoolDataSourceFactory.java

License:Apache License

@Override
public void setProperties(Properties properties) {
    try {/*from   w  ww. ja v  a 2 s  .c o m*/
        Map<String, Object> map = Maps.newHashMap();
        properties.forEach((key, value) -> {
            if (StringUtils.isNotEmpty((String) value) && ((String) value).startsWith("${")
                    && ((String) value).endsWith("}")) {
                return;
            }

            map.put((String) key, value);
        });

        TomcatJdbcConfig config = TomcatJdbcConfig.mapToBean(map, TomcatJdbcConfig.class);
        if (TomcatJdbcDataSource != null) {
            TomcatJdbcDataSource.getMethod("setDriverClassName", String.class).invoke(dataSource,
                    config.getDriver());
            TomcatJdbcDataSource.getMethod("setUrl", String.class).invoke(dataSource, config.getUrl());
            TomcatJdbcDataSource.getMethod("setUsername", String.class).invoke(dataSource,
                    config.getUserName());
            TomcatJdbcDataSource.getMethod("setPassword", String.class).invoke(dataSource, config.getPasswd());

            if (config.getInitialSize() != null) {
                TomcatJdbcDataSource.getMethod("setInitialSize", int.class).invoke(dataSource,
                        config.getInitialSize());
            }

            if (config.getMinIdle() != null) {
                TomcatJdbcDataSource.getMethod("setMinIdle", int.class).invoke(dataSource, config.getMinIdle());
            }

            if (config.getMaxWait() != null) {
                TomcatJdbcDataSource.getMethod("setMaxWait", int.class).invoke(dataSource, config.getMaxWait());
            }

            if (config.getMaxActive() != null) {
                TomcatJdbcDataSource.getMethod("setMaxActive", int.class).invoke(dataSource,
                        config.getMaxActive());
            }

            if (config.getTestWhileIdle() != null) {
                TomcatJdbcDataSource.getMethod("setTestWhileIdle", boolean.class).invoke(dataSource,
                        config.getTestWhileIdle());
            }

            if (config.getTestOnBorrow() != null) {
                TomcatJdbcDataSource.getMethod("setTestOnBorrow", boolean.class).invoke(dataSource,
                        config.getTestOnBorrow());
            }

            if (config.getValidationInterval() != null) {
                TomcatJdbcDataSource.getMethod("setValidationInterval", long.class).invoke(dataSource,
                        config.getValidationInterval());
            }

            if (config.getTimeBetweenEvictionRunsMillis() != null) {
                TomcatJdbcDataSource.getMethod("setTimeBetweenEvictionRunsMillis", int.class).invoke(dataSource,
                        config.getTimeBetweenEvictionRunsMillis());
            }

            if (config.getLogAbandoned() != null) {
                TomcatJdbcDataSource.getMethod("setLogAbandoned", boolean.class).invoke(dataSource,
                        config.getLogAbandoned());
            }

            if (config.getRemoveAbandoned() != null) {
                TomcatJdbcDataSource.getMethod("setRemoveAbandoned", boolean.class).invoke(dataSource,
                        config.getRemoveAbandoned());
            }

            if (config.getRemoveAbandonedTimeout() != null) {
                TomcatJdbcDataSource.getMethod("setRemoveAbandonedTimeout", int.class).invoke(dataSource,
                        config.getRemoveAbandonedTimeout());
            }

            if (config.getMinEvictableIdleTimeMillis() != null) {
                TomcatJdbcDataSource.getMethod("setMinEvictableIdleTimeMillis", int.class).invoke(dataSource,
                        config.getMinEvictableIdleTimeMillis());
            }

            if (config.getJdbcInterceptors() != null) {
                TomcatJdbcDataSource.getMethod("setJdbcInterceptors", String.class).invoke(dataSource,
                        config.getJdbcInterceptors());
            }

            if (config.getJmxEnabled() != null) {
                TomcatJdbcDataSource.getMethod("setJmxEnabled", boolean.class).invoke(dataSource,
                        config.getJmxEnabled());
            }
        } else {
            throw new DataSourceException("Unknown class [ org.apache.tomcat.jdbc.pool.DataSource ]");
        }
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
            | NoSuchMethodException | SecurityException e) {
        throw new DataSourceException(e.getMessage(), e);
    }
}