~ubuntu-branches/ubuntu/oneiric/mysql-connector-java/oneiric

« back to all changes in this revision

Viewing changes to src/com/mysql/jdbc/JDBC4ClientInfoProviderSP.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2007-11-30 10:34:13 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20071130103413-mxm4lpfrr4fnjbuj
Tags: 5.1.5+dfsg-1
* New upstream release. Closes: #450718.
* Add Homepage field to debian/control.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 2002-2007 MySQL AB
 
3
 
 
4
 This program is free software; you can redistribute it and/or modify
 
5
 it under the terms of version 2 of the GNU General Public License as 
 
6
 published by the Free Software Foundation.
 
7
 
 
8
 There are special exceptions to the terms and conditions of the GPL 
 
9
 as it is applied to this software. View the full text of the 
 
10
 exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
 
11
 software distribution.
 
12
 
 
13
 This program is distributed in the hope that it will be useful,
 
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 GNU General Public License for more details.
 
17
 
 
18
 You should have received a copy of the GNU General Public License
 
19
 along with this program; if not, write to the Free Software
 
20
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 
 
22
 */
 
23
 
 
24
package com.mysql.jdbc;
 
25
 
 
26
import java.sql.PreparedStatement;
 
27
import java.sql.ResultSet;
 
28
import java.sql.SQLException;
 
29
import java.sql.SQLClientInfoException;
 
30
import java.util.Enumeration;
 
31
import java.util.Properties;
 
32
 
 
33
public class JDBC4ClientInfoProviderSP implements JDBC4ClientInfoProvider {
 
34
        PreparedStatement setClientInfoSp;
 
35
 
 
36
        PreparedStatement getClientInfoSp;
 
37
 
 
38
        PreparedStatement getClientInfoBulkSp;
 
39
 
 
40
        public synchronized void initialize(java.sql.Connection conn,
 
41
                        Properties configurationProps) throws SQLException {
 
42
                String identifierQuote = conn.getMetaData().getIdentifierQuoteString();
 
43
                String setClientInfoSpName = configurationProps.getProperty(
 
44
                                "clientInfoSetSPName", "setClientInfo");
 
45
                String getClientInfoSpName = configurationProps.getProperty(
 
46
                                "clientInfoGetSPName", "getClientInfo");
 
47
                String getClientInfoBulkSpName = configurationProps.getProperty(
 
48
                                "clientInfoGetBulkSPName", "getClientInfoBulk");
 
49
                String clientInfoCatalog = configurationProps.getProperty(
 
50
                                "clientInfoCatalog", ""); // "" means use current from
 
51
                                                                                        // connection
 
52
 
 
53
                String catalog = "".equals(clientInfoCatalog) ? conn.getCatalog()
 
54
                                : clientInfoCatalog;
 
55
 
 
56
                this.setClientInfoSp = ((com.mysql.jdbc.Connection) conn)
 
57
                                .clientPrepareStatement("CALL " + identifierQuote + catalog
 
58
                                                + identifierQuote + "." + identifierQuote
 
59
                                                + setClientInfoSpName + identifierQuote + "(?, ?)");
 
60
                
 
61
                this.getClientInfoSp = ((com.mysql.jdbc.Connection) conn)
 
62
                                .clientPrepareStatement("CALL" + identifierQuote + catalog
 
63
                                                + identifierQuote + "." + identifierQuote
 
64
                                                + getClientInfoSpName + identifierQuote + "(?)");
 
65
                
 
66
                this.getClientInfoBulkSp = ((com.mysql.jdbc.Connection) conn)
 
67
                                .clientPrepareStatement("CALL " + identifierQuote + catalog
 
68
                                                + identifierQuote + "." + identifierQuote
 
69
                                                + getClientInfoBulkSpName + identifierQuote + "()");
 
70
        }
 
71
 
 
72
        public synchronized void destroy() throws SQLException {
 
73
                if (this.setClientInfoSp != null) {
 
74
                        this.setClientInfoSp.close();
 
75
                        this.setClientInfoSp = null;
 
76
                }
 
77
 
 
78
                if (this.getClientInfoSp != null) {
 
79
                        this.getClientInfoSp.close();
 
80
                        this.getClientInfoSp = null;
 
81
                }
 
82
 
 
83
                if (this.getClientInfoBulkSp != null) {
 
84
                        this.getClientInfoBulkSp.close();
 
85
                        this.getClientInfoBulkSp = null;
 
86
                }
 
87
        }
 
88
 
 
89
        public synchronized Properties getClientInfo(java.sql.Connection conn)
 
90
                        throws SQLException {
 
91
                ResultSet rs = null;
 
92
 
 
93
                Properties props = new Properties();
 
94
                
 
95
                try {
 
96
                        this.getClientInfoBulkSp.execute();
 
97
 
 
98
                        rs = this.getClientInfoBulkSp.getResultSet();
 
99
 
 
100
                        while (rs.next()) {
 
101
                                props.setProperty(rs.getString(1), rs.getString(2));
 
102
                        }
 
103
                } finally {
 
104
                        if (rs != null) {
 
105
                                rs.close();
 
106
                        }
 
107
                }
 
108
                
 
109
                return props;
 
110
        }
 
111
 
 
112
        public synchronized String getClientInfo(java.sql.Connection conn,
 
113
                        String name) throws SQLException {
 
114
                ResultSet rs = null;
 
115
 
 
116
                String clientInfo = null;
 
117
                
 
118
                try {
 
119
                        this.getClientInfoSp.setString(1, name);
 
120
                        this.getClientInfoSp.execute();
 
121
 
 
122
                        rs = this.getClientInfoSp.getResultSet();
 
123
 
 
124
                        if (rs.next()) {
 
125
                                clientInfo = rs.getString(1);
 
126
                        }
 
127
                } finally {
 
128
                        if (rs != null) {
 
129
                                rs.close();
 
130
                        }
 
131
                }
 
132
                
 
133
                return clientInfo;
 
134
        }
 
135
 
 
136
        public synchronized void setClientInfo(java.sql.Connection conn,
 
137
                        Properties properties) throws SQLClientInfoException {
 
138
                try {
 
139
                        Enumeration propNames = properties.propertyNames();
 
140
 
 
141
                        while (propNames.hasMoreElements()) {
 
142
                                String name = (String) propNames.nextElement();
 
143
                                String value = properties.getProperty(name);
 
144
 
 
145
                                setClientInfo(conn, name, value);
 
146
                        }
 
147
                } catch (SQLException sqlEx) {
 
148
                        SQLClientInfoException clientInfoEx = new SQLClientInfoException();
 
149
                        clientInfoEx.initCause(sqlEx);
 
150
 
 
151
                        throw clientInfoEx;
 
152
                }
 
153
        }
 
154
 
 
155
        public synchronized void setClientInfo(java.sql.Connection conn,
 
156
                        String name, String value) throws SQLClientInfoException {
 
157
                try {
 
158
                        this.setClientInfoSp.setString(1, name);
 
159
                        this.setClientInfoSp.setString(2, value);
 
160
                        this.setClientInfoSp.execute();
 
161
                } catch (SQLException sqlEx) {
 
162
                        SQLClientInfoException clientInfoEx = new SQLClientInfoException();
 
163
                        clientInfoEx.initCause(sqlEx);
 
164
 
 
165
                        throw clientInfoEx;
 
166
                }
 
167
        }
 
168
}
 
 
b'\\ No newline at end of file'