Search in sources :

Example 6 with PostgreDatabase

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.

the class PostgreDatabaseManager method generateAlterActions.

private void generateAlterActions(DBRProgressMonitor monitor, List<DBEPersistAction> actionList, ObjectChangeCommand command) throws DBException {
    final PostgreDatabase database = command.getObject();
    final String alterPrefix = "ALTER DATABASE " + DBUtils.getQuotedIdentifier(command.getObject()) + " ";
    if (command.hasProperty("defaultTablespace")) {
        actionList.add(new SQLDatabasePersistAction(alterPrefix + "SET TABLESPACE " + DBUtils.getQuotedIdentifier(database.getDefaultTablespace(monitor))));
    }
    if (command.hasProperty("defaultEncoding")) {
        actionList.add(new SQLDatabasePersistAction(alterPrefix + "SET ENCODING " + DBUtils.getQuotedIdentifier(database.getDefaultEncoding(monitor))));
    }
    if (command.hasProperty("dBA")) {
        actionList.add(new SQLDatabasePersistAction(alterPrefix + "OWNER TO " + DBUtils.getQuotedIdentifier(database.getDBA(monitor))));
    }
}
Also used : PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 7 with PostgreDatabase

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.

the class PostgreDatabaseManager method addObjectExtraActions.

@Override
protected void addObjectExtraActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, NestedObjectCommand<PostgreDatabase, PropertyHandler> command, Map<String, Object> options) throws DBException {
    if (command.hasProperty(DBConstants.PROP_ID_DESCRIPTION)) {
        PostgreDatabase database = command.getObject();
        actions.add(new SQLDatabasePersistAction("COMMENT ON DATABASE " + DBUtils.getQuotedIdentifier(database) + " IS " + SQLUtils.quoteString(database, CommonUtils.notEmpty(database.getDescription()))));
    }
}
Also used : PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 8 with PostgreDatabase

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.

the class PostgreDatabaseBackupSettings method loadDatabaseExportInfo.

private PostgreDatabaseBackupInfo loadDatabaseExportInfo(DBRRunnableContext runnableContext, String catalogId, List<String> schemaNames, List<String> tableNames) {
    PostgreDatabaseBackupInfo[] exportInfo = new PostgreDatabaseBackupInfo[1];
    try {
        runnableContext.run(true, true, monitor -> {
            try {
                PostgreDatabase database = (PostgreDatabase) DBUtils.findObjectById(monitor, getProject(), catalogId);
                if (database == null) {
                    throw new DBException("Database " + catalogId + " not found");
                }
                List<PostgreSchema> schemas = null;
                List<PostgreTableBase> tables = null;
                if (!CommonUtils.isEmpty(schemaNames)) {
                    schemas = new ArrayList<>();
                    for (String schemaName : schemaNames) {
                        PostgreSchema schema = database.getSchema(monitor, schemaName);
                        if (schema != null) {
                            schemas.add(schema);
                        } else {
                            log.debug("Schema '" + schemaName + "' not found in database '" + database.getName() + "'");
                        }
                    }
                }
                if (!CommonUtils.isEmpty(tableNames) && !CommonUtils.isEmpty(schemas)) {
                    PostgreSchema schema = schemas.get(0);
                    tables = new ArrayList<>();
                    for (String tableName : tableNames) {
                        PostgreTableBase table = schema.getTableCache().getObject(monitor, schema, tableName);
                        if (table != null) {
                            tables.add(table);
                        } else {
                            log.debug("Table '" + tableName + "' not found in schema '" + schema.getName() + "'");
                        }
                    }
                }
                exportInfo[0] = new PostgreDatabaseBackupInfo(database, schemas, tables);
            } catch (Throwable e) {
                throw new InvocationTargetException(e);
            }
        });
    } catch (InvocationTargetException e) {
        log.error("Error loading objects configuration", e);
    } catch (InterruptedException e) {
    // Ignore
    }
    return exportInfo[0];
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreTableBase(org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) InvocationTargetException(java.lang.reflect.InvocationTargetException) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)

Example 9 with PostgreDatabase

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.

the class PostgreDatabaseBackupSettings method fillExportObjectsFromInput.

public void fillExportObjectsFromInput() {
    Map<PostgreDatabase, PostgreDatabaseBackupInfo> objMap = new LinkedHashMap<>();
    for (DBSObject object : getDatabaseObjects()) {
        PostgreDatabase database = null;
        PostgreSchema schema = null;
        if (object instanceof PostgreDatabase) {
            database = (PostgreDatabase) object;
        } else if (object instanceof PostgreSchema) {
            database = ((PostgreSchema) object).getDatabase();
            schema = (PostgreSchema) object;
        } else if (object instanceof PostgreTableBase) {
            database = ((PostgreTableBase) object).getDatabase();
            schema = ((PostgreTableBase) object).getSchema();
        }
        if (database == null) {
            continue;
        }
        PostgreDatabaseBackupInfo info = objMap.computeIfAbsent(database, db -> new PostgreDatabaseBackupInfo(db, null, null));
        if (schema != null) {
            List<PostgreSchema> schemas = info.getSchemas();
            if (schemas == null) {
                schemas = new ArrayList<>();
                info.setSchemas(schemas);
            }
            if (!schemas.contains(schema)) {
                schemas.add(schema);
            }
        }
        if (object instanceof PostgreTableBase) {
            List<PostgreTableBase> tables = info.getTables();
            if (tables == null) {
                tables = new ArrayList<>();
                info.setTables(tables);
            }
            tables.add((PostgreTableBase) object);
        }
    }
    getExportObjects().addAll(objMap.values());
    updateDataSourceContainer();
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) PostgreTableBase(org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with PostgreDatabase

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.

the class PostgreDatabaseRestoreSettings method loadSettings.

@Override
public void loadSettings(DBRRunnableContext runnableContext, DBPPreferenceStore store) throws DBException {
    super.loadSettings(runnableContext, store);
    inputFile = store.getString("pg.restore.inputFile");
    cleanFirst = store.getBoolean("pg.restore.cleanFirst");
    noOwner = store.getBoolean("pg.restore.noOwner");
    if (store instanceof DBPPreferenceMap) {
        String catalogId = store.getString("pg.restore.database");
        if (!CommonUtils.isEmpty(catalogId)) {
            try {
                runnableContext.run(true, true, monitor -> {
                    try {
                        PostgreDatabase database = (PostgreDatabase) DBUtils.findObjectById(monitor, getProject(), catalogId);
                        if (database == null) {
                            throw new DBException("Database " + catalogId + " not found");
                        }
                        restoreInfo = new PostgreDatabaseRestoreInfo(database);
                    } catch (Throwable e) {
                        throw new InvocationTargetException(e);
                    }
                });
            } catch (InvocationTargetException e) {
                log.error("Error loading objects configuration", e);
            } catch (InterruptedException e) {
            // Ignore
            }
        } else {
            for (DBSObject object : getDatabaseObjects()) {
                if (object instanceof PostgreDatabase) {
                    restoreInfo = new PostgreDatabaseRestoreInfo((PostgreDatabase) object);
                    break;
                }
            }
        }
    }
    if (restoreInfo == null) {
        throw new DBException("Cannot find database for restoring");
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPPreferenceMap(org.jkiss.dbeaver.model.preferences.DBPPreferenceMap) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

PostgreDatabase (org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase)25 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)12 PostgreSchema (org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)11 DBException (org.jkiss.dbeaver.DBException)8 PostgreProcedure (org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure)5 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 PostgreTableBase (org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase)4 NativeToolWizardDialog (org.jkiss.dbeaver.tasks.ui.nativetool.NativeToolWizardDialog)4 PostgreDataSource (org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource)3 LinkedHashMap (java.util.LinkedHashMap)2 PostgreObject (org.jkiss.dbeaver.ext.postgresql.model.PostgreObject)2 DBPPreferenceMap (org.jkiss.dbeaver.model.preferences.DBPPreferenceMap)2 ActiveWizardDialog (org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog)2 HashMap (java.util.HashMap)1 IContainer (org.eclipse.core.resources.IContainer)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)1 SQLDatabasePersistActionAtomic (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionAtomic)1 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)1