Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to Jasig under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Jasig licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.jasig.portlet.utils.jdbc;
 
 
 
Factory bean that creates a Tomcat Pooled org.apache.tomcat.jdbc.pool.DataSource instance. Handles JMX registration via an autowired javax.management.MBeanServer. Also supports delayed setting of the validation query via DelayedValidationQueryResolver.

Author(s):
Eric Dalquist
 
         implements BeanNameAwarePoolConfiguration {
     
     private final PoolConfiguration poolConfiguration = new PoolProperties();
     private MBeanServer mBeanServer;
     private String baseObjectName;
 
     private ObjectName objectName;
 
     @Override
     public void setBeanName(String name) {
         this..setName(name);
     }
 
     @Autowired(required = false)
     public void setmBeanServer(MBeanServer mBeanServer) {
         this. = mBeanServer;
     }
 
     @Autowired(required = false)
     public void setDelayedValidationQueryResolver(
             DelayedValidationQueryResolver delayedValidationQueryResolver) {
         this. = delayedValidationQueryResolver;
     }
 
     public void setBaseObjectName(String baseObjectName) {
         this. = baseObjectName;
     }
 
     @Override
     public Class<?> getObjectType() {
         return DataSource.class;
     }
 
     @Override
     protected DataSource createInstance() throws Exception {
         final DataSource dataSource = new DataSource(this.);
 
         if (this. != null) {
             try {
                 final ConnectionPool pool = dataSource.createPool();
                 final org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = pool
                         .getJmxPool();
     
                 
                 this. = ObjectName.getInstance(this. + this..getName());
                 .info("Registering DataSource " + this..getName() + " in MBeanServer under name: " + this.);
                 
                 final ObjectInstance instance = this..registerMBean(
                         jmxPoolthis.);
                 this. = instance.getObjectName();
             }
             catch (Exception e) {
                 .warn("Failed to register connection pool with MBeanServer. JMX information will not be available for: " + this..getName(), e);
            }
        }
        
        if (dataSource.getValidationQuery() == null && this. != null) {
            .info("Attempting to resolve validation query for: " + this..getName());
            try {
                    @Override
                    public void setValidationQuery(String validationQuery) {
                        .info("Resolved validation query '" + validationQuery + "' for " + .getName());
                        dataSource.setValidationQuery(validationQuery);
                    }
                });
            }
            catch (Exception e) {
                .warn("Failed to resolve validation query for: " + this..getName(), e);
            }
        }
        return dataSource;
    }
    @Override
    protected void destroyInstance(DataSource instancethrows Exception {
        if (this. != null) {
            try {
                this..unregisterMBean(this.);
            }
            catch (Exception e) {
                .warn("Failed to unregister connection pool with MBeanServer for: " + this..getName(), e);
            }
        }
        instance.close();
    }
    @Override
    public void setAbandonWhenPercentageFull(int percentage) {
        this..setAbandonWhenPercentageFull(percentage);
    }
    @Override
    public int getAbandonWhenPercentageFull() {
        return this..getAbandonWhenPercentageFull();
    }
    @Override
    public boolean isFairQueue() {
        return this..isFairQueue();
    }
    @Override
    public void setFairQueue(boolean fairQueue) {
        this..setFairQueue(fairQueue);
    }
    @Override
    public boolean isAccessToUnderlyingConnectionAllowed() {
    }
    @Override
            boolean accessToUnderlyingConnectionAllowed) {
        this.
                .setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
    }
    @Override
    public String getConnectionProperties() {
        return this..getConnectionProperties();
    }
    @Override
    public void setConnectionProperties(String connectionProperties) {
        this..setConnectionProperties(connectionProperties);
    }
    @Override
    public Properties getDbProperties() {
        return this..getDbProperties();
    }
    @Override
    public void setDbProperties(Properties dbProperties) {
        this..setDbProperties(dbProperties);
    }
    @Override
    public Boolean isDefaultAutoCommit() {
        return this..isDefaultAutoCommit();
    }
    @Override
    public Boolean getDefaultAutoCommit() {
        return this..getDefaultAutoCommit();
    }
    @Override
    public void setDefaultAutoCommit(Boolean defaultAutoCommit) {
        this..setDefaultAutoCommit(defaultAutoCommit);
    }
    @Override
    public String getDefaultCatalog() {
        return this..getDefaultCatalog();
    }
    @Override
    public void setDefaultCatalog(String defaultCatalog) {
        this..setDefaultCatalog(defaultCatalog);
    }
    @Override
    public Boolean isDefaultReadOnly() {
        return this..isDefaultReadOnly();
    }
    @Override
    public Boolean getDefaultReadOnly() {
        return this..getDefaultReadOnly();
    }
    @Override
    public void setDefaultReadOnly(Boolean defaultReadOnly) {
        this..setDefaultReadOnly(defaultReadOnly);
    }
    @Override
    public int getDefaultTransactionIsolation() {
    }
    @Override
    public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
        this.
                .setDefaultTransactionIsolation(defaultTransactionIsolation);
    }
    @Override
    public String getDriverClassName() {
        return this..getDriverClassName();
    }
    @Override
    public void setDriverClassName(String driverClassName) {
        this..setDriverClassName(driverClassName);
    }
    @Override
    public int getInitialSize() {
        return this..getInitialSize();
    }
    @Override
    public void setInitialSize(int initialSize) {
        this..setInitialSize(initialSize);
    }
    @Override
    public boolean isLogAbandoned() {
        return this..isLogAbandoned();
    }
    @Override
    public void setLogAbandoned(boolean logAbandoned) {
        this..setLogAbandoned(logAbandoned);
    }
    @Override
    public int getMaxActive() {
        return this..getMaxActive();
    }
    @Override
    public void setMaxActive(int maxActive) {
        this..setMaxActive(maxActive);
    }
    @Override
    public int getMaxIdle() {
        return this..getMaxIdle();
    }
    @Override
    public void setMaxIdle(int maxIdle) {
        this..setMaxIdle(maxIdle);
    }
    @Override
    public int getMaxWait() {
        return this..getMaxWait();
    }
    @Override
    public void setMaxWait(int maxWait) {
        this..setMaxWait(maxWait);
    }
    @Override
    public int getMinEvictableIdleTimeMillis() {
        return this..getMinEvictableIdleTimeMillis();
    }
    @Override
    public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
        this.
                .setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    }
    @Override
    public int getMinIdle() {
        return this..getMinIdle();
    }
    @Override
    public void setMinIdle(int minIdle) {
        this..setMinIdle(minIdle);
    }
    @Override
    public String getName() {
        return this..getName();
    }
    @Override
    public void setName(String name) {
        this..setName(name);
    }
    @Override
    public int getNumTestsPerEvictionRun() {
        return this..getNumTestsPerEvictionRun();
    }
    @Override
    public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
        this.
                .setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    }
    @Override
    public String getPassword() {
        return this..getPassword();
    }
    @Override
    public void setPassword(String password) {
        this..setPassword(password);
    }
    @Override
    public String getPoolName() {
        return this..getPoolName();
    }
    @Override
    public String getUsername() {
        return this..getUsername();
    }
    @Override
    public void setUsername(String username) {
        this..setUsername(username);
    }
    @Override
    public boolean isRemoveAbandoned() {
        return this..isRemoveAbandoned();
    }
    @Override
    public void setRemoveAbandoned(boolean removeAbandoned) {
        this..setRemoveAbandoned(removeAbandoned);
    }
    @Override
    public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
        this.
                .setRemoveAbandonedTimeout(removeAbandonedTimeout);
    }
    @Override
    public int getRemoveAbandonedTimeout() {
        return this..getRemoveAbandonedTimeout();
    }
    @Override
    public boolean isTestOnBorrow() {
        return this..isTestOnBorrow();
    }
    @Override
    public void setTestOnBorrow(boolean testOnBorrow) {
        this..setTestOnBorrow(testOnBorrow);
    }
    @Override
    public boolean isTestOnReturn() {
        return this..isTestOnReturn();
    }
    @Override
    public void setTestOnReturn(boolean testOnReturn) {
        this..setTestOnReturn(testOnReturn);
    }
    @Override
    public boolean isTestWhileIdle() {
        return this..isTestWhileIdle();
    }
    @Override
    public void setTestWhileIdle(boolean testWhileIdle) {
        this..setTestWhileIdle(testWhileIdle);
    }
    @Override
    public int getTimeBetweenEvictionRunsMillis() {
    }
    @Override
            int timeBetweenEvictionRunsMillis) {
        this.
                .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    }
    @Override
    public String getUrl() {
        return this..getUrl();
    }
    @Override
    public void setUrl(String url) {
        this..setUrl(url);
    }
    @Override
    public String getValidationQuery() {
        return this..getValidationQuery();
    }
    @Override
    public void setValidationQuery(String validationQuery) {
        this..setValidationQuery(validationQuery);
    }
    @Override
    public String getValidatorClassName() {
        return this..getValidatorClassName();
    }
    @Override
    public void setValidatorClassName(String className) {
        this..setValidatorClassName(className);
    }
    @Override
    public Validator getValidator() {
        return this..getValidator();
    }
    @Override
    public void setValidator(Validator validator) {
        this..setValidator(validator);
    }
    @Override
    public long getValidationInterval() {
        return this..getValidationInterval();
    }
    @Override
    public void setValidationInterval(long validationInterval) {
        this..setValidationInterval(validationInterval);
    }
    @Override
    public String getInitSQL() {
        return this..getInitSQL();
    }
    @Override
    public void setInitSQL(String initSQL) {
        this..setInitSQL(initSQL);
    }
    @Override
    public boolean isTestOnConnect() {
        return this..isTestOnConnect();
    }
    @Override
    public void setTestOnConnect(boolean testOnConnect) {
        this..setTestOnConnect(testOnConnect);
    }
    @Override
    public String getJdbcInterceptors() {
        return this..getJdbcInterceptors();
    }
    @Override
    public void setJdbcInterceptors(String jdbcInterceptors) {
        this..setJdbcInterceptors(jdbcInterceptors);
    }
    @Override
        return this..getJdbcInterceptorsAsArray();
    }
    @Override
    public boolean isJmxEnabled() {
        return this..isJmxEnabled();
    }
    @Override
    public void setJmxEnabled(boolean jmxEnabled) {
        this..setJmxEnabled(jmxEnabled);
    }
    @Override
    public boolean isPoolSweeperEnabled() {
        return this..isPoolSweeperEnabled();
    }
    @Override
    public boolean isUseEquals() {
        return this..isUseEquals();
    }
    @Override
    public void setUseEquals(boolean useEquals) {
        this..setUseEquals(useEquals);
    }
    @Override
    public long getMaxAge() {
        return this..getMaxAge();
    }
    @Override
    public void setMaxAge(long maxAge) {
        this..setMaxAge(maxAge);
    }
    @Override
    public boolean getUseLock() {
        return this..getUseLock();
    }
    @Override
    public void setUseLock(boolean useLock) {
        this..setUseLock(useLock);
    }
    @Override
    public void setSuspectTimeout(int seconds) {
        this..setSuspectTimeout(seconds);
    }
    @Override
    public int getSuspectTimeout() {
        return this..getSuspectTimeout();
    }
    @Override
    public void setDataSource(Object ds) {
        this..setDataSource(ds);
    }
    @Override
    public Object getDataSource() {
        return this..getDataSource();
    }
    @Override
    public void setDataSourceJNDI(String jndiDS) {
        this..setDataSourceJNDI(jndiDS);
    }
    @Override
    public String getDataSourceJNDI() {
        return this..getDataSourceJNDI();
    }
    @Override
    public boolean isAlternateUsernameAllowed() {
        return this..isAlternateUsernameAllowed();
    }
    @Override
    public void setAlternateUsernameAllowed(boolean alternateUsernameAllowed) {
        this.
                .setAlternateUsernameAllowed(alternateUsernameAllowed);
    }
    @Override
    public void setCommitOnReturn(boolean commitOnReturn) {
        this..setCommitOnReturn(commitOnReturn);
    }
    @Override
    public boolean getCommitOnReturn() {
        return this..getCommitOnReturn();
    }
    @Override
    public void setRollbackOnReturn(boolean rollbackOnReturn) {
        this..setRollbackOnReturn(rollbackOnReturn);
    }
    @Override
    public boolean getRollbackOnReturn() {
        return this..getRollbackOnReturn();
    }
    @Override
            boolean useDisposableConnectionFacade) {
        this.
                .setUseDisposableConnectionFacade(useDisposableConnectionFacade);
    }
    @Override
    public boolean getUseDisposableConnectionFacade() {
    }
    @Override
    public void setLogValidationErrors(boolean logValidationErrors) {
        this..setLogValidationErrors(logValidationErrors);
    }
    @Override
    public boolean getLogValidationErrors() {
        return this..getLogValidationErrors();
    }
    @Override
    public boolean getPropagateInterruptState() {
        return this..getPropagateInterruptState();
    }
    @Override
    public void setPropagateInterruptState(boolean propagateInterruptState) {
        this.
                .setPropagateInterruptState(propagateInterruptState);
    }
New to GrepCode? Check out our FAQ X