Search in sources :

Example 6 with DBPPreferenceMap

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceMap in project dbeaver by serge-rider.

the class MySQLExportSettings method saveSettings.

@Override
public void saveSettings(DBRRunnableContext runnableContext, DBPPreferenceStore store) {
    super.saveSettings(runnableContext, store);
    store.setValue("MySQL.export.method", method.name());
    store.setValue("MySQL.export.noCreateStatements", noCreateStatements);
    store.setValue("MySQL.export.addDropStatements", addDropStatements);
    store.setValue("MySQL.export.disableKeys", disableKeys);
    store.setValue("MySQL.export.extendedInserts", extendedInserts);
    store.setValue("MySQL.export.dumpEvents", dumpEvents);
    store.setValue("MySQL.export.comments", comments);
    store.setValue("MySQL.export.removeDefiner", removeDefiner);
    store.setValue("MySQL.export.binariesInHex", binariesInHex);
    store.setValue("MySQL.export.noData", noData);
    store.setValue("MySQL.export.showViews", showViews);
    store.setValue(MySQLNativeCredentialsSettings.PREFERENCE_NAME, overrideCredentials);
    if (store instanceof DBPPreferenceMap && !CommonUtils.isEmpty(exportObjects)) {
        // Save input objects to task properties
        List<Map<String, Object>> objectList = new ArrayList<>();
        for (MySQLDatabaseExportInfo object : exportObjects) {
            Map<String, Object> objInfo = new LinkedHashMap<>();
            objInfo.put("catalog", DBUtils.getObjectFullId(object.getDatabase()));
            if (!CommonUtils.isEmpty(object.getTables())) {
                List<String> tableList = new ArrayList<>();
                for (MySQLTableBase table : object.getTables()) {
                    tableList.add(table.getName());
                }
                objInfo.put("tables", tableList);
            }
            objectList.add(objInfo);
        }
        ((DBPPreferenceMap) store).getPropertyMap().put("exportObjects", objectList);
    }
}
Also used : DBPPreferenceMap(org.jkiss.dbeaver.model.preferences.DBPPreferenceMap) MySQLTableBase(org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase) ArrayList(java.util.ArrayList) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPPreferenceMap(org.jkiss.dbeaver.model.preferences.DBPPreferenceMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with DBPPreferenceMap

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceMap in project dbeaver by serge-rider.

the class AbstractNativeToolSettings method saveSettings.

public void saveSettings(DBRRunnableContext runnableContext, DBPPreferenceStore preferenceStore) {
    preferenceStore.setValue("project", getProject().getName());
    if (dataSourceContainer != null) {
        preferenceStore.setValue("dataSource", dataSourceContainer.getId());
    }
    if (preferenceStore instanceof DBPPreferenceMap) {
        // Save input objects to task properties
        Map<String, Object> propertyMap = ((DBPPreferenceMap) preferenceStore).getPropertyMap();
        List<String> objectList = new ArrayList<>();
        for (BASE_OBJECT object : databaseObjects) {
            objectList.add(DBUtils.getObjectFullId(object));
        }
        propertyMap.put("databaseObjects", objectList);
        try {
            final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
            if (!CommonUtils.isEmpty(toolUserName)) {
                propertyMap.put("tool.user", encrypter.encrypt(toolUserName));
            } else {
                propertyMap.put("tool.user", "");
            }
            if (!CommonUtils.isEmpty(toolUserPassword)) {
                propertyMap.put("tool.password", encrypter.encrypt(toolUserPassword));
            } else {
                propertyMap.put("tool.password", "");
            }
        } catch (Exception e) {
            log.debug(e);
        }
    }
    preferenceStore.setValue(PROP_NAME_EXTRA_ARGS, extraCommandArgs);
    if (clientHomeName != null) {
        preferenceStore.setValue("clientHomeName", clientHomeName);
    }
}
Also used : DBPPreferenceMap(org.jkiss.dbeaver.model.preferences.DBPPreferenceMap) SecuredPasswordEncrypter(org.jkiss.dbeaver.runtime.encode.SecuredPasswordEncrypter) ArrayList(java.util.ArrayList) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Example 8 with DBPPreferenceMap

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceMap in project dbeaver by serge-rider.

the class AbstractNativeToolSettings method loadSettings.

public void loadSettings(DBRRunnableContext runnableContext, DBPPreferenceStore preferenceStore) throws DBException {
    if (dataSourceContainer == null && !CommonUtils.isEmpty(databaseObjects)) {
        BASE_OBJECT baseObject = databaseObjects.get(0);
        dataSourceContainer = baseObject instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) baseObject : baseObject.getDataSource().getContainer();
    }
    if (dataSourceContainer == null) {
        String dsID = preferenceStore.getString("dataSource");
        if (!CommonUtils.isEmpty(dsID)) {
            String projectName = preferenceStore.getString("project");
            DBPProject project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
            if (project == null) {
                if (!CommonUtils.isEmpty(projectName)) {
                    log.error("Can't find project '" + projectName + "' for tool configuration");
                }
                project = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
            }
            dataSourceContainer = project.getDataSourceRegistry().getDataSource(dsID);
            if (dataSourceContainer == null) {
                log.error("Can't find datasource '" + dsID + "' in project '" + project.getName() + "' for tool configuration");
            }
        }
    }
    if (preferenceStore instanceof DBPPreferenceMap && dataSourceContainer != null) {
        List<String> databaseObjectList = ((DBPPreferenceMap) preferenceStore).getObject("databaseObjects");
        if (!CommonUtils.isEmpty(databaseObjectList)) {
            DBPProject finalProject = dataSourceContainer.getProject();
            try {
                runnableContext.run(true, true, monitor -> {
                    monitor.beginTask("Load database object list", databaseObjectList.size());
                    try {
                        for (String objectId : databaseObjectList) {
                            monitor.subTask("Load " + objectId);
                            try {
                                DBSObject object = DBUtils.findObjectById(monitor, finalProject, objectId);
                                if (object != null) {
                                    databaseObjects.add((BASE_OBJECT) object);
                                    dataSourceContainer = object instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) object : object.getDataSource().getContainer();
                                }
                            } catch (Throwable e) {
                                throw new DBException("Can't find database object '" + objectId + "' in project '" + finalProject.getName() + "' for task configuration", e);
                            }
                            monitor.worked(1);
                        }
                    } catch (Exception e) {
                        throw new InvocationTargetException(e);
                    } finally {
                        monitor.done();
                    }
                });
            } catch (InvocationTargetException e) {
                throw new DBException("Error loading objects configuration", e.getTargetException());
            } catch (InterruptedException e) {
            // Ignore
            }
        }
    }
    extraCommandArgs = preferenceStore.getString(PROP_NAME_EXTRA_ARGS);
    clientHomeName = preferenceStore.getString("clientHomeName");
    if (preferenceStore instanceof DBPPreferenceMap) {
        toolUserName = preferenceStore.getString("tool.user");
        toolUserPassword = preferenceStore.getString("tool.password");
        try {
            final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
            if (!CommonUtils.isEmpty(toolUserName))
                toolUserName = encrypter.decrypt(toolUserName);
            if (!CommonUtils.isEmpty(toolUserPassword))
                toolUserPassword = encrypter.decrypt(toolUserPassword);
        } catch (Exception e) {
            throw new DBException("Error decrypting user credentials", e);
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPPreferenceMap(org.jkiss.dbeaver.model.preferences.DBPPreferenceMap) SecuredPasswordEncrypter(org.jkiss.dbeaver.runtime.encode.SecuredPasswordEncrypter) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 9 with DBPPreferenceMap

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceMap in project dbeaver by serge-rider.

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)

Example 10 with DBPPreferenceMap

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceMap in project dbeaver by dbeaver.

the class MySQLExportSettings method saveSettings.

@Override
public void saveSettings(DBRRunnableContext runnableContext, DBPPreferenceStore store) {
    super.saveSettings(runnableContext, store);
    store.setValue("MySQL.export.method", method.name());
    store.setValue("MySQL.export.noCreateStatements", noCreateStatements);
    store.setValue("MySQL.export.addDropStatements", addDropStatements);
    store.setValue("MySQL.export.disableKeys", disableKeys);
    store.setValue("MySQL.export.extendedInserts", extendedInserts);
    store.setValue("MySQL.export.dumpEvents", dumpEvents);
    store.setValue("MySQL.export.comments", comments);
    store.setValue("MySQL.export.removeDefiner", removeDefiner);
    store.setValue("MySQL.export.binariesInHex", binariesInHex);
    store.setValue("MySQL.export.noData", noData);
    store.setValue("MySQL.export.showViews", showViews);
    store.setValue(MySQLNativeCredentialsSettings.PREFERENCE_NAME, overrideCredentials);
    if (store instanceof DBPPreferenceMap && !CommonUtils.isEmpty(exportObjects)) {
        // Save input objects to task properties
        List<Map<String, Object>> objectList = new ArrayList<>();
        for (MySQLDatabaseExportInfo object : exportObjects) {
            Map<String, Object> objInfo = new LinkedHashMap<>();
            objInfo.put("catalog", DBUtils.getObjectFullId(object.getDatabase()));
            if (!CommonUtils.isEmpty(object.getTables())) {
                List<String> tableList = new ArrayList<>();
                for (MySQLTableBase table : object.getTables()) {
                    tableList.add(table.getName());
                }
                objInfo.put("tables", tableList);
            }
            objectList.add(objInfo);
        }
        ((DBPPreferenceMap) store).getPropertyMap().put("exportObjects", objectList);
    }
}
Also used : DBPPreferenceMap(org.jkiss.dbeaver.model.preferences.DBPPreferenceMap) MySQLTableBase(org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase) ArrayList(java.util.ArrayList) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPPreferenceMap(org.jkiss.dbeaver.model.preferences.DBPPreferenceMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

DBPPreferenceMap (org.jkiss.dbeaver.model.preferences.DBPPreferenceMap)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 ArrayList (java.util.ArrayList)6 DBException (org.jkiss.dbeaver.DBException)6 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 SecuredPasswordEncrypter (org.jkiss.dbeaver.runtime.encode.SecuredPasswordEncrypter)4 MySQLTableBase (org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase)2 PostgreDatabase (org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase)2 PostgreSchema (org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)2 PostgreTableBase (org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)2