use of org.pentaho.di.core.exception.KettleConfigException in project pentaho-kettle by pentaho.
the class PropertySetter method setProperty.
// this should not be a static/factory method in order to allow caching of
// compiled ognl expressions
public void setProperty(Object obj, String property, String value) throws KettleConfigException {
String[] expression = value.split(":");
Object val;
if (expression.length == 0) {
throw new KettleConfigException("No value found for property [" + property + "] and obbject class [" + obj.getClass().getName() + "]");
}
String directive = expression[0];
if (I18N.equalsIgnoreCase(directive)) {
if (expression.length == 3) {
String packageName = expression[1];
String key = expression[2];
val = BaseMessages.getString(packageName, key);
} else {
throw new KettleConfigException("the i18, directive need 3 parameters: i18n, the package name and the key, but " + expression.length + " parameters were found in [" + value + "]");
}
} else if (OGNL.equalsIgnoreCase(directive)) {
if (expression.length >= 2) {
OgnlExpression expr = ognl.get(value);
if (expr == null) {
synchronized (ognl) {
try {
ognl.put(value, expr = new OgnlExpression(expression[1]));
} catch (OgnlException e) {
throw new KettleConfigException("Unable to parse expression [" + expression[1] + "] with Ognl", e);
}
}
}
// evaluate
try {
val = expr.getValue(octx, this);
} catch (OgnlException e) {
throw new KettleConfigException("Unable to get value for expression [" + expression[1] + "] with Ognl", e);
}
} else {
throw new KettleConfigException("the ognl, directive need at least 2 parameters: ongl and the expression but " + expression.length + " parameters were found in [" + value + "]");
}
} else {
val = value;
}
try {
// SET!
BeanUtils.setProperty(obj, property, val);
} catch (Exception e) {
throw new KettleConfigException(e);
}
}
use of org.pentaho.di.core.exception.KettleConfigException in project pentaho-kettle by pentaho.
the class CombinationLookup method preloadCache.
/**
* Preload the cache
*
* @param hashRowMeta The RowMeta of the hashRow
* @throws KettleDatabaseException If something went wrong while selecting the values from the db
* @throws KettleValueException If something went wrong while adding the data to the cache
* @throws KettleConfigException If the step configuration is incomplete
* @author nwyrwa
*/
private void preloadCache(RowMetaInterface hashRowMeta) throws KettleDatabaseException, KettleValueException, KettleConfigException {
// fast exit if no preload cache or no cache
if (meta.getPreloadCache() && meta.getCacheSize() >= 0) {
if (hashRowMeta == null) {
throw new KettleConfigException(BaseMessages.getString(PKG, "CombinationLookup.Log.UnexpectedError"));
}
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
if (databaseMeta == null) {
throw new KettleConfigException(BaseMessages.getString(PKG, "CombinationLookup.Log.UnexpectedError"));
}
String lookupKeys = "";
String sql = "";
List<Object[]> cacheValues;
// Build a string representation of the lookupKeys
for (int i = 0; i < meta.getKeyLookup().length; i++) {
lookupKeys += databaseMeta.quoteField(meta.getKeyLookup()[i]);
// No comma after last field
if (i < meta.getKeyLookup().length - 1) {
lookupKeys += "," + Const.CR;
}
}
// Use min in case of disambiguation
sql += "SELECT " + Const.CR;
sql += "MIN(" + databaseMeta.quoteField(meta.getTechnicalKeyField()) + ") as " + databaseMeta.quoteField(meta.getTechnicalKeyField()) + "," + Const.CR;
sql += lookupKeys + Const.CR;
sql += "FROM " + data.schemaTable + Const.CR;
sql += "GROUP BY" + Const.CR;
sql += lookupKeys + Const.CR;
if (log.isDebug()) {
logDebug("Using preload cache statement:" + Const.CR + sql);
}
cacheValues = data.db.getRows(databaseMeta.stripCR(sql), meta.getCacheSize());
for (Object[] cacheRow : cacheValues) {
// Create a correctly structured array for the cache
Object[] hashRow = new Object[data.hashRowMeta.size()];
// Assumes the technical key is at position 0 !!
System.arraycopy(cacheRow, 1, hashRow, 0, hashRow.length);
// Potential Cache Overflow is ahndled inside
addToCache(hashRowMeta, hashRow, (Long) cacheRow[0]);
incrementLinesInput();
}
}
}
Aggregations