Java Code Examples for org.apache.tomcat.jdbc.pool.PoolProperties#setUsername()
The following examples show how to use
org.apache.tomcat.jdbc.pool.PoolProperties#setUsername() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerfTestProcessEngine.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected static javax.sql.DataSource createDatasource(Properties properties) { PoolProperties p = new PoolProperties(); p.setUrl(properties.getProperty("databaseUrl")); p.setDriverClassName(properties.getProperty("databaseDriver")); p.setUsername(properties.getProperty("databaseUser")); p.setPassword(properties.getProperty("databasePassword")); p.setJmxEnabled(false); p.setMaxActive(100); p.setInitialSize(10); DataSource datasource = new DataSource(); datasource.setPoolProperties(p); return datasource; }
Example 2
Source File: DataSourceUtil.java From das with Apache License 2.0 | 5 votes |
private static DataSource createDataSource(String url, String userName, String password, String driverClass) throws Exception { PoolProperties p = new PoolProperties(); //System.out.println(url); p.setUrl(url); p.setUsername(userName); p.setPassword(password); p.setDriverClassName(driverClass); p.setJmxEnabled(false); p.setTestWhileIdle(false); p.setTestOnBorrow(true); p.setTestOnReturn(false); p.setValidationQuery("SELECT 1"); p.setValidationQueryTimeout(5); p.setValidationInterval(30000L); p.setTimeBetweenEvictionRunsMillis(300000); p.setNumTestsPerEvictionRun(50); p.setMaxActive(100); p.setMinIdle(0); p.setMaxWait(10000); p.setMaxAge(0L); p.setInitialSize(1); p.setRemoveAbandonedTimeout(60); p.setRemoveAbandoned(true); p.setLogAbandoned(true); p.setMinEvictableIdleTimeMillis(3600000); p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(p); ds.createPool(); return ds; }
Example 3
Source File: DataSourceUtil.java From das with Apache License 2.0 | 5 votes |
private static DataSource createDataSource(String url, String userName, String password, String driverClass) throws Exception { PoolProperties p = new PoolProperties(); p.setUrl(url); p.setUsername(userName); p.setPassword(password); p.setDriverClassName(driverClass); p.setJmxEnabled(false); p.setTestWhileIdle(false); p.setTestOnBorrow(true); p.setTestOnReturn(false); p.setValidationQuery("SELECT 1"); p.setValidationQueryTimeout(5); p.setValidationInterval(30000L); p.setTimeBetweenEvictionRunsMillis(5000); p.setMaxActive(100); p.setMinIdle(0); p.setMaxWait(10000); p.setMaxAge(0L); p.setInitialSize(1); p.setRemoveAbandonedTimeout(60); p.setRemoveAbandoned(true); p.setLogAbandoned(true); p.setMinEvictableIdleTimeMillis(30000); p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(p); ds.createPool(); return ds; }
Example 4
Source File: PoolPropertiesHelper.java From das with Apache License 2.0 | 5 votes |
public PoolProperties copy(PoolProperties from) { PoolProperties properties = new PoolProperties(); properties.setUrl(from.getUrl()); properties.setUsername(from.getUsername()); properties.setPassword(from.getPassword()); properties.setDriverClassName(from.getDriverClassName()); properties.setTestWhileIdle(from.isTestWhileIdle()); properties.setTestOnBorrow(from.isTestOnBorrow()); properties.setTestOnReturn(from.isTestOnReturn()); properties.setValidationQuery(from.getValidationQuery()); properties.setValidationQueryTimeout(from.getValidationQueryTimeout()); properties.setValidationInterval(from.getValidationInterval()); properties.setTimeBetweenEvictionRunsMillis(from.getTimeBetweenEvictionRunsMillis()); properties.setMinEvictableIdleTimeMillis(from.getMinEvictableIdleTimeMillis()); properties.setMaxAge(from.getMaxAge()); properties.setMaxActive(from.getMaxActive()); properties.setMinIdle(from.getMinIdle()); properties.setMaxWait(from.getMaxWait()); properties.setInitialSize(from.getInitialSize()); properties.setRemoveAbandonedTimeout(from.getRemoveAbandonedTimeout()); properties.setRemoveAbandoned(from.isRemoveAbandoned()); properties.setLogAbandoned(from.isLogAbandoned()); properties.setConnectionProperties(from.getConnectionProperties()); properties.setValidatorClassName(from.getValidatorClassName()); properties.setInitSQL(from.getInitSQL()); properties.setJmxEnabled(from.isJmxEnabled()); properties.setJdbcInterceptors(from.getJdbcInterceptors()); return properties; }
Example 5
Source File: DFDbUtil.java From dfactor with MIT License | 5 votes |
public static DataSource createMysqlDbSource(String url, String user, String pwd, int initSize, int maxActive, int maxWait, int maxIdle, int minIdle){ PoolProperties p = new PoolProperties(); p.setDriverClassName("com.mysql.jdbc.Driver"); p.setUrl(url); p.setUsername(user); p.setPassword(pwd); p.setJmxEnabled(true); p.setTestWhileIdle(true); p.setTestOnBorrow(false); p.setTestOnReturn(false); p.setValidationQuery("SELECT 1"); p.setValidationInterval(30000); p.setTimeBetweenEvictionRunsMillis(30000); p.setMaxActive(maxActive); p.setInitialSize(initSize); p.setMaxWait(maxWait); //conn timeout p.setRemoveAbandonedTimeout(60); p.setMinEvictableIdleTimeMillis(30000); p.setMaxIdle(maxIdle); p.setMinIdle(minIdle); p.setLogAbandoned(true); p.setRemoveAbandoned(true); p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); final DataSource dbSrc = new DataSource(); dbSrc.setPoolProperties(p); return dbSrc; }
Example 6
Source File: TestTomcatJdbcPoolBehavior.java From aceql-http with GNU Lesser General Public License v2.1 | 5 votes |
public static void createPool() throws Exception { // Modify this code in order to extract a Connection from your // connection pooling system: // Driver parameters to use: String driverClassName = "org.postgresql.Driver"; String url = "jdbc:postgresql://localhost:5432/sampledb"; String username = "user1"; String password = "password1"; // Creating the DataSource bean and populating the values: // Mandatory values to set PoolProperties p = new PoolProperties(); p.setDriverClassName(driverClassName); p.setUrl(url); p.setUsername(username); p.setPassword(password); // Other possible values to set p.setTestOnBorrow(true); p.setValidationQuery("SELECT 1"); p.setTestOnReturn(false); p.setValidationInterval(30000); p.setTimeBetweenEvictionRunsMillis(30000); p.setMaxActive(2); p.setInitialSize(2); p.setMaxWait(10000); p.setRemoveAbandonedTimeout(60); p.setMinEvictableIdleTimeMillis(30000); p.setMinIdle(2); p.setMaxIdle(2); p.setLogAbandoned(true); p.setRemoveAbandoned(true); p.setJdbcInterceptors("ConnectionState;StatementFinalizer"); dataSource = new DataSource(); dataSource.setPoolProperties(p); }
Example 7
Source File: DataSourceUtil.java From dal with Apache License 2.0 | 5 votes |
private static DataSource createDataSource(String url, String userName, String password, String driverClass) throws Exception { PoolProperties p = new PoolProperties(); p.setUrl(url); p.setUsername(userName); p.setPassword(password); p.setDriverClassName(driverClass); p.setJmxEnabled(false); p.setTestWhileIdle(false); p.setTestOnBorrow(true); p.setTestOnReturn(false); p.setValidationQuery("SELECT 1"); p.setValidationQueryTimeout(5); p.setValidationInterval(30000L); p.setTimeBetweenEvictionRunsMillis(5000); p.setMaxActive(100); p.setMinIdle(0); p.setMaxWait(10000); p.setMaxAge(0L); p.setInitialSize(1); p.setRemoveAbandonedTimeout(60); p.setRemoveAbandoned(true); p.setLogAbandoned(true); p.setMinEvictableIdleTimeMillis(30000); p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(p); ds.createPool(); return ds; }
Example 8
Source File: BaseDeviceManagementCertificateTest.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
private DataSource getDataSource(DataSourceConfig config) { PoolProperties properties = new PoolProperties(); properties.setUrl(config.getUrl()); properties.setDriverClassName(config.getDriverClassName()); properties.setUsername(config.getUser()); properties.setPassword(config.getPassword()); return new org.apache.tomcat.jdbc.pool.DataSource(properties); }
Example 9
Source File: BaseDeviceManagementTest.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
protected DataSource getDataSource(DataSourceConfig config) { if (!isMock()) { PoolProperties properties = new PoolProperties(); properties.setUrl(config.getUrl()); properties.setDriverClassName(config.getDriverClassName()); properties.setUsername(config.getUser()); properties.setPassword(config.getPassword()); return new org.apache.tomcat.jdbc.pool.DataSource(properties); } else { return new MockDataSource(config.getUrl()); } }
Example 10
Source File: BasePolicyManagementDAOTest.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
private DataSource getDataSource(DataSourceConfig config) { PoolProperties properties = new PoolProperties(); properties.setUrl(config.getUrl()); properties.setDriverClassName(config.getDriverClassName()); properties.setUsername(config.getUser()); properties.setPassword(config.getPassword()); return new org.apache.tomcat.jdbc.pool.DataSource(properties); }
Example 11
Source File: MockedTomcatJdbcConnection.java From liquibase-percona with Apache License 2.0 | 5 votes |
/** * Creates a mocked SQL connection, that looks like a tomcat-jdbc pooled connection. * @param username the username to use * @param password the password to use * @return the connection * @throws SQLException */ public static Connection create(String username, String password) throws SQLException { PoolProperties poolProps = new PoolProperties(); poolProps.setUsername(username); poolProps.setPassword(password); poolProps.setDataSource(new MockDataSource()); ConnectionPool pool = new ConnectionPool(poolProps); PooledConnection pooledConnection = new PooledConnection(poolProps, pool); pooledConnection.connect(); ProxyConnection proxyConnection = new ProxyConnection(null, pooledConnection, true) {}; DisposableConnectionFacade invocationHandler = new DisposableConnectionFacade(proxyConnection) {}; Connection connection = (Connection) Proxy.newProxyInstance(DisposableConnectionFacade.class.getClassLoader(), new Class[] {Connection.class}, invocationHandler); return connection; }
Example 12
Source File: LocalXADataSource.java From carbon-commons with Apache License 2.0 | 5 votes |
private void createConnectionPool() throws SQLException { PoolProperties props = new PoolProperties(); props.setUrl(this.getUrl()); props.setUsername(this.getUsername()); props.setPassword(this.getPassword()); props.setDriverClassName(this.getDriverClassName()); props.setValidationQuery(this.getValidationQuery()); this.connectionPool = new ConnectionPool(props); }
Example 13
Source File: SQLService.java From odo with Apache License 2.0 | 5 votes |
/** * Obtain instance of the SQL Service * * @return instance of SQLService * @throws Exception exception */ public static SQLService getInstance() throws Exception { if (_instance == null) { _instance = new SQLService(); _instance.startServer(); // default pool size is 20 // can be overriden by env variable int dbPool = 20; if (Utils.getEnvironmentOptionValue(Constants.SYS_DATABASE_POOL_SIZE) != null) { dbPool = Integer.valueOf(Utils.getEnvironmentOptionValue(Constants.SYS_DATABASE_POOL_SIZE)); } // initialize connection pool PoolProperties p = new PoolProperties(); String connectString = "jdbc:h2:tcp://" + _instance.databaseHost + ":" + _instance.port + "/./" + _instance.databaseName + "/proxydb;MULTI_THREADED=true;AUTO_RECONNECT=TRUE;AUTOCOMMIT=ON"; p.setUrl(connectString); p.setDriverClassName("org.h2.Driver"); p.setUsername("sa"); p.setJmxEnabled(true); p.setTestWhileIdle(false); p.setTestOnBorrow(true); p.setValidationQuery("SELECT 1"); p.setTestOnReturn(false); p.setValidationInterval(5000); p.setTimeBetweenEvictionRunsMillis(30000); p.setMaxActive(dbPool); p.setInitialSize(5); p.setMaxWait(30000); p.setRemoveAbandonedTimeout(60); p.setMinEvictableIdleTimeMillis(30000); p.setMinIdle(10); p.setLogAbandoned(true); p.setRemoveAbandoned(true); _instance.datasource = new DataSource(); _instance.datasource.setPoolProperties(p); } return _instance; }
Example 14
Source File: PoolPropertiesHelper.java From das with Apache License 2.0 | 4 votes |
public PoolProperties convert(DataSourceConfigure config) { PoolProperties properties = new PoolProperties(); /** * It is assumed that user name/password/url/driver class name are provided in pool config If not, it should be * provided by the config provider */ properties.setUrl(config.getConnectionUrl()); properties.setUsername(config.getUserName()); properties.setPassword(config.getPassword()); properties.setDriverClassName(config.getDriverClass()); properties.setTestWhileIdle(config.getBooleanProperty(TESTWHILEIDLE, DEFAULT_TESTWHILEIDLE)); properties.setTestOnBorrow(config.getBooleanProperty(TESTONBORROW, DEFAULT_TESTONBORROW)); properties.setTestOnReturn(config.getBooleanProperty(TESTONRETURN, DEFAULT_TESTONRETURN)); properties.setValidationQuery(config.getProperty(VALIDATIONQUERY, DEFAULT_VALIDATIONQUERY)); properties.setValidationQueryTimeout( config.getIntProperty(VALIDATIONQUERYTIMEOUT, DEFAULT_VALIDATIONQUERYTIMEOUT)); properties.setValidationInterval(config.getLongProperty(VALIDATIONINTERVAL, DEFAULT_VALIDATIONINTERVAL)); properties.setTimeBetweenEvictionRunsMillis( config.getIntProperty(TIMEBETWEENEVICTIONRUNSMILLIS, DEFAULT_TIMEBETWEENEVICTIONRUNSMILLIS)); properties.setMinEvictableIdleTimeMillis( config.getIntProperty(MINEVICTABLEIDLETIMEMILLIS, DEFAULT_MINEVICTABLEIDLETIMEMILLIS)); properties.setMaxAge(config.getIntProperty(MAX_AGE, DEFAULT_MAXAGE)); properties.setMaxActive(config.getIntProperty(MAXACTIVE, DEFAULT_MAXACTIVE)); properties.setMinIdle(config.getIntProperty(MINIDLE, DEFAULT_MINIDLE)); properties.setMaxWait(config.getIntProperty(MAXWAIT, DEFAULT_MAXWAIT)); properties.setInitialSize(config.getIntProperty(INITIALSIZE, DEFAULT_INITIALSIZE)); properties.setRemoveAbandonedTimeout( config.getIntProperty(REMOVEABANDONEDTIMEOUT, DEFAULT_REMOVEABANDONEDTIMEOUT)); properties.setRemoveAbandoned(config.getBooleanProperty(REMOVEABANDONED, DEFAULT_REMOVEABANDONED)); properties.setLogAbandoned(config.getBooleanProperty(LOGABANDONED, DEFAULT_LOGABANDONED)); properties.setConnectionProperties(config.getProperty(CONNECTIONPROPERTIES, DEFAULT_CONNECTIONPROPERTIES)); properties.setValidatorClassName(config.getProperty(VALIDATORCLASSNAME, DEFAULT_VALIDATORCLASSNAME)); String initSQL = config.getProperty(INIT_SQL); if (initSQL != null && !initSQL.isEmpty()) { properties.setInitSQL(initSQL); } String initSQL2 = config.getProperty(INIT_SQL2); if (initSQL2 != null && !initSQL2.isEmpty()) { properties.setInitSQL(initSQL2); } // This are current hard coded as default value properties.setJmxEnabled(DEFAULT_JMXENABLED); properties.setJdbcInterceptors(config.getProperty(JDBC_INTERCEPTORS, DEFAULT_JDBCINTERCEPTORS)); return properties; }
Example 15
Source File: PoolPropertiesHelper.java From dal with Apache License 2.0 | 4 votes |
public PoolProperties convert(DataSourceConfigure config) { PoolProperties properties = new PoolProperties(); /** * It is assumed that user name/password/url/driver class name are provided in pool config If not, it should be * provided by the config provider */ properties.setUrl(config.getConnectionUrl()); properties.setUsername(config.getUserName()); properties.setPassword(config.getPassword()); properties.setDriverClassName(config.getDriverClass()); properties.setTestWhileIdle(config.getBooleanProperty(TESTWHILEIDLE, DEFAULT_TESTWHILEIDLE)); properties.setTestOnBorrow(config.getBooleanProperty(TESTONBORROW, DEFAULT_TESTONBORROW)); properties.setTestOnReturn(config.getBooleanProperty(TESTONRETURN, DEFAULT_TESTONRETURN)); properties.setValidationQuery(config.getProperty(VALIDATIONQUERY, DEFAULT_VALIDATIONQUERY)); properties.setValidationQueryTimeout( config.getIntProperty(VALIDATIONQUERYTIMEOUT, DEFAULT_VALIDATIONQUERYTIMEOUT)); properties.setValidationInterval(config.getLongProperty(VALIDATIONINTERVAL, DEFAULT_VALIDATIONINTERVAL)); properties.setTimeBetweenEvictionRunsMillis( config.getIntProperty(TIMEBETWEENEVICTIONRUNSMILLIS, DEFAULT_TIMEBETWEENEVICTIONRUNSMILLIS)); properties.setMinEvictableIdleTimeMillis( config.getIntProperty(MINEVICTABLEIDLETIMEMILLIS, DEFAULT_MINEVICTABLEIDLETIMEMILLIS)); properties.setMaxAge(config.getIntProperty(MAX_AGE, DEFAULT_MAXAGE)); properties.setMaxActive(config.getIntProperty(MAXACTIVE, DEFAULT_MAXACTIVE)); properties.setMinIdle(config.getIntProperty(MINIDLE, DEFAULT_MINIDLE)); properties.setMaxWait(config.getIntProperty(MAXWAIT, DEFAULT_MAXWAIT)); properties.setInitialSize(config.getIntProperty(INITIALSIZE, DEFAULT_INITIALSIZE)); properties.setRemoveAbandonedTimeout( config.getIntProperty(REMOVEABANDONEDTIMEOUT, DEFAULT_REMOVEABANDONEDTIMEOUT)); properties.setRemoveAbandoned(config.getBooleanProperty(REMOVEABANDONED, DEFAULT_REMOVEABANDONED)); properties.setLogAbandoned(config.getBooleanProperty(LOGABANDONED, DEFAULT_LOGABANDONED)); properties.setConnectionProperties(config.getProperty(CONNECTIONPROPERTIES, DEFAULT_CONNECTIONPROPERTIES)); properties.setValidatorClassName(config.getProperty(VALIDATORCLASSNAME, DEFAULT_VALIDATORCLASSNAME)); String initSQL = config.getProperty(INIT_SQL); if (initSQL != null && !initSQL.isEmpty()) properties.setInitSQL(initSQL); String initSQL2 = config.getProperty(INIT_SQL2); if (initSQL2 != null && !initSQL2.isEmpty()) properties.setInitSQL(initSQL2); // This are current hard coded as default value properties.setJmxEnabled(DEFAULT_JMXENABLED); properties.setJdbcInterceptors(config.getProperty(JDBC_INTERCEPTORS, DEFAULT_JDBCINTERCEPTORS)); return properties; }
Example 16
Source File: TomcatJdbcDataSourcePool.java From Zebra with Apache License 2.0 | 4 votes |
@Override public DataSource build(DataSourceConfig config, boolean withDefaultValue) { PoolProperties properties = new PoolProperties(); properties.setUrl(config.getJdbcUrl()); properties.setUsername(config.getUsername()); properties.setPassword(config.getPassword()); properties.setDriverClassName(JdbcDriverClassHelper.getDriverClassNameByJdbcUrl(config.getJdbcUrl())); if (withDefaultValue) { properties.setInitialSize(getIntProperty(config, "initialPoolSize", 5)); properties.setMaxActive(getIntProperty(config, "maxPoolSize", 30)); properties.setMinIdle(getIntProperty(config, "minPoolSize", 5)); properties.setMaxIdle(getIntProperty(config, "maxPoolSize", 20)); properties.setMaxWait(getIntProperty(config, "checkoutTimeout", 1000)); properties.setValidationQuery(getStringProperty(config, "preferredTestQuery", "SELECT 1")); properties.setMinEvictableIdleTimeMillis(getIntProperty(config, "minEvictableIdleTimeMillis", 300000));// 5min properties.setTimeBetweenEvictionRunsMillis(getIntProperty(config, "timeBetweenEvictionRunsMillis", 30000)); // 30s properties.setNumTestsPerEvictionRun(getIntProperty(config, "numTestsPerEvictionRun", 6)); properties.setValidationQueryTimeout(getIntProperty(config, "validationQueryTimeout", 0)); properties.setValidationInterval(getIntProperty(config, "validationInterval", 30000));// 30s properties.setRemoveAbandonedTimeout(getIntProperty(config, "removeAbandonedTimeout", 300)); if (StringUtils.isNotBlank(getStringProperty(config, "connectionInitSql", null))) { properties.setInitSQL(getStringProperty(config, "connectionInitSql", null)); } properties.setTestWhileIdle(true); properties.setTestOnBorrow(false); properties.setTestOnReturn(false); properties.setRemoveAbandoned(true); } else { try { PropertiesInit<PoolProperties> propertiesInit = new PropertiesInit<PoolProperties>(properties); propertiesInit.initPoolProperties(config); } catch (Exception e) { throw new ZebraConfigException( String.format("tomcat-jdbc dataSource [%s] created error : ", config.getId()), e); } } org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource(); datasource.setPoolProperties(properties); this.pool = datasource; LOGGER.info(String.format("New dataSource [%s] created.", config.getId())); return this.pool; }