use of org.pentaho.di.trans.steps.tableoutput.TableOutputData in project pentaho-kettle by pentaho.
the class TableAgileMart method adjustSchema.
@Override
public boolean adjustSchema() {
TableOutputMeta meta = getMeta();
TableOutputData data = getData();
TransMeta transMeta = getTransMeta();
StepMeta stepMeta = meta.getParentStepMeta();
DBCache dbcache = transMeta.getDbCache();
StringBuilder messageBuffer = new StringBuilder();
try {
RowMetaInterface prev = transMeta.getPrevStepFields(stepMeta.getName());
if (log.isDetailed()) {
logDetailed("Attempting to auto adjust table structure");
}
if (log.isDetailed()) {
logDetailed("getTransMeta: " + getTransMeta());
}
if (log.isDetailed()) {
logDetailed("getStepname: " + getStepname());
}
SQLStatement statement = meta.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
if (log.isDetailed()) {
logDetailed("Statement: " + statement);
}
if (log.isDetailed() && statement != null) {
logDetailed("Statement has SQL: " + statement.hasSQL());
}
if (statement != null && statement.hasSQL()) {
String sql = statement.getSQL();
if (log.isDetailed()) {
logDetailed("Trying: " + sql);
}
try {
log.logDetailed("Executing SQL: " + Const.CR + sql);
data.db.execStatement(sql);
// Clear the database cache, in case we're using one...
if (dbcache != null) {
dbcache.clear(data.databaseMeta.getName());
}
} catch (Exception dbe) {
String error = BaseMessages.getString(PKG, "SQLEditor.Log.SQLExecError", sql, dbe.toString());
messageBuffer.append(error).append(Const.CR);
return false;
}
if (log.isDetailed()) {
logDetailed("Successfull: " + sql);
}
} else if (statement.getError() == null) {
// there were no changes to be made
return true;
} else {
this.message = statement.getError();
logError(statement.getError());
return false;
}
} catch (Exception e) {
logError("An error ocurred trying to adjust the table schema", e);
}
return true;
}
use of org.pentaho.di.trans.steps.tableoutput.TableOutputData in project pentaho-kettle by pentaho.
the class TableAgileMart method dropTable.
@Override
public boolean dropTable() {
TableOutputMeta meta = getMeta();
TableOutputData data = getData();
String schema = meta.getSchemaName();
String table = meta.getTableName();
if (schema != null && !schema.equals("")) {
table = schema + "." + table;
}
String sql = "drop table " + table + ";";
try {
Result result = data.db.execStatement(sql);
int status = result.getExitStatus();
if (status == 0) {
util.updateMetadata(meta, -1);
}
return status == 0;
} catch (KettleDatabaseException e) {
message = "Could not drop table: " + table;
logError(message, e);
}
return false;
}
use of org.pentaho.di.trans.steps.tableoutput.TableOutputData in project pentaho-kettle by pentaho.
the class TableAgileMart method truncateTable.
@Override
public boolean truncateTable() {
TableOutputMeta meta = getMeta();
TableOutputData data = getData();
try {
data.db.truncateTable(environmentSubstitute(meta.getSchemaName()), environmentSubstitute(meta.getTableName()));
util.updateMetadata(meta, -1);
return true;
} catch (KettleDatabaseException e) {
message = "Could not truncate table: " + meta.getTableName();
logError(message, e);
}
return false;
}
Aggregations