package com.ca.chorus.datapipes; import java.sql.ResultSet; import java.sql.Statement; import java.sql.Types; import java.util.List; import org.junit.Before; import org.junit.Test; import org.teiid.adminapi.impl.ModelMetaData; import org.teiid.deployers.VirtualDatabaseException; import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException; import org.teiid.jdbc.ConnectionImpl; import org.teiid.jdbc.PreparedStatementImpl; import org.teiid.jdbc.RequestOptions; import org.teiid.jdbc.StatementCallback; import org.teiid.language.Call; import org.teiid.metadata.MetadataFactory; import org.teiid.metadata.Procedure; import org.teiid.metadata.RuntimeMetadata; import org.teiid.runtime.EmbeddedConfiguration; import org.teiid.runtime.EmbeddedServer; import org.teiid.translator.DataNotAvailableException; import org.teiid.translator.ExecutionContext; import org.teiid.translator.ExecutionFactory; import org.teiid.translator.ProcedureExecution; import org.teiid.translator.Translator; import org.teiid.translator.TranslatorException; import org.teiid.translator.TypeFacility; import com.google.common.collect.Lists; public class ContinuousExecutionLobIndexOutOfBounds { private EmbeddedServer server; static public class LobExecution implements ProcedureExecution { enum State { returnResult, returnNull; } State state = State.returnResult; @Override public List next() throws TranslatorException, DataNotAvailableException { try { switch (this.state) { case returnResult: return Lists.newArrayList((Object) new Object[] { "A", "B", "C" }); case returnNull: return null; default: throw new IllegalStateException(this.state.name()); } } finally { switch (this.state) { case returnResult: this.state = State.returnNull; } } } @Override public void close() { // } @Override public void cancel() throws TranslatorException { // } @Override public void execute() throws TranslatorException { // } @Override public List getOutputParameterValues() throws TranslatorException { // TODO Auto-generated method stub return null; } } @Translator(name = "testing") static public class LobExecutionFactory extends ExecutionFactory { public LobExecutionFactory() { setSourceRequired(false); setSourceRequiredForMetadata(false); } @Override public void getMetadata(final MetadataFactory metadataFactory, final Void conn) throws TranslatorException { final Procedure lobProc = metadataFactory.addProcedure("lob"); metadataFactory.addProcedureResultSetColumn("v", TypeFacility.getDataTypeNameFromSQLType(Types.ARRAY), lobProc); } @Override public ProcedureExecution createProcedureExecution(final Call command, final ExecutionContext executionContext, final RuntimeMetadata metadata, final Void connection) throws TranslatorException { return new LobExecution(); } @Override public Void getConnection(final Void factory, final ExecutionContext executionContext) throws TranslatorException { return null; } } @Before public void setup() throws VirtualDatabaseException, ConnectorManagerException, TranslatorException { this.server = new EmbeddedServer(); final EmbeddedConfiguration dqpConfiguration = new EmbeddedConfiguration(); this.server.start(dqpConfiguration); this.server.addTranslator(new LobExecutionFactory()); this.server.addConnectionFactoryProvider("void", new EmbeddedServer.ConnectionFactoryProvider() { @Override public Void getConnectionFactory() throws TranslatorException { return null; } }); final ModelMetaData testingModelMetaData = new ModelMetaData(); testingModelMetaData.setName("testing"); testingModelMetaData.setSchemaSourceType("native"); testingModelMetaData.addSourceMapping("testing", "testing", "void"); this.server.deployVDB("test", testingModelMetaData); } @Test public void test() throws Exception { final ConnectionImpl connect = this.server.getDriver().connect("jdbc:teiid:test", null); final PreparedStatementImpl statement = connect.prepareStatement("call testing.lob()"); statement.submitExecute(new StatementCallback() { @Override public void onRow(final Statement s, final ResultSet rs) throws Exception { System.out.println("here"); } @Override public void onException(final Statement s, final Exception e) throws Exception { e.printStackTrace(); } @Override public void onComplete(final Statement s) throws Exception { // TODO Auto-generated method stub } }, new RequestOptions().continuous(true)); Thread.sleep(10000); } }