goja-web/src/main/java/goja/initialize/DruidDbIntializer.java
public static DruidPlugin druidPlugin(
            Properties dbProp
    ) {

        String dbUrl = dbProp.getProperty(GojaPropConst.DBURL),
                username = dbProp.getProperty(GojaPropConst.DBUSERNAME),
                password = dbProp.getProperty(GojaPropConst.DBPASSWORD);
        if (!Strings.isNullOrEmpty(dbUrl)) {
            String dbtype = JdbcUtils.getDbType(dbUrl, StringUtils.EMPTY);
            String driverClassName;
            try {
                driverClassName = JdbcUtils.getDriverClassName(dbUrl);
            } catch (SQLException e) {
                throw new DatabaseException(e.getMessage(), e);
            }
            final DruidPlugin druidPlugin = new DruidPlugin(dbUrl, username, password, driverClassName);

            // set validator
            setValidatorQuery(dbtype, druidPlugin);
            druidPlugin.addFilter(new StatFilter());

            final String initialSize = dbProp.getProperty(GojaPropConst.DB_INITIAL_SIZE);
            if (!Strings.isNullOrEmpty(initialSize)) {
                druidPlugin.setInitialSize(MoreObjects.firstNonNull(Ints.tryParse(initialSize), 6));
            }
            final String initial_minidle = dbProp.getProperty(GojaPropConst.DB_INITIAL_MINIDLE);
            if (!Strings.isNullOrEmpty(initial_minidle)) {
                druidPlugin.setMinIdle(MoreObjects.firstNonNull(Ints.tryParse(initial_minidle), 5));
            }

            final String initial_maxwait = dbProp.getProperty(GojaPropConst.DB_INITIAL_MAXWAIT);
            if (!Strings.isNullOrEmpty(initial_maxwait)) {
                druidPlugin.setMaxWait(MoreObjects.firstNonNull(Ints.tryParse(initial_maxwait), 5));
            }
            final String initial_active = dbProp.getProperty(GojaPropConst.DB_INITIAL_ACTIVE);
            if (!Strings.isNullOrEmpty(initial_active)) {
                druidPlugin.setMaxActive(MoreObjects.firstNonNull(Ints.tryParse(initial_active), 5));
            }
            final String timeBetweenEvictionRunsMillis =
                    dbProp.getProperty(GojaPropConst.DB_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
            if (!Strings.isNullOrEmpty(timeBetweenEvictionRunsMillis)) {
                final Integer millis = MoreObjects.firstNonNull(Ints.tryParse(timeBetweenEvictionRunsMillis), 10000);
                druidPlugin.setTimeBetweenEvictionRunsMillis(millis);
            }
            final String minEvictableIdleTimeMillis =
                    dbProp.getProperty(GojaPropConst.DB_MIN_EVICTABLE_IDLE_TIME_MILLIS);
            if (!Strings.isNullOrEmpty(minEvictableIdleTimeMillis)) {
                final Integer idleTimeMillis = MoreObjects.firstNonNull(Ints.tryParse(minEvictableIdleTimeMillis), 10000);
                druidPlugin.setMinEvictableIdleTimeMillis(idleTimeMillis);
            }

            final WallFilter wall = new WallFilter();
            wall.setDbType(dbtype);
            druidPlugin.addFilter(wall);
            if (GojaConfig.getPropertyToBoolean(GojaPropConst.DBLOGFILE, false)) {
                // 增加 LogFilter 输出JDBC执行的日志
                druidPlugin.addFilter(new Slf4jLogFilter());
            }


            return druidPlugin;
        }
        return null;
    }
public static DruidPlugin druidPlugin(
            Properties dbProp
    ) {

        String dbUrl = dbProp.getProperty(GojaPropConst.DBURL),
                username = dbProp.getProperty(GojaPropConst.DBUSERNAME),
                password = dbProp.getProperty(GojaPropConst.DBPASSWORD);
        if (!Strings.isNullOrEmpty(dbUrl)) {
            String dbtype = JdbcUtils.getDbType(dbUrl, StringUtils.EMPTY);
            String driverClassName;
            try {
                driverClassName = JdbcUtils.getDriverClassName(dbUrl);
            } catch (SQLException e) {
                throw new DatabaseException(e.getMessage(), e);
            }
            final DruidPlugin druidPlugin = new DruidPlugin(dbUrl, username, password, driverClassName);

            // set validator
            setValidatorQuery(dbtype, druidPlugin);
            druidPlugin.addFilter(new StatFilter());

            final String initialSize = dbProp.getProperty(GojaPropConst.DB_INITIAL_SIZE);
            if (!Strings.isNullOrEmpty(initialSize)) {
                druidPlugin.setInitialSize(MoreObjects.firstNonNull(Ints.tryParse(initialSize), 6));
            }
            final String initial_minidle = dbProp.getProperty(GojaPropConst.DB_INITIAL_MINIDLE);
            if (!Strings.isNullOrEmpty(initial_minidle)) {
                druidPlugin.setMinIdle(MoreObjects.firstNonNull(Ints.tryParse(initial_minidle), 5));
            }

            final String initial_maxwait = dbProp.getProperty(GojaPropConst.DB_INITIAL_MAXWAIT);
            if (!Strings.isNullOrEmpty(initial_maxwait)) {
                druidPlugin.setMaxWait(MoreObjects.firstNonNull(Ints.tryParse(initial_maxwait), 5));
            }
            final String initial_active = dbProp.getProperty(GojaPropConst.DB_INITIAL_ACTIVE);
            if (!Strings.isNullOrEmpty(initial_active)) {
                druidPlugin.setMaxActive(MoreObjects.firstNonNull(Ints.tryParse(initial_active), 5));
            }
            final String timeBetweenEvictionRunsMillis =
                    dbProp.getProperty(GojaPropConst.DB_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
            if (!Strings.isNullOrEmpty(timeBetweenEvictionRunsMillis)) {
                final Integer millis = MoreObjects.firstNonNull(Ints.tryParse(timeBetweenEvictionRunsMillis), 10000);
                druidPlugin.setTimeBetweenEvictionRunsMillis(millis);
            }
            final String minEvictableIdleTimeMillis =
                    dbProp.getProperty(GojaPropConst.DB_MIN_EVICTABLE_IDLE_TIME_MILLIS);
            if (!Strings.isNullOrEmpty(minEvictableIdleTimeMillis)) {
                final Integer idleTimeMillis = MoreObjects.firstNonNull(Ints.tryParse(minEvictableIdleTimeMillis), 10000);
                druidPlugin.setMinEvictableIdleTimeMillis(idleTimeMillis);
            }

            final WallFilter wall = new WallFilter();
            wall.setDbType(dbtype);
            druidPlugin.addFilter(wall);
            if (GojaConfig.getPropertyToBoolean(GojaPropConst.DBLOGFILE, false)) {
                // 增加 LogFilter 输出JDBC执行的日志
                druidPlugin.addFilter(new Slf4jLogFilter());
            }


            return druidPlugin;
        }
        return null;
    }
public static DruidPlugin druidPlugin ( Properties dbProp ) { String dbUrl = dbProp . getProperty ( GojaPropConst . DBURL ) , username = dbProp . getProperty ( GojaPropConst . DBUSERNAME ) , password = dbProp . getProperty ( GojaPropConst . DBPASSWORD ) ; if ( ! Strings . isNullOrEmpty ( dbUrl ) ) { String dbtype = JdbcUtils . getDbType ( dbUrl , StringUtils . EMPTY ) ; String driverClassName ; try { driverClassName = JdbcUtils . getDriverClassName ( dbUrl ) ; } catch ( SQLException e ) { throw new DatabaseException ( e . getMessage ( ) , e ) ; } final DruidPlugin druidPlugin = new DruidPlugin ( dbUrl , username , password , driverClassName ) ; // set validator setValidatorQuery ( dbtype , druidPlugin ) ; druidPlugin . addFilter ( new StatFilter ( ) ) ; final String initialSize = dbProp . getProperty ( GojaPropConst . DB_INITIAL_SIZE ) ; if ( ! Strings . isNullOrEmpty ( initialSize ) ) { druidPlugin . setInitialSize ( MoreObjects . firstNonNull ( Ints . tryParse ( initialSize ) , 6 ) ) ; } final String initial_minidle = dbProp . getProperty ( GojaPropConst . DB_INITIAL_MINIDLE ) ; if ( ! Strings . isNullOrEmpty ( initial_minidle ) ) { druidPlugin . setMinIdle ( MoreObjects . firstNonNull ( Ints . tryParse ( initial_minidle ) , 5 ) ) ; } final String initial_maxwait = dbProp . getProperty ( GojaPropConst . DB_INITIAL_MAXWAIT ) ; if ( ! Strings . isNullOrEmpty ( initial_maxwait ) ) { druidPlugin . setMaxWait ( MoreObjects . firstNonNull ( Ints . tryParse ( initial_maxwait ) , 5 ) ) ; } final String initial_active = dbProp . getProperty ( GojaPropConst . DB_INITIAL_ACTIVE ) ; if ( ! Strings . isNullOrEmpty ( initial_active ) ) { druidPlugin . setMaxActive ( MoreObjects . firstNonNull ( Ints . tryParse ( initial_active ) , 5 ) ) ; } final String timeBetweenEvictionRunsMillis = dbProp . getProperty ( GojaPropConst . DB_TIME_BETWEEN_EVICTION_RUNS_MILLIS ) ; if ( ! Strings . isNullOrEmpty ( timeBetweenEvictionRunsMillis ) ) { final Integer millis = MoreObjects . firstNonNull ( Ints . tryParse ( timeBetweenEvictionRunsMillis ) , 10000 ) ; druidPlugin . setTimeBetweenEvictionRunsMillis ( millis ) ; } final String minEvictableIdleTimeMillis = dbProp . getProperty ( GojaPropConst . DB_MIN_EVICTABLE_IDLE_TIME_MILLIS ) ; if ( ! Strings . isNullOrEmpty ( minEvictableIdleTimeMillis ) ) { final Integer idleTimeMillis = MoreObjects . firstNonNull ( Ints . tryParse ( minEvictableIdleTimeMillis ) , 10000 ) ; druidPlugin . setMinEvictableIdleTimeMillis ( idleTimeMillis ) ; } final WallFilter wall = new WallFilter ( ) ; wall . setDbType ( dbtype ) ; druidPlugin . addFilter ( wall ) ; if ( GojaConfig . getPropertyToBoolean ( GojaPropConst . DBLOGFILE , false ) ) { // 增加 LogFilter 输出JDBC执行的日志 druidPlugin . addFilter ( new Slf4jLogFilter ( ) ) ; } return druidPlugin ; } return null ; }
The configuration database, specify the name of the database.

@param dbProp 数据库配置
The configuration database specify the name of the database .