Search in sources :

Example 11 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class SimpleDBUpdateVisitor method visit.

@Override
public void visit(SetClause obj) {
    Column column = obj.getSymbol().getMetadataObject();
    if (obj.getValue() instanceof Literal) {
        try {
            Literal l = (Literal) obj.getValue();
            this.attributes.put(SimpleDBMetadataProcessor.getName(column), SimpleDBDataTypeManager.convertToSimpleDBType(l.getValue(), column.getJavaType()));
        } catch (TranslatorException e) {
            this.exceptions.add(e);
        }
    } else if (obj.getValue() instanceof Array) {
        try {
            Array array = (Array) obj.getValue();
            String[] result = SimpleDBInsertVisitor.getValuesArray(array);
            this.attributes.put(SimpleDBMetadataProcessor.getName(column), result);
        } catch (TranslatorException e) {
            this.exceptions.add(e);
        }
    } else {
        this.exceptions.add(new TranslatorException(SimpleDBPlugin.Event.TEIID24001, SimpleDBPlugin.Util.gs(SimpleDBPlugin.Event.TEIID24001)));
    }
}
Also used : Array(org.teiid.language.Array) Column(org.teiid.metadata.Column) Literal(org.teiid.language.Literal) TranslatorException(org.teiid.translator.TranslatorException)

Example 12 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class AutoGenDataService method registerRequest.

@Override
public ConnectorWork registerRequest(AtomicRequestMessage message) throws TeiidComponentException {
    List projectedSymbols = (message.getCommand()).getProjectedSymbols();
    List[] results = createResults(projectedSymbols, rows, useIntCounter);
    if (RelationalNodeUtil.isUpdate(message.getCommand())) {
        results = new List[] { Arrays.asList(1) };
    }
    final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results);
    msg.setFinalRow(rows);
    return new ConnectorWork() {

        boolean returnedInitial;

        @Override
        public boolean isDataAvailable() {
            return dataAvailable;
        }

        @Override
        public AtomicResultsMessage more() throws TranslatorException {
            if (dataNotAvailable != null) {
                int delay = dataNotAvailable;
                dataNotAvailable = null;
                DataNotAvailableException dnae = new DataNotAvailableException(delay);
                dnae.setStrict(strict);
                throw dnae;
            }
            if (addWarning) {
                msg.setWarnings(Arrays.asList(new Exception()));
            }
            if (!returnedInitial) {
                returnedInitial = true;
                return msg;
            }
            // $NON-NLS-1$
            throw new RuntimeException("Should not be called");
        }

        @Override
        public void execute() throws TranslatorException {
            executeCount.incrementAndGet();
            if (sleep > 0) {
                try {
                    Thread.sleep(sleep);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            if (latch != null) {
                try {
                    latch.countDown();
                    latch.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            if (throwExceptionOnExecute) {
                // $NON-NLS-1$
                throw new TranslatorException("Connector Exception");
            }
        }

        @Override
        public void close() {
            closeCount.incrementAndGet();
        }

        @Override
        public void cancel(boolean abnormal) {
        }

        @Override
        public CacheDirective getCacheDirective() {
            return cacheDirective;
        }

        @Override
        public boolean isForkable() {
            return true;
        }

        @Override
        public boolean isThreadBound() {
            return threadBound;
        }

        @Override
        public AtomicRequestID getId() {
            return null;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TranslatorException(org.teiid.translator.TranslatorException) ConnectorWork(org.teiid.dqp.internal.datamgr.ConnectorWork) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) TeiidComponentException(org.teiid.core.TeiidComponentException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) IOException(java.io.IOException)

Example 13 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class TestConnectorWorkItem method testConversionError.

@Test
public void testConversionError() throws Exception {
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {

        @Override
        public boolean isSourceRequired() {
            return false;
        }

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            List<String> list1 = new ArrayList<String>();
            list1.add("1");
            List<String> list2 = new ArrayList<String>();
            list2.add("a");
            final Iterator<List<String>> iter = Arrays.asList(list1, list2).iterator();
            return new ResultSetExecution() {

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (iter.hasNext()) {
                        return iter.next();
                    }
                    return null;
                }
            };
        }
    };
    ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
    ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector") {

        public ExecutionFactory getExecutionFactory() {
            return ef;
        }

        public Object getConnectionFactory() {
            return null;
        }
    };
    cm.start();
    ef.setCopyLobs(true);
    AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
    // $NON-NLS-1$
    requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
    requestMsg.setBufferManager(bm);
    ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    AtomicResultsMessage message = cwi.more();
    List[] results = message.getResults();
    assertEquals(1, results.length);
    List<?> tuple = results[0];
    assertEquals(1, tuple.get(0));
    assertEquals(-1, message.getFinalRow());
    try {
        cwi.more();
        fail();
    } catch (TranslatorException e) {
    // should throw the conversion error
    }
}
Also used : ArrayList(java.util.ArrayList) ExecutionFactory(org.teiid.translator.ExecutionFactory) BufferManager(org.teiid.common.buffer.BufferManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) List(java.util.List) ArrayList(java.util.ArrayList) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TranslatorException(org.teiid.translator.TranslatorException) QueryExpression(org.teiid.language.QueryExpression) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 14 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class TestConnectorWorkItem method testProcedureBatching.

@Test
public void testProcedureBatching() throws Exception {
    ProcedureExecution exec = new FakeProcedureExecution(2, 1);
    // this has two result set columns and 1 out parameter
    int total_columns = 3;
    // $NON-NLS-1$
    StoredProcedure command = (StoredProcedure) helpGetCommand("{call pm2.spTest8(?)}", EXAMPLE_BQT);
    command.getInputParameters().get(0).setExpression(new Constant(1));
    Call proc = new LanguageBridgeFactory(EXAMPLE_BQT).translate(command);
    ProcedureBatchHandler pbh = new ProcedureBatchHandler(proc, exec);
    assertEquals(total_columns, pbh.padRow(Arrays.asList(null, null)).size());
    List params = pbh.getParameterRow();
    assertEquals(total_columns, params.size());
    // check the parameter value
    assertEquals(Integer.valueOf(0), params.get(2));
    try {
        pbh.padRow(Arrays.asList(1));
        // $NON-NLS-1$
        fail("Expected exception from resultset mismatch");
    } catch (TranslatorException err) {
        assertEquals("TEIID30479 Could not process stored procedure results for EXEC spTest8(1).  Expected 2 result set columns, but was 1.  Please update your models to allow for stored procedure results batching.", // $NON-NLS-1$
        err.getMessage());
    }
}
Also used : Call(org.teiid.language.Call) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) ProcedureExecution(org.teiid.translator.ProcedureExecution) Constant(org.teiid.query.sql.symbol.Constant) List(java.util.List) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) SourceHint(org.teiid.query.sql.lang.SourceHint) Test(org.junit.Test)

Example 15 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class TestConnectorCapabilitiesFinder method testFindRequiresSource.

@Test
public void testFindRequiresSource() throws Exception {
    // $NON-NLS-1$
    String modelName = "model";
    // $NON-NLS-1$
    String functionName = "fakeFunction";
    ArrayList<String> bindings = new ArrayList<String>();
    bindings.add(modelName);
    VDBMetaData vdb = Mockito.mock(VDBMetaData.class);
    ModelMetaData model = Mockito.mock(ModelMetaData.class);
    Mockito.stub(vdb.getModel(modelName)).toReturn(model);
    Mockito.stub(model.getSourceNames()).toReturn(bindings);
    BasicSourceCapabilities basicSourceCapabilities = new BasicSourceCapabilities();
    basicSourceCapabilities.setFunctionSupport(functionName, true);
    ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
    ConnectorManager cm = Mockito.mock(ConnectorManager.class);
    Mockito.stub(cm.getCapabilities()).toThrow(new TranslatorException());
    Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(cm);
    CachedFinder finder = new CachedFinder(repo, vdb);
    // Test
    SourceCapabilities actual = finder.findCapabilities(modelName);
    // $NON-NLS-1$
    assertNotNull(actual);
    assertFalse(finder.isValid(modelName));
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) SourceCapabilities(org.teiid.query.optimizer.capabilities.SourceCapabilities) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

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