Skip to content

Commit

Permalink
CB-5138 force use default properties for default database (#2751)
Browse files Browse the repository at this point in the history
* CB-5138 force use default properties for default database

* CB-5138 review fix

---------

Co-authored-by: Evgenia Bezborodova <[email protected]>
  • Loading branch information
alexander-skoblikov and EvgeniaBzzz authored Jul 2, 2024
1 parent faafcee commit 1e2eee8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,17 @@ public void initialize() throws DBException {

LoggingProgressMonitor monitor = new LoggingProgressMonitor(log);

if (isDefaultH2Configuration(databaseConfiguration)) {
//force use default values even if they are explicitly specified
databaseConfiguration.setUser(null);
databaseConfiguration.setPassword(null);
databaseConfiguration.setSchema(null);
}

String dbUser = databaseConfiguration.getUser();
String dbPassword = databaseConfiguration.getPassword();
String schemaName = databaseConfiguration.getSchema();

if (CommonUtils.isEmpty(dbUser) && driver.isEmbedded()) {
File pwdFile = application.getDataDirectory(true).resolve(DEFAULT_DB_PWD_FILE).toFile();
if (!driver.isAnonymousAccess()) {
Expand Down Expand Up @@ -191,7 +200,6 @@ public void initialize() throws DBException {
DatabaseMetaData metaData = connection.getMetaData();
log.debug("\tConnected to " + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion());

var schemaName = databaseConfiguration.getSchema();
if (dialect instanceof SQLDialectSchemaController && CommonUtils.isNotEmpty(schemaName)) {
var dialectSchemaController = (SQLDialectSchemaController) dialect;
var schemaExistQuery = dialectSchemaController.getSchemaExistQuery(schemaName);
Expand Down Expand Up @@ -578,4 +586,11 @@ public SQLDialect getDialect() {
return dialect;
}

public static boolean isDefaultH2Configuration(WebDatabaseConfig databaseConfiguration) {
var v1DefaultUrl = "jdbc:h2:/opt/cloudbeaver/workspace/.data/" + V1_DB_NAME;
var v2DefaultUrl = "jdbc:h2:/opt/cloudbeaver/workspace/.data/" + V2_DB_NAME;
return v1DefaultUrl.equals(databaseConfiguration.getUrl())
|| v2DefaultUrl.equals(databaseConfiguration.getUrl());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,16 @@ public boolean isBackupEnabled() {
public String getSchema() {
return schema;
}

void setPassword(String password) {
this.password = password;
}

void setSchema(String schema) {
this.schema = schema;
}

void setUser(String user) {
this.user = user;
}
}

0 comments on commit 1e2eee8

Please sign in to comment.