Search in sources :

Example 16 with PostgreDatabase

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

the class PostgreDatabaseManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectCreateCommand command, Map<String, Object> options) {
    final PostgreDatabase database = command.getObject();
    StringBuilder sql = new StringBuilder();
    sql.append("CREATE DATABASE ").append(DBUtils.getQuotedIdentifier(database));
    if (database.getInitialOwner() != null) {
        sql.append("\nOWNER = ").append(DBUtils.getQuotedIdentifier(database.getInitialOwner()));
    }
    if (!CommonUtils.isEmpty(database.getTemplateName())) {
        sql.append("\nTEMPLATE = ").append(DBUtils.getQuotedIdentifier(database.getDataSource(), database.getTemplateName()));
    }
    if (database.getInitialEncoding() != null) {
        sql.append("\nENCODING = '").append(database.getInitialEncoding().getName()).append("'");
    }
    if (database.getInitialTablespace() != null) {
        sql.append("\nTABLESPACE = ").append(DBUtils.getQuotedIdentifier(database.getDataSource(), database.getInitialTablespace().getName()));
    }
    actions.add(new CreateDatabaseAction(database, sql));
}
Also used : PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase)

Example 17 with PostgreDatabase

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

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 18 with PostgreDatabase

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

the class PostgreToolRestore method execute.

@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
    for (DBSObject object : objects) {
        PostgreDatabase database;
        if (object instanceof PostgreSchema) {
            database = ((PostgreSchema) object).getDatabase();
        } else if (object instanceof PostgreDatabase) {
            database = (PostgreDatabase) object;
        } else {
            continue;
        }
        NativeToolWizardDialog dialog = new NativeToolWizardDialog(window, new PostgreRestoreWizard(database));
        dialog.open();
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) NativeToolWizardDialog(org.jkiss.dbeaver.tasks.ui.nativetool.NativeToolWizardDialog)

Example 19 with PostgreDatabase

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

the class PostgreFDWConfigTool method execute.

@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
    for (DBSObject object : objects) {
        PostgreDatabase database;
        if (object instanceof PostgreObject) {
            database = ((PostgreObject) object).getDatabase();
        } else {
            continue;
        }
        ActiveWizardDialog dialog = new ActiveWizardDialog(window, new PostgreFDWConfigWizard(database));
        dialog.setFinishButtonLabel("Install");
        dialog.open();
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) PostgreObject(org.jkiss.dbeaver.ext.postgresql.model.PostgreObject)

Example 20 with PostgreDatabase

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

the class PostgreSqlDebugCore method resolveFunction.

public static PostgreProcedure resolveFunction(DBRProgressMonitor monitor, DBPDataSourceContainer dsContainer, Map<String, Object> configuration) throws DBException {
    if (!dsContainer.isConnected()) {
        dsContainer.connect(monitor, true, true);
    }
    long functionId = CommonUtils.toLong(configuration.get(PostgreDebugConstants.ATTR_FUNCTION_OID));
    String databaseName = (String) configuration.get(PostgreDebugConstants.ATTR_DATABASE_NAME);
    String schemaName = (String) configuration.get(PostgreDebugConstants.ATTR_SCHEMA_NAME);
    PostgreDataSource ds = (PostgreDataSource) dsContainer.getDataSource();
    PostgreDatabase database = ds.getDatabase(databaseName);
    if (database != null) {
        PostgreSchema schema = database.getSchema(monitor, schemaName);
        if (schema != null) {
            PostgreProcedure function = schema.getProcedure(monitor, functionId);
            if (function != null) {
                return function;
            }
            throw new DBException("Function " + functionId + " not found in schema " + schemaName);
        } else {
            throw new DBException("Schema '" + schemaName + "' not found in database " + databaseName);
        }
    } else {
        throw new DBException("Database '" + databaseName + "' not found");
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)

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