comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 869:676725ad17b5

Remove not needed/used internal method checkValidProperty() Make the MonetConnection target variable private and final.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 01 Feb 2024 20:55:01 +0100 (15 months ago)
parents 5a59910e8f87
children dc33533e6468
comparison
equal deleted inserted replaced
868:a227deba0e26 869:676725ad17b5
38 import org.monetdb.mcl.net.MapiSocket; 38 import org.monetdb.mcl.net.MapiSocket;
39 import org.monetdb.mcl.net.Target; 39 import org.monetdb.mcl.net.Target;
40 import org.monetdb.mcl.parser.HeaderLineParser; 40 import org.monetdb.mcl.parser.HeaderLineParser;
41 import org.monetdb.mcl.parser.MCLParseException; 41 import org.monetdb.mcl.parser.MCLParseException;
42 import org.monetdb.mcl.parser.StartOfHeaderParser; 42 import org.monetdb.mcl.parser.StartOfHeaderParser;
43
44 import javax.net.ssl.SSLException;
45 43
46 /** 44 /**
47 *<pre> 45 *<pre>
48 * A {@link Connection} suitable for the MonetDB database. 46 * A {@link Connection} suitable for the MonetDB database.
49 * 47 *
74 public class MonetConnection 72 public class MonetConnection
75 extends MonetWrapper 73 extends MonetWrapper
76 implements Connection, AutoCloseable 74 implements Connection, AutoCloseable
77 { 75 {
78 /* All connection parameters */ 76 /* All connection parameters */
79 Target target; 77 private final Target target;
80 /** A connection to mserver5 using a TCP socket */ 78 /** A connection to mserver5 using a TCP socket */
81 private final MapiSocket server; 79 private final MapiSocket server;
82 /** The Reader from the server */ 80 /** The Reader from the server */
83 private final BufferedMCLReader in; 81 private final BufferedMCLReader in;
84 /** The Writer to the server */ 82 /** The Writer to the server */
135 /** A cache to reduce the number of DatabaseMetaData objects created by getMetaData() to maximum 1 per connection */ 133 /** A cache to reduce the number of DatabaseMetaData objects created by getMetaData() to maximum 1 per connection */
136 private DatabaseMetaData dbmd; 134 private DatabaseMetaData dbmd;
137 135
138 /** 136 /**
139 * Constructor of a Connection for MonetDB. 137 * Constructor of a Connection for MonetDB.
140 * This constructor is only accessible to 138 * This constructor is only accessible to classes from the jdbc package.
141 * classes from the jdbc package.
142 * 139 *
143 * @param target a {@link Target} object containing all connection parameters 140 * @param target a {@link Target} object containing all connection parameters
144 * @throws SQLException if a database error occurs 141 * @throws SQLException if a database error occurs
145 * @throws IllegalArgumentException is one of the arguments is null or empty 142 * @throws IllegalArgumentException is one of the arguments is null or empty
146 */ 143 */
210 out = server.getWriter(); 207 out = server.getWriter();
211 208
212 final String error = in.discardRemainder(); 209 final String error = in.discardRemainder();
213 if (error != null) 210 if (error != null)
214 throw new SQLNonTransientConnectionException((error.length() > 6) ? error.substring(6) : error, "08001"); 211 throw new SQLNonTransientConnectionException((error.length() > 6) ? error.substring(6) : error, "08001");
215 } catch (SSLException e) { 212 } catch (javax.net.ssl.SSLException e) {
216 throw new SQLNonTransientConnectionException("Cannot establish secure connection: " + e.getMessage(), e); 213 throw new SQLNonTransientConnectionException("Cannot establish secure connection: " + e.getMessage(), e);
217 } catch (IOException e) { 214 } catch (IOException e) {
218 throw new SQLNonTransientConnectionException("Cannot connect: " + e.getMessage(), "08006", e); 215 throw new SQLNonTransientConnectionException("Cannot connect: " + e.getMessage(), "08006", e);
219 } catch (MCLParseException e) { 216 } catch (MCLParseException e) {
220 throw new SQLNonTransientConnectionException(e.getMessage(), "08001"); 217 throw new SQLNonTransientConnectionException(e.getMessage(), "08001");
1669 * 1666 *
1670 * @return the MonetDB JDBC Connection URL (without user name and password). 1667 * @return the MonetDB JDBC Connection URL (without user name and password).
1671 */ 1668 */
1672 String getJDBCURL() { 1669 String getJDBCURL() {
1673 return target.buildUrl(); 1670 return target.buildUrl();
1674 }
1675
1676 /**
1677 * Utility method to check if connection property name is supported.
1678 * If it is not supported a warning is added to this Connection.
1679 *
1680 * @param name the connection property name to check
1681 * @param context the method name from where this is called
1682 * @return valid true or false
1683 */
1684 private boolean checkValidProperty(String name, String context) {
1685 // supported MonetDB connection properties.
1686 // See also MonetDriver.connect()
1687 if (name.equals("host")
1688 || name.equals("port")
1689 || name.equals("user")
1690 || name.equals("password")
1691 || name.equals("language")
1692 || name.equals("database")
1693 || name.equals("debug")
1694 || name.equals("logfile")
1695 || name.equals("hash")
1696 || name.equals("treat_blob_as_binary")
1697 || name.equals("treat_clob_as_varchar")
1698 || name.equals("autocommit")
1699 || name.equals("so_timeout")
1700 || name.equals("fetchsize")) // only supported by servers from version 11.41.1 onwards
1701 return true;
1702
1703 addWarning(context + " property name '" + name + "' is not recognized", "01M07");
1704 return false;
1705 } 1671 }
1706 1672
1707 // Internal caches for 4 static mserver5 environment values 1673 // Internal caches for 4 static mserver5 environment values
1708 private String env_current_user; 1674 private String env_current_user;
1709 private String env_monet_version; 1675 private String env_monet_version;