KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > net > ClientJDBCObjectFactoryImpl


1 /*
2  
3    Derby - Class org.apache.derby.client.net.ClientJDBCObjectFactoryImpl
4  
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11  
12       http://www.apache.org/licenses/LICENSE-2.0
13  
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19  
20  */

21
22 package org.apache.derby.client.net;
23
24 import java.rmi.UnexpectedException JavaDoc;
25 import java.sql.Connection JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import org.apache.derby.client.ClientPooledConnection;
28 import org.apache.derby.client.am.CallableStatement;
29 import org.apache.derby.client.am.ClientJDBCObjectFactory;
30 import org.apache.derby.client.am.LogicalConnection;
31 import org.apache.derby.client.am.ParameterMetaData;
32 import org.apache.derby.client.am.PreparedStatement;
33 import org.apache.derby.client.am.Configuration;
34 import org.apache.derby.client.am.LogWriter;
35 import org.apache.derby.client.am.Agent;
36 import org.apache.derby.client.am.Section;
37 import org.apache.derby.client.am.Statement;
38 import org.apache.derby.client.am.SqlException;
39 import org.apache.derby.client.am.Cursor;
40 import org.apache.derby.jdbc.ClientBaseDataSource;
41 import org.apache.derby.client.am.ColumnMetaData;
42
43 /**
44  * Implements the the ClientJDBCObjectFactory interface and returns the classes
45  * that implement the JDBC3.0/2.0 interfaces
46  * For Eg. newCallableStatement would return
47  * org.apache.derby.client.am.CallableStatement
48  */

49
50 public class ClientJDBCObjectFactoryImpl implements ClientJDBCObjectFactory{
51     /**
52      * Returns an instance of org.apache.derby.client.ClientPooledConnection
53      */

54     public ClientPooledConnection newClientPooledConnection(ClientBaseDataSource ds,
55             LogWriter logWriter,String JavaDoc user,
56             String JavaDoc password) throws SQLException JavaDoc {
57         return new ClientPooledConnection(ds,logWriter,user,password);
58     }
59     /**
60      * Returns an instance of org.apache.derby.client.ClientPooledConnection
61      */

62     public ClientPooledConnection newClientPooledConnection(ClientBaseDataSource ds,
63             LogWriter logWriter,String JavaDoc user,
64             String JavaDoc password,int rmId) throws SQLException JavaDoc {
65         return new ClientPooledConnection(ds,logWriter,user,password,rmId);
66     }
67     /**
68      * Returns an instance of org.apache.derby.client.am.CallableStatement.
69      *
70      * @param agent The instance of NetAgent associated with this
71      * CallableStatement object.
72      * @param connection The connection object associated with this
73      * PreparedStatement Object.
74      * @param sql A String object that is the SQL statement to be sent
75      * to the database.
76      * @param type One of the ResultSet type constants
77      * @param concurrency One of the ResultSet concurrency constants
78      * @param holdability One of the ResultSet holdability constants
79      * @param cpc The PooledConnection object that will be used to
80      * notify the PooledConnection reference of the Error
81      * Occurred and the Close events.
82      * @return a CallableStatement object
83      * @throws SqlException
84      */

85     public CallableStatement newCallableStatement(Agent agent,
86             org.apache.derby.client.am.Connection connection,
87             String JavaDoc sql,int type,int concurrency,
88             int holdability,ClientPooledConnection cpc) throws SqlException {
89         return new CallableStatement(agent,connection,sql,type,
90                 concurrency,holdability,cpc);
91     }
92    
93     /**
94      * Returns an instance of org.apache.derby.client.am.LogicalConnection
95      */

96     public LogicalConnection newLogicalConnection(
97                     org.apache.derby.client.am.Connection physicalConnection,
98                     ClientPooledConnection pooledConnection)
99         throws SqlException {
100         return new LogicalConnection(physicalConnection, pooledConnection);
101     }
102     
103     /**
104      * This method returns an instance of PreparedStatement
105      * which implements java.sql.PreparedStatement. It has the
106      * ClientPooledConnection as one of its parameters
107      * this is used to raise the Statement Events when the prepared
108      * statement is closed.
109      *
110      * @param agent The instance of NetAgent associated with this
111      * CallableStatement object.
112      * @param connection The connection object associated with this
113      * PreparedStatement Object.
114      * @param sql A String object that is the SQL statement to be sent
115      * to the database.
116      * @param section Section
117      * @param cpc The ClientPooledConnection wraps the underlying physical
118      * connection associated with this prepared statement.
119      * It is used to pass the Statement closed and the Statement
120      * error occurred events that occur back to the
121      * ClientPooledConnection.
122      * @return a PreparedStatement object
123      * @throws SqlException
124      */

125     public PreparedStatement newPreparedStatement(Agent agent,
126             org.apache.derby.client.am.Connection connection,
127             String JavaDoc sql,Section section,ClientPooledConnection cpc)
128             throws SqlException {
129         return new PreparedStatement(agent,connection,sql,section,cpc);
130     }
131     
132     /**
133      *
134      * This method returns an instance of PreparedStatement
135      * which implements java.sql.PreparedStatement.
136      * It has the ClientPooledConnection as one of its parameters
137      * this is used to raise the Statement Events when the prepared
138      * statement is closed.
139      *
140      * @param agent The instance of NetAgent associated with this
141      * CallableStatement object.
142      * @param connection The connection object associated with this
143      * PreparedStatement Object.
144      * @param sql A String object that is the SQL statement
145      * to be sent to the database.
146      * @param type One of the ResultSet type constants.
147      * @param concurrency One of the ResultSet concurrency constants.
148      * @param holdability One of the ResultSet holdability constants.
149      * @param autoGeneratedKeys a flag indicating whether auto-generated
150      * keys should be returned.
151      * @param columnNames an array of column names indicating the columns that
152      * should be returned from the inserted row or rows.
153      * @param cpc The ClientPooledConnection wraps the underlying physical
154      * connection associated with this prepared statement
155      * it is used to pass the Statement closed and the Statement
156      * error occurred events that occur back to the
157      * ClientPooledConnection.
158      * @return a PreparedStatement object
159      * @throws SqlException
160      *
161      */

162     public PreparedStatement newPreparedStatement(Agent agent,
163             org.apache.derby.client.am.Connection connection,
164             String JavaDoc sql,int type,int concurrency,int holdability,
165             int autoGeneratedKeys,String JavaDoc [] columnNames,
166             ClientPooledConnection cpc)
167             throws SqlException {
168         return new PreparedStatement(agent,connection,sql,type,concurrency,
169                 holdability,autoGeneratedKeys,columnNames,cpc);
170     }
171
172     /**
173      * returns an instance of org.apache.derby.client.net.NetConnection
174      */

175     public org.apache.derby.client.am.Connection newNetConnection(
176             org.apache.derby.client.am.LogWriter netLogWriter,
177             String JavaDoc databaseName,java.util.Properties JavaDoc properties)
178             throws SqlException {
179         return (org.apache.derby.client.am.Connection)
180         (new NetConnection((NetLogWriter)netLogWriter,databaseName,properties));
181     }
182     /**
183      * returns an instance of org.apache.derby.client.net.NetConnection
184      */

185     public org.apache.derby.client.am.Connection newNetConnection(
186             org.apache.derby.client.am.LogWriter netLogWriter,
187             org.apache.derby.jdbc.ClientBaseDataSource clientDataSource,
188             String JavaDoc user,String JavaDoc password) throws SqlException {
189         return (org.apache.derby.client.am.Connection)
190         (new NetConnection((NetLogWriter)netLogWriter,clientDataSource
191                 ,user,password));
192     }
193     /**
194      * returns an instance of org.apache.derby.client.net.NetConnection
195      */

196     public org.apache.derby.client.am.Connection newNetConnection(
197             org.apache.derby.client.am.LogWriter netLogWriter,
198             int driverManagerLoginTimeout,String JavaDoc serverName,
199             int portNumber,String JavaDoc databaseName,
200             java.util.Properties JavaDoc properties) throws SqlException {
201         return (org.apache.derby.client.am.Connection)
202         (new NetConnection((NetLogWriter)netLogWriter,driverManagerLoginTimeout,
203                 serverName,portNumber,databaseName,properties));
204     }
205     /**
206      * returns an instance of org.apache.derby.client.net.NetConnection
207      */

208     public org.apache.derby.client.am.Connection newNetConnection(
209             org.apache.derby.client.am.LogWriter netLogWriter,String JavaDoc user,
210             String JavaDoc password,
211             org.apache.derby.jdbc.ClientBaseDataSource dataSource,
212             int rmId,boolean isXAConn) throws SqlException {
213         return (org.apache.derby.client.am.Connection)
214         (new NetConnection((NetLogWriter)netLogWriter,user,password,dataSource,rmId,
215                 isXAConn));
216     }
217     /**
218      * returns an instance of org.apache.derby.client.net.NetConnection
219      */

220     public org.apache.derby.client.am.Connection newNetConnection(
221             org.apache.derby.client.am.LogWriter netLogWriter,
222             String JavaDoc ipaddr,int portNumber,
223             org.apache.derby.jdbc.ClientBaseDataSource dataSource,
224             boolean isXAConn) throws SqlException {
225         return (org.apache.derby.client.am.Connection)
226         new NetConnection((NetLogWriter)netLogWriter,ipaddr,portNumber,dataSource,
227                 isXAConn);
228     }
229     /**
230      * Returns an instance of org.apache.derby.client.net.NetConnection.
231      * @param netLogWriter Placeholder for NetLogWriter object associated
232      * with this connection.
233      * @param user user id for this connection.
234      * @param password password for this connection.
235      * @param dataSource The DataSource object passed from the PooledConnection
236      * object from which this constructor was called.
237      * @param rmId The Resource Manager ID for XA Connections
238      * @param isXAConn true if this is a XA connection
239      * @param cpc The ClientPooledConnection object from which this
240      * NetConnection constructor was called. This is used to
241      * pass StatementEvents back to the pooledConnection
242      * object.
243      * @return a org.apache.derby.client.am.Connection object
244      * @throws SqlException
245      */

246     public org.apache.derby.client.am.Connection newNetConnection(
247             org.apache.derby.client.am.LogWriter netLogWriter,String JavaDoc user,
248             String JavaDoc password,
249             org.apache.derby.jdbc.ClientBaseDataSource dataSource,
250             int rmId,boolean isXAConn,
251             ClientPooledConnection cpc) throws SqlException {
252         return (org.apache.derby.client.am.Connection)
253         (new NetConnection((NetLogWriter)netLogWriter,user,password,dataSource,rmId,
254                 isXAConn,cpc));
255     }
256     /**
257      * returns an instance of org.apache.derby.client.net.NetResultSet
258      */

259     public org.apache.derby.client.am.ResultSet newNetResultSet(Agent netAgent,
260             org.apache.derby.client.am.MaterialStatement netStatement,
261             Cursor cursor,
262             int qryprctyp,int sqlcsrhld,int qryattscr,int qryattsns,
263             int qryattset,long qryinsid,int actualResultSetType,
264             int actualResultSetConcurrency,
265             int actualResultSetHoldability) throws SqlException {
266         return new NetResultSet((NetAgent)netAgent,
267                 (NetStatement)netStatement,cursor,qryprctyp,sqlcsrhld,qryattscr,
268                 qryattsns,qryattset,qryinsid,actualResultSetType,
269                 actualResultSetConcurrency,actualResultSetHoldability);
270     }
271     /**
272      * returns an instance of org.apache.derby.client.net.NetDatabaseMetaData
273      */

274     public org.apache.derby.client.am.DatabaseMetaData newNetDatabaseMetaData(Agent netAgent,
275             org.apache.derby.client.am.Connection netConnection) {
276         return new NetDatabaseMetaData((NetAgent)netAgent,
277                 (NetConnection)netConnection);
278     }
279     
280     /**
281      * This method provides an instance of Statement
282      * @param agent Agent
283      * @param connection Connection
284      * @return a java.sql.Statement implementation
285      * @throws SqlException
286      *
287      */

288      public Statement newStatement(Agent agent, org.apache.derby.client.am.Connection connection)
289                                             throws SqlException {
290          return new Statement(agent,connection);
291      }
292      
293      /**
294      * This method provides an instance of Statement
295      * @param agent Agent
296      * @param connection Connection
297      * @param type int
298      * @param concurrency int
299      * @param holdability int
300      * @param autoGeneratedKeys int
301      * @param columnNames String[]
302      * @return a java.sql.Statement implementation
303      * @throws SqlException
304      *
305      */

306      public Statement newStatement(Agent agent,
307                      org.apache.derby.client.am.Connection connection, int type,
308                      int concurrency, int holdability,
309                      int autoGeneratedKeys, String JavaDoc[] columnNames)
310                      throws SqlException {
311          return new Statement(agent,connection,type,concurrency,holdability,
312                  autoGeneratedKeys,columnNames);
313      }
314      
315      /**
316      * Returns an instanceof ColumnMetaData
317      *
318      * @param logWriter LogWriter
319      * @return a ColumnMetaData implementation
320      *
321      */

322     public ColumnMetaData newColumnMetaData(LogWriter logWriter) {
323         return new ColumnMetaData(logWriter);
324     }
325
326     /**
327      * Returns an instanceof ColumnMetaData or ColumnMetaData40 depending
328      * on the jdk version under use
329      *
330      * @param logWriter LogWriter
331      * @param upperBound int
332      * @return a ColumnMetaData implementation
333      *
334      */

335     public ColumnMetaData newColumnMetaData(LogWriter logWriter, int upperBound) {
336         return new ColumnMetaData(logWriter,upperBound);
337     }
338     
339     /**
340      *
341      * returns an instance of ParameterMetaData
342      *
343      * @param columnMetaData ColumnMetaData
344      * @return a ParameterMetaData implementation
345      *
346      */

347     public ParameterMetaData newParameterMetaData(ColumnMetaData columnMetaData) {
348         return new ParameterMetaData(columnMetaData);
349     }
350 }
351
Popular Tags