Search in sources :

Example 1 with DBCache

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

the class Database method getQueryFields.

public RowMetaInterface getQueryFields(String sql, boolean param, RowMetaInterface inform, Object[] data) throws KettleDatabaseException {
    RowMetaInterface fields;
    DBCache dbcache = DBCache.getInstance();
    DBCacheEntry entry = null;
    // 
    if (dbcache != null) {
        entry = new DBCacheEntry(databaseMeta.getName(), sql);
        fields = dbcache.get(entry);
        if (fields != null) {
            return fields;
        }
    }
    if (connection == null) {
        // Cache test without connect.
        return null;
    }
    // 
    try {
        if (databaseMeta.supportsPreparedStatementMetadataRetrieval()) {
            // On with the regular program.
            // 
            fields = getQueryFieldsFromPreparedStatement(sql);
        } else {
            fields = getQueryFieldsFromDatabaseMetaData();
        }
    } catch (Exception e) {
        /*
       * databaseMeta.getDatabaseType()==DatabaseMeta.TYPE_DATABASE_SYBASEIQ ) {
       */
        fields = getQueryFieldsFallback(sql, param, inform, data);
    }
    // Store in cache!!
    if (dbcache != null && entry != null) {
        if (fields != null) {
            dbcache.put(entry, fields);
        }
    }
    return fields;
}
Also used : DBCache(org.pentaho.di.core.DBCache) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DBCacheEntry(org.pentaho.di.core.DBCacheEntry) KettleValueException(org.pentaho.di.core.exception.KettleValueException) BatchUpdateException(java.sql.BatchUpdateException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleDatabaseBatchException(org.pentaho.di.core.exception.KettleDatabaseBatchException)

Example 2 with DBCache

use of org.pentaho.di.core.DBCache 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)

Aggregations

DBCache (org.pentaho.di.core.DBCache)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 KettleException (org.pentaho.di.core.exception.KettleException)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 BatchUpdateException (java.sql.BatchUpdateException)1 SQLException (java.sql.SQLException)1 DBCacheEntry (org.pentaho.di.core.DBCacheEntry)1 SQLStatement (org.pentaho.di.core.SQLStatement)1 KettleDatabaseBatchException (org.pentaho.di.core.exception.KettleDatabaseBatchException)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 TransMeta (org.pentaho.di.trans.TransMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 TableOutputData (org.pentaho.di.trans.steps.tableoutput.TableOutputData)1 TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)1