2
Copyright (C) 2002-2007 MySQL AB
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.
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.
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.
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
24
package com.mysql.jdbc;
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;
33
public class JDBC4ClientInfoProviderSP implements JDBC4ClientInfoProvider {
34
PreparedStatement setClientInfoSp;
36
PreparedStatement getClientInfoSp;
38
PreparedStatement getClientInfoBulkSp;
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
53
String catalog = "".equals(clientInfoCatalog) ? conn.getCatalog()
56
this.setClientInfoSp = ((com.mysql.jdbc.Connection) conn)
57
.clientPrepareStatement("CALL " + identifierQuote + catalog
58
+ identifierQuote + "." + identifierQuote
59
+ setClientInfoSpName + identifierQuote + "(?, ?)");
61
this.getClientInfoSp = ((com.mysql.jdbc.Connection) conn)
62
.clientPrepareStatement("CALL" + identifierQuote + catalog
63
+ identifierQuote + "." + identifierQuote
64
+ getClientInfoSpName + identifierQuote + "(?)");
66
this.getClientInfoBulkSp = ((com.mysql.jdbc.Connection) conn)
67
.clientPrepareStatement("CALL " + identifierQuote + catalog
68
+ identifierQuote + "." + identifierQuote
69
+ getClientInfoBulkSpName + identifierQuote + "()");
72
public synchronized void destroy() throws SQLException {
73
if (this.setClientInfoSp != null) {
74
this.setClientInfoSp.close();
75
this.setClientInfoSp = null;
78
if (this.getClientInfoSp != null) {
79
this.getClientInfoSp.close();
80
this.getClientInfoSp = null;
83
if (this.getClientInfoBulkSp != null) {
84
this.getClientInfoBulkSp.close();
85
this.getClientInfoBulkSp = null;
89
public synchronized Properties getClientInfo(java.sql.Connection conn)
93
Properties props = new Properties();
96
this.getClientInfoBulkSp.execute();
98
rs = this.getClientInfoBulkSp.getResultSet();
101
props.setProperty(rs.getString(1), rs.getString(2));
112
public synchronized String getClientInfo(java.sql.Connection conn,
113
String name) throws SQLException {
116
String clientInfo = null;
119
this.getClientInfoSp.setString(1, name);
120
this.getClientInfoSp.execute();
122
rs = this.getClientInfoSp.getResultSet();
125
clientInfo = rs.getString(1);
136
public synchronized void setClientInfo(java.sql.Connection conn,
137
Properties properties) throws SQLClientInfoException {
139
Enumeration propNames = properties.propertyNames();
141
while (propNames.hasMoreElements()) {
142
String name = (String) propNames.nextElement();
143
String value = properties.getProperty(name);
145
setClientInfo(conn, name, value);
147
} catch (SQLException sqlEx) {
148
SQLClientInfoException clientInfoEx = new SQLClientInfoException();
149
clientInfoEx.initCause(sqlEx);
155
public synchronized void setClientInfo(java.sql.Connection conn,
156
String name, String value) throws SQLClientInfoException {
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);
b'\\ No newline at end of file'