Search in sources :

Example 1 with HasDatabasesInterface

use of org.pentaho.di.trans.HasDatabasesInterface in project pentaho-kettle by pentaho.

the class SpoonDBDelegate method editConnection.

public void editConnection(DatabaseMeta databaseMeta) {
    HasDatabasesInterface hasDatabasesInterface = spoon.getActiveHasDatabasesInterface();
    if (hasDatabasesInterface == null) {
        // program error, exit just to make sure.
        return;
    }
    String originalName = databaseMeta.getName();
    getDatabaseDialog().setDatabaseMeta(databaseMeta);
    getDatabaseDialog().setDatabases(hasDatabasesInterface.getDatabases());
    String newname = getDatabaseDialog().open();
    if (!Utils.isEmpty(newname)) {
        // null: CANCEL
        databaseMeta.setName(originalName);
        databaseMeta = getDatabaseDialog().getDatabaseMeta();
        if (!newname.equals(originalName) && databaseMeta.findDatabase(hasDatabasesInterface.getDatabases(), newname) != null) {
            databaseMeta.setName(newname.trim());
            DatabaseDialog.showDatabaseExistsDialog(spoon.getShell(), databaseMeta);
            databaseMeta.setName(originalName);
            databaseMeta.setDisplayName(originalName);
            return;
        }
        databaseMeta.setName(newname.trim());
        databaseMeta.setDisplayName(newname.trim());
        saveConnection(databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION);
        if (databaseMeta.isShared()) {
            sharedObjectSyncUtil.synchronizeConnections(databaseMeta, originalName);
        }
        saveConnection(databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION);
        if (databaseMeta.isShared()) {
            sharedObjectSyncUtil.synchronizeConnections(databaseMeta, originalName);
        }
        spoon.refreshTree();
    }
    spoon.setShellText();
}
Also used : HasDatabasesInterface(org.pentaho.di.trans.HasDatabasesInterface)

Example 2 with HasDatabasesInterface

use of org.pentaho.di.trans.HasDatabasesInterface in project pentaho-kettle by pentaho.

the class SpoonDBDelegate method exploreDB.

/**
 * return a schema, table combination from the explorer
 *
 * @param databaseMeta
 * @param aLook
 * @return schema [0] and table [1]
 */
public String[] exploreDB(DatabaseMeta databaseMeta, boolean aLook) {
    List<DatabaseMeta> databases = null;
    HasDatabasesInterface activeHasDatabasesInterface = spoon.getActiveHasDatabasesInterface();
    if (activeHasDatabasesInterface != null) {
        databases = activeHasDatabasesInterface.getDatabases();
    }
    DatabaseExplorerDialog std = new DatabaseExplorerDialog(spoon.getShell(), SWT.NONE, databaseMeta, databases, aLook);
    std.open();
    return new String[] { std.getSchemaName(), std.getTableName() };
}
Also used : HasDatabasesInterface(org.pentaho.di.trans.HasDatabasesInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog)

Example 3 with HasDatabasesInterface

use of org.pentaho.di.trans.HasDatabasesInterface in project pentaho-kettle by pentaho.

the class DatabaseConfigurationImportRule method verifyRule.

@Override
public List<ImportValidationFeedback> verifyRule(Object subject) {
    List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>();
    if (!isEnabled()) {
        return feedback;
    }
    if (databaseMeta == null) {
        feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "This rule contains no database to validate against."));
        return feedback;
    }
    DatabaseMeta verify = null;
    if (subject instanceof HasDatabasesInterface) {
        HasDatabasesInterface dbs = (HasDatabasesInterface) subject;
        verify = dbs.findDatabase(databaseMeta.getName());
    } else if (subject instanceof DatabaseMeta) {
        // 
        if (databaseMeta.getName().equals(((DatabaseMeta) subject).getName())) {
            verify = (DatabaseMeta) subject;
        }
    }
    if (verify == null) {
        return feedback;
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getDatabaseName())) {
        if (!databaseMeta.getDatabaseName().equals(verify.getDatabaseName())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The name of the database is not set to the expected value '" + databaseMeta.getDatabaseName() + "'."));
        }
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getHostname())) {
        if (!databaseMeta.getHostname().equals(verify.getHostname())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The host name of the database is not set to the expected value '" + databaseMeta.getHostname() + "'."));
        }
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getDatabasePortNumberString())) {
        if (!databaseMeta.getDatabasePortNumberString().equals(verify.getDatabasePortNumberString())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The database port of the database is not set to the expected value '" + databaseMeta.getDatabasePortNumberString() + "'."));
        }
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getUsername())) {
        if (!databaseMeta.getUsername().equals(verify.getUsername())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The username of the database is not set to the expected value '" + databaseMeta.getUsername() + "'."));
        }
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getPassword())) {
        if (!databaseMeta.getPassword().equals(verify.getPassword())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The password of the database is not set to the expected value."));
        }
    }
    if (feedback.isEmpty()) {
        feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The database connection was found and verified."));
    }
    return feedback;
}
Also used : ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback) ArrayList(java.util.ArrayList) HasDatabasesInterface(org.pentaho.di.trans.HasDatabasesInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 4 with HasDatabasesInterface

use of org.pentaho.di.trans.HasDatabasesInterface in project pentaho-kettle by pentaho.

the class Spoon method delConnection.

public void delConnection() {
    if (RepositorySecurityUI.verifyOperations(shell, rep, RepositoryOperation.DELETE_DATABASE)) {
        return;
    }
    final DatabaseMeta databaseMeta = (DatabaseMeta) selectionObject;
    MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
    mb.setMessage(BaseMessages.getString(PKG, "Spoon.ExploreDB.DeleteConnectionAsk.Message", databaseMeta.getName()));
    mb.setText(BaseMessages.getString(PKG, "Spoon.ExploreDB.DeleteConnectionAsk.Title"));
    int response = mb.open();
    if (response != SWT.YES) {
        return;
    }
    final HasDatabasesInterface hasDatabasesInterface = (HasDatabasesInterface) selectionObjectParent;
    delegates.db.delConnection(hasDatabasesInterface, databaseMeta);
}
Also used : HasDatabasesInterface(org.pentaho.di.trans.HasDatabasesInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 5 with HasDatabasesInterface

use of org.pentaho.di.trans.HasDatabasesInterface in project pentaho-kettle by pentaho.

the class Spoon method getActiveDatabases.

public List<DatabaseMeta> getActiveDatabases() {
    Map<String, DatabaseMeta> map = new Hashtable<>();
    HasDatabasesInterface hasDatabasesInterface = getActiveHasDatabasesInterface();
    if (hasDatabasesInterface != null) {
        for (int i = 0; i < hasDatabasesInterface.nrDatabases(); i++) {
            map.put(hasDatabasesInterface.getDatabase(i).getName(), hasDatabasesInterface.getDatabase(i));
        }
    }
    if (rep != null) {
        try {
            List<DatabaseMeta> repDBs = rep.readDatabases();
            for (DatabaseMeta databaseMeta : repDBs) {
                map.put(databaseMeta.getName(), databaseMeta);
            }
        } catch (Exception e) {
            log.logError("Unexpected error reading databases from the repository: " + e.toString());
            log.logError(Const.getStackTracker(e));
        }
    }
    List<DatabaseMeta> databases = new ArrayList<>();
    databases.addAll(map.values());
    return databases;
}
Also used : Hashtable(java.util.Hashtable) HasDatabasesInterface(org.pentaho.di.trans.HasDatabasesInterface) ArrayList(java.util.ArrayList) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException)

Aggregations

HasDatabasesInterface (org.pentaho.di.trans.HasDatabasesInterface)9 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)7 ArrayList (java.util.ArrayList)3 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)3 Point (org.pentaho.di.core.gui.Point)3 KettleException (org.pentaho.di.core.exception.KettleException)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 MalformedURLException (java.net.MalformedURLException)1 Hashtable (java.util.Hashtable)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 SWTException (org.eclipse.swt.SWTException)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 KettleAuthException (org.pentaho.di.core.exception.KettleAuthException)1 KettleFileException (org.pentaho.di.core.exception.KettleFileException)1 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)1 KettleRowException (org.pentaho.di.core.exception.KettleRowException)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1 LifecycleException (org.pentaho.di.core.lifecycle.LifecycleException)1 ImportValidationFeedback (org.pentaho.di.imp.rule.ImportValidationFeedback)1