Search in sources :

Example 61 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryJobEntryDelegate method loadJobEntryCopy.

/**
 * Load the chef graphical entry from repository We load type, name & description if no entry can be found.
 *
 * @param log
 *          the logging channel
 * @param rep
 *          the Repository
 * @param jobId
 *          The job ID
 * @param jobEntryCopyId
 *          The jobentry copy ID
 * @param jobentries
 *          A list with all jobentries
 * @param databases
 *          A list with all defined databases
 */
public JobEntryCopy loadJobEntryCopy(ObjectId jobId, ObjectId jobEntryCopyId, List<JobEntryInterface> jobentries, List<DatabaseMeta> databases, List<SlaveServer> slaveServers, String jobname) throws KettleException {
    JobEntryCopy jobEntryCopy = new JobEntryCopy();
    try {
        jobEntryCopy.setObjectId(jobEntryCopyId);
        // Handle GUI information: nr, location, ...
        RowMetaAndData r = getJobEntryCopy(jobEntryCopyId);
        if (r != null) {
            // These are the jobentry_copy fields...
            // 
            ObjectId jobEntryId = new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_JOBENTRY_COPY_ID_JOBENTRY, 0));
            ObjectId jobEntryTypeId = new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_JOBENTRY_COPY_ID_JOBENTRY_TYPE, 0));
            jobEntryCopy.setNr((int) r.getInteger(KettleDatabaseRepository.FIELD_JOBENTRY_COPY_NR, 0));
            int locx = (int) r.getInteger(KettleDatabaseRepository.FIELD_JOBENTRY_COPY_GUI_LOCATION_X, 0);
            int locy = (int) r.getInteger(KettleDatabaseRepository.FIELD_JOBENTRY_COPY_GUI_LOCATION_Y, 0);
            boolean isdrawn = r.getBoolean(KettleDatabaseRepository.FIELD_JOBENTRY_COPY_GUI_DRAW, false);
            boolean isparallel = r.getBoolean(KettleDatabaseRepository.FIELD_JOBENTRY_COPY_PARALLEL, false);
            // Do we have the jobentry already?
            // 
            jobEntryCopy.setEntry(JobMeta.findJobEntry(jobentries, jobEntryId));
            if (jobEntryCopy.getEntry() == null) {
                // What type of jobentry do we load now?
                // Get the jobentry type code
                // 
                RowMetaAndData rt = getJobEntryType(new LongObjectId(jobEntryTypeId));
                if (rt != null) {
                    String jet_code = rt.getString(KettleDatabaseRepository.FIELD_JOBENTRY_TYPE_CODE, null);
                    JobEntryInterface jobEntry = null;
                    PluginRegistry registry = PluginRegistry.getInstance();
                    PluginInterface jobPlugin = registry.findPluginWithId(JobEntryPluginType.class, jet_code);
                    if (jobPlugin == null) {
                        jobEntry = new MissingEntry(jobname, jet_code);
                    } else {
                        jobEntry = (JobEntryInterface) registry.loadClass(jobPlugin);
                    }
                    if (jobEntry != null) {
                        jobEntryCopy.setEntry(jobEntry);
                        // 
                        if (jobEntry instanceof JobEntryBase) {
                            loadJobEntryBase((JobEntryBase) jobEntry, jobEntryId, databases, slaveServers);
                            ((JobEntryBase) jobEntry).setAttributesMap(loadJobEntryAttributesMap(jobId, jobEntryId));
                        }
                        compatibleJobEntryLoadRep(jobEntry, repository, jobEntryTypeId, databases, slaveServers);
                        jobEntry.loadRep(repository, repository.metaStore, jobEntryId, databases, slaveServers);
                        jobEntryCopy.getEntry().setObjectId(jobEntryId);
                        jobentries.add(jobEntryCopy.getEntry());
                    } else {
                        throw new KettleException("JobEntryLoader was unable to find Job Entry Plugin with description [" + jet_code + "].");
                    }
                } else {
                    throw new KettleException("Unable to find Job Entry Type with id=" + jobEntryTypeId + " in the repository");
                }
            }
            jobEntryCopy.setLocation(locx, locy);
            jobEntryCopy.setDrawn(isdrawn);
            jobEntryCopy.setLaunchingInParallel(isparallel);
            return jobEntryCopy;
        } else {
            throw new KettleException("Unable to find job entry copy in repository with id_jobentry_copy=" + jobEntryCopyId);
        }
    } catch (KettleDatabaseException dbe) {
        throw new KettleException("Unable to load job entry copy from repository with id_jobentry_copy=" + jobEntryCopyId, dbe);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) MissingEntry(org.pentaho.di.job.entries.missing.MissingEntry) JobEntryBase(org.pentaho.di.job.entry.JobEntryBase) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry)

Example 62 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepository method create.

@Override
public void create() {
    if (repositoryMeta.getConnection() != null) {
        if (repositoryMeta.getConnection().getAccessType() == DatabaseMeta.TYPE_ACCESS_ODBC) {
            // This will change in a future story
            log.logDebug("ODBC type is not advised for repository use");
        }
        try {
            if (!getDatabaseMeta().getDatabaseInterface().supportsRepository()) {
                // show error about not being valid
                log.logError("This database type does not support being a repository");
            }
            connectionDelegate.connect(true, true);
            boolean upgrade = false;
            try {
                String userTableName = getDatabaseMeta().quoteField(KettleDatabaseRepository.TABLE_R_USER);
                upgrade = getDatabase().checkTableExists(userTableName);
                if (upgrade) {
                    // This will change in future story
                    log.logDebug("Database upgrade will now take place");
                }
            } catch (KettleDatabaseException dbe) {
                // Roll back the connection: this is required for certain databases like PGSQL
                // Otherwise we can't execute any other DDL statement.
                // 
                rollback();
            // Don't show an error anymore, just go ahead and propose to create the repository!
            }
            if (upgrade) {
                // authenticate as admin before upgrade
                reconnectAsAdminForUpgrade();
            }
            createRepositorySchema(null, upgrade, new ArrayList<String>(), false);
            disconnect();
        } catch (KettleException ke) {
            log.logError("An error has occurred creating a repository");
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 63 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException 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 64 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.

the class SQLStatementsDialog method exec.

private void exec() {
    int[] idx = wFields.table.getSelectionIndices();
    // None selected: don't waste users time: select them all!
    if (idx.length == 0) {
        idx = new int[stats.size()];
        for (int i = 0; i < stats.size(); i++) {
            idx[i] = i;
        }
    }
    int errors = 0;
    for (int i = 0; i < idx.length; i++) {
        SQLStatement stat = stats.get(idx[i]);
        if (stat.hasError()) {
            errors++;
        }
    }
    if (errors == 0) {
        for (int i = 0; i < idx.length; i++) {
            SQLStatement stat = stats.get(idx[i]);
            DatabaseMeta di = stat.getDatabase();
            if (di != null && !stat.hasError()) {
                Database db = new Database(loggingObject, di);
                try {
                    db.connect();
                    try {
                        db.execStatements(stat.getSQL());
                    } catch (KettleDatabaseException dbe) {
                        errors++;
                        new ErrorDialog(shell, BaseMessages.getString(PKG, "SQLStatementDialog.Error.Title"), BaseMessages.getString(PKG, "SQLStatementDialog.Error.CouldNotExec", stat.getSQL()), dbe);
                    }
                } catch (KettleDatabaseException dbe) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SQLStatementDialog.Error.Title"), BaseMessages.getString(PKG, "SQLStatementDialog.Error.CouldNotConnect", (di == null ? "" : di.getName())), dbe);
                } finally {
                    db.disconnect();
                }
            }
        }
        if (errors == 0) {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
            mb.setMessage(BaseMessages.getString(PKG, "SQLStatementDialog.Success.Message", Integer.toString(idx.length)));
            mb.setText(BaseMessages.getString(PKG, "SQLStatementDialog.Success.Title"));
            mb.open();
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "SQLStatementDialog.Error.Message", Integer.toString(errors)));
        mb.setText(BaseMessages.getString(PKG, "SQLStatementDialog.Error.Title"));
        mb.open();
    }
}
Also used : KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Database(org.pentaho.di.core.database.Database) SQLStatement(org.pentaho.di.core.SQLStatement) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 65 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.

the class Job method beginProcessing.

/**
 * Handle logging at start
 *
 * @return true if it went OK.
 *
 * @throws KettleException
 */
public boolean beginProcessing() throws KettleException {
    currentDate = new Date();
    logDate = new Date();
    startDate = Const.MIN_DATE;
    endDate = currentDate;
    resetErrors();
    final JobLogTable jobLogTable = jobMeta.getJobLogTable();
    int intervalInSeconds = Const.toInt(environmentSubstitute(jobLogTable.getLogInterval()), -1);
    if (jobLogTable.isDefined()) {
        DatabaseMeta logcon = jobMeta.getJobLogTable().getDatabaseMeta();
        String schemaName = environmentSubstitute(jobMeta.getJobLogTable().getActualSchemaName());
        String tableName = environmentSubstitute(jobMeta.getJobLogTable().getActualTableName());
        String schemaAndTable = jobMeta.getJobLogTable().getDatabaseMeta().getQuotedSchemaTableCombination(schemaName, tableName);
        Database ldb = new Database(this, logcon);
        ldb.shareVariablesWith(this);
        ldb.connect();
        ldb.setCommit(logCommitSize);
        try {
            // See if we have to add a batch id...
            Long id_batch = new Long(1);
            if (jobMeta.getJobLogTable().isBatchIdUsed()) {
                id_batch = logcon.getNextBatchId(ldb, schemaName, tableName, jobLogTable.getKeyField().getFieldName());
                setBatchId(id_batch.longValue());
                if (getPassedBatchId() <= 0) {
                    setPassedBatchId(id_batch.longValue());
                }
            }
            Object[] lastr = ldb.getLastLogDate(schemaAndTable, jobMeta.getName(), true, LogStatus.END);
            if (!Utils.isEmpty(lastr)) {
                Date last;
                try {
                    last = ldb.getReturnRowMeta().getDate(lastr, 0);
                } catch (KettleValueException e) {
                    throw new KettleJobException(BaseMessages.getString(PKG, "Job.Log.ConversionError", "" + tableName), e);
                }
                if (last != null) {
                    startDate = last;
                }
            }
            depDate = currentDate;
            ldb.writeLogRecord(jobMeta.getJobLogTable(), LogStatus.START, this, null);
            if (!ldb.isAutoCommit()) {
                ldb.commitLog(true, jobMeta.getJobLogTable());
            }
            ldb.disconnect();
            // 
            if (intervalInSeconds > 0) {
                final Timer timer = new Timer(getName() + " - interval logging timer");
                TimerTask timerTask = new TimerTask() {

                    public void run() {
                        try {
                            endProcessing();
                        } catch (Exception e) {
                            log.logError(BaseMessages.getString(PKG, "Job.Exception.UnableToPerformIntervalLogging"), e);
                            // Also stop the show...
                            // 
                            errors.incrementAndGet();
                            stopAll();
                        }
                    }
                };
                timer.schedule(timerTask, intervalInSeconds * 1000, intervalInSeconds * 1000);
                addJobListener(new JobAdapter() {

                    public void jobFinished(Job job) {
                        timer.cancel();
                    }
                });
            }
            // Add a listener at the end of the job to take of writing the final job
            // log record...
            // 
            addJobListener(new JobAdapter() {

                public void jobFinished(Job job) throws KettleException {
                    try {
                        endProcessing();
                    } catch (KettleJobException e) {
                        log.logError(BaseMessages.getString(PKG, "Job.Exception.UnableToWriteToLoggingTable", jobLogTable.toString()), e);
                        // job is failed in case log database record is failed!
                        throw new KettleException(e);
                    }
                }
            });
        } catch (KettleDatabaseException dbe) {
            // This is even before actual execution
            addErrors(1);
            throw new KettleJobException(BaseMessages.getString(PKG, "Job.Log.UnableToProcessLoggingStart", "" + tableName), dbe);
        } finally {
            ldb.disconnect();
        }
    }
    // If we need to write out the job entry logging information, do so at the end of the job:
    // 
    JobEntryLogTable jobEntryLogTable = jobMeta.getJobEntryLogTable();
    if (jobEntryLogTable.isDefined()) {
        addJobListener(new JobAdapter() {

            public void jobFinished(Job job) throws KettleException {
                try {
                    writeJobEntryLogInformation();
                } catch (KettleException e) {
                    throw new KettleException(BaseMessages.getString(PKG, "Job.Exception.UnableToPerformJobEntryLoggingAtJobEnd"), e);
                }
            }
        });
    }
    // If we need to write the log channel hierarchy and lineage information,
    // add a listener for that too...
    // 
    ChannelLogTable channelLogTable = jobMeta.getChannelLogTable();
    if (channelLogTable.isDefined()) {
        addJobListener(new JobAdapter() {

            public void jobFinished(Job job) throws KettleException {
                try {
                    writeLogChannelInformation();
                } catch (KettleException e) {
                    throw new KettleException(BaseMessages.getString(PKG, "Job.Exception.UnableToPerformLoggingAtTransEnd"), e);
                }
            }
        });
    }
    JobExecutionExtension extension = new JobExecutionExtension(this, result, null, false);
    ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.JobBeginProcessing.id, extension);
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobLogTable(org.pentaho.di.core.logging.JobLogTable) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Date(java.util.Date) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) KettleJobException(org.pentaho.di.core.exception.KettleJobException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleJobException(org.pentaho.di.core.exception.KettleJobException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) Database(org.pentaho.di.core.database.Database) FileObject(org.apache.commons.vfs2.FileObject) JobEntryLogTable(org.pentaho.di.core.logging.JobEntryLogTable) KettleValueException(org.pentaho.di.core.exception.KettleValueException) JobEntryJob(org.pentaho.di.job.entries.job.JobEntryJob)

Aggregations

KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)279 KettleException (org.pentaho.di.core.exception.KettleException)176 SQLException (java.sql.SQLException)69 Database (org.pentaho.di.core.database.Database)46 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)41 KettleValueException (org.pentaho.di.core.exception.KettleValueException)39 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)37 KettleDatabaseBatchException (org.pentaho.di.core.exception.KettleDatabaseBatchException)33 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)31 BatchUpdateException (java.sql.BatchUpdateException)27 ResultSet (java.sql.ResultSet)27 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)26 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)25 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)24 RowMeta (org.pentaho.di.core.row.RowMeta)22 FileObject (org.apache.commons.vfs2.FileObject)18 LongObjectId (org.pentaho.di.repository.LongObjectId)17 Savepoint (java.sql.Savepoint)16 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)14