use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class JobTrackerExecution method after.
@After
public void after() throws KettleDatabaseException {
// DatabaseMeta databaseMeta = new DatabaseMeta( NAME, "H2", "JDBC", null, TMP, null, USER, USER );
DatabaseMeta databaseMeta = new DatabaseMeta(NAME, "Hypersonic", "JDBC", null, "mem:HSQLDB-JUNIT-LOGJOB", null, null, null);
LoggingObjectInterface log = new SimpleLoggingObject("junit", LoggingObjectType.GENERAL, null);
Database db = new Database(log, databaseMeta);
db.connect();
db.execStatements("DROP SCHEMA PUBLIC CASCADE");
db.commit(true);
db.disconnect();
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class GetQueryFieldsProgressDialog method open.
public RowMetaInterface open() {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
db = new Database(Spoon.loggingObject, dbMeta);
try {
db.connect();
result = db.getQueryFields(sql, false);
if (monitor.isCanceled()) {
throw new InvocationTargetException(new Exception("This operation was cancelled!"));
}
} catch (Exception e) {
throw new InvocationTargetException(e, "Problem encountered determining query fields: " + e.toString());
} finally {
db.disconnect();
}
}
};
try {
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
// Run something in the background to cancel active database queries, forecably if needed!
Runnable run = new Runnable() {
public void run() {
IProgressMonitor monitor = pmd.getProgressMonitor();
while (pmd.getShell() == null || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// Ignore
}
}
if (monitor.isCanceled()) {
try {
db.cancelQuery();
} catch (Exception e) {
// Ignore
}
}
}
};
// Dump the cancel looker in the background!
new Thread(run).start();
pmd.run(true, true, op);
} catch (InvocationTargetException e) {
showErrorDialog(e);
return null;
} catch (InterruptedException e) {
showErrorDialog(e);
return null;
}
return result;
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class XulDatabaseExplorerController method getDDLForOther.
public void getDDLForOther() {
if (databases != null) {
try {
// Now select the other connection...
// Only take non-SAP ERP connections....
List<DatabaseMeta> dbs = new ArrayList<DatabaseMeta>();
for (int i = 0; i < databases.size(); i++) {
if (((databases.get(i)).getDatabaseInterface().isExplorable())) {
dbs.add(databases.get(i));
}
}
String[] conn = new String[dbs.size()];
for (int i = 0; i < conn.length; i++) {
conn[i] = (dbs.get(i)).getName();
}
EnterSelectionDialog esd = new EnterSelectionDialog(this.dbExplorerDialog.getShell(), conn, BaseMessages.getString(PKG, "DatabaseExplorerDialog.TargetDatabase.Title"), BaseMessages.getString(PKG, "DatabaseExplorerDialog.TargetDatabase.Message"));
String target = esd.open();
if (target != null) {
DatabaseMeta targetdbi = DatabaseMeta.findDatabase(dbs, target);
Database targetdb = new Database(null, targetdbi);
try {
targetdb.connect();
String tableName = getSchemaAndTable(model);
RowMetaInterface r = targetdb.getTableFields(tableName);
String sql = targetdb.getCreateTableStatement(tableName, r, null, false, null, true);
SQLEditor se = new SQLEditor(this.getDatabaseMeta(), this.dbExplorerDialog.getShell(), SWT.NONE, this.model.getDatabaseMeta(), this.dbcache, sql);
se.open();
} finally {
targetdb.disconnect();
}
}
} catch (KettleDatabaseException dbe) {
new ErrorDialog(this.dbExplorerDialog.getShell(), BaseMessages.getString(PKG, "Dialog.Error.Header"), BaseMessages.getString(PKG, "DatabaseExplorerDialog.Error.GenDDL"), dbe);
}
} else {
MessageBox mb = new MessageBox(this.dbExplorerDialog.getShell(), SWT.NONE | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "DatabaseExplorerDialog.NoConnectionsKnown.Message"));
mb.setText(BaseMessages.getString(PKG, "DatabaseExplorerDialog.NoConnectionsKnown.Title"));
mb.open();
}
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class GetPreviewTableProgressDialog method open.
public List<Object[]> open() {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
db = new Database(Spoon.loggingObject, dbMeta);
try {
db.connect();
if (limit > 0) {
db.setQueryLimit(limit);
}
rows = db.getFirstRows(tableName, limit, new ProgressMonitorAdapter(monitor));
rowMeta = db.getReturnRowMeta();
} catch (KettleException e) {
throw new InvocationTargetException(e, "Couldn't find any rows because of an error :" + e.toString());
} finally {
db.disconnect();
}
}
};
try {
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
// Run something in the background to cancel active database queries, forecably if needed!
Runnable run = new Runnable() {
public void run() {
IProgressMonitor monitor = pmd.getProgressMonitor();
while (pmd.getShell() == null || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// Ignore
}
}
if (monitor.isCanceled()) {
try {
db.cancelQuery();
} catch (Exception e) {
// Ignore
}
}
}
};
// Start the cancel tracker in the background!
new Thread(run).start();
pmd.run(true, true, op);
} catch (InvocationTargetException e) {
showErrorDialog(e);
return null;
} catch (InterruptedException e) {
showErrorDialog(e);
return null;
}
return rows;
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class JobEntryWaitForSQLDialog method getSQL.
private void getSQL() {
DatabaseMeta inf = jobMeta.findDatabase(wConnection.getText());
if (inf != null) {
DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, jobMeta.getDatabases());
if (std.open()) {
String sql = "SELECT *" + Const.CR + "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
wSQL.setText(sql);
MessageBox yn = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
yn.setMessage(BaseMessages.getString(PKG, "JobEntryWaitForSQL.IncludeFieldNamesInSQL"));
yn.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.DialogCaptionQuestion"));
int id = yn.open();
switch(id) {
case SWT.CANCEL:
break;
case SWT.NO:
wSQL.setText(sql);
break;
case SWT.YES:
Database db = new Database(loggingObject, inf);
try {
db.connect();
RowMetaInterface fields = db.getQueryFields(sql, false);
if (fields != null) {
sql = "SELECT" + Const.CR;
for (int i = 0; i < fields.size(); i++) {
ValueMetaInterface field = fields.getValueMeta(i);
if (i == 0) {
sql += " ";
} else {
sql += ", ";
}
sql += inf.quoteField(field.getName()) + Const.CR;
}
sql += "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
wSQL.setText(sql);
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "JobEntryWaitForSQL.ERROR_CouldNotRetrieveFields") + Const.CR + BaseMessages.getString(PKG, "JobEntryWaitForSQL.PerhapsNoPermissions"));
mb.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.DialogCaptionError2"));
mb.open();
}
} catch (KettleException e) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.DialogCaptionError3"));
mb.setMessage(BaseMessages.getString(PKG, "JobEntryWaitForSQL.AnErrorOccurred") + Const.CR + e.getMessage());
mb.open();
} finally {
db.disconnect();
}
break;
default:
break;
}
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "JobEntryWaitForSQL.ConnectionNoLongerAvailable"));
mb.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.DialogCaptionError4"));
mb.open();
}
}
Aggregations