Search in sources :

Example 86 with Database

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();
}
Also used : Database(org.pentaho.di.core.database.Database) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) After(org.junit.After)

Example 87 with Database

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Database(org.pentaho.di.core.database.Database) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 88 with Database

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();
    }
}
Also used : KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) XulMessageBox(org.pentaho.ui.xul.components.XulMessageBox) MessageBox(org.eclipse.swt.widgets.MessageBox) Database(org.pentaho.di.core.database.Database) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog)

Example 89 with Database

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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Database(org.pentaho.di.core.database.Database) ProgressMonitorAdapter(org.pentaho.di.core.ProgressMonitorAdapter) InvocationTargetException(java.lang.reflect.InvocationTargetException) KettleException(org.pentaho.di.core.exception.KettleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 90 with Database

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();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

Database (org.pentaho.di.core.database.Database)238 KettleException (org.pentaho.di.core.exception.KettleException)135 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)90 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)82 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)62 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)46 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)32 KettleStepException (org.pentaho.di.core.exception.KettleStepException)30 MessageBox (org.eclipse.swt.widgets.MessageBox)28 CheckResult (org.pentaho.di.core.CheckResult)25 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)25 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)24 RowMeta (org.pentaho.di.core.row.RowMeta)22 SQLStatement (org.pentaho.di.core.SQLStatement)21 EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)21 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)18 KettleValueException (org.pentaho.di.core.exception.KettleValueException)17 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)16 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)15