View Javadoc

1   /*
2    * Copyright 2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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  
17  package org.apache.commons.scaffold.sql;
18  
19  
20  /**
21   * ConnectionAdaptor for Poolman.
22   * <p>
23   * When an application initializes it should create an instance
24   * of this class to use Poolman for SQL connections.
25   *
26   * @author Ted Husted
27   * @version $Revision: 155464 $ $Date: 2005-02-26 13:26:54 +0000 (Sat, 26 Feb 2005) $
28   */
29  
30  import java.sql.SQLException;
31  
32  import javax.sql.DataSource;
33  
34  import com.codestudio.sql.PoolMan;
35  
36  
37  public class PoolmanAdaptor extends ConnectionAdaptor {
38  
39      /**
40       * An exception message to throw if poolman returns null.
41       */
42      private static final String POOLMAN_MESSAGE = "Connection pool " +
43          "not available. Check your poolman.xml config, and be sure " +
44          "you are using a valid dbname parameter (use dbname, not jndiName)";
45  
46  
47          // Inherits JavaDoc
48      protected DataSource getDataSource(String key)
49              throws SQLException {
50  
51          if (null==key) return null;
52  
53          return PoolMan.findDataSource(key);
54  
55      }
56  
57  
58       // Required
59      public PoolmanAdaptor() {
60  
61          setMessage(POOLMAN_MESSAGE);
62          if (null==pool) pool = this;
63  
64      }
65  
66  
67  } // end PoolmanAdaptor
68