KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > hajdbc > sql > MockDataSourceFactory


1 /*
2  * HA-JDBC: High-Availability JDBC
3  * Copyright (c) 2004-2006 Paul Ferraro
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2.1 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: ferraro@users.sourceforge.net
20  */

21 package net.sf.hajdbc.sql;
22
23 import java.io.PrintWriter JavaDoc;
24 import java.io.StringWriter JavaDoc;
25 import java.sql.Connection JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import javax.naming.Context JavaDoc;
30 import javax.naming.Name JavaDoc;
31 import javax.naming.spi.ObjectFactory JavaDoc;
32 import javax.sql.DataSource JavaDoc;
33
34 /**
35  * Mock data source factory that creates a mock data source that references a mock connection.
36  *
37  * @author Paul Ferraro
38  * @since 1.1
39  */

40 public class MockDataSourceFactory implements ObjectFactory JavaDoc
41 {
42     /**
43      * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
44      */

45     public Object JavaDoc getObjectInstance(Object JavaDoc arg0, Name JavaDoc arg1, Context JavaDoc arg2, Hashtable JavaDoc arg3) throws Exception JavaDoc
46     {
47         return new MockDataSource();
48     }
49     
50     private class MockDataSource implements DataSource
51     {
52         /**
53          * @see javax.sql.DataSource#getConnection()
54          */

55         public Connection getConnection() throws SQLException JavaDoc
56         {
57             return new MockConnection();
58         }
59
60         /**
61          * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
62          */

63         public Connection getConnection(String JavaDoc arg0, String JavaDoc arg1) throws SQLException JavaDoc
64         {
65             return this.getConnection();
66         }
67
68         /**
69          * @see javax.sql.DataSource#getLogWriter()
70          */

71         public PrintWriter JavaDoc getLogWriter() throws SQLException JavaDoc
72         {
73             return new PrintWriter JavaDoc(new StringWriter JavaDoc());
74         }
75
76         /**
77          * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
78          */

79         public void setLogWriter(PrintWriter JavaDoc writer) throws SQLException JavaDoc
80         {
81         }
82
83         /**
84          * @see javax.sql.DataSource#setLoginTimeout(int)
85          */

86         public void setLoginTimeout(int timeout) throws SQLException JavaDoc
87         {
88         }
89
90         /**
91          * @see javax.sql.DataSource#getLoginTimeout()
92          */

93         public int getLoginTimeout() throws SQLException JavaDoc
94         {
95             return 0;
96         }
97     }
98 }
99
Popular Tags