Search in sources :

Example 1 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(List<DBEPersistAction> actions, ObjectCreateCommand command) {
    final PostgreDatabase database = command.getObject();
    actions.add(//$NON-NLS-2$
    new SQLDatabasePersistAction("Create database", "CREATE DATABASE " + DBUtils.getQuotedIdentifier(database)));
}
Also used : PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 2 with PostgreDatabase

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

the class PostgreSqlDebugCore method createConfiguration.

public static ILaunchConfigurationWorkingCopy createConfiguration(DBSObject launchable) throws CoreException {
    boolean isInstance = launchable instanceof PostgreProcedure;
    if (!isInstance) {
        throw DebugCore.abort(PostgreDebugCoreMessages.PostgreSqlDebugCore_e_procedure_required);
    }
    PostgreProcedure procedure = (PostgreProcedure) launchable;
    PostgreDataSource dataSource = procedure.getDataSource();
    DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
    PostgreDatabase database = procedure.getDatabase();
    PostgreSchema schema = procedure.getContainer();
    String databaseName = database.getName();
    String schemaName = schema.getName();
    String procedureName = procedure.getName();
    Object[] bindings = new Object[] { dataSourceContainer.getName(), databaseName, procedureName, schemaName };
    String name = NLS.bind(PostgreDebugCoreMessages.PostgreSqlDebugCore_launch_configuration_name, bindings);
    // Let's use metadata area for storage
    IContainer container = null;
    ILaunchConfigurationWorkingCopy workingCopy = DebugCore.createConfiguration(container, CONFIGURATION_TYPE, name);
    workingCopy.setAttribute(DebugCore.ATTR_DRIVER_ID, dataSourceContainer.getDriver().getId());
    workingCopy.setAttribute(DebugCore.ATTR_DATASOURCE_ID, dataSourceContainer.getId());
    workingCopy.setAttribute(DebugCore.ATTR_DATABASE_NAME, databaseName);
    workingCopy.setAttribute(DebugCore.ATTR_SCHEMA_NAME, schemaName);
    workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_OID, String.valueOf(procedure.getObjectId()));
    workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_NAME, procedureName);
    workingCopy.setAttribute(DebugCore.ATTR_ATTACH_PROCESS, DebugCore.ATTR_ATTACH_PROCESS_DEFAULT);
    workingCopy.setAttribute(DebugCore.ATTR_ATTACH_KIND, DebugCore.ATTR_ATTACH_KIND_DEFAULT);
    workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_EXECUTE, DebugCore.ATTR_SCRIPT_EXECUTE_DEFAULT);
    workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_TEXT, DebugCore.composeScriptText(procedure));
    final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
    DBNDatabaseNode node = navigatorModel.getNodeByObject(procedure);
    workingCopy.setAttribute(DebugCore.ATTR_NODE_PATH, node.getNodeItemPath());
    return workingCopy;
}
Also used : PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IContainer(org.eclipse.core.resources.IContainer) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 3 with PostgreDatabase

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

the class PostgreResolver method resolveObject.

@Override
public DBSObject resolveObject(Map<String, Object> context, Object identifier, DBRProgressMonitor monitor) throws DBException {
    Long oid = null;
    final String errorIdentifier = String.format("Unknown procedure identifier %s", identifier);
    if (identifier instanceof Number) {
        Number number = (Number) identifier;
        oid = number.longValue();
    } else if (identifier instanceof String) {
        String string = (String) identifier;
        try {
            oid = Long.parseLong(string);
        } catch (NumberFormatException e) {
            throw new DBException(errorIdentifier, e, dataSource);
        }
    }
    if (oid == null) {
        throw new DBException(errorIdentifier);
    }
    String databaseName = String.valueOf(context.get(DBGController.DATABASE_NAME));
    PostgreDatabase database = dataSource.getDatabase(databaseName);
    if (database == null) {
        return null;
    }
    String schemaName = String.valueOf(context.get(DBGController.SCHEMA_NAME));
    PostgreSchema schema = null;
    schema = database.getSchema(monitor, schemaName);
    if (schema == null) {
        return null;
    }
    PostgreProcedure procedure = schema.getProcedure(monitor, oid);
    return procedure;
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)

Example 4 with PostgreDatabase

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

the class PostgreDatabaseManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(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));
    try {
        VoidProgressMonitor monitor = new VoidProgressMonitor();
        if (database.getDBA(monitor) != null) {
            sql.append("\nOWNER = ").append(database.getDBA(monitor).getName());
        }
        if (!CommonUtils.isEmpty(database.getTemplateName())) {
            sql.append("\nTEMPLATE = ").append(database.getTemplateName());
        }
        if (database.getDefaultEncoding(monitor) != null) {
            sql.append("\nENCODING = '").append(database.getDefaultEncoding(monitor).getName()).append("'");
        }
        if (database.getDefaultTablespace(monitor) != null) {
            sql.append("\nTABLESPACE = ").append(database.getDefaultTablespace(monitor).getName());
        }
    } catch (DBException e) {
        log.error(e);
    }
    actions.add(new SQLDatabasePersistActionAtomic("Create database", sql.toString()));
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) SQLDatabasePersistActionAtomic(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionAtomic)

Example 5 with PostgreDatabase

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

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)

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