use of org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryIT method testDatabaseRepository.
public void testDatabaseRepository() throws Exception {
KettleEnvironment.init();
String filename = File.createTempFile("kdrtest", "").getAbsolutePath();
System.out.println("Using file '" + filename + "' as a H2 database repository");
try {
DatabaseMeta databaseMeta = new DatabaseMeta("H2Repo", "H2", "JDBC", null, filename, null, null, null);
repositoryMeta = new KettleDatabaseRepositoryMeta("KettleDatabaseRepository", "H2Repo", "H2 Repository", databaseMeta);
repository = new KettleDatabaseRepository();
repository.init(repositoryMeta);
repository.connectionDelegate.connect(true, true);
KettleDatabaseRepositoryCreationHelper helper = new KettleDatabaseRepositoryCreationHelper(repository);
helper.createRepositorySchema(null, false, new ArrayList<String>(), false);
repository.disconnect();
// Test connecting...
//
repository.connect("admin", "admin");
assertTrue(repository.isConnected());
// Test database save
DatabaseMeta dataBaseForSave = new DatabaseMeta("H2Test", "H2", "JDBC", null, filename, null, null, null);
repository.save(dataBaseForSave, "User creates new database");
// load new database from repository by generated id on save step
DatabaseMeta loadedDataBase = repository.loadDatabaseMeta(dataBaseForSave.getObjectId(), "User creates new database");
assertEquals("Database object before save and after load form database is diffenert", dataBaseForSave, loadedDataBase);
// Test loading the directory tree
tree = repository.loadRepositoryDirectoryTree();
assertNotNull(tree);
// Test directory creation
//
RepositoryDirectoryInterface fooDirectory = repository.createRepositoryDirectory(tree, "foo");
RepositoryDirectoryInterface barDirectory = repository.createRepositoryDirectory(fooDirectory, "bar");
RepositoryDirectoryInterface samplesDirectory = repository.createRepositoryDirectory(fooDirectory, "samples");
// Test directory path lookup
RepositoryDirectoryInterface checkBar = tree.findDirectory("/foo/bar");
assertNotNull(checkBar);
assertTrue(checkBar.equals(barDirectory));
// Save all the transformations samples.
//
verifyTransformationSamples(samplesDirectory);
verifyJobSamples(samplesDirectory);
// Verify metastore functionality
//
IMetaStore metaStore = repository.getMetaStore();
KettleMetaStoreTestBase testBase = new KettleMetaStoreTestBase();
testBase.testFunctionality(metaStore);
// Finally test disconnecting
repository.disconnect();
assertFalse(repository.isConnected());
} catch (Exception e) {
e.printStackTrace();
throw new KettleException("Error during database repository unit testing", e);
} finally {
// Remove the H2 database file
//
assertTrue(new File(filename + ".h2.db").delete());
assertTrue(new File(filename + ".trace.db").delete());
}
}
use of org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta in project pentaho-kettle by pentaho.
the class RepositoryUnitIT method setUpBeforeClass.
/**
* setUpBeforeClass is a method called once before all tests are run. For this test suite, it is
* used to set up and connect to the test database repository, to increase performance and reduce
* unnecessary initialization, connects/disconnects from each test case. If repository
* initialization and/or connection/disconnection
*
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
KettleEnvironment.init();
registry = PluginRegistry.getInstance();
filename = File.createTempFile("kdrtest", "").getAbsolutePath();
System.out.println("Using file '" + filename + "' as a H2 database repository");
try {
DatabaseMeta databaseMeta = new DatabaseMeta("H2Repo", "H2", "JDBC", null, filename, null, null, null);
repositoryMeta = new KettleDatabaseRepositoryMeta("KettleDatabaseRepository", "H2Repo", "H2 Repository", databaseMeta);
repository = new KettleDatabaseRepository();
repository.init(repositoryMeta);
repository.connectionDelegate.connect(true, true);
KettleDatabaseRepositoryCreationHelper helper = new KettleDatabaseRepositoryCreationHelper(repository);
helper.createRepositorySchema(null, false, new ArrayList<String>(), false);
// Reconnect as admin
repository.disconnect();
repository.connect("admin", "admin");
} catch (Exception e) {
e.printStackTrace();
throw new KettleException("Error during database repository unit testing", e);
}
}
use of org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta in project pentaho-kettle by pentaho.
the class ExplorerHarness method main.
/**
* @param args
*/
@SuppressWarnings("nls")
public static void main(String[] args) {
KettleDatabaseRepositoryMeta repositoryMeta;
KettleDatabaseRepository repository;
@SuppressWarnings("unused") UserInfo userInfo;
repositoryMeta = new KettleDatabaseRepositoryMeta();
repositoryMeta.setName("Kettle Database Repository");
repositoryMeta.setDescription("Kettle database test repository");
DatabaseMeta connection = new DatabaseMeta();
connection.setDatabaseType("Hypersonic");
connection.setHostname("localhost");
connection.setDBName("kettle_repository_4x");
connection.setDBPort("9002");
connection.setUsername("sa");
repositoryMeta.setConnection(connection);
userInfo = new UserInfo("admin", "admin", "Administrator", "The system administrator", true);
repository = new KettleDatabaseRepository();
repository.init(repositoryMeta);
@SuppressWarnings("unused") RepositoryExplorerCallback cb = new RepositoryExplorerCallback() {
public boolean open(UIRepositoryContent element, String revision) throws Exception {
System.out.println("Name: ".concat(element.getName()));
System.out.println("Type: ".concat(element.getRepositoryElementType().name()));
System.out.println("Directory: ".concat(element.getRepositoryDirectory().toString()));
System.out.println("Revision: ".concat(revision == null ? "null" : revision));
// do not close explorer
return false;
}
@Override
public boolean error(String message) throws Exception {
System.out.println("Error message: ".concat(message));
return true;
}
};
/*
* try { repository.connect(userInfo.getLogin(), userInfo.getPassword()); //RepositoryExplorer explorer = new
* RepositoryExplorer(new Shell(), repository, cb, null); //explorer.show(); } catch (XulException e) {
* e.printStackTrace(); } catch (KettleSecurityException e) { e.printStackTrace(); } catch (KettleException e) {
* e.printStackTrace(); }
*/
}
use of org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta 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();
}
}
use of org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryDialog method drop.
private void drop() {
KettleDatabaseRepositoryMeta repositoryMeta = new KettleDatabaseRepositoryMeta();
getInfo(repositoryMeta);
try {
KettleDatabaseRepository rep = (KettleDatabaseRepository) PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
rep.init(repositoryMeta);
MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ConfirmRemovalOfRepository.Message"));
qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ConfirmRemovalOfRepository.Title"));
int answer = qmb.open();
if (answer == SWT.YES) {
EnterPasswordDialog etd = new EnterPasswordDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.AskAdminPassword.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.AskAdminPassword.Message"), "");
String pwd = etd.open();
if (pwd != null) {
try {
// Connect as admin user
rep.connect("admin", pwd);
try {
rep.dropRepositorySchema();
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.RemovedRepositoryTables.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.RemovedRepositoryTables.Title"));
mb.open();
} catch (KettleDatabaseException dbe) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToRemoveRepository.Message") + Const.CR + dbe.getMessage());
mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToRemoveRepository.Title"));
mb.open();
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyAdminUser.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyAdminUser.Message"), e);
} finally {
rep.disconnect();
}
}
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.NoRepositoryFoundOnConnection.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.NoRepositoryFoundOnConnection.Message"), ke);
}
}
Aggregations