1 | /* |
---|
2 | Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
---|
3 | |
---|
4 | |
---|
5 | The MySQL Connector/J is licensed under the terms of the GPLv2 |
---|
6 | <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors. |
---|
7 | There are special exceptions to the terms and conditions of the GPLv2 as it is applied to |
---|
8 | this software, see the FLOSS License Exception |
---|
9 | <http://www.mysql.com/about/legal/licensing/foss-exception.html>. |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify it under the terms |
---|
12 | of the GNU General Public License as published by the Free Software Foundation; version 2 |
---|
13 | of the License. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
---|
16 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
17 | See the GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License along with this |
---|
20 | program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth |
---|
21 | Floor, Boston, MA 02110-1301 USA |
---|
22 | |
---|
23 | */ |
---|
24 | |
---|
25 | package com.mysql.jdbc; |
---|
26 | |
---|
27 | import java.sql.ResultSet; |
---|
28 | import java.sql.RowIdLifetime; |
---|
29 | import java.sql.SQLException; |
---|
30 | import java.sql.Types; |
---|
31 | import java.util.ArrayList; |
---|
32 | |
---|
33 | import java.util.List; |
---|
34 | |
---|
35 | import com.mysql.jdbc.Field; |
---|
36 | |
---|
37 | public class JDBC4DatabaseMetaData extends DatabaseMetaData { |
---|
38 | public JDBC4DatabaseMetaData(MySQLConnection connToSet, String databaseToSet) { |
---|
39 | super(connToSet, databaseToSet); |
---|
40 | } |
---|
41 | |
---|
42 | public RowIdLifetime getRowIdLifetime() throws SQLException { |
---|
43 | return RowIdLifetime.ROWID_UNSUPPORTED; |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Returns true if this either implements the interface argument or is directly or indirectly a wrapper |
---|
48 | * for an object that does. Returns false otherwise. If this implements the interface then return true, |
---|
49 | * else if this is a wrapper then return the result of recursively calling <code>isWrapperFor</code> on the wrapped |
---|
50 | * object. If this does not implement the interface and is not a wrapper, return false. |
---|
51 | * This method should be implemented as a low-cost operation compared to <code>unwrap</code> so that |
---|
52 | * callers can use this method to avoid expensive <code>unwrap</code> calls that may fail. If this method |
---|
53 | * returns true then calling <code>unwrap</code> with the same argument should succeed. |
---|
54 | * |
---|
55 | * @param interfaces a Class defining an interface. |
---|
56 | * @return true if this implements the interface or directly or indirectly wraps an object that does. |
---|
57 | * @throws java.sql.SQLException if an error occurs while determining whether this is a wrapper |
---|
58 | * for an object with the given interface. |
---|
59 | * @since 1.6 |
---|
60 | */ |
---|
61 | public boolean isWrapperFor(Class<?> iface) throws SQLException { |
---|
62 | // This works for classes that aren't actually wrapping |
---|
63 | // anything |
---|
64 | return iface.isInstance(this); |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * Returns an object that implements the given interface to allow access to non-standard methods, |
---|
69 | * or standard methods not exposed by the proxy. |
---|
70 | * The result may be either the object found to implement the interface or a proxy for that object. |
---|
71 | * If the receiver implements the interface then that is the object. If the receiver is a wrapper |
---|
72 | * and the wrapped object implements the interface then that is the object. Otherwise the object is |
---|
73 | * the result of calling <code>unwrap</code> recursively on the wrapped object. If the receiver is not a |
---|
74 | * wrapper and does not implement the interface, then an <code>SQLException</code> is thrown. |
---|
75 | * |
---|
76 | * @param iface A Class defining an interface that the result must implement. |
---|
77 | * @return an object that implements the interface. May be a proxy for the actual implementing object. |
---|
78 | * @throws java.sql.SQLException If no object found that implements the interface |
---|
79 | * @since 1.6 |
---|
80 | */ |
---|
81 | public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException { |
---|
82 | try { |
---|
83 | // This works for classes that aren't actually wrapping |
---|
84 | // anything |
---|
85 | return iface.cast(this); |
---|
86 | } catch (ClassCastException cce) { |
---|
87 | throw SQLError.createSQLException("Unable to unwrap to " + iface.toString(), |
---|
88 | SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.conn.getExceptionInterceptor()); |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * Retrieves a list of the client info properties |
---|
94 | * that the driver supports. The result set contains the following columns |
---|
95 | * <p> |
---|
96 | * <ol> |
---|
97 | * <li><b>NAME</b> String=> The name of the client info property<br> |
---|
98 | * <li><b>MAX_LEN</b> int=> The maximum length of the value for the property<br> |
---|
99 | * <li><b>DEFAULT_VALUE</b> String=> The default value of the property<br> |
---|
100 | * <li><b>DESCRIPTION</b> String=> A description of the property. This will typically |
---|
101 | * contain information as to where this property is |
---|
102 | * stored in the database. |
---|
103 | * </ol> |
---|
104 | * <p> |
---|
105 | * The <code>ResultSet</code> is sorted by the NAME column |
---|
106 | * <p> |
---|
107 | * @return A <code>ResultSet</code> object; each row is a supported client info |
---|
108 | * property |
---|
109 | * <p> |
---|
110 | * @exception SQLException if a database access error occurs |
---|
111 | * <p> |
---|
112 | * @since 1.6 |
---|
113 | */ |
---|
114 | public ResultSet getClientInfoProperties() |
---|
115 | throws SQLException { |
---|
116 | // We don't have any built-ins, we actually support whatever |
---|
117 | // the client wants to provide, however we don't have a way |
---|
118 | // to express this with the interface given |
---|
119 | Field[] fields = new Field[4]; |
---|
120 | fields[0] = new Field("", "NAME", Types.VARCHAR, 255); |
---|
121 | fields[1] = new Field("", "MAX_LEN", Types.INTEGER, 10); |
---|
122 | fields[2] = new Field("", "DEFAULT_VALUE", Types.VARCHAR, 255); |
---|
123 | fields[3] = new Field("", "DESCRIPTION", Types.VARCHAR, 255); |
---|
124 | |
---|
125 | ArrayList tuples = new ArrayList(); |
---|
126 | |
---|
127 | return buildResultSet(fields, tuples, this.conn); |
---|
128 | } |
---|
129 | |
---|
130 | public boolean autoCommitFailureClosesAllResultSets() throws SQLException { |
---|
131 | return false; |
---|
132 | } |
---|
133 | |
---|
134 | /** |
---|
135 | * Retrieves a description of the system and user functions available |
---|
136 | * in the given catalog. |
---|
137 | * <P> |
---|
138 | * Only system and user function descriptions matching the schema and |
---|
139 | * function name criteria are returned. They are ordered by |
---|
140 | * <code>FUNCTION_CAT</code>, <code>FUNCTION_SCHEM</code>, |
---|
141 | * <code>FUNCTION_NAME</code> and |
---|
142 | * <code>SPECIFIC_ NAME</code>. |
---|
143 | * |
---|
144 | * <P>Each function description has the the following columns: |
---|
145 | * <OL> |
---|
146 | * <LI><B>FUNCTION_CAT</B> String => function catalog (may be <code>null</code>) |
---|
147 | * <LI><B>FUNCTION_SCHEM</B> String => function schema (may be <code>null</code>) |
---|
148 | * <LI><B>FUNCTION_NAME</B> String => function name. This is the name |
---|
149 | * used to invoke the function |
---|
150 | * <LI><B>REMARKS</B> String => explanatory comment on the function |
---|
151 | * <LI><B>FUNCTION_TYPE</B> short => kind of function: |
---|
152 | * <UL> |
---|
153 | * <LI>functionResultUnknown - Cannot determine if a return value |
---|
154 | * or table will be returned |
---|
155 | * <LI> functionNoTable- Does not return a table |
---|
156 | * <LI> functionReturnsTable - Returns a table |
---|
157 | * </UL> |
---|
158 | * <LI><B>SPECIFIC_NAME</B> String => the name which uniquely identifies |
---|
159 | * this function within its schema. This is a user specified, or DBMS |
---|
160 | * generated, name that may be different then the <code>FUNCTION_NAME</code> |
---|
161 | * for example with overload functions |
---|
162 | * </OL> |
---|
163 | * <p> |
---|
164 | * A user may not have permission to execute any of the functions that are |
---|
165 | * returned by <code>getFunctions</code> |
---|
166 | * |
---|
167 | * @param catalog a catalog name; must match the catalog name as it |
---|
168 | * is stored in the database; "" retrieves those without a catalog; |
---|
169 | * <code>null</code> means that the catalog name should not be used to narrow |
---|
170 | * the search |
---|
171 | * @param schemaPattern a schema name pattern; must match the schema name |
---|
172 | * as it is stored in the database; "" retrieves those without a schema; |
---|
173 | * <code>null</code> means that the schema name should not be used to narrow |
---|
174 | * the search |
---|
175 | * @param functionNamePattern a function name pattern; must match the |
---|
176 | * function name as it is stored in the database |
---|
177 | * @return <code>ResultSet</code> - each row is a function description |
---|
178 | * @exception SQLException if a database access error occurs |
---|
179 | * @see #getSearchStringEscape |
---|
180 | * @since 1.6 |
---|
181 | */ |
---|
182 | public java.sql.ResultSet getFunctions(String catalog, String schemaPattern, |
---|
183 | String functionNamePattern) throws SQLException { |
---|
184 | Field[] fields = new Field[6]; |
---|
185 | |
---|
186 | fields[0] = new Field("", "FUNCTION_CAT", Types.CHAR, 255); |
---|
187 | fields[1] = new Field("", "FUNCTION_SCHEM", Types.CHAR, 255); |
---|
188 | fields[2] = new Field("", "FUNCTION_NAME", Types.CHAR, 255); |
---|
189 | fields[3] = new Field("", "REMARKS", Types.CHAR, 255); |
---|
190 | fields[4] = new Field("", "FUNCTION_TYPE", Types.SMALLINT, 6); |
---|
191 | fields[5] = new Field("", "SPECIFIC_NAME", Types.CHAR, 255); |
---|
192 | |
---|
193 | return getProceduresAndOrFunctions( |
---|
194 | fields, |
---|
195 | catalog, |
---|
196 | schemaPattern, |
---|
197 | functionNamePattern, |
---|
198 | false, |
---|
199 | true); |
---|
200 | } |
---|
201 | |
---|
202 | protected int getJDBC4FunctionNoTableConstant() { |
---|
203 | return functionNoTable; |
---|
204 | } |
---|
205 | } |
---|