public ConnectorWork registerRequest(AtomicRequestMessage message) throws TeiidComponentException { checkStatus(); AtomicRequestID atomicRequestId = message.getAtomicRequestID(); LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {atomicRequestId, "Create State"}); //$NON-NLS-1$ final ConnectorWorkItem item = new ConnectorWorkItem(message, this); ConnectorWork proxy = (ConnectorWork) Proxy.newProxyInstance(ConnectorWork.class.getClassLoader(), new Class[] { ConnectorWork.class }, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { ClassLoader originalCL = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getExecutionFactory().getClass().getClassLoader()); return method.invoke(item, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } finally { Thread.currentThread().setContextClassLoader(originalCL); } } }); Assertion.isNull(requestStates.put(atomicRequestId, proxy), "State already existed"); //$NON-NLS-1$ return proxy; }
public synchronized AtomicResultsMessage more() throws TranslatorException { if (this.execution == null) { return null; //already closed } if (this.dnae != null) { //clear the exception if it has been set DataNotAvailableException e = this.dnae; this.dnae = null; throw e; } if (this.conversionError != null) { throw handleError(this.conversionError); } LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Processing MORE request"}); //$NON-NLS-1$ try { timer.start(); return handleBatch(); } catch (Throwable t) { throw handleError(t); } finally { timer.stop(); } }
public HardcodedDataManager(QueryMetadataInterface metadata, CommandContext context, SourceCapabilities capabilities) { this(true); this.lbf = new LanguageBridgeFactory(metadata); ConnectorWorkItem.initLanguageBridgeFactory(lbf, context, capabilities); }
public synchronized void execute() throws TranslatorException { if(isCancelled()) { throw new TranslatorException(QueryPlugin.Event.TEIID30476, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30476)); exec = connector.createExecution(translatedCommand, this.securityContext, queryMetadata, (unwrapped == null) ? this.connection:unwrapped); setExecution(command, translatedCommand, exec); LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Executed command"}); //$NON-NLS-1$ } catch (Throwable t) { throw handleError(t); } finally { timer.stop();
private AtomicResultsMessage helpExecuteUpdate(boolean batch, boolean single) throws Exception, Throwable { Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT); //$NON-NLS-1$ if (batch) { command = new BatchedUpdateCommand(Arrays.asList(command, command)); } AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1); arm.setCommand(command); ConnectorManager connectorManager = TestConnectorManager.getConnectorManager(); ((FakeConnector)connectorManager.getExecutionFactory()).setReturnSingleUpdate(single); ConnectorWorkItem synchConnectorWorkItem = new ConnectorWorkItem(arm, connectorManager); synchConnectorWorkItem.execute(); return synchConnectorWorkItem.more(); }
row = new ArrayList<Object>(row); row = correctTypes(row); } catch (UnsupportedOperationException | ArrayStoreException e) { row = correctTypes(row); if (row != null) { try { row = correctTypes(row); rows.add(row); this.rowCount += 1; AtomicResultsMessage response = createResultsMessage(rows.toArray(new List[currentRowCount]));
@Test public void testTypeConversionClob() throws Exception { BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); String str = "hello world"; Clob clob = (Clob) ConnectorWorkItem.convertToRuntimeType(bm, new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(str.getBytes(Streamable.CHARSET)); } }, DataTypeManager.DefaultDataClasses.CLOB, null); assertEquals(str, clob.getSubString(1, str.length())); }
@Test public void testIsThreadBound() throws Exception { Command command = helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT); //$NON-NLS-1$ AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1); TransactionContext tc = new TransactionContext(); tc.setTransactionType(Scope.LOCAL); arm.setTransactionContext(tc); arm.setCommand(command); final FakeConnector c = new FakeConnector() { public boolean supportsMultipleOpenExecutions() { return false; } }; ConnectorManager cm = new ConnectorManager("FakeConnector","FakeConnector") { //$NON-NLS-1$ //$NON-NLS-2$ public ExecutionFactory getExecutionFactory() { return c; } public Object getConnectionFactory(){ return c; } }; cm.start(); ConnectorWorkItem cwi = new ConnectorWorkItem(arm, cm); assertTrue(cwi.isThreadBound()); cwi = new ConnectorWorkItem(arm, TestConnectorManager.getConnectorManager()); assertFalse(cwi.isThreadBound()); }
final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results); msg.setFinalRow(rows); return new ConnectorWork() {
@Override public void logCommand(Object... command) { if (this.workItem != null) { this.workItem.logCommand(command); } }
public synchronized void execute() throws TranslatorException { if(isCancelled()) { throw new TranslatorException(QueryPlugin.Event.TEIID30476, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30476)); exec = connector.createExecution(translatedCommand, this.securityContext, queryMetadata, (unwrapped == null) ? this.connection:unwrapped); setExecution(command, translatedCommand, exec); LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Executed command"}); //$NON-NLS-1$ } catch (Throwable t) { throw handleError(t); } finally { timer.stop();
requestMsg.setCommand(helpGetCommand("SELECT CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT)); //$NON-NLS-1$ requestMsg.setBufferManager(bm); ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); AtomicResultsMessage message = cwi.more(); List[] resutls = message.getResults(); cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); message = cwi.more(); resutls = message.getResults(); cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); message = cwi.more(); resutls = message.getResults();
row = new ArrayList<Object>(row); row = correctTypes(row); } catch (UnsupportedOperationException | ArrayStoreException e) { row = correctTypes(row); if (row != null) { try { row = correctTypes(row); rows.add(row); this.rowCount += 1; AtomicResultsMessage response = createResultsMessage(rows.toArray(new List[currentRowCount]));
@Test public void testTypeConversion() throws Exception { BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); String str = "hello world"; Object source = new StreamSource(new StringReader(str)); XMLType xml = (XMLType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.XML, null); assertEquals(str, xml.getString()); source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<a/>"))); xml = (XMLType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.XML, null); XMLInputFactory in = XMLType.getXmlInputFactory(); XMLStreamReader reader = in.createXMLStreamReader(new StringReader(xml.getString())); assertEquals(XMLEvent.START_DOCUMENT, reader.getEventType()); assertEquals(XMLEvent.START_ELEMENT, reader.next()); assertEquals("a", reader.getLocalName()); assertEquals(XMLEvent.END_ELEMENT, reader.next()); byte[] bytes = str.getBytes(Streamable.ENCODING); source = new InputStreamFactory.BlobInputStreamFactory(BlobType.createBlob(bytes)); BlobType blob = (BlobType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.BLOB, null); assertArrayEquals(bytes, ObjectConverterUtil.convertToByteArray(blob.getBinaryStream())); }
@Override public void logCommand(Object... command) { if (this.workItem != null) { this.workItem.logCommand(command); } }
public synchronized void execute() throws TranslatorException { if(isCancelled()) { throw new TranslatorException(QueryPlugin.Event.TEIID30476, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30476)); exec = connector.createExecution(translatedCommand, this.securityContext, queryMetadata, (unwrapped == null) ? this.connection:unwrapped); setExecution(command, translatedCommand, exec); LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Executed command"}); //$NON-NLS-1$ } catch (Throwable t) { throw handleError(t); } finally { timer.stop();
requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT)); //$NON-NLS-1$ requestMsg.setBufferManager(bm); ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); AtomicResultsMessage message = cwi.more(); List[] results = message.getResults(); assertEquals(1, results.length); assertEquals(-1, message.getFinalRow()); try { cwi.more(); fail(); } catch (TranslatorException e) {
row = new ArrayList<Object>(row); row = correctTypes(row); } catch (UnsupportedOperationException | ArrayStoreException e) { row = correctTypes(row); if (row != null) { try { row = correctTypes(row); rows.add(row); this.rowCount += 1; AtomicResultsMessage response = createResultsMessage(rows.toArray(new List[currentRowCount]));
throw handleError(this.conversionError); scope = TeiidTracingUtil.getInstance().activateSpan(span); return handleBatch(); } catch (Throwable t) { throw handleError(t); } finally { timer.stop();
Object result = convertToRuntimeType(requestMsg.getBufferManager(), value, this.schema[i], this.requestMsg.getCommandContext()); if (value == result && !DataTypeManager.DefaultDataClasses.OBJECT.equals(this.schema[i])) { convertToRuntimeType[i] = false;