org.apache.tomcat.jdbc.pool.DataSourceFactory Java Examples
The following examples show how to use
org.apache.tomcat.jdbc.pool.DataSourceFactory.
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: DataSourceManager.java From metacat with Apache License 2.0 | 6 votes |
private synchronized void createDataSource(final String name, final Map props) { if (dataSources.get(name) == null) { final Properties dataSourceProperties = new Properties(); props.forEach((key, value) -> { final String prop = String.valueOf(key); if (prop.startsWith(JDO_PREFIX)) { dataSourceProperties.put(prop.substring(JDO_PREFIX.length()), value); } }); if (!dataSourceProperties.isEmpty()) { try { final DataSource dataSource = new DataSourceFactory().createDataSource(dataSourceProperties); // // Explicitly registering the datasource with the JMX server bean. // ((org.apache.tomcat.jdbc.pool.DataSource) dataSource) .preRegister(null, new ObjectName(String.format("jdbc.pool:name=%s", name))); dataSources.put(name, dataSource); } catch (Exception e) { throw new RuntimeException(String .format("Failed to load the data source for catalog %s with error [%s]", name, e.getMessage()), e); } } } }
Example #2
Source File: SakaiBasicDataSource.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Set the default transaction isolation level from a string value, based on the settings and values in java.sql.Connection * * @param defaultTransactionIsolation */ public void setDefaultTransactionIsolationString(String defaultTransactionIsolation) { if ((defaultTransactionIsolation == null) || (defaultTransactionIsolation.trim().length() == 0)) { setDefaultTransactionIsolation(DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_NONE")) { setDefaultTransactionIsolation(Connection.TRANSACTION_NONE); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_READ_UNCOMMITTED")) { setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_READ_COMMITTED")) { setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_REPEATABLE_READ")) { setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_SERIALIZABLE")) { setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); } else { setDefaultTransactionIsolation(DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION); log.warn("invalid transaction isolation level: " + defaultTransactionIsolation); } }
Example #3
Source File: SakaiBasicDataSource.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Set the default transaction isolation level from a string value, based on the settings and values in java.sql.Connection * * @param defaultTransactionIsolation */ public void setDefaultTransactionIsolationString(String defaultTransactionIsolation) { if ((defaultTransactionIsolation == null) || (defaultTransactionIsolation.trim().length() == 0)) { setDefaultTransactionIsolation(DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_NONE")) { setDefaultTransactionIsolation(Connection.TRANSACTION_NONE); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_READ_UNCOMMITTED")) { setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_READ_COMMITTED")) { setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_REPEATABLE_READ")) { setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); } else if (defaultTransactionIsolation.trim().equalsIgnoreCase("TRANSACTION_SERIALIZABLE")) { setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); } else { setDefaultTransactionIsolation(DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION); log.warn("invalid transaction isolation level: " + defaultTransactionIsolation); } }
Example #4
Source File: DefaultProperties.java From Tomcat8-Source-Read with MIT License | 4 votes |
public DefaultProperties() { setDbProperties(new Properties()); //mysql //url = System.getProperty("url","jdbc:mysql://localhost:3306/mysql?autoReconnect=true"); //driverClassName = System.getProperty("driverClassName","com.mysql.jdbc.Driver"); //derby //url = System.getProperty("url","jdbc:derby:derbyDB;create=true"); //driverClassName = System.getProperty("driverClassName","org.apache.derby.jdbc.EmbeddedDriver"); setUrl(System.getProperty("url","jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE")); setDriverClassName(System.getProperty("driverClassName","org.h2.Driver")); System.setProperty("h2.serverCachedObjects", "10000"); setPassword(System.getProperty("password","password")); setUsername(System.getProperty("username","root")); setValidationQuery(System.getProperty("validationQuery","SELECT 1")); setDefaultAutoCommit(Boolean.TRUE); setDefaultReadOnly(Boolean.FALSE); setDefaultTransactionIsolation(DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION); setConnectionProperties(null); setDefaultCatalog(null); setInitialSize(10); setMaxActive(100); setMaxIdle(getInitialSize()); setMinIdle(getInitialSize()); setMaxWait(10000); setTestOnBorrow(true); setTestOnReturn(false); setTestWhileIdle(true); setTimeBetweenEvictionRunsMillis(5000); setNumTestsPerEvictionRun(0); setMinEvictableIdleTimeMillis(1000); setRemoveAbandoned(true); setRemoveAbandonedTimeout(5000); setLogAbandoned(true); setValidationInterval(0); //always validate setInitSQL(null); setTestOnConnect(false); getDbProperties().setProperty("user",getUsername()); getDbProperties().setProperty("password",getPassword()); }
Example #5
Source File: DefaultProperties.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
public DefaultProperties() { setDbProperties(new Properties()); //mysql //url = System.getProperty("url","jdbc:mysql://localhost:3306/mysql?autoReconnect=true"); //driverClassName = System.getProperty("driverClassName","com.mysql.jdbc.Driver"); //derby //url = System.getProperty("url","jdbc:derby:derbyDB;create=true"); //driverClassName = System.getProperty("driverClassName","org.apache.derby.jdbc.EmbeddedDriver"); setUrl(System.getProperty("url","jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE")); setDriverClassName(System.getProperty("driverClassName","org.h2.Driver")); System.setProperty("h2.serverCachedObjects", "10000"); setPassword(System.getProperty("password","password")); setUsername(System.getProperty("username","root")); setValidationQuery(System.getProperty("validationQuery","SELECT 1")); setDefaultAutoCommit(Boolean.TRUE); setDefaultReadOnly(Boolean.FALSE); setDefaultTransactionIsolation(DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION); setConnectionProperties(null); setDefaultCatalog(null); setInitialSize(10); setMaxActive(100); setMaxIdle(getInitialSize()); setMinIdle(getInitialSize()); setMaxWait(10000); setTestOnBorrow(true); setTestOnReturn(false); setTestWhileIdle(true); setTimeBetweenEvictionRunsMillis(5000); setNumTestsPerEvictionRun(0); setMinEvictableIdleTimeMillis(1000); setRemoveAbandoned(true); setRemoveAbandonedTimeout(5000); setLogAbandoned(true); setValidationInterval(0); //always validate setInitSQL(null); setTestOnConnect(false); getDbProperties().setProperty("user",getUsername()); getDbProperties().setProperty("password",getPassword()); }
Example #6
Source File: DefaultProperties.java From tomcatsrc with Apache License 2.0 | 4 votes |
public DefaultProperties() { setDbProperties(new Properties()); //mysql //url = System.getProperty("url","jdbc:mysql://localhost:3306/mysql?autoReconnect=true"); //driverClassName = System.getProperty("driverClassName","com.mysql.jdbc.Driver"); //derby //url = System.getProperty("url","jdbc:derby:derbyDB;create=true"); //driverClassName = System.getProperty("driverClassName","org.apache.derby.jdbc.EmbeddedDriver"); setUrl(System.getProperty("url","jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE")); setDriverClassName(System.getProperty("driverClassName","org.h2.Driver")); System.setProperty("h2.serverCachedObjects", "10000"); setPassword(System.getProperty("password","password")); setUsername(System.getProperty("username","root")); setValidationQuery(System.getProperty("validationQuery","SELECT 1")); setDefaultAutoCommit(Boolean.TRUE); setDefaultReadOnly(Boolean.FALSE); setDefaultTransactionIsolation(DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION); setConnectionProperties(null); setDefaultCatalog(null); setInitialSize(10); setMaxActive(100); setMaxIdle(getInitialSize()); setMinIdle(getInitialSize()); setMaxWait(10000); setTestOnBorrow(true); setTestOnReturn(false); setTestWhileIdle(true); setTimeBetweenEvictionRunsMillis(5000); setNumTestsPerEvictionRun(0); setMinEvictableIdleTimeMillis(1000); setRemoveAbandoned(true); setRemoveAbandonedTimeout(5000); setLogAbandoned(true); setValidationInterval(0); //always validate setInitSQL(null); setTestOnConnect(false); getDbProperties().setProperty("user",getUsername()); getDbProperties().setProperty("password",getPassword()); }