Search in sources :

Example 1 with TableOutputData

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;
}
Also used : TableOutputData(org.pentaho.di.trans.steps.tableoutput.TableOutputData) DBCache(org.pentaho.di.core.DBCache) TransMeta(org.pentaho.di.trans.TransMeta) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Example 2 with TableOutputData

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;
}
Also used : TableOutputData(org.pentaho.di.trans.steps.tableoutput.TableOutputData) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) Result(org.pentaho.di.core.Result)

Example 3 with TableOutputData

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;
}
Also used : TableOutputData(org.pentaho.di.trans.steps.tableoutput.TableOutputData) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)

Aggregations

KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3 TableOutputData (org.pentaho.di.trans.steps.tableoutput.TableOutputData)3 TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)3 DBCache (org.pentaho.di.core.DBCache)1 Result (org.pentaho.di.core.Result)1 SQLStatement (org.pentaho.di.core.SQLStatement)1 KettleException (org.pentaho.di.core.exception.KettleException)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 TransMeta (org.pentaho.di.trans.TransMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1