Mercurial > hg > monetdb-java
annotate src/main/java/org/monetdb/jdbc/MonetWrapper.java @ 451:3dfcd06fd8ba
Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 04 Mar 2021 18:57:51 +0100 (2021-03-04) |
parents | 95d15f1d750d |
children | 6aa38e8c0f2d |
rev | line source |
---|---|
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 /* |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
5 * |
406
bf9f6b6ecf40
Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
391
diff
changeset
|
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
7 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
8 |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
9 package org.monetdb.jdbc; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
10 |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
11 import java.sql.SQLException; |
262
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
12 import java.sql.SQLFeatureNotSupportedException; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
13 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
14 /** |
451
3dfcd06fd8ba
Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
425
diff
changeset
|
15 *<pre> |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
16 * A Wrapper class which provide the ability to retrieve the delegate instance |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
17 * when the instance in question is in fact a proxy class. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
18 * |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
19 * The wrapper pattern is employed by many JDBC driver implementations to provide |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
20 * extensions beyond the traditional JDBC API that are specific to a data source. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
21 * Developers may wish to gain access to these resources that are wrapped (the delegates) |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
22 * as proxy class instances representing the the actual resources. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
23 * This class contains a standard mechanism to access these wrapped resources |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
24 * represented by their proxy, to permit direct access to the resource delegates. |
451
3dfcd06fd8ba
Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
425
diff
changeset
|
25 *</pre> |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
26 * |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
27 * @author Fabian Groffen, Martin van Dinther |
425
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
28 * @version 1.2 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
29 */ |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
30 public class MonetWrapper implements java.sql.Wrapper { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
31 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
32 * Returns true if this either implements the interface argument or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
33 * is directly or indirectly a wrapper for an object that does. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
34 * Returns false otherwise. If this implements the interface then |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
35 * return true, else if this is a wrapper then return the result of |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
36 * recursively calling <code>isWrapperFor</code> on the wrapped object. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
37 * If this does not implement the interface and is not a wrapper, return |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
38 * false. This method should be implemented as a low-cost operation |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
39 * compared to <code>unwrap</code> so that callers can use this method to avoid |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
40 * expensive <code>unwrap</code> calls that may fail. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
41 * If this method returns true then calling <code>unwrap</code> with the same argument should succeed. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
42 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
43 * @param iface a Class defining an interface. |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
44 * @return true if this implements the interface or directly or indirectly wraps an object that does. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
45 * @throws SQLException if an error occurs while determining whether this is a wrapper |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
46 * for an object with the given interface. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
47 * @since 1.6 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
48 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
49 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
50 public boolean isWrapperFor(final Class<?> iface) throws SQLException { |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
51 return iface != null && iface.isAssignableFrom(getClass()); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
52 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
53 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
54 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
55 * Returns an object that implements the given interface to allow |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
56 * access to non-standard methods, or standard methods not exposed by the proxy. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
57 * The result may be either the object found to implement the interface |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
58 * or a proxy for that object. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
59 * If the receiver implements the interface then the result is the receiver |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
60 * or a proxy for the receiver. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
61 * If the receiver is a wrapper and the wrapped object implements the interface |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
62 * then the result is the wrapped object or a proxy for the wrapped object. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
63 * Otherwise return the result of calling <code>unwrap</code> recursively on |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
64 * the wrapped object or a proxy for that result. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
65 * If the receiver is not a wrapper and does not implement the interface, |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
66 * then an <code>SQLException</code> is thrown. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
67 * |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
68 * @param iface A Class defining an interface that the result must implement. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
69 * @return an object that implements the interface. May be a proxy for the actual implementing object. |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
70 * @throws SQLException If no object found that implements the interface |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
71 * @since 1.6 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
72 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
73 @Override |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
74 @SuppressWarnings("unchecked") |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
75 public <T> T unwrap(final Class<T> iface) throws SQLException { |
18
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
76 if (isWrapperFor(iface)) { |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
77 return (T) this; |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
78 } |
8e57d20b5e80
Corrected implementation of java.sql.Wrapper methods isWrapperFor() and unwrap().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
79 throw new SQLException("Cannot unwrap to interface: " + (iface != null ? iface.getName() : ""), "0A000"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
80 } |
262
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
81 |
425
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
82 |
262
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
83 /** |
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
84 * Small helper method that formats the "Method ... not implemented" message |
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
85 * and creates a new SQLFeatureNotSupportedException object |
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
86 * whose SQLState is set to "0A000": feature not supported. |
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
87 * |
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
88 * @param name the method name |
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
89 * @return a new created SQLFeatureNotSupportedException object with SQLState 0A000 |
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
90 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
91 static final SQLFeatureNotSupportedException newSQLFeatureNotSupportedException(final String name) { |
262
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
92 return new SQLFeatureNotSupportedException("Method " + name + " not implemented", "0A000"); |
2d62ca1f758b
Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
93 } |
425
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
94 |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
95 /** |
451
3dfcd06fd8ba
Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
425
diff
changeset
|
96 * General utility function to add double quotes around an SQL Identifier |
425
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
97 * such as column or table or schema name in SQL queries. |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
98 * It also adds escapes for special characters: double quotes and the escape character |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
99 * |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
100 * FYI: it is made public as it is also called from util/Exporter.java |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
101 * |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
102 * @param in the string to quote |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
103 * @return the double quoted string |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
104 */ |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
105 public static final String dq(final String in) { |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
106 String ret = in; |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
107 if (ret.contains("\\\\")) |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
108 // all double slashes in input need to be escaped. |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
109 ret = ret.replaceAll("\\\\", "\\\\\\\\"); |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
110 if (ret.contains("\"")) |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
111 // all double quotes in input need to be escaped. |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
112 ret = ret.replaceAll("\"", "\\\\\""); |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
113 return "\"" + ret + "\""; |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
114 } |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
115 |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
116 /** |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
117 * General utility function to add single quotes around string literals as used in SQL queries. |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
118 * It also adds escapes for special characters: single quotes and the escape character |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
119 * |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
120 * FYI: it is made public as it is also called from util/Exporter.java |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
121 * |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
122 * @param in the string to quote |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
123 * @return the single quoted string |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
124 */ |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
125 public static final String sq(final String in) { |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
126 String ret = in; |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
127 if (ret.contains("\\\\")) |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
128 // all double slashes in input need to be escaped. |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
129 ret = ret.replaceAll("\\\\", "\\\\\\\\"); |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
130 if (ret.contains("'")) |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
131 // all single quotes in input need to be escaped. |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
132 ret = ret.replaceAll("'", "\\\\'"); |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
133 return "'" + ret + "'"; |
95d15f1d750d
Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
134 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
135 } |