use of org.pentaho.di.ui.repository.dialog.UpgradeRepositoryProgressDialog in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryDialog method create.
private void create() {
System.out.println("Loading repository info...");
KettleDatabaseRepositoryMeta repositoryMeta = new KettleDatabaseRepositoryMeta();
getInfo(repositoryMeta);
if (repositoryMeta.getConnection() != null) {
if (repositoryMeta.getConnection().getAccessType() == DatabaseMeta.TYPE_ACCESS_ODBC) {
// Show a warning: using ODBC is not always the best choice ;-)
System.out.println("Show ODBC warning...");
MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ODBCIsNotSafe.Message", Const.CR, Const.CR));
qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ODBCIsNotSafe.Title"));
int answer = qmb.open();
if (answer != SWT.YES) {
// Don't continue
return;
}
}
try {
System.out.println("Allocating repository...");
KettleDatabaseRepository rep = (KettleDatabaseRepository) PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
rep.init(repositoryMeta);
if (!rep.getDatabaseMeta().getDatabaseInterface().supportsRepository()) {
// Show a warning box "This database type is not supported for the use as a database repository."
System.out.println("Show database type is not supported warning...");
MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.DBTypeNotSupport.Message", Const.CR, Const.CR));
qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.DBTypeNotSupport.Title"));
int answer = qmb.open();
if (answer != SWT.YES) {
// Don't continue
return;
}
}
System.out.println("Connecting to database for repository creation...");
rep.connectionDelegate.connect(true, true);
boolean upgrade = false;
String cu = BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Create");
try {
String userTableName = rep.getDatabaseMeta().quoteField(KettleDatabaseRepository.TABLE_R_USER);
upgrade = rep.getDatabase().checkTableExists(userTableName);
if (upgrade) {
cu = BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Upgrade");
}
} catch (KettleDatabaseException dbe) {
// Roll back the connection: this is required for certain databases like PGSQL
// Otherwise we can't execute any other DDL statement.
//
rep.rollback();
// Don't show an error anymore, just go ahead and propose to create the repository!
}
MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Message1") + cu + BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Message2"));
qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Title"));
int answer = qmb.open();
if (answer == SWT.YES) {
boolean goAhead = !upgrade;
if (!goAhead) {
EnterPasswordDialog etd = new EnterPasswordDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.EnterPassword.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.EnterPassword.Message"), "");
etd.setModal();
String pwd = etd.open();
if (pwd != null) {
try {
// authenticate as admin before upgrade
// disconnect before connecting, we connected above already
//
rep.disconnect();
rep.connect("admin", pwd, true);
goAhead = true;
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyUser.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyUser.Message"), e);
}
}
}
if (goAhead) {
System.out.println(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.TryingToUpgradeRepository.Message1") + cu + BaseMessages.getString(PKG, "RepositoryDialog.Dialog.TryingToUpgradeRepository.Message2"));
UpgradeRepositoryProgressDialog urpd = new UpgradeRepositoryProgressDialog(shell, rep, upgrade);
if (urpd.open()) {
if (urpd.isDryRun()) {
StringBuilder sql = new StringBuilder();
sql.append("-- Repository creation/upgrade DDL: ").append(Const.CR);
sql.append("--").append(Const.CR);
sql.append("-- Nothing was created nor modified in the target repository database.").append(Const.CR);
sql.append("-- Hit the OK button to execute the generated SQL or Close to reject the changes.").append(Const.CR);
sql.append("-- Please note that it is possible to change/edit the generated SQL before execution.").append(Const.CR);
sql.append("--").append(Const.CR);
for (String statement : urpd.getGeneratedStatements()) {
if (statement.endsWith(";")) {
sql.append(statement).append(Const.CR);
} else {
sql.append(statement).append(";").append(Const.CR).append(Const.CR);
}
}
SQLEditor editor = new SQLEditor(rep.getDatabaseMeta(), shell, SWT.NONE, rep.getDatabaseMeta(), DBCache.getInstance(), sql.toString());
editor.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UpgradeFinished.Message1") + cu + BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UpgradeFinished.Message2"));
mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UpgradeFinished.Title"));
mb.open();
}
}
}
}
rep.disconnect();
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToConnectToUpgrade.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToConnectToUpgrade.Message") + Const.CR, ke);
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.FirstCreateAValidConnection.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.FirstCreateAValidConnection.Title"));
mb.open();
}
}
Aggregations