Skip to content

Added support for custom DB port (default is also set) #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public abstract class DataAdapter extends AbstractConnectionPool implements Type
public final SQLSyntax syntax;

public String server;
public Integer port;
public String instance;
public String dataBase;
public String userID;
Expand All @@ -50,13 +51,14 @@ public abstract class DataAdapter extends AbstractConnectionPool implements Type

protected abstract void ensureDB(boolean cleanDB) throws Exception;

protected DataAdapter(SQLSyntax syntax, String dataBase, String server, String instance, String userID, String password, Long connectTimeout, boolean cleanDB) throws Exception {
protected DataAdapter(SQLSyntax syntax, String dataBase, String server, Integer port, String instance, String userID, String password, Long connectTimeout, boolean cleanDB) throws Exception {

Class.forName(syntax.getClassName());

this.syntax = syntax;

this.dataBase = dataBase;
this.port = port;
this.server = server;
this.userID = userID;
this.password = password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ public class PostgreDataAdapter extends DataAdapter {
private String binPath;
private String dumpDir;

public PostgreDataAdapter(String dataBase, String server, String userID, String password) throws Exception {
this(dataBase, server, userID, password, false);
public PostgreDataAdapter(String dataBase, String server, Integer port, String userID, String password) throws Exception {
this(dataBase, server, port, userID, password, false);
}

public PostgreDataAdapter(String dataBase, String server, String userID, String password, boolean cleanDB) throws Exception{
this(dataBase, server, userID, password, null, null, null, cleanDB);
public PostgreDataAdapter(String dataBase, String server, Integer port, String userID, String password, boolean cleanDB) throws Exception{
this(dataBase, server, port, userID, password, null, null, null, cleanDB);
}

public PostgreDataAdapter(String dataBase, String server, String userID, String password, Long connectTimeout, String binPath, String dumpDir) throws Exception {
this(dataBase, server, userID, password, connectTimeout, binPath, dumpDir, false);
public PostgreDataAdapter(String dataBase, String server, Integer port, String userID, String password, Long connectTimeout, String binPath, String dumpDir) throws Exception {
this(dataBase, server, port, userID, password, connectTimeout, binPath, dumpDir, false);
}

public PostgreDataAdapter(String dataBase, String server, String userID, String password, Long connectTimeout, String binPath, String dumpDir, boolean cleanDB) throws Exception {
super(PostgreSQLSyntax.instance, dataBase, server, null, userID, password, connectTimeout, cleanDB);
public PostgreDataAdapter(String dataBase, String server, Integer port, String userID, String password, Long connectTimeout, String binPath, String dumpDir, boolean cleanDB) throws Exception {
super(PostgreSQLSyntax.instance, dataBase, server, port, null, userID, password, connectTimeout, cleanDB);

this.defaultBinPath = binPath;
this.defaultDumpDir = dumpDir;
Expand All @@ -71,7 +71,7 @@ public void ensureDB(boolean cleanDB) throws Exception {
Connection connect = null;
while(connect == null) {
try {
connect = DriverManager.getConnection("jdbc:postgresql://" + server + "/postgres?user=" + userID + "&password=" + password);
connect = DriverManager.getConnection("jdbc:postgresql://" + server + ":" + port + "/postgres?user=" + userID + "&password=" + password);
} catch (PSQLException e) {
ServerLoggers.startLogger.error(String.format("%s (host: %s, user: %s)", e.getMessage(), server, userID));
logger.error("EnsureDB error: ", e);
Expand Down Expand Up @@ -129,7 +129,7 @@ protected String getPath() {
public Connection startConnection() throws SQLException {
long started = System.currentTimeMillis();
try {
return DriverManager.getConnection("jdbc:postgresql://" + server + "/" + dataBase.toLowerCase() + "?user=" + userID + "&password=" + password + "&connectTimeout=" + (int) (connectTimeout / 1000));
return DriverManager.getConnection("jdbc:postgresql://" + server + ":" + port + "/" + dataBase.toLowerCase() + "?user=" + userID + "&password=" + password + "&connectTimeout=" + (int) (connectTimeout / 1000));
} finally {
long elapsed = System.currentTimeMillis() - started;
if(elapsed > connectTimeout)
Expand Down Expand Up @@ -318,7 +318,7 @@ public void dropDB(String dbName) throws IOException {
public List<List<List<Object>>> readCustomRestoredColumns(String dbName, String table, List<String> keys, List<String> columns) throws SQLException {
List<List<Object>> dataKeys = new ArrayList<>();
List<List<Object>> dataColumns = new ArrayList<>();
try(Connection connection = DriverManager.getConnection("jdbc:postgresql://" + server + "/" + dbName.toLowerCase() + "?user=" + userID + "&password=" + password)) {
try(Connection connection = DriverManager.getConnection("jdbc:postgresql://" + server + ":" + port + "/" + dbName.toLowerCase() + "?user=" + userID + "&password=" + password)) {
try (Statement statement = connection.createStatement()) {
String column = "";
for(String k : keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void executeInternal(final ExecutionContext<ClassPropertyInterface> conte
try {
String type = (String) findProperty("uploadStaticNameType[]").read(context);
String host = (String) findProperty("uploadHost[]").read(context);
Integer port = (Integer) findProperty("uploadPort[]").read(context);
String user = (String) findProperty("uploadUser[]").read(context);
String password = (String) findProperty("uploadPassword[]").read(context);
String db = (String) findProperty("uploadDB[]").read(context);
Expand All @@ -37,7 +38,7 @@ public void executeInternal(final ExecutionContext<ClassPropertyInterface> conte
final DataAdapter adapter;
try {
if(type.trim().equals("Service_DBType.POSTGRE"))
adapter = new PostgreDataAdapter(db, host, user, password);
adapter = new PostgreDataAdapter(db, host, port, user, password);
// else if(type.trim().equals("Service_DBType.MSSQL"))
// adapter = new MSSQLDataAdapter(db, host, user, password, instance);
else
Expand Down
1 change: 1 addition & 0 deletions server/src/main/resources/lsfusion.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<bean id="dataAdapter" class="lsfusion.server.data.sql.adapter.PostgreDataAdapter">
<constructor-arg value="${db.name:lsfusion}"/>
<constructor-arg value="${db.server:localhost}"/>
<constructor-arg value="${db.port:5432}"/>
<constructor-arg value="${db.user:postgres}"/>
<constructor-arg value="${db.password:}"/>
<constructor-arg value="${db.connectTimeout:1000}"/>
Expand Down