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();
}
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() };
}
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;
}
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);
}
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;
}
Aggregations