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