001: /*
002: * Copyright 2007 The Kuali Foundation
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.rice.database;
017:
018: import java.sql.SQLException;
019:
020: import javax.transaction.TransactionManager;
021:
022: import org.enhydra.jdbc.pool.StandardXAPoolDataSource;
023: import org.enhydra.jdbc.standard.StandardXADataSource;
024: import org.kuali.rice.exceptions.RiceRuntimeException;
025: import org.springframework.beans.factory.DisposableBean;
026: import org.springframework.beans.factory.InitializingBean;
027:
028: /**
029: * StandardXAPoolDataSource subclass that adds some convienance getters and setters and implements our Lifecycle interface.
030: */
031: public class XAPoolDataSource extends StandardXAPoolDataSource
032: implements InitializingBean, DisposableBean {
033:
034: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
035: .getLogger(XAPoolDataSource.class);
036:
037: private static final long serialVersionUID = -3698043954102287887L;
038: public static final String DRIVER_CLASS_NAME = "driverClassName";
039: public static final String URL = "url";
040: public static final String USERNAME = "username";
041: public static final String PASSWORD = "password";
042: public static final String MAX_SIZE = "maxSize";
043: public static final String MIN_SIZE = "minSize";
044: public static final String MAX_WAIT = "maxWait";
045: public static final String VALIDATION_QUERY = "validationQuery";
046:
047: private StandardXADataSource dataSource = new StandardXADataSource();
048:
049: public XAPoolDataSource() {
050: setDataSource(this .dataSource);
051: // NOTE: the following line prevents a bug in XAPool from manifesting itself where
052: // prepared statements aren't closed resulting in a "maximum open cursors exceeded" message
053: // from the Oracle JDBC driver
054: this .dataSource.setPreparedStmtCacheSize(0);
055: setCheckLevelObject(2);
056: }
057:
058: public void afterPropertiesSet() {
059: }
060:
061: public void destroy() {
062: LOG.info("Destroying WorkflowManagedDatasource.");
063: shutdown(true);
064: }
065:
066: public String getDriverClassName() throws SQLException {
067: return this .dataSource.getDriverName();
068: }
069:
070: public long getMaxWait() {
071: return super .getDeadLockMaxWait();
072: }
073:
074: public String getUrl() {
075: return this .dataSource.getUrl();
076: }
077:
078: public String getUsername() {
079: return this .dataSource.getUser();
080: }
081:
082: public String getValidationQuery() {
083: return super .getJdbcTestStmt();
084: }
085:
086: public void setBeanName(String dataSourceName) {
087: this .dataSourceName = dataSourceName;
088: }
089:
090: public void setDriverClassName(String driverClassName) {
091: try {
092: this .dataSource.setDriverName(driverClassName);
093: } catch (SQLException e) {
094: throw new RiceRuntimeException(
095: "Problem setting the driver name to: "
096: + driverClassName, e);
097: }
098: }
099:
100: public void setMaxWait(long maxWait) {
101: super .setDeadLockMaxWait(maxWait);
102: }
103:
104: public void setPassword(String password) {
105: // passwrd needs to be set in both places or else there will be an error
106: this .dataSource.setPassword(password);
107: super .setPassword(password);
108: }
109:
110: public void setTransactionManager(
111: TransactionManager transactionManager) {
112: this .dataSource.setTransactionManager(transactionManager);
113: }
114:
115: public void setUrl(String url) {
116: this .dataSource.setUrl(url);
117: }
118:
119: public void setUsername(String username) {
120: // username needs to be set in both places or else there will be an error
121: this .dataSource.setUser(username);
122: super .setUser(username);
123: }
124:
125: public void setValidationQuery(String validationQuery) {
126: super.setJdbcTestStmt(validationQuery);
127: }
128:
129: }
|