Package com.alibaba.druid.pool

Examples of com.alibaba.druid.pool.DruidDataSource


    private static final long serialVersionUID = 1026193803901107651L;

    private DruidDataSource dataSource;

    public DruidConnectionProvider() {
        dataSource = new DruidDataSource();
    }
View Full Code Here


        ModularRealmAuthorizer authorizer = new ModularRealmAuthorizer();
        authorizer.setPermissionResolver(new WildcardPermissionResolver());
        securityManager.setAuthorizer(authorizer);

        //设置Realm
        DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://localhost:3306/shiro");
        ds.setUsername("root");
        ds.setPassword("");

        JdbcRealm jdbcRealm = new JdbcRealm();
        jdbcRealm.setDataSource(ds);
        jdbcRealm.setPermissionsLookupEnabled(true);
        securityManager.setRealms(Arrays.asList((Realm) jdbcRealm));
View Full Code Here

        return jdbcTemplate;
    }

    private static JdbcTemplate createJdbcTemplate() {

        DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://localhost:3306/shiro");
        ds.setUsername("root");
        ds.setPassword("");

        return new JdbcTemplate(ds);
    }
View Full Code Here

        return jdbcTemplate;
    }

    private static JdbcTemplate createJdbcTemplate() {

        DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://localhost:3306/shiro");
        ds.setUsername("root");
        ds.setPassword("");

        return new JdbcTemplate(ds);
    }
View Full Code Here

        return jdbcTemplate;
    }

    private static JdbcTemplate createJdbcTemplate() {

        DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://localhost:3306/shiro");
        ds.setUsername("root");
        ds.setPassword("");

        return new JdbcTemplate(ds);
    }
View Full Code Here

    filterList.add(filter);
    return this;
  }
 
  public boolean start() {
    ds = new DruidDataSource();
   
    ds.setUrl(url);
    ds.setUsername(username);
    ds.setPassword(password);
    ds.setDriverClassName(driverClass);
View Full Code Here

    public void init() {
        try {
            ManagementFactory.getPlatformMBeanServer().registerMBean(JdbcStatManager.getInstance(), new ObjectName("com.alibaba.druid:type=JdbcStatManager"));

            DruidDataSource dataSource = new DruidDataSource();

            ManagementFactory.getPlatformMBeanServer().registerMBean(dataSource, new ObjectName("com.alibaba.druid:type=DataSource"));

            dataSource.setUrl("jdbc:mock:");
            dataSource.setFilters("stat,trace");

            Connection conn = dataSource.getConnection();
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT 1");
            while (rs.next()) {

            }
View Full Code Here

    public Connection getConnection(MultiDataSourceConnection connectionProxy, String sql) throws SQLException {
        MultiDataSource multiDataSource = connectionProxy.getHaDataSource();

        Object[] array = multiDataSource.getDataSources().toArray();

        DruidDataSource minDataSource = null;
        int min = 0;
        for (Object item : array) {
            DruidDataSource dataSource = (DruidDataSource) item;

            if (!dataSource.isEnable()) {
                continue;
            }

            int activeCount = dataSource.getActiveCount();

            if (minDataSource == null || activeCount < min) {
                minDataSource = dataSource;
                min = activeCount;
            }

            if (activeCount >= maxActive) {
                continue;
            }

            return dataSource.getConnection();
        }

        if (minDataSource != null) {
            return minDataSource.getConnection();
        }
View Full Code Here

                throw new SQLException("can not get connection, no availabe datasources");
            }

            int index = (int) (connectionId % size);

            DruidDataSource dataSource = null;

            try {
                // 处理并发时的错误
                dataSource = multiDataSource.getDataSources().get(index);
            } catch (Exception ex) {
                indexErrorCount.incrementAndGet();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("getDataSource error, index : " + index, ex);
                }
                continue;
            }

            assert dataSource != null;

            if (!dataSource.isEnable()) {
                multiDataSource.handleNotAwailableDatasource(dataSource);
                continue;
            }

            Connection conn = null;

            try {
                tryCount++;
                conn = dataSource.getConnection();
            } catch (SQLException ex) {
                LOG.error("getConnection error", ex);

                if (tryCount >= size) {
                    throw ex;
View Full Code Here

        for (Object item : dataSources) {
            if (!(item instanceof DruidDataSource)) {
                continue;
            }

            DruidDataSource dataSource = (DruidDataSource) item;

            if (collectSqlEnable) {
                DruidDataSourceStatValue statValue = dataSource.getStatValueAndReset();
                statValueList.add(statValue);
            }

            if (collectSqlWallEnable) {
                WallProviderStatValue wallStatValue = dataSource.getWallStatValue(true);
                if (wallStatValue != null && wallStatValue.getCheckCount() > 0) {
                    wallStatValueList.add(wallStatValue);
                }
            }
        }
View Full Code Here

TOP

Related Classes of com.alibaba.druid.pool.DruidDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.