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 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 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; }
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(); }
@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()); }
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(); cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); message = cwi.more(); cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); message = cwi.more();
@Ignore @Test public void testIsImmutablePropertySucceeds() throws Exception { /* * Setup: * 1. requestMsg.isTransactional() must be TRUE * 2. manager.isXa() must be FALSE () * 3. command must NOT be a SELECT * 4. Then, set isImmutable to TRUE, we should SUCCEED */ ConnectorManager cm = TestConnectorManager.getConnectorManager(); ((FakeConnector)cm.getExecutionFactory()).setImmutable(true); // command must not be a SELECT Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT); //$NON-NLS-1$ AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand(command); // To make the AtomicRequestMessage transactional, construct your own requestMsg.setTransactionContext( new TransactionContext(){ @Override public Xid getXid() { return Mockito.mock(Xid.class); }} ); new ConnectorWorkItem(requestMsg, cm); }
@Ignore @Test(expected=TranslatorException.class) public void testIsImmutablePropertyFails() throws Exception { /* * Setup: * 1. requestMsg.isTransactional() must be TRUE * 2. manager.isXa() must be FALSE () * 3. command must NOT be a SELECT * 4. Then, set isImmutable to FALSE, and we should FAIL */ ConnectorManager cm = TestConnectorManager.getConnectorManager(); ((FakeConnector)cm.getExecutionFactory()).setImmutable(false); // command must not be a SELECT Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT); //$NON-NLS-1$ AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand(command); // To make the AtomicRequestMessage transactional, construct your own requestMsg.setTransactionContext( new TransactionContext(){ @Override public Xid getXid() { return Mockito.mock(Xid.class); }} ); new ConnectorWorkItem(requestMsg, cm); }
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();
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();