Skip to content

Commit

Permalink
Use ConnectionInfoHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
ndepomereu committed Aug 12, 2024
1 parent a3bc776 commit 9f6a29f
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 50 deletions.
81 changes: 51 additions & 30 deletions src/main/java/com/aceql/jdbc/commons/ConnectionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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<String, String> 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
Expand Down
135 changes: 135 additions & 0 deletions src/main/java/com/aceql/jdbc/commons/ConnectionInfoHolder.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> getRequestProperties() {
return requestProperties;
}
public void setRequestProperties(Map<String, String> 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 + "]";
}




}
16 changes: 3 additions & 13 deletions src/main/java/com/aceql/jdbc/commons/InternalWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -162,7 +162,7 @@ public InputStream callWithGetReturnStream(String url)
}

try {
Thread.sleep(retryIntervalInMilliseconds);
Thread.sleep(retryIntervalMs);
} catch (InterruptedException ignore) {
// e1.printStackTrace();
}
Expand Down Expand Up @@ -242,7 +242,7 @@ public InputStream callWithPost(URL theUrl, Map<String, String> parameters)
throws IOException, ProtocolException, SocketTimeoutException, UnsupportedEncodingException {

int maxRetries = 3;
int retryIntervalInMilliseconds = 1000;
int retryIntervalMs = 1000;

/*
* if (httpVersion == 1) { return callWithGetInputStreamHttp11(url); } else {
Expand All @@ -262,7 +262,7 @@ public InputStream callWithPost(URL theUrl, Map<String, String> parameters)
}

try {
Thread.sleep(retryIntervalInMilliseconds);
Thread.sleep(retryIntervalMs);
} catch (InterruptedException ignore) {
// e1.printStackTrace();
}
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/com/aceql/jdbc/driver/free/AceQLDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 9f6a29f

Please sign in to comment.