View Javadoc

1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.core.database;
17  
18  import java.sql.SQLException;
19  
20  import javax.transaction.TransactionManager;
21  
22  import org.enhydra.jdbc.pool.StandardXAPoolDataSource;
23  import org.kuali.rice.core.exception.RiceRuntimeException;
24  import org.springframework.beans.factory.DisposableBean;
25  import org.springframework.beans.factory.InitializingBean;
26  
27  /**
28   * StandardXAPoolDataSource subclass that adds some convienance getters and setters and implements our Lifecycle interface.
29   * 
30   * @deprecated We will be removing this file from a future release in order to get rid of our dependencies on XAPool.  If you
31   * desire to continue using JOTM and XAPool, please configure using org.enhyrdra.jdbc.standard.StandardXADataSource directly
32   * instead of using this class.
33   */
34  public class XAPoolDataSource extends StandardXAPoolDataSource implements InitializingBean, DisposableBean {
35  
36      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(XAPoolDataSource.class);
37  
38      private static final long serialVersionUID = -3698043954102287887L;
39      public static final String DRIVER_CLASS_NAME = "driverClassName";
40      public static final String URL = "url";
41      public static final String USERNAME = "username";
42      public static final String PASSWORD = "password";
43      public static final String MAX_SIZE = "maxSize";
44      public static final String MIN_SIZE = "minSize";
45      public static final String MAX_WAIT = "maxWait";
46      public static final String VALIDATION_QUERY = "validationQuery";
47  
48      private RiceXADataSource dataSource = new RiceXADataSource();
49      private boolean started = false;
50  
51      public XAPoolDataSource() {
52          setDataSource(this.dataSource);
53          setPreparedStmtCacheSize(0);
54          setCheckLevelObject(2);
55      }
56  
57      public void afterPropertiesSet() throws Exception {
58      }
59  
60      public void destroy() throws Exception {
61          LOG.info("Destroying WorkflowManagedDatasource.");
62          shutdown(true);
63          this.started = false;
64      }
65  
66      public boolean isStarted() {
67          return this.started;
68      }
69  
70      public String getDriverClassName() throws SQLException {
71          return this.dataSource.getDriverName();
72      }
73  
74      public long getMaxWait() {
75          return super.getDeadLockMaxWait();
76      }
77  
78      public String getUrl() {
79          return this.dataSource.getUrl();
80      }
81  
82      public String getUsername() {
83          return this.dataSource.getUser();
84      }
85  
86      public String getValidationQuery() {
87          return super.getJdbcTestStmt();
88      }
89  
90      public void setBeanName(String dataSourceName) {
91          this.dataSourceName = dataSourceName;
92      }
93  
94      public void setDriverClassName(String driverClassName) {
95          try {
96              this.dataSource.setDriverName(driverClassName);
97          } catch (SQLException e) {
98              throw new RiceRuntimeException("Problem setting the driver name to: " + driverClassName, e);
99          }
100     }
101 
102     public void setMaxWait(long maxWait) {
103         super.setDeadLockMaxWait(maxWait);
104     }
105 
106     public void setPassword(String password) {
107         // passwrd needs to be set in both places or else there will be an error
108         this.dataSource.setPassword(password);
109         super.setPassword(password);
110     }
111 
112     public void setTransactionManager(TransactionManager transactionManager) {
113         this.dataSource.setTransactionManager(transactionManager);
114     }
115 
116     public void setUrl(String url) {
117         this.dataSource.setUrl(url);
118     }
119 
120     public void setUsername(String username) {
121         // username needs to be set in both places or else there will be an error
122         this.dataSource.setUser(username);
123         super.setUser(username);
124     }
125 
126     public void setValidationQuery(String validationQuery) {
127         super.setJdbcTestStmt(validationQuery);
128     }
129 
130     public void setPreparedStmtCacheSize(int preparedStatementCacheSize) {
131     	this.dataSource.setPreparedStatementCacheSize(preparedStatementCacheSize);
132     }
133 }