package com.ca.chorus.server.translator.async; import java.util.Collections; import java.util.List; import java.util.Random; import org.teiid.translator.DataNotAvailableException; import org.teiid.translator.ExecutionContext; import org.teiid.translator.ProcedureExecution; import org.teiid.translator.TranslatorException; import com.google.common.collect.Lists; public class RandomNumberStoredProcedureExecution implements ProcedureExecution { private final ExecutionContext ctx; public RandomNumberStoredProcedureExecution(final org.teiid.translator.ExecutionContext executionContext) { super(); // TODO Auto-generated constructor stub this.ctx = executionContext; } private enum State { returnValue, done } private State state = State.returnValue; private static final Random RANDOM = new Random(); @Override public List next() throws TranslatorException, DataNotAvailableException { try { switch (this.state) { case returnValue: { final List row = Lists.newArrayList(); row.add(Integer.valueOf(RANDOM.nextInt(100000))); return row; } case done: return null; default: throw new java.lang.IllegalStateException("state is " + this.state); } } finally { switch (this.state) { case returnValue: this.state = State.done; break; case done: break; } } } @Override public void close() { // TODO Auto-generated method stub } @Override public void cancel() throws TranslatorException { // TODO Auto-generated method stub } @Override public void execute() throws TranslatorException { System.err.println("GeneralHint ** " + this.ctx.getGeneralHint()); System.err.println("getSourceHint ** " + this.ctx.getSourceHint()); this.state = State.returnValue; } @Override public List getOutputParameterValues() throws TranslatorException { return Collections.emptyList(); } }