Example usage for org.apache.ibatis.datasource.pooled PooledDataSource setPoolTimeToWait

List of usage examples for org.apache.ibatis.datasource.pooled PooledDataSource setPoolTimeToWait

Introduction

In this page you can find the example usage for org.apache.ibatis.datasource.pooled PooledDataSource setPoolTimeToWait.

Prototype

public void setPoolTimeToWait(int poolTimeToWait) 

Source Link

Document

The time to wait before retrying to get a connection.

Usage

From source file:com.raise.orgs.impl.cfg.ProcessEngineConfigurationImpl.java

License:Apache License

protected void initDataSource() {
    if (dataSource == null) {
        if (dataSourceJndiName != null) {
            try {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
            } catch (Exception e) {
                throw new ActivitiException(
                        "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
            }/*w  ww  . ja v a2s . c  om*/

        } else if (jdbcUrl != null) {
            if ((jdbcDriver == null) || (jdbcUrl == null) || (jdbcUsername == null)) {
                throw new ActivitiException(
                        "DataSource or JDBC properties have to be specified in a process engine configuration");
            }

            log.debug("initializing datasource to db: {}", jdbcUrl);

            PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver,
                    jdbcUrl, jdbcUsername, jdbcPassword);

            if (jdbcMaxActiveConnections > 0) {
                pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
            }
            if (jdbcMaxIdleConnections > 0) {
                pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
            }
            if (jdbcMaxCheckoutTime > 0) {
                pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
            }
            if (jdbcMaxWaitTime > 0) {
                pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
            }
            if (jdbcPingEnabled == true) {
                pooledDataSource.setPoolPingEnabled(true);
                if (jdbcPingQuery != null) {
                    pooledDataSource.setPoolPingQuery(jdbcPingQuery);
                }
                pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
            }
            if (jdbcDefaultTransactionIsolationLevel > 0) {
                pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel);
            }
            dataSource = pooledDataSource;
        }

        if (dataSource instanceof PooledDataSource) {
            // ACT-233: connection pool of Ibatis is not properely initialized if this is not called!
            ((PooledDataSource) dataSource).forceCloseAll();
        }
    }

    if (databaseType == null) {
        initDatabaseType();
    }
}

From source file:org.activiti.crystalball.simulator.impl.cfg.SimulationEngineConfigurationImpl.java

License:Apache License

protected void initDataSource() {
    if (dataSource == null) {
        if (dataSourceJndiName != null) {
            try {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
            } catch (Exception e) {
                throw new ActivitiException(
                        "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
            }//from  w ww  . j a va 2 s  .  co  m

        } else if (jdbcUrl != null) {
            if ((jdbcDriver == null) || (jdbcUrl == null) || (jdbcUsername == null)) {
                throw new ActivitiException(
                        "DataSource or JDBC properties have to be specified in a process engine configuration");
            }

            log.fine("initializing datasource to db: " + jdbcUrl);

            PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver,
                    jdbcUrl, jdbcUsername, jdbcPassword);

            if (jdbcMaxActiveConnections > 0) {
                pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
            }
            if (jdbcMaxIdleConnections > 0) {
                pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
            }
            if (jdbcMaxCheckoutTime > 0) {
                pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
            }
            if (jdbcMaxWaitTime > 0) {
                pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
            }
            if (jdbcPingEnabled == true) {
                pooledDataSource.setPoolPingEnabled(true);
                if (jdbcPingQuery != null) {
                    pooledDataSource.setPoolPingQuery(jdbcPingQuery);
                }
                pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
            }
            dataSource = pooledDataSource;
        }

        if (dataSource instanceof PooledDataSource) {
            // ACT-233: connection pool of Ibatis is not properely initialized if this is not called!
            ((PooledDataSource) dataSource).forceCloseAll();
        }
    }

    if (databaseType == null) {
        initDatabaseType();
    }
}

From source file:org.activiti.engine.AbstractEngineConfiguration.java

License:Apache License

protected void initDataSource() {
    if (dataSource == null) {
        if (dataSourceJndiName != null) {
            try {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
            } catch (Exception e) {
                throw new ActivitiException(
                        "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
            }//  www  . j  a  v a  2 s .co  m

        } else if (jdbcUrl != null) {
            if ((jdbcDriver == null) || (jdbcUsername == null)) {
                throw new ActivitiException(
                        "DataSource or JDBC properties have to be specified in a process engine configuration");
            }

            logger.debug("initializing datasource to db: {}", jdbcUrl);

            if (logger.isInfoEnabled()) {
                logger.info("Configuring Datasource with following properties (omitted password for security)");
                logger.info("datasource driver: " + jdbcDriver);
                logger.info("datasource url : " + jdbcUrl);
                logger.info("datasource user name : " + jdbcUsername);
            }

            PooledDataSource pooledDataSource = new PooledDataSource(this.getClass().getClassLoader(),
                    jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword);

            if (jdbcMaxActiveConnections > 0) {
                pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
            }
            if (jdbcMaxIdleConnections > 0) {
                pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
            }
            if (jdbcMaxCheckoutTime > 0) {
                pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
            }
            if (jdbcMaxWaitTime > 0) {
                pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
            }
            if (jdbcPingEnabled == true) {
                pooledDataSource.setPoolPingEnabled(true);
                if (jdbcPingQuery != null) {
                    pooledDataSource.setPoolPingQuery(jdbcPingQuery);
                }
                pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
            }
            if (jdbcDefaultTransactionIsolationLevel > 0) {
                pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel);
            }
            dataSource = pooledDataSource;
        }

        if (dataSource instanceof PooledDataSource) {
            // ACT-233: connection pool of Ibatis is not properly
            // initialized if this is not called!
            ((PooledDataSource) dataSource).forceCloseAll();
        }
    }

    if (databaseType == null) {
        initDatabaseType();
    }
}

From source file:org.activiti.MybatisMultiTenantDatasourceConfiguration.java

License:Apache License

public DataSource getDataSource() {
    logger.info("Creating datasource for tenant " + tenantId + " at jdbc url " + jdbcUrl);

    DataSource dataSource = null;
    if (jdbcUrl != null) {

        if ((jdbcDriver == null) || (jdbcUsername == null)) {
            throw new ActivitiException(
                    "DataSource or JDBC properties have to be specified in a process engine configuration");
        }//from   w  ww.  j  a  v  a 2s.com

        PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver,
                jdbcUrl, jdbcUsername, jdbcPassword);

        if (jdbcMaxActiveConnections > 0) {
            pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
        }
        if (jdbcMaxIdleConnections > 0) {
            pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
        }
        if (jdbcMaxCheckoutTime > 0) {
            pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
        }
        if (jdbcMaxWaitTime > 0) {
            pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
        }
        if (jdbcPingEnabled == true) {
            pooledDataSource.setPoolPingEnabled(true);
            if (jdbcPingQuery != null) {
                pooledDataSource.setPoolPingQuery(jdbcPingQuery);
            }
            pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
        }
        if (jdbcDefaultTransactionIsolationLevel > 0) {
            pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel);
        }

        dataSource = pooledDataSource;
    }

    if (dataSource instanceof PooledDataSource) {
        // ACT-233: connection pool of Ibatis is not properly
        // initialized if this is not called!
        ((PooledDataSource) dataSource).forceCloseAll();
    }

    return dataSource;
}

From source file:org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl.java

License:Apache License

protected void initDataSource() {
    if (dataSource == null) {
        if (dataSourceJndiName != null) {
            try {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
            } catch (Exception e) {
                throw new ProcessEngineException(
                        "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
            }/*from w  ww .  ja v  a  2s  .co  m*/

        } else if (jdbcUrl != null) {
            if ((jdbcDriver == null) || (jdbcUrl == null) || (jdbcUsername == null)) {
                throw new ProcessEngineException(
                        "DataSource or JDBC properties have to be specified in a process engine configuration");
            }

            PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver,
                    jdbcUrl, jdbcUsername, jdbcPassword);

            if (jdbcMaxActiveConnections > 0) {
                pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
            }
            if (jdbcMaxIdleConnections > 0) {
                pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
            }
            if (jdbcMaxCheckoutTime > 0) {
                pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
            }
            if (jdbcMaxWaitTime > 0) {
                pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
            }
            if (jdbcPingEnabled == true) {
                pooledDataSource.setPoolPingEnabled(true);
                if (jdbcPingQuery != null) {
                    pooledDataSource.setPoolPingQuery(jdbcPingQuery);
                }
                pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
            }
            dataSource = pooledDataSource;
        }

        if (dataSource instanceof PooledDataSource) {
            // ACT-233: connection pool of Ibatis is not properely initialized if this is not called!
            ((PooledDataSource) dataSource).forceCloseAll();
        }
    }

    if (databaseType == null) {
        initDatabaseType();
    }
}

From source file:org.fastcatsearch.analytics.db.CommonDBHandler.java

License:Open Source License

public boolean load() {

    if (driverProperties == null) {
        driverProperties = new Properties();
    }/*  ww w  .  j av a2s  . c  om*/

    String dbType = settings.getString("type");
    driverProperties.setProperty("user", settings.getString("user"));
    driverProperties.setProperty("password", settings.getString("password"));
    driverProperties.setProperty("driver.encoding", "UTF-8");

    boolean isAutoCommit = settings.getBoolean("autocommit", true);
    boolean usePooling = settings.getBoolean("usePooling", true);

    DataSource dataSource = null;
    if (usePooling) {
        PooledDataSource pooledDataSource = new PooledDataSource(settings.getString("driver"),
                settings.getString("url"), driverProperties);
        boolean poolPingEnabled = settings.getBoolean("poolPingEnabled", true);
        String poolPingQuery = settings.getString("poolPingQuery");
        int poolPingConnectionsNotUsedFor = settings.getInt("poolPingConnectionsNotUsedFor", -1);
        int poolTimeToWait = settings.getInt("poolTimeToWait", -1);
        int poolMaximumActiveConnections = settings.getInt("poolMaximumActiveConnections", -1);
        int poolMaximumIdleConnections = settings.getInt("poolMaximumIdleConnections", -1);

        pooledDataSource.setPoolPingEnabled(poolPingEnabled);

        if (poolPingQuery != null) {
            pooledDataSource.setPoolPingQuery(poolPingQuery);
        }
        if (poolPingConnectionsNotUsedFor != -1) {
            pooledDataSource.setPoolPingConnectionsNotUsedFor(poolPingConnectionsNotUsedFor);
        }
        if (poolTimeToWait != -1) {
            pooledDataSource.setPoolTimeToWait(poolTimeToWait);
        }
        if (poolMaximumActiveConnections != -1) {
            pooledDataSource.setPoolMaximumActiveConnections(poolMaximumActiveConnections);
        }
        if (poolMaximumIdleConnections != -1) {
            pooledDataSource.setPoolMaximumIdleConnections(poolMaximumIdleConnections);
        }
        //autocommit
        pooledDataSource.setDefaultAutoCommit(isAutoCommit);

        dataSource = pooledDataSource;

    } else {
        UnpooledDataSource unpooledDataSource = new UnpooledDataSource(settings.getString("driver"),
                settings.getString("url"), driverProperties);
        unpooledDataSource.setAutoCommit(isAutoCommit);
        dataSource = unpooledDataSource;
    }

    org.apache.ibatis.mapping.Environment environment = new org.apache.ibatis.mapping.Environment("ID",
            new JdbcTransactionFactory(), dataSource);
    Configuration configuration = new Configuration(environment);
    if (globalParam != null) {
        configuration.getVariables().putAll(globalParam);
    }

    if (mapperList != null) {
        List<URL> mapperFileList = new ArrayList<URL>();
        for (Class<?> mapperDAO : mapperList) {
            try {
                String mapperFilePath = mapperDAO.getName().replace('.', '/') + "_" + dbType + ".xml";
                URL mapperFile = Resources.getResourceURL(mapperFilePath);
                mapperFileList.add(mapperFile);
            } catch (IOException e) {
                logger.error("error load MapperFile", e);
            }
        }

        for (URL mapperFile : mapperFileList) {
            addSqlMappings(configuration, mapperFile);
        }
    }

    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    return true;
}

From source file:org.flowable.common.engine.impl.AbstractEngineConfiguration.java

License:Apache License

protected void initDataSource() {
    if (dataSource == null) {
        if (dataSourceJndiName != null) {
            try {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
            } catch (Exception e) {
                throw new FlowableException(
                        "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
            }/*from   w ww .  j a  va  2 s . co m*/

        } else if (jdbcUrl != null) {
            if ((jdbcDriver == null) || (jdbcUsername == null)) {
                throw new FlowableException(
                        "DataSource or JDBC properties have to be specified in a process engine configuration");
            }

            logger.debug("initializing datasource to db: {}", jdbcUrl);

            if (logger.isInfoEnabled()) {
                logger.info("Configuring Datasource with following properties (omitted password for security)");
                logger.info("datasource driver : {}", jdbcDriver);
                logger.info("datasource url : {}", jdbcUrl);
                logger.info("datasource user name : {}", jdbcUsername);
            }

            PooledDataSource pooledDataSource = new PooledDataSource(this.getClass().getClassLoader(),
                    jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword);

            if (jdbcMaxActiveConnections > 0) {
                pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
            }
            if (jdbcMaxIdleConnections > 0) {
                pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
            }
            if (jdbcMaxCheckoutTime > 0) {
                pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
            }
            if (jdbcMaxWaitTime > 0) {
                pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
            }
            if (jdbcPingEnabled) {
                pooledDataSource.setPoolPingEnabled(true);
                if (jdbcPingQuery != null) {
                    pooledDataSource.setPoolPingQuery(jdbcPingQuery);
                }
                pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
            }
            if (jdbcDefaultTransactionIsolationLevel > 0) {
                pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel);
            }
            dataSource = pooledDataSource;
        }
    }

    if (databaseType == null) {
        initDatabaseType();
    }
}

From source file:org.flowable.engine.common.AbstractEngineConfiguration.java

License:Apache License

protected void initDataSource() {
    if (dataSource == null) {
        if (dataSourceJndiName != null) {
            try {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
            } catch (Exception e) {
                throw new FlowableException(
                        "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
            }/*from w ww  .  j  av a 2  s  .c  o m*/

        } else if (jdbcUrl != null) {
            if ((jdbcDriver == null) || (jdbcUsername == null)) {
                throw new FlowableException(
                        "DataSource or JDBC properties have to be specified in a process engine configuration");
            }

            logger.debug("initializing datasource to db: {}", jdbcUrl);

            if (logger.isInfoEnabled()) {
                logger.info("Configuring Datasource with following properties (omitted password for security)");
                logger.info("datasource driver : {}", jdbcDriver);
                logger.info("datasource url : {}", jdbcUrl);
                logger.info("datasource user name : {}", jdbcUsername);
            }

            PooledDataSource pooledDataSource = new PooledDataSource(this.getClass().getClassLoader(),
                    jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword);

            if (jdbcMaxActiveConnections > 0) {
                pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
            }
            if (jdbcMaxIdleConnections > 0) {
                pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
            }
            if (jdbcMaxCheckoutTime > 0) {
                pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
            }
            if (jdbcMaxWaitTime > 0) {
                pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
            }
            if (jdbcPingEnabled == true) {
                pooledDataSource.setPoolPingEnabled(true);
                if (jdbcPingQuery != null) {
                    pooledDataSource.setPoolPingQuery(jdbcPingQuery);
                }
                pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
            }
            if (jdbcDefaultTransactionIsolationLevel > 0) {
                pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel);
            }
            dataSource = pooledDataSource;
        }

        if (dataSource instanceof PooledDataSource) {
            // ACT-233: connection pool of Ibatis is not properly
            // initialized if this is not called!
            ((PooledDataSource) dataSource).forceCloseAll();
        }
    }

    if (databaseType == null) {
        initDatabaseType();
    }
}

From source file:uap.workflow.engine.cfg.ProcessEngineConfigurationImpl.java

License:Apache License

protected void initDataSource() {
    if (dataSource == null) {
        if (dataSourceJndiName != null) {
            try {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
            } catch (Exception e) {
                throw new WorkflowException(
                        "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
            }/*from w  w w.  j  av  a 2s  .co  m*/
        } else if (jdbcUrl != null) {
            if ((jdbcDriver == null) || (jdbcUrl == null) || (jdbcUsername == null)) {
                throw new WorkflowException(
                        "DataSource or JDBC properties have to be specified in a process engine configuration");
            }
            log.fine("initializing datasource to db: " + jdbcUrl);
            PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver,
                    jdbcUrl, jdbcUsername, jdbcPassword);
            if (jdbcMaxActiveConnections > 0) {
                pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
            }
            if (jdbcMaxIdleConnections > 0) {
                pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
            }
            if (jdbcMaxCheckoutTime > 0) {
                pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
            }
            if (jdbcMaxWaitTime > 0) {
                pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
            }
            if (jdbcPingEnabled == true) {
                pooledDataSource.setPoolPingEnabled(true);
                if (jdbcPingQuery != null) {
                    pooledDataSource.setPoolPingQuery(jdbcPingQuery);
                }
                pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
            }
            dataSource = pooledDataSource;
        }
        if (dataSource instanceof PooledDataSource) {
            // ACT-233: connection pool of Ibatis is not properely
            // initialized if this is not called!
            ((PooledDataSource) dataSource).forceCloseAll();
        }
    }
    if (databaseType == null) {
        initDatabaseType();
    }
}