use of org.teiid.core.types.TransformationException in project teiid by teiid.
the class SQLXMLToStringTransform method transformDirect.
/**
* This method transforms a value of the source type into a value
* of the target type.
* @param value Incoming value of source type
* @return Outgoing value of target type
* @throws TransformationException if value is an incorrect input type or
* the transformation fails
*/
public Object transformDirect(Object value) throws TransformationException {
XMLType source = (XMLType) value;
Reader reader = null;
try {
char[] result = new char[DataTypeManager.MAX_STRING_LENGTH];
reader = source.getCharacterStream();
int read = reader.read(result);
return new String(result, 0, read);
} catch (SQLException e) {
throw new TransformationException(CorePlugin.Event.TEIID10080, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10080, new Object[] { getSourceType().getName(), getTargetType().getName() }));
} catch (IOException e) {
throw new TransformationException(CorePlugin.Event.TEIID10080, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10080, new Object[] { getSourceType().getName(), getTargetType().getName() }));
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
}
}
}
use of org.teiid.core.types.TransformationException in project teiid by teiid.
the class ClobToStringTransform method transformDirect.
/**
* This method transforms a value of the source type into a value
* of the target type.
* @param value Incoming value of source type
* @return Outgoing value of target type
* @throws TransformationException if value is an incorrect input type or
* the transformation fails
*/
public Object transformDirect(Object value) throws TransformationException {
ClobType source = (ClobType) value;
BufferedReader reader = null;
try {
reader = new BufferedReader(source.getCharacterStream());
StringBuffer contents = new StringBuffer();
int chr = reader.read();
while (chr != -1 && contents.length() < DataTypeManager.MAX_STRING_LENGTH) {
contents.append((char) chr);
chr = reader.read();
}
return contents.toString();
} catch (SQLException e) {
throw new TransformationException(CorePlugin.Event.TEIID10080, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10080, new Object[] { getSourceType().getName(), getTargetType().getName() }));
} catch (IOException e) {
throw new TransformationException(CorePlugin.Event.TEIID10080, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10080, new Object[] { getSourceType().getName(), getTargetType().getName() }));
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
}
}
}
}
use of org.teiid.core.types.TransformationException in project teiid by teiid.
the class StringToDateTransform method transformDirect.
/**
* This method transforms a value of the source type into a value
* of the target type.
* @param value Incoming value of source type
* @return Outgoing value of target type
* @throws TransformationException if value is an incorrect input type or
* the transformation fails
*/
public Object transformDirect(Object value) throws TransformationException {
value = ((String) value).trim();
Date result = null;
try {
result = Date.valueOf((String) value);
} catch (Exception e) {
if (!validate && pattern.matcher((String) value).matches()) {
throw new TransformationException(CorePlugin.Event.TEIID10060, CorePlugin.Util.gs(CorePlugin.Event.TEIID10060, value, getTargetType().getSimpleName()));
}
throw new TransformationException(CorePlugin.Event.TEIID10061, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10061, value));
}
if (!result.toString().equals(value)) {
throw new TransformationException(CorePlugin.Event.TEIID10060, CorePlugin.Util.gs(CorePlugin.Event.TEIID10060, value, getTargetType().getSimpleName()));
}
return result;
}
use of org.teiid.core.types.TransformationException in project teiid by teiid.
the class TextTableNode method process.
private void process() throws TeiidProcessingException {
while (true) {
synchronized (this) {
if (isBatchFull()) {
return;
}
StringBuilder line = readLine(lineWidth, table.isFixedWidth());
if (line == null) {
terminateBatches();
break;
}
String parentSelector = null;
if (table.getSelector() != null) {
if (line.length() < table.getSelector().length()) {
continue;
}
if (!line.substring(0, table.getSelector().length()).equals(table.getSelector())) {
if (parentLines == null) {
// doesn't match any selector
continue;
}
parentSelector = line.substring(0, table.getSelector().length());
if (!parentLines.containsKey(parentSelector)) {
// doesn't match any selector
continue;
}
}
}
List<String> vals = parseLine(line);
if (parentSelector != null) {
this.parentLines.put(parentSelector, vals);
continue;
} else if (table.getSelector() != null && !table.getSelector().equals(vals.get(0))) {
continue;
}
rowNumber++;
List<Object> tuple = new ArrayList<Object>(projectionIndexes.length);
for (int output : projectionIndexes) {
TextColumn col = table.getColumns().get(output);
String val = null;
int index = output;
if (col.isOrdinal()) {
if (rowNumber > Integer.MAX_VALUE) {
throw new TeiidRuntimeException(new TeiidProcessingException(QueryPlugin.Event.TEIID31174, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31174)));
}
tuple.add((int) rowNumber);
continue;
}
if (col.getSelector() != null) {
vals = this.parentLines.get(col.getSelector());
index = col.getPosition() - 1;
} else if (nameIndexes != null) {
index = nameIndexes.get(col.getName());
}
if (vals == null || index >= vals.size()) {
// throw new TeiidProcessingException(QueryPlugin.Util.getString("TextTableNode.no_value", col.getName(), textLine, systemId)); //$NON-NLS-1$
tuple.add(null);
continue;
}
val = vals.get(index);
try {
tuple.add(DataTypeManager.transformValue(val, table.getColumns().get(output).getSymbol().getType()));
} catch (TransformationException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30176, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30176, col.getName(), textLine, systemId));
}
}
addBatchRow(tuple);
if (rowNumber == limit) {
terminateBatches();
break;
}
}
}
}
use of org.teiid.core.types.TransformationException in project teiid by teiid.
the class ExcelExecution method convertFromExcelType.
Object convertFromExcelType(final Double value, Cell cell, final Class<?> expectedType) throws TranslatorException {
if (value == null) {
return null;
}
if (expectedType.isAssignableFrom(Double.class)) {
return value;
} else if (expectedType.isAssignableFrom(Timestamp.class)) {
Date date = cell.getDateCellValue();
return new Timestamp(date.getTime());
} else if (expectedType.isAssignableFrom(java.sql.Date.class)) {
Date date = cell.getDateCellValue();
return TimestampWithTimezone.createDate(date);
} else if (expectedType.isAssignableFrom(java.sql.Time.class)) {
Date date = cell.getDateCellValue();
return TimestampWithTimezone.createTime(date);
}
if (expectedType == String.class && dataFormatter != null) {
return dataFormatter.formatCellValue(cell);
}
Object val = value;
if (DateUtil.isCellDateFormatted(cell)) {
Date date = cell.getDateCellValue();
val = new java.sql.Timestamp(date.getTime());
}
try {
return DataTypeManager.transformValue(val, expectedType);
} catch (TransformationException e) {
throw new TranslatorException(e);
}
}
Aggregations