net.sf.farrago.runtime
Class FarragoJavaUdxIterator

java.lang.Object
  extended by org.eigenbase.runtime.QueueIterator
      extended by org.eigenbase.runtime.ThreadIterator
          extended by net.sf.farrago.runtime.FarragoJavaUdxIterator
All Implemented Interfaces:
Runnable, Iterator, Iterable, RestartableIterator, TupleIter, ClosableAllocation

public abstract class FarragoJavaUdxIterator
extends ThreadIterator
implements RestartableIterator, TupleIter

FarragoJavaUdxIterator provides runtime support for a call to a Java UDX. It supports both the blocking interface Iterator and the non-blocking TupleIter.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/runtime/FarragoJavaUdxIterator.java#23 $
Author:
John V. Sichi

Nested Class Summary
 class FarragoJavaUdxIterator.PreparedStatementInvocationHandler
           
 
Nested classes/interfaces inherited from class org.eigenbase.runtime.QueueIterator
QueueIterator.TimeoutException
 
Nested classes/interfaces inherited from interface org.eigenbase.runtime.TupleIter
TupleIter.NoDataReason, TupleIter.TimeoutException
 
Field Summary
private  long defaultTimeout
           
private  int iRow
           
private  CountDownLatch latch
           
private  ParameterMetaData parameterMetaData
           
private static int QUEUE_ARRAY_SIZE
           
private  List<TupleIter> restartableInputs
           
private  PreparedStatement resultInserter
           
private  FarragoSyntheticObject[] rowObjs
           
protected  FarragoSessionRuntimeContext runtimeContext
           
private  boolean stopThread
           
private  boolean timeoutAsUnderflow
           
protected static Logger tracer
           
 
Fields inherited from class org.eigenbase.runtime.QueueIterator
hasNext, next, queue, throwable
 
Fields inherited from interface org.eigenbase.runtime.TupleIter
EMPTY_ITERATOR
 
Constructor Summary
protected FarragoJavaUdxIterator(FarragoSessionRuntimeContext runtimeContext, Class rowClass, RelDataType rowType)
           
 
Method Summary
protected  void addRestartableInput(TupleIter inputIter)
          Called by generated code to add an input cursor's iterator so that it can be restarted as needed.
private  void checkCancel()
           
 void closeAllocation()
          Closes this object.
protected  void doWork()
          The implementation should call QueueIterator.put(java.lang.Object) with each row.
protected abstract  void executeUdx()
          Calls specific UDX to produce result set.
 Object fetchNext()
          Returns the next element in the iteration.
 FarragoSyntheticObject getCurrentRow()
           
 PreparedStatement getResultInserter()
           
 boolean hasNext()
           
 boolean hasNext(long timeout)
          As QueueIterator.hasNext, but throws QueueIterator.TimeoutException if no row is available within the timeout.
 void restart()
          Restarts this iterator, so that a subsequent call to next() returns the first element in the collection being iterated.
 boolean setTimeout(long timeout, boolean asUnderflow)
          Sets a timeout for TupleIter.fetchNext(); (optional operation).
private  void startWithLatch()
           
private  void stopWithLatch()
           
 
Methods inherited from class org.eigenbase.runtime.ThreadIterator
iterator, onEndOfQueue, run, start
 
Methods inherited from class org.eigenbase.runtime.QueueIterator
checkTermination, done, next, next, offer, put, remove, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Iterator
next, remove
 

Field Detail

QUEUE_ARRAY_SIZE

private static final int QUEUE_ARRAY_SIZE
See Also:
Constant Field Values

tracer

protected static final Logger tracer

rowObjs

private final FarragoSyntheticObject[] rowObjs

resultInserter

private final PreparedStatement resultInserter

runtimeContext

protected final FarragoSessionRuntimeContext runtimeContext

iRow

private int iRow

defaultTimeout

private long defaultTimeout

timeoutAsUnderflow

private boolean timeoutAsUnderflow

stopThread

private boolean stopThread

latch

private CountDownLatch latch

parameterMetaData

private final ParameterMetaData parameterMetaData

restartableInputs

private List<TupleIter> restartableInputs
Constructor Detail

FarragoJavaUdxIterator

protected FarragoJavaUdxIterator(FarragoSessionRuntimeContext runtimeContext,
                                 Class rowClass,
                                 RelDataType rowType)
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator
Overrides:
hasNext in class QueueIterator

hasNext

public boolean hasNext(long timeout)
                throws QueueIterator.TimeoutException
Description copied from class: QueueIterator
As QueueIterator.hasNext, but throws QueueIterator.TimeoutException if no row is available within the timeout.

Overrides:
hasNext in class QueueIterator
Parameters:
timeout - Milliseconds to wait; less than or equal to zero means don't wait
Throws:
QueueIterator.TimeoutException

setTimeout

public boolean setTimeout(long timeout,
                          boolean asUnderflow)
Description copied from interface: TupleIter
Sets a timeout for TupleIter.fetchNext(); (optional operation). Not all implementing classes support a timeout. For those that do, this method provides a common interface, For those that do not, the adapter TimeoutQueueTupleIter puts a timeout queue on top.

Specified by:
setTimeout in interface TupleIter
Parameters:
timeout - in milliseconds. 0 means poll, infinity means block.
asUnderflow - true means indicate timeout by returning TupleIter.NoDataReason.UNDERFLOW; false means throw TupleIter.TimeoutException on a timeout.
Returns:
true if the timeout was set, false if the implementing class does not support a timeout.

fetchNext

public Object fetchNext()
Description copied from interface: TupleIter
Returns the next element in the iteration. If there is no next value, it returns a value from the TupleIter.NoDataReason enumeration indicating why no data was returned.

If this method returns TupleIter.NoDataReason.END_OF_DATA, no further data will be returned by this iterator unless TupleIter.restart() is called.

If this method returns TupleIter.NoDataReason.UNDERFLOW, no data is currently available, but may be come available in the future. It is possible for consecutive calls to return UNDERFLOW and then END_OF_DATA.

The object returned by this method may be re-used for each subsequent call to fetchNext(). In other words, callers must either make certain that the returned value is no longer needed or is copied before any subsequent calls to fetchNext().

Specified by:
fetchNext in interface TupleIter
Returns:
the next element in the iteration, or an instance of TupleIter.NoDataReason.

addRestartableInput

protected void addRestartableInput(TupleIter inputIter)
Called by generated code to add an input cursor's iterator so that it can be restarted as needed.

Parameters:
inputIter - input cursor's iterator

doWork

protected void doWork()
Description copied from class: ThreadIterator
The implementation should call QueueIterator.put(java.lang.Object) with each row.

Specified by:
doWork in class ThreadIterator

getResultInserter

public PreparedStatement getResultInserter()

getCurrentRow

public FarragoSyntheticObject getCurrentRow()

restart

public void restart()
Description copied from interface: RestartableIterator
Restarts this iterator, so that a subsequent call to next() returns the first element in the collection being iterated.

Specified by:
restart in interface RestartableIterator
Specified by:
restart in interface TupleIter

closeAllocation

public void closeAllocation()
Description copied from interface: ClosableAllocation
Closes this object.

Specified by:
closeAllocation in interface ClosableAllocation

stopWithLatch

private void stopWithLatch()

startWithLatch

private void startWithLatch()

checkCancel

private void checkCancel()

executeUdx

protected abstract void executeUdx()
Calls specific UDX to produce result set. Subclass implementation is typically code-generated.