Task: Add custom properties info to connection factory for get connection in cubetiq sql core

This commit is contained in:
Sambo Chea 2022-09-15 15:28:00 +07:00
parent 903cc804f9
commit 95c95f1481
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490

View File

@ -6,6 +6,7 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger; import java.util.logging.Logger;
public final class ConnectionFactory { public final class ConnectionFactory {
@ -15,6 +16,8 @@ public final class ConnectionFactory {
private String user; private String user;
private String password; private String password;
private Properties info;
public ConnectionBuilder driver(String driver) { public ConnectionBuilder driver(String driver) {
this.driver = driver; this.driver = driver;
return this; return this;
@ -35,11 +38,22 @@ public final class ConnectionFactory {
return this; return this;
} }
public ConnectionBuilder info(Properties info) {
this.info = info;
return this;
}
public ConnectionBuilder properties(DataSourceProps properties) { public ConnectionBuilder properties(DataSourceProps properties) {
this.driver = properties.getDriver(); if (properties != null) {
this.url = properties.getUrl(); this.driver = properties.getDriver();
this.user = properties.getUser(); this.url = properties.getUrl();
this.password = properties.getPassword(); this.user = properties.getUser();
this.password = properties.getPassword();
if (properties.getProperties() != null && !properties.getProperties().isEmpty()) {
this.info = new Properties();
this.info.putAll(properties.getProperties());
}
}
return this; return this;
} }
@ -55,6 +69,10 @@ public final class ConnectionFactory {
} }
if (user == null && password == null) { if (user == null && password == null) {
if (info != null) {
return DriverManager.getConnection(url, info);
}
return DriverManager.getConnection(url); return DriverManager.getConnection(url);
} }