package com.ca.chorus.teiid.translator.async; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import org.teiid.language.QueryExpression; import org.teiid.translator.DataNotAvailableException; import org.teiid.translator.ExecutionContext; import org.teiid.translator.TranslatorException; import org.teiid.translator.jdbc.JDBCPlugin; import org.teiid.translator.jdbc.JDBCQueryExecution; public class SampleJDBCAsyncExecution extends JDBCQueryExecution// implements ReusableExecution { AtomicInteger cnt = new AtomicInteger(0); int waited = 0; public SampleJDBCAsyncExecution(QueryExpression command, ExecutionContext executionContext, Connection conn, SampleJDBCAsyncExecutionFactory env) { super(command, conn, executionContext, env); } @Override public java.util.List next() throws org.teiid.translator.TranslatorException ,org.teiid.translator.DataNotAvailableException { List vals = null; try { if (results.next()) { /* * Attempt to close the continuous execution */ // if (cnt.incrementAndGet() > 1) // { // System.out.println("Attempt to stop at:" + count); // throw new TranslatorException("THIS IS ENOUGH!!!"); // } vals = new ArrayList(columnDataTypes.length); for (int i = 0; i < columnDataTypes.length; i++) { Object value = this.executionFactory.retrieveValue(results, i+1, columnDataTypes[i]); vals.add(value); } System.out.println("!!! ROW: " + Arrays.toString(vals.toArray())); // } else { // if (waited++ < 2) // { // System.out.println("!!! Data not available ... " + waited); // throw new DataNotAvailableException(5000); // } } } catch (SQLException e) { throw new TranslatorException(e, JDBCPlugin.Util.getString("JDBCTranslator.Unexpected_exception_translating_results___8", e.getMessage())); //$NON-NLS-1$ } return vals; }; @Override public void close() { System.out.println("!!! Close !!!"); super.close(); } /* * Needed for ReusableExecution: */ // // @Override // public void reset(Command c, ExecutionContext executionContext, // Object connection) { // System.out.println("!!! Reset !!!"); // cnt.set(0); // } // // @Override // public void dispose() { // System.out.println("!!! Dispose !!!"); // } }