use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class ValueDataUtil method loadFileContentInBinary.
public static Object loadFileContentInBinary(ValueMetaInterface metaA, Object dataA) throws KettleValueException {
if (dataA == null) {
return null;
}
FileObject file = null;
FileInputStream fis = null;
try {
file = KettleVFS.getFileObject(dataA.toString());
fis = (FileInputStream) ((LocalFile) file).getInputStream();
int fileSize = (int) file.getContent().getSize();
byte[] content = Const.createByteArray(fileSize);
fis.read(content, 0, fileSize);
return content;
} catch (Exception e) {
throw new KettleValueException(e);
} finally {
try {
if (fis != null) {
fis.close();
}
fis = null;
if (file != null) {
file.close();
}
file = null;
} catch (Exception e) {
// Ignore
}
}
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class ValueDataUtil method addMonths.
public static Object addMonths(ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB) throws KettleValueException {
if (dataA != null && dataB != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(metaA.getDate(dataA));
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
month += metaB.getInteger(dataB).intValue();
int newyear = year + (int) Math.floor(month / 12);
int newmonth = month % 12;
cal.set(newyear, newmonth, 1);
int newday = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
if (newday < day) {
cal.set(Calendar.DAY_OF_MONTH, newday);
} else {
cal.set(Calendar.DAY_OF_MONTH, day);
}
return (cal.getTime());
} else {
throw new KettleValueException("Unable to add months with a null value");
}
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class Props method convertArguments.
public static final String[] convertArguments(RowMetaAndData row) {
String[] args = new String[10];
for (int i = 0; i < row.size(); i++) {
ValueMetaInterface valueMeta = row.getValueMeta(i);
int argNr = getArgumentNumber(valueMeta);
if (argNr >= 0 && argNr < 10) {
try {
args[argNr] = row.getString(i, "");
} catch (KettleValueException e) {
// Should never happen
args[argNr] = "";
}
}
}
return args;
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class RowMetaAndData method isEmptyValue.
public boolean isEmptyValue(String valueName) throws KettleValueException {
int idx = rowMeta.indexOfValue(valueName);
if (idx < 0) {
throw new KettleValueException("Unknown column '" + valueName + "'");
}
ValueMetaInterface metaType = rowMeta.getValueMeta(idx);
// find by source value type
switch(metaType.getType()) {
case ValueMetaInterface.TYPE_STRING:
return rowMeta.getString(data, idx) == null;
case ValueMetaInterface.TYPE_BOOLEAN:
return rowMeta.getBoolean(data, idx) == null;
case ValueMetaInterface.TYPE_INTEGER:
return rowMeta.getInteger(data, idx) == null;
case ValueMetaInterface.TYPE_NUMBER:
return rowMeta.getNumber(data, idx) == null;
case ValueMetaInterface.TYPE_BIGNUMBER:
return rowMeta.getBigNumber(data, idx) == null;
case ValueMetaInterface.TYPE_BINARY:
return rowMeta.getBinary(data, idx) == null;
case ValueMetaInterface.TYPE_DATE:
case ValueMetaInterface.TYPE_TIMESTAMP:
return rowMeta.getDate(data, idx) == null;
case ValueMetaInterface.TYPE_INET:
return rowMeta.getString(data, idx) == null;
}
throw new KettleValueException("Unknown source type: " + metaType.getTypeDesc());
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class BaseDatabaseMeta method getSQLValue.
@Override
public String getSQLValue(ValueMetaInterface valueMeta, Object valueData, String dateFormat) throws KettleValueException {
StringBuilder ins = new StringBuilder();
if (valueMeta.isNull(valueData)) {
ins.append("null");
} else {
//
switch(valueMeta.getType()) {
case ValueMetaInterface.TYPE_BOOLEAN:
case ValueMetaInterface.TYPE_STRING:
String string = valueMeta.getString(valueData);
// Have the database dialect do the quoting.
// This also adds the single quotes around the string (thanks to PostgreSQL)
//
string = quoteSQLString(string);
ins.append(string);
break;
case ValueMetaInterface.TYPE_DATE:
Date date = valueMeta.getDate(valueData);
if (Utils.isEmpty(dateFormat)) {
ins.append("'" + valueMeta.getString(valueData) + "'");
} else {
try {
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(dateFormat);
ins.append("'" + formatter.format(date) + "'");
} catch (Exception e) {
throw new KettleValueException("Error : ", e);
}
}
break;
default:
ins.append(valueMeta.getString(valueData));
break;
}
}
return ins.toString();
}
Aggregations