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();
}
}
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);
}
Aggregations