1   package com.javaranch.unittest.helper.sql.pool;
2   
3   
4   import java.io.PrintWriter;
5   import java.sql.Connection;
6   import java.sql.DriverManager;
7   
8   import javax.naming.Reference;
9   import javax.sql.DataSource;
10  
11  /*******************************************************************************
12   *  Copyright (c) 2005, 2006 Imola Informatica.
13   *  All rights reserved. This program and the accompanying materials
14   *  are made available under the terms of the LGPL License v2.1
15   *  which accompanies this distribution, and is available at
16   *  http://www.gnu.org/licenses/lgpl.html
17   *******************************************************************************/
18  class SimpleDataSource extends Reference implements DataSource
19  {
20  
21      String dbDriver;
22      String dbServer;
23      String dbLogin;
24      String dbPassword;
25      SimpleDataSource()
26      {
27          super( SimpleDataSource.class.getName() );
28      }
29  
30      /**
31       * Method getConnection creates Connection to the database.
32       *
33       *
34       * @return New Connection each time.
35       *
36       * @throws java.sql.SQLException
37       *
38       */
39      public Connection getConnection()
40      throws java.sql.SQLException
41      {
42          return getConnection( dbLogin, dbPassword );
43      }
44  
45      /**
46       * Method getConnection
47       *
48       *
49       * @param parm1
50       * @param parm2
51       *
52       * @return
53       *
54       * @throws java.sql.SQLException
55       *
56       */
57      public Connection getConnection( String dbLogin, String dbPassword )
58      throws java.sql.SQLException
59      {
60        try
61        {
62            Class.forName( dbDriver );
63        }
64        catch ( ClassNotFoundException cnfe )
65        {
66            throw new java.sql.SQLException( cnfe.getMessage() );
67        }
68        return DriverManager.getConnection( dbServer, dbLogin, dbPassword );
69      }
70  
71      /**
72       * Method getLogWriter not yet implemented.
73       *
74       *
75       * @return
76       *
77       * @throws java.sql.SQLException
78       *
79       */
80      public PrintWriter getLogWriter()
81      throws java.sql.SQLException
82      {
83  
84          /**@todo: Implement this javax.sql.DataSource method*/
85          throw new java.lang.UnsupportedOperationException(
86              "Method getLogWriter() not yet implemented." );
87      }
88  
89      /**
90       * Method getLoginTimeout not yet implemented.
91       *
92       *
93       * @return
94       *
95       * @throws java.sql.SQLException
96       *
97       */
98      public int getLoginTimeout()
99      throws java.sql.SQLException
100     {
101 
102         /**@todo: Implement this javax.sql.DataSource method*/
103         throw new java.lang.UnsupportedOperationException(
104             "Method getLoginTimeout() not yet implemented." );
105     }
106 
107     /**
108      * Method setLogWriter not yet implemented.
109      *
110      *
111      * @param parm1
112      *
113      * @throws java.sql.SQLException
114      *
115      */
116     public void setLogWriter( PrintWriter parm1 )
117     throws java.sql.SQLException
118     {
119 
120         /**@todo: Implement this javax.sql.DataSource method*/
121         throw new java.lang.UnsupportedOperationException(
122             "Method setLogWriter() not yet implemented." );
123     }
124 
125     /**
126      * Method setLoginTimeout not yet implemented.
127      *
128      *
129      * @param parm1
130      *
131      * @throws java.sql.SQLException
132      *
133      */
134     public void setLoginTimeout( int parm1 )
135     throws java.sql.SQLException
136     {
137 
138         /**@todo: Implement this javax.sql.DataSource method*/
139         throw new java.lang.UnsupportedOperationException(
140             "Method setLoginTimeout() not yet implemented." );
141     }
142 }