KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > c3p0 > DriverManagerDataSourceFactory


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.c3p0;
25
26 import java.beans.PropertyChangeEvent JavaDoc;
27 import java.sql.SQLException JavaDoc;
28 import java.util.Properties JavaDoc;
29 import javax.sql.DataSource JavaDoc;
30
31 /**
32  * <P>A static factory that creates DataSources which simply forward
33  * calls to java.sql.DriverManager without any pooling or other fanciness.</P>
34  *
35  * <P>The DataSources returned are Refereneable and Serializable; they should
36  * be suitable for placement in a wide variety of JNDI Naming Services.</P>
37  *
38  * @deprecated Use the new factories in {@link com.mchange.v2.c3p0.DataSources}. See examples.
39  */

40 public final class DriverManagerDataSourceFactory
41 {
42     /**
43      * Creates an unpooled DataSource that users <TT>java.sql.DriverManager</TT>
44      * behind the scenes to acquire Connections.
45      *
46      * @param driverClass a jdbc driver class that can resolve <TT>jdbcUrl</TT>.
47      * @param jdbcUrl the jdbcUrl of the RDBMS that Connections should be made to.
48      * @param dfltUser a username (may be null) for authentication to the RDBMS
49      * @param dfltPassword a password (may be null) for authentication to the RDBMS
50      * @param refFactoryLoc a codebase url where JNDI clients can find the
51      * c3p0 libraries. Use null if clients will be expected to have the
52      * libraries available locally.
53      */

54     public static DataSource JavaDoc create(String JavaDoc driverClass,
55                     String JavaDoc jdbcUrl,
56                     String JavaDoc dfltUser,
57                     String JavaDoc dfltPassword,
58                     String JavaDoc refFactoryLoc)
59     throws SQLException JavaDoc
60     {
61         DriverManagerDataSource out = new DriverManagerDataSource();
62         out.setDriverClass( driverClass );
63         out.setJdbcUrl( jdbcUrl );
64         out.setUser( dfltUser );
65         out.setPassword( dfltPassword );
66         out.setFactoryClassLocation( refFactoryLoc );
67         return out;
68     }
69
70     /**
71      * Creates an unpooled DataSource that users <TT>java.sql.DriverManager</TT>
72      * behind the scenes to acquire Connections.
73      *
74      * @param driverClass a jdbc driver class that can resolve <TT>jdbcUrl</TT>.
75      * @param jdbcUrl the jdbcUrl of the RDBMS that Connections should be made to.
76      * @param props propertis object that should be passed to DriverManager.getConnection()
77      * @param refFactoryLoc a codebase url where JNDI clients can find the
78      * c3p0 libraries. Use null if clients will be expected to have the
79      * libraries available locally.
80      */

81     public static DataSource JavaDoc create(String JavaDoc driverClass,
82                     String JavaDoc jdbcUrl,
83                     Properties JavaDoc props,
84                     String JavaDoc refFactoryLoc)
85     throws SQLException JavaDoc
86     {
87         DriverManagerDataSource out = new DriverManagerDataSource();
88         out.setDriverClass( driverClass );
89         out.setJdbcUrl( jdbcUrl );
90         out.setProperties( props );
91         out.setFactoryClassLocation( refFactoryLoc );
92         return out;
93     }
94
95     /**
96      * Creates an unpooled DataSource that users <TT>java.sql.DriverManager</TT>
97      * behind the scenes to acquire Connections.
98      *
99      * @param driverClass a jdbc driver class that can resolve <TT>jdbcUrl</TT>.
100      * @param jdbcUrl the jdbcUrl of the RDBMS that Connections should be made to.
101      * @param dfltUser a username (may be null) for authentication to the RDBMS
102      * @param dfltPassword a password (may be null) for authentication to the RDBMS
103      */

104     public static DataSource JavaDoc create(String JavaDoc driverClass,
105                     String JavaDoc jdbcUrl,
106                     String JavaDoc dfltUser,
107                     String JavaDoc dfltPassword)
108     throws SQLException JavaDoc
109     { return create( driverClass, jdbcUrl, dfltUser, dfltPassword, null ); }
110
111     /**
112      * Creates an unpooled DataSource that users <TT>java.sql.DriverManager</TT>
113      * behind the scenes to acquire Connections.
114      *
115      * @param driverClass a jdbc driver class that can resolve <TT>jdbcUrl</TT>.
116      * @param jdbcUrl the jdbcUrl of the RDBMS that Connections should be made to.
117      */

118     public static DataSource JavaDoc create(String JavaDoc driverClass, String JavaDoc jdbcUrl)
119     throws SQLException JavaDoc
120     { return DriverManagerDataSourceFactory.create( driverClass, jdbcUrl, (String JavaDoc) null, null); }
121
122     /**
123      * Creates an unpooled DataSource that users <TT>java.sql.DriverManager</TT>
124      * behind the scenes to acquire Connections.
125      *
126      * <P>Warning: since you do not set the driver class, the resulting DataSource
127      * will be less suitable for use via JNDI: JNDI clients will have to
128      * know the driver class and make sure themselves that it is preloaded!!!
129      *
130      * @param jdbcUrl the jdbcUrl of the RDBMS that Connections should be made to.
131      * @param dfltUser a username (may be null) for authentication to the RDBMS
132      * @param dfltPassword a password (may be null) for authentication to the RDBMS
133      */

134     public static DataSource JavaDoc create(String JavaDoc jdbcUrl, String JavaDoc dfltUser, String JavaDoc dfltPassword)
135     throws SQLException JavaDoc
136     { return DriverManagerDataSourceFactory.create( null, jdbcUrl, dfltUser, dfltPassword ); }
137
138     /**
139      * Creates an unpooled DataSource that users <TT>java.sql.DriverManager</TT>
140      * behind the scenes to acquire Connections.
141      *
142      * <P>Warning: since you do not set the driver class, the resulting DataSource
143      * will be less suitable for use via JNDI: JNDI clients will have to
144      * know the driver class and make sure themselves that it is preloaded!!!
145      *
146      * @param jdbcUrl the jdbcUrl of the RDBMS that Connections should be made to.
147      */

148     public static DataSource JavaDoc create(String JavaDoc jdbcUrl)
149     throws SQLException JavaDoc
150     { return DriverManagerDataSourceFactory.create( null, jdbcUrl, (String JavaDoc) null, null ); }
151
152     private DriverManagerDataSourceFactory()
153     {}
154 }
155
Popular Tags