Search in sources :

Example 56 with TranslatorException

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);
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) TranslatorException(org.teiid.translator.TranslatorException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 57 with TranslatorException

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);
    }
}
Also used : TransformationException(org.teiid.core.types.TransformationException) Timestamp(java.sql.Timestamp) TranslatorException(org.teiid.translator.TranslatorException) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 58 with TranslatorException

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);
    }
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) TranslatorException(org.teiid.translator.TranslatorException) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) File(java.io.File) Sheet(org.apache.poi.ss.usermodel.Sheet) FileInputStream(java.io.FileInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 59 with TranslatorException

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())));
    }
}
Also used : Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException)

Example 60 with TranslatorException

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())));
    }
}
Also used : Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) TranslatorException(org.teiid.translator.TranslatorException)

Aggregations

TranslatorException (org.teiid.translator.TranslatorException)227 ArrayList (java.util.ArrayList)51 Column (org.teiid.metadata.Column)47 List (java.util.List)32 Table (org.teiid.metadata.Table)30 IOException (java.io.IOException)26 SQLException (java.sql.SQLException)26 ResourceException (javax.resource.ResourceException)26 Test (org.junit.Test)16 Expression (org.teiid.language.Expression)16 Literal (org.teiid.language.Literal)16 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)16 Blob (java.sql.Blob)15 Argument (org.teiid.language.Argument)13 DBObject (com.mongodb.DBObject)11 HashMap (java.util.HashMap)11 ColumnReference (org.teiid.language.ColumnReference)11 ExecutionContext (org.teiid.translator.ExecutionContext)11 BasicDBObject (com.mongodb.BasicDBObject)10 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)10