Search in sources :

Example 16 with CsvTransformGeneratorException

use of org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException in project data-access by pentaho.

the class StagingTransformGenerator method execSqlStatement.

public void execSqlStatement(String sqlScript, DatabaseMeta ci, StringBuilder message) throws IllegalArgumentException, CsvTransformGeneratorException {
    if (ci == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("DatabaesMeta cannot be null");
    }
    Database db = getDatabase(ci);
    try {
        db.connect(null);
        // Multiple statements have to be split into parts
        // We use the ";" to separate statements...
        String all = sqlScript + Const.CR;
        int from = 0;
        int to = 0;
        int length = all.length();
        while (to < length) {
            char c = all.charAt(to);
            if (c == '"') {
                to++;
                c = ' ';
                while (to < length && c != '"') {
                    c = all.charAt(to);
                    to++;
                }
            } else if (c == '\'') {
                // skip until next '
                to++;
                c = ' ';
                while (to < length && c != '\'') {
                    c = all.charAt(to);
                    to++;
                }
            }
            c = all.charAt(to);
            if (c == ';' || to >= length - 1) {
                // end of statement
                if (to >= length - 1) {
                    // grab last char also!
                    to++;
                }
                String stat = all.substring(from, to);
                String sql = Const.trim(stat);
                try {
                    if (!sql.equals("")) {
                        // $NON-NLS-1$
                        db.execStatement(sql);
                    }
                } catch (Exception dbe) {
                    // $NON-NLS-1$
                    error("Error executing DDL", dbe);
                    throw new CsvTransformGeneratorException(dbe.getMessage(), dbe, getStackTraceAsString(dbe));
                }
                to++;
                from = to;
            } else {
                to++;
            }
        }
    } catch (KettleDatabaseException dbe) {
        // $NON-NLS-1$
        error("Connection error", dbe);
        // $NON-NLS-1$
        throw new CsvTransformGeneratorException("Connection error", dbe, getStackTraceAsString(dbe));
    } finally {
        db.disconnect();
    }
}
Also used : CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Database(org.pentaho.di.core.database.Database) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)

Example 17 with CsvTransformGeneratorException

use of org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException in project data-access by pentaho.

the class StagingTransformGenerator method preview.

public void preview(IPentahoSession session) throws CsvTransformGeneratorException {
    Trans trans = createTransform(false);
    try {
        prepareTransform(trans, session);
    } catch (Exception e) {
        // $NON-NLS-1$
        error("Preview Failed: transformation preparation", e);
        throw new CsvTransformGeneratorException("Preview Failed: transformation preparation: preview", e, // $NON-NLS-1$
        getStackTraceAsString(e));
    }
    String[] stepNames = trans.getTransMeta().getStepNames();
    executeTransformSync(trans, stepNames[stepNames.length - 1], session);
}
Also used : CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) Trans(org.pentaho.di.trans.Trans) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)

Aggregations

CsvTransformGeneratorException (org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)17 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)9 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)9 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)8 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)4 KettleException (org.pentaho.di.core.exception.KettleException)4 Database (org.pentaho.di.core.database.Database)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3 CsvTransformGenerator (org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGenerator)3 XStream (com.thoughtworks.xstream.XStream)2 ArrayList (java.util.ArrayList)2 Trans (org.pentaho.di.trans.Trans)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)2 Domain (org.pentaho.metadata.model.Domain)2 LogicalModel (org.pentaho.metadata.model.LogicalModel)2 DatasourceDTO (org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO)2 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1