diff --git a/src/main/java/com/aceql/jdbc/commons/ConnectionInfo.java b/src/main/java/com/aceql/jdbc/commons/ConnectionInfo.java index f4ed878..f297fa5 100644 --- a/src/main/java/com/aceql/jdbc/commons/ConnectionInfo.java +++ b/src/main/java/com/aceql/jdbc/commons/ConnectionInfo.java @@ -71,38 +71,59 @@ public class ConnectionInfo { /** * Package protected constructor, Driver users can not instantiate the class. * - * @param url - * @param database - * @param authentication - * @param passwordIsSessionId - * @param proxy - * @param proxyAuthentication - * @param connectTimeout - * @param readTimeout - * @param gzipResult - * @param resultSetMetaDataPolicy - * @param requestProperties - * @param clobReadCharset - * @param clobWriteCharset + * @param ConnectionInfoHolder all the info set and passed. */ - ConnectionInfo(String url, String database, PasswordAuthentication authentication, boolean passwordIsSessionId, - Proxy proxy, PasswordAuthentication proxyAuthentication, int connectTimeout, int readTimeout, - boolean gzipResult, ResultSetMetaDataPolicy resultSetMetaDataPolicy, Map requestProperties, - String clobReadCharset, String clobWriteCharset) { - this.url = url; - this.database = database; - this.authentication = authentication; - this.passwordIsSessionId = passwordIsSessionId; - this.proxy = proxy; - this.proxyAuthentication = proxyAuthentication; - this.connectTimeout = connectTimeout; - this.readTimeout = readTimeout; - this.gzipResult = gzipResult; - this.resultSetMetaDataPolicy = resultSetMetaDataPolicy; - this.requestProperties = requestProperties; - this.clobReadCharset = clobReadCharset; - this.clobWriteCharset = clobWriteCharset; + ConnectionInfo(ConnectionInfoHolder connectionInfoHolder) { + this.url = connectionInfoHolder.getUrl(); + this.database = connectionInfoHolder.getDatabase(); + this.authentication = connectionInfoHolder.getAuthentication(); + this.passwordIsSessionId = connectionInfoHolder.isPasswordIsSessionId(); + this.proxy = connectionInfoHolder.getProxy(); + this.proxyAuthentication = connectionInfoHolder.getProxyAuthentication(); + this.connectTimeout = connectionInfoHolder.getConnectTimeout(); + this.readTimeout = connectionInfoHolder.getReadTimeout(); + this.gzipResult = connectionInfoHolder.isGzipResult(); + this.resultSetMetaDataPolicy = connectionInfoHolder.getResultSetMetaDataPolicy(); + this.requestProperties = connectionInfoHolder.getRequestProperties(); + this.clobReadCharset = connectionInfoHolder.getClobReadCharset(); + this.clobWriteCharset = connectionInfoHolder.getClobWriteCharset(); } + +// /** +// * Package protected constructor, Driver users can not instantiate the class. +// * +// * @param url +// * @param database +// * @param authentication +// * @param passwordIsSessionId +// * @param proxy +// * @param proxyAuthentication +// * @param connectTimeout +// * @param readTimeout +// * @param gzipResult +// * @param resultSetMetaDataPolicy +// * @param requestProperties +// * @param clobReadCharset +// * @param clobWriteCharset +// */ +// ConnectionInfo(String url, String database, PasswordAuthentication authentication, boolean passwordIsSessionId, +// Proxy proxy, PasswordAuthentication proxyAuthentication, int connectTimeout, int readTimeout, +// boolean gzipResult, ResultSetMetaDataPolicy resultSetMetaDataPolicy, Map requestProperties, +// String clobReadCharset, String clobWriteCharset) { +// this.url = url; +// this.database = database; +// this.authentication = authentication; +// this.passwordIsSessionId = passwordIsSessionId; +// this.proxy = proxy; +// this.proxyAuthentication = proxyAuthentication; +// this.connectTimeout = connectTimeout; +// this.readTimeout = readTimeout; +// this.gzipResult = gzipResult; +// this.resultSetMetaDataPolicy = resultSetMetaDataPolicy; +// this.requestProperties = requestProperties; +// this.clobReadCharset = clobReadCharset; +// this.clobWriteCharset = clobWriteCharset; +// } /** * Gets the URL of the remote database diff --git a/src/main/java/com/aceql/jdbc/commons/ConnectionInfoHolder.java b/src/main/java/com/aceql/jdbc/commons/ConnectionInfoHolder.java new file mode 100644 index 0000000..d120ad3 --- /dev/null +++ b/src/main/java/com/aceql/jdbc/commons/ConnectionInfoHolder.java @@ -0,0 +1,135 @@ +package com.aceql.jdbc.commons; + +import java.net.PasswordAuthentication; +import java.net.Proxy; +import java.util.HashMap; +import java.util.Map; + +import com.aceql.jdbc.commons.metadata.ResultSetMetaDataPolicy; + +public class ConnectionInfoHolder { + + private String url; + private String database; + private PasswordAuthentication authentication; + + private boolean passwordIsSessionId; + private Proxy proxy; + private PasswordAuthentication proxyAuthentication; + + private int connectTimeout = 0; + private int readTimeout = 0; + private boolean gzipResult; + private ResultSetMetaDataPolicy resultSetMetaDataPolicy = ResultSetMetaDataPolicy.off; + private Map requestProperties = new HashMap<>(); + private String clobReadCharset; + private String clobWriteCharset; + + // New 9.4 + private int maxRetries = 0; + private int retryIntervalMs = 0; + public String getUrl() { + return url; + } + public void setUrl(String url) { + this.url = url; + } + public String getDatabase() { + return database; + } + public void setDatabase(String database) { + this.database = database; + } + public PasswordAuthentication getAuthentication() { + return authentication; + } + public void setAuthentication(PasswordAuthentication authentication) { + this.authentication = authentication; + } + public boolean isPasswordIsSessionId() { + return passwordIsSessionId; + } + public void setPasswordIsSessionId(boolean passwordIsSessionId) { + this.passwordIsSessionId = passwordIsSessionId; + } + public Proxy getProxy() { + return proxy; + } + public void setProxy(Proxy proxy) { + this.proxy = proxy; + } + public PasswordAuthentication getProxyAuthentication() { + return proxyAuthentication; + } + public void setProxyAuthentication(PasswordAuthentication proxyAuthentication) { + this.proxyAuthentication = proxyAuthentication; + } + public int getConnectTimeout() { + return connectTimeout; + } + public void setConnectTimeout(int connectTimeout) { + this.connectTimeout = connectTimeout; + } + public int getReadTimeout() { + return readTimeout; + } + public void setReadTimeout(int readTimeout) { + this.readTimeout = readTimeout; + } + public boolean isGzipResult() { + return gzipResult; + } + public void setGzipResult(boolean gzipResult) { + this.gzipResult = gzipResult; + } + public ResultSetMetaDataPolicy getResultSetMetaDataPolicy() { + return resultSetMetaDataPolicy; + } + public void setResultSetMetaDataPolicy(ResultSetMetaDataPolicy resultSetMetaDataPolicy) { + this.resultSetMetaDataPolicy = resultSetMetaDataPolicy; + } + public Map getRequestProperties() { + return requestProperties; + } + public void setRequestProperties(Map requestProperties) { + this.requestProperties = requestProperties; + } + public String getClobReadCharset() { + return clobReadCharset; + } + public void setClobReadCharset(String clobReadCharset) { + this.clobReadCharset = clobReadCharset; + } + public String getClobWriteCharset() { + return clobWriteCharset; + } + public void setClobWriteCharset(String clobWriteCharset) { + this.clobWriteCharset = clobWriteCharset; + } + public int getMaxRetries() { + return maxRetries; + } + public void setMaxRetries(int maxRetries) { + this.maxRetries = maxRetries; + } + public int getRetryIntervalMs() { + return retryIntervalMs; + } + public void setRetryIntervalMs(int retryIntervalMs) { + this.retryIntervalMs = retryIntervalMs; + } + @Override + public String toString() { + return "ConnectionInfoHolder [url=" + url + ", database=" + database + ", authentication=" + authentication + + ", passwordIsSessionId=" + passwordIsSessionId + ", proxy=" + proxy + ", proxyAuthentication=" + + proxyAuthentication + ", connectTimeout=" + connectTimeout + ", readTimeout=" + readTimeout + + ", gzipResult=" + gzipResult + ", resultSetMetaDataPolicy=" + resultSetMetaDataPolicy + + ", requestProperties=" + requestProperties + ", clobReadCharset=" + clobReadCharset + + ", clobWriteCharset=" + clobWriteCharset + ", maxRetries=" + maxRetries + ", retryIntervalMs=" + + retryIntervalMs + "]"; + } + + + + +} diff --git a/src/main/java/com/aceql/jdbc/commons/InternalWrapper.java b/src/main/java/com/aceql/jdbc/commons/InternalWrapper.java index 26f68b8..9280c00 100644 --- a/src/main/java/com/aceql/jdbc/commons/InternalWrapper.java +++ b/src/main/java/com/aceql/jdbc/commons/InternalWrapper.java @@ -24,7 +24,6 @@ import java.net.PasswordAuthentication; import java.net.Proxy; import java.sql.SQLException; -import java.time.Instant; import java.util.Map; import com.aceql.jdbc.commons.main.http.AceQLHttpApi; @@ -77,20 +76,11 @@ public static AceQLHttpApi getAceQLHttpApi(AceQLConnection aceQLConnection) { return aceQLHttpApi; } - public static ConnectionInfo connectionInfoBuilder(String url, String database, - PasswordAuthentication authentication, boolean passwordIsSessionId, Proxy proxy, - PasswordAuthentication proxyAuthentication, int connectTimeout, int readTimeout, boolean gzipResult, - ResultSetMetaDataPolicy resultSetMetaDataPolicy, Map requestProperties, - String clobReadCharset, String clobWriteCharset) { - ConnectionInfo connectionInfo = new ConnectionInfo(url, database, authentication, passwordIsSessionId, proxy, - proxyAuthentication, connectTimeout, readTimeout, gzipResult, resultSetMetaDataPolicy, requestProperties, - clobReadCharset, clobWriteCharset); - return connectionInfo; - } - public static void setCreationDateTime(ConnectionInfo connectionInfo, Instant instant) { - connectionInfo.setCreationDateTime(instant); + public static ConnectionInfo connectionInfoBuilder(ConnectionInfoHolder ConnectionInfoHolder) { + return new ConnectionInfo(ConnectionInfoHolder); } + public static DatabaseInfo databaseInfoBuilder(AceQLHttpApi aceQLHttpApi) throws AceQLException { DatabaseInfoDto databaseInfoDto = aceQLHttpApi.getDatabaseInfoDto(); diff --git a/src/main/java/com/aceql/jdbc/commons/main/http/HttpManager.java b/src/main/java/com/aceql/jdbc/commons/main/http/HttpManager.java index bc4f213..fe2972b 100644 --- a/src/main/java/com/aceql/jdbc/commons/main/http/HttpManager.java +++ b/src/main/java/com/aceql/jdbc/commons/main/http/HttpManager.java @@ -142,7 +142,7 @@ public InputStream callWithGetReturnStream(String url) throws MalformedURLException, IOException, UnsupportedEncodingException { int maxRetries = 3; - int retryIntervalInMilliseconds = 1000; + int retryIntervalMs = 1000; /* * if (httpVersion == 1) { return callWithGetInputStreamHttp11(url); } else { @@ -162,7 +162,7 @@ public InputStream callWithGetReturnStream(String url) } try { - Thread.sleep(retryIntervalInMilliseconds); + Thread.sleep(retryIntervalMs); } catch (InterruptedException ignore) { // e1.printStackTrace(); } @@ -242,7 +242,7 @@ public InputStream callWithPost(URL theUrl, Map parameters) throws IOException, ProtocolException, SocketTimeoutException, UnsupportedEncodingException { int maxRetries = 3; - int retryIntervalInMilliseconds = 1000; + int retryIntervalMs = 1000; /* * if (httpVersion == 1) { return callWithGetInputStreamHttp11(url); } else { @@ -262,7 +262,7 @@ public InputStream callWithPost(URL theUrl, Map parameters) } try { - Thread.sleep(retryIntervalInMilliseconds); + Thread.sleep(retryIntervalMs); } catch (InterruptedException ignore) { // e1.printStackTrace(); } diff --git a/src/main/java/com/aceql/jdbc/driver/free/AceQLDriver.java b/src/main/java/com/aceql/jdbc/driver/free/AceQLDriver.java index 961b10f..b2b19f9 100644 --- a/src/main/java/com/aceql/jdbc/driver/free/AceQLDriver.java +++ b/src/main/java/com/aceql/jdbc/driver/free/AceQLDriver.java @@ -39,6 +39,7 @@ import com.aceql.jdbc.commons.AceQLConnection; import com.aceql.jdbc.commons.ConnectionInfo; +import com.aceql.jdbc.commons.ConnectionInfoHolder; import com.aceql.jdbc.commons.InternalWrapper; import com.aceql.jdbc.commons.driver.util.DriverPropertyInfoBuilder; import com.aceql.jdbc.commons.driver.util.DriverUtil; @@ -262,10 +263,24 @@ public Connection connect(String url, Properties info) throws SQLException { passwordIsSessionId = true; } - ConnectionInfo connectionInfo = InternalWrapper.connectionInfoBuilder(url, database, authentication, passwordIsSessionId, - proxy, proxyAuthentication, connectTimeout, readTimeout, gzipResult, - resultSetMetaDataPolicy, requestProperties, clobReadCharset, clobWriteCharset); + ConnectionInfoHolder connectionInfoHolder = new ConnectionInfoHolder(); + connectionInfoHolder.setAuthentication(authentication); + connectionInfoHolder.setClobReadCharset(clobReadCharset); + connectionInfoHolder.setClobWriteCharset(clobWriteCharset); + connectionInfoHolder.setConnectTimeout(connectTimeout); + connectionInfoHolder.setDatabase(database); + connectionInfoHolder.setGzipResult(gzipResult); + connectionInfoHolder.setMaxRetries(3); + connectionInfoHolder.setPasswordIsSessionId(passwordIsSessionId); + connectionInfoHolder.setProxy(proxy); + connectionInfoHolder.setReadTimeout(readTimeout); + connectionInfoHolder.setRequestProperties(requestProperties); + connectionInfoHolder.setResultSetMetaDataPolicy(resultSetMetaDataPolicy); + connectionInfoHolder.setRetryIntervalMs(1000); + connectionInfoHolder.setUrl(url); + + ConnectionInfo connectionInfo = InternalWrapper.connectionInfoBuilder(connectionInfoHolder); AceQLConnection connection = InternalWrapper.connectionBuilder(connectionInfo); if (!AceQLConnectionUtil.isVersion12_2OrHigher(connection)) {