Skip to content

Commit

Permalink
#20602 apply global properties from the main page instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Destrolaric committed Jan 23, 2024
1 parent 8433959 commit baa1e88
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.jkiss.dbeaver.ext.postgresql.ui;

import java.util.Locale;

import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
Expand All @@ -37,6 +39,7 @@
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.connection.DBPDriverConfigurationType;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.registry.DBConnectionConstants;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.DBeaverIcons;
Expand All @@ -48,8 +51,6 @@
import org.jkiss.dbeaver.ui.internal.UIConnectionMessages;
import org.jkiss.utils.CommonUtils;

import java.util.Locale;

/**
* PostgreConnectionPage
*/
Expand Down Expand Up @@ -270,6 +271,7 @@ public void loadSettings() {
@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
applyGlobalProperties(connectionInfo);
if (typeURLRadio != null) {
connectionInfo.setConfigurationType(
typeURLRadio.getSelection() ? DBPDriverConfigurationType.URL : DBPDriverConfigurationType.MANUAL);
Expand Down Expand Up @@ -297,6 +299,24 @@ public void saveSettings(DBPDataSourceContainer dataSource) {
super.saveSettings(dataSource);
}

private static void applyGlobalProperties(DBPConnectionConfiguration connectionInfo) {
// Additional page can be not loaded at all, if this is the case just to be sure we need to apply global settings
String[] propertiesToCheck = {
PostgreConstants.PROP_SHOW_NON_DEFAULT_DB,
PostgreConstants.PROP_SHOW_UNAVAILABLE_DB,
PostgreConstants.PROP_SHOW_TEMPLATES_DB,
PostgreConstants.PROP_READ_ALL_DATA_TYPES,
PostgreConstants.PROP_READ_KEYS_WITH_COLUMNS,
PostgreConstants.PROP_SHOW_DATABASE_STATISTICS
};
DBPPreferenceStore preferenceStore = DBWorkbench.getPlatform().getPreferenceStore();
for (String property : propertiesToCheck) {
if (CommonUtils.isEmpty(connectionInfo.getProviderProperty(property))) {
connectionInfo.setProviderProperty(property, preferenceStore.getString(property));
}
}
}

@Override
public IDialogPage[] getDialogPages(boolean extrasOnly, boolean forceCreate) {
return new IDialogPage[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,15 @@ public class PostgreDataSource extends JDBCDataSource implements DBSInstanceCont

private static final String LEGACY_UA_TIMEZONE = "Europe/Kiev";
private static final String NEW_UA_TIMEZONE = "Europe/Kyiv";
private final DBPPreferenceStore globalPrefs = DBWorkbench.getPlatform().getPreferenceStore();

public PostgreDataSource(DBRProgressMonitor monitor, DBPDataSourceContainer container)
throws DBException
{
super(monitor, container, new PostgreDialect());

// Statistics was disabled then mark it as already read
this.hasStatistics = !CommonUtils.getBoolean(
container.getConnectionConfiguration().getProviderProperty(PostgreConstants.PROP_SHOW_DATABASE_STATISTICS),
globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_DATABASE_STATISTICS)
);
this.hasStatistics = !CommonUtils.getBoolean(container.getConnectionConfiguration().getProviderProperty(
PostgreConstants.PROP_SHOW_DATABASE_STATISTICS));
}

// Constructor for tests
Expand Down Expand Up @@ -187,7 +185,6 @@ protected void initializeRemoteInstance(@NotNull DBRProgressMonitor monitor) thr
// ignore
}
}

private void loadAvailableDatabases(@NotNull DBRProgressMonitor monitor, DBPConnectionConfiguration configuration, List<PostgreDatabase> dbList) throws DBException {
DBExecUtils.startContextInitiation(getContainer());
try (Connection bootstrapConnection = openConnection(monitor, null, "Read PostgreSQL database list")) {
Expand Down Expand Up @@ -223,32 +220,23 @@ private void loadAvailableDatabases(@NotNull DBRProgressMonitor monitor, DBPConn
protected boolean isReadDatabaseList(DBPConnectionConfiguration configuration) {
// It is configurable by default
return configuration.getConfigurationType() != DBPDriverConfigurationType.URL &&
CommonUtils.getBoolean(configuration.getProviderProperty(
PostgreConstants.PROP_SHOW_NON_DEFAULT_DB),
globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_NON_DEFAULT_DB)
);
CommonUtils.getBoolean(configuration.getProviderProperty(PostgreConstants.PROP_SHOW_NON_DEFAULT_DB), false);
}

protected PreparedStatement prepareReadDatabaseListStatement(
@NotNull DBRProgressMonitor monitor,
@NotNull Connection bootstrapConnection,
@NotNull DBPConnectionConfiguration configuration) throws SQLException
{
DBPPreferenceStore globalPrefs = DBWorkbench.getPlatform().getPreferenceStore();
// Make initial connection to read database list
DBSObjectFilter catalogFilters = getContainer().getObjectFilter(PostgreDatabase.class, null, false);
StringBuilder catalogQuery = new StringBuilder("SELECT db.oid,db.* FROM pg_catalog.pg_database db WHERE 1 = 1");
boolean addExclusionName = false;
String connectionDBName = getContainer().getConnectionConfiguration().getDatabaseName();
{
final boolean showTemplates = CommonUtils.getBoolean(configuration.getProviderProperty(
PostgreConstants.PROP_SHOW_TEMPLATES_DB),
globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_TEMPLATES_DB)
);
final boolean showUnavailable = CommonUtils.getBoolean(
configuration.getProviderProperty(PostgreConstants.PROP_SHOW_UNAVAILABLE_DB),
globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_TEMPLATES_DB)
);
final boolean showTemplates = CommonUtils.toBoolean(configuration.getProviderProperty(PostgreConstants.PROP_SHOW_TEMPLATES_DB));
final boolean showUnavailable =
CommonUtils.toBoolean(configuration.getProviderProperty(PostgreConstants.PROP_SHOW_UNAVAILABLE_DB));

if (!showUnavailable) {
catalogQuery.append(" AND datallowconn");
Expand Down Expand Up @@ -321,7 +309,7 @@ protected Map<String, String> getInternalConnectionProperties(
}
PostgreServerType serverType = getType();
if (serverType.turnOffPreparedStatements()
&& !CommonUtils.getBoolean(
&& !CommonUtils.toBoolean(
getContainer().getActualConnectionConfiguration().getProviderProperty(PostgreConstants.PROP_USE_PREPARED_STATEMENTS))) {
// Turn off prepared statements using, to avoid error: "ERROR: prepared statement "S_1" already exists" from PGBouncer #10742
props.put("prepareThreshold", "0");
Expand Down Expand Up @@ -930,19 +918,20 @@ public DBCQueryTransformer createQueryTransformer(@NotNull DBCQueryTransformType
}

public boolean supportReadingAllDataTypes() {
return CommonUtils.getBoolean(
getContainer().getActualConnectionConfiguration().getProviderProperty(PostgreConstants.PROP_READ_ALL_DATA_TYPES),
globalPrefs.getBoolean(PostgreConstants.PROP_READ_ALL_DATA_TYPES));
return CommonUtils.toBoolean(
getContainer().getActualConnectionConfiguration().getProviderProperty(PostgreConstants.PROP_READ_ALL_DATA_TYPES));
}

public boolean supportsReadingKeysWithColumns() {
return CommonUtils.getBoolean(
getContainer().getActualConnectionConfiguration().getProviderProperty(PostgreConstants.PROP_READ_KEYS_WITH_COLUMNS),
globalPrefs.getBoolean(PostgreConstants.PROP_READ_KEYS_WITH_COLUMNS)
);
return CommonUtils.toBoolean(
getContainer().getActualConnectionConfiguration().getProviderProperty(PostgreConstants.PROP_READ_KEYS_WITH_COLUMNS));
}

public boolean isSupportsEnumTable() {
return supportsEnumTable;
}

private DBPPreferenceStore getGlobalPreferences() {
return DBWorkbench.getPlatform().getPreferenceStore();
}
}

0 comments on commit baa1e88

Please sign in to comment.