use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class TestEmbeddedServer method testMultiSourceMetadataMissingSource.
/**
* Check that we'll consult each source
* @throws Exception
*/
@Test
public void testMultiSourceMetadataMissingSource() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
es.start(ec);
es.addTranslator("t", new ExecutionFactory<Object, Object>() {
@Override
public Object getConnection(Object factory) throws TranslatorException {
return factory;
}
@Override
public void closeConnection(Object connection, Object factory) {
}
@Override
public void getMetadata(MetadataFactory metadataFactory, Object conn) throws TranslatorException {
assertNotNull(conn);
Table t = metadataFactory.addTable("x");
metadataFactory.addColumn("a", "string", t);
}
});
es.addConnectionFactory("b", new Object());
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("b");
mmd1.setSupportsMultiSourceBindings(true);
// a is missing
mmd1.addSourceMapping("x", "t", "a");
mmd1.addSourceMapping("y", "t", "b");
es.deployVDB("vdb", mmd1);
}
use of org.teiid.translator.TranslatorException 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);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ExcelMetadataProcessor method process.
public void process(MetadataFactory mf, FileConnection conn) throws TranslatorException {
if (this.excelFileName == null) {
// $NON-NLS-1$
throw new TranslatorException(ExcelPlugin.Event.TEIID23004, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23004, "importer.ExcelFileName"));
}
try {
File xlsFile = conn.getFile(this.excelFileName);
if (xlsFile.isDirectory()) {
File[] files = xlsFile.listFiles();
if (files.length > 0) {
xlsFile = files[0];
}
}
if (xlsFile.isDirectory() || !xlsFile.exists()) {
throw new TranslatorException(ExcelPlugin.Event.TEIID23005, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23005, xlsFile.getName()));
}
String extension = getFileExtension(xlsFile);
FileInputStream xlsFileStream = new FileInputStream(xlsFile);
try {
Workbook workbook = null;
if (extension.equalsIgnoreCase("xls")) {
// $NON-NLS-1$
workbook = new HSSFWorkbook(xlsFileStream);
} else if (extension.equalsIgnoreCase("xlsx")) {
// $NON-NLS-1$
workbook = new XSSFWorkbook(xlsFileStream);
}
int sheetCount = workbook.getNumberOfSheets();
for (int i = 0; i < sheetCount; i++) {
Sheet sheet = workbook.getSheetAt(i);
addTable(mf, sheet, xlsFile.getName(), this.excelFileName);
}
} finally {
xlsFileStream.close();
}
} catch (ResourceException e) {
throw new TranslatorException(e);
} catch (IOException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ExcelQueryVisitor method visit.
@Override
public void visit(In obj) {
visitNode(obj.getLeftExpression());
Column column = (Column) this.onGoingExpression.pop();
visitNodes(obj.getRightExpressions());
if (isPartOfPrimaryKey(column)) {
ArrayList<Integer> values = new ArrayList<Integer>();
// NOTE: we are popping in reverse order to IN stmt
for (int i = 0; i < obj.getRightExpressions().size(); i++) {
values.add((Integer) this.onGoingExpression.pop());
}
this.filters.add(new InFilter(values.toArray(new Integer[values.size()])));
} else {
this.exceptions.add(new TranslatorException(ExcelPlugin.Event.TEIID23008, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23008, column.getName())));
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ExcelQueryVisitor method visit.
@Override
public void visit(Comparison obj) {
visitNode(obj.getLeftExpression());
Column column = (Column) this.onGoingExpression.pop();
visitNode(obj.getRightExpression());
Integer rightExpr = (Integer) this.onGoingExpression.pop();
if (isPartOfPrimaryKey(column)) {
switch(obj.getOperator()) {
case EQ:
this.filters.add(new CompareFilter(rightExpr - 1, Operator.EQ));
break;
case NE:
this.filters.add(new CompareFilter(rightExpr - 1, Operator.NE));
break;
case LT:
this.filters.add(new CompareFilter(rightExpr - 1, Operator.LT));
break;
case LE:
this.filters.add(new CompareFilter(rightExpr - 1, Operator.LE));
break;
case GT:
this.filters.add(new CompareFilter(rightExpr - 1, Operator.GT));
break;
case GE:
this.filters.add(new CompareFilter(rightExpr - 1, Operator.GE));
break;
}
} else {
this.exceptions.add(new TranslatorException(ExcelPlugin.Event.TEIID23008, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23008, column.getName())));
}
}
Aggregations