net.sf.farrago.runtime
Class FarragoRuntimeContext

java.lang.Object
  extended by org.eigenbase.util.CompoundClosableAllocation
      extended by net.sf.farrago.util.FarragoCompoundAllocation
          extended by net.sf.farrago.runtime.FarragoRuntimeContext
All Implemented Interfaces:
FennelJavaErrorTarget, FennelJavaStreamMap, FarragoSessionRuntimeContext, FarragoAllocation, FarragoAllocationOwner, RelOptConnection, ClosableAllocation, ClosableAllocationOwner
Direct Known Subclasses:
LucidDbRuntimeContext

public class FarragoRuntimeContext
extends FarragoCompoundAllocation
implements FarragoSessionRuntimeContext, RelOptConnection, FennelJavaStreamMap, FennelJavaErrorTarget

FarragoRuntimeContext defines runtime support routines needed by generated code.

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

Nested Class Summary
private static class FarragoRuntimeContext.StreamOwner
          Inner class for taking care of closing streams without deallocating them.
 
Field Summary
protected  FarragoObjectCache codeCache
           
private  long currentTime
           
private  boolean cursorActive
           
protected  Object cursorMonitor
           
protected  FarragoDataWrapperCache dataWrapperCache
           
private  EnkiMDSession detachedSession
           
protected  Object[] dynamicParamValues
           
private  FennelExecutionHandle execHandle
           
private  FennelTxnContext fennelTxnContext
           
private  FarragoSessionIndexMap indexMap
           
private  boolean isCanceled
           
protected  boolean isClosed
           
private  boolean isDml
           
private  NativeRuntimeContext nativeContext
           
private  FarragoRepos repos
           
protected  Map<String,RelDataType> resultSetTypeMap
           
private  FarragoSession session
           
private  FarragoSessionVariables sessionVariables
           
private  ClassLoader statementClassLoader
           
protected  long stmtId
           
private  FarragoStreamFactoryProvider streamFactoryProvider
           
protected  FennelStreamGraph streamGraph
           
private  Map<Integer,FennelJavaHandle> streamIdToHandleMap
          Maps stream id to the corresponding java object.
protected  FarragoCompoundAllocation streamOwner
          responsible for closing the FennelStreamGraph
private static ThreadLocal<List<FarragoUdrInvocationFrame>> threadInvocationStack
           
protected static Logger tracer
           
private  Map<String,FarragoTransform> transformMap
           
private  Map<String,FarragoObjectCache.Entry> txnCodeCache
           
private  FarragoWarningQueue warningQueue
           
 
Fields inherited from class org.eigenbase.util.CompoundClosableAllocation
allocations
 
Constructor Summary
FarragoRuntimeContext(FarragoSessionRuntimeParams params)
          Creates a new FarragoRuntimeContext.
 
Method Summary
 void addAllocation(ClosableAllocation allocation)
          Assigns ownership of a ClosableAllocation to this owner.
 void cancel()
          Requests cancellation of this execution (either for asynchronous abort, or because execution has ended).
 void checkCancel()
          Throws an exception if execution has been canceled.
 void checkNotNull(String targetName, NullableValue nullableValue)
          Called when a nullable value is cast to a NOT NULL type.
 void checkNotNull(String targetName, Object obj)
          Called when a nullable value is cast to a NOT NULL type.
 void closeAllocation()
          Closes this object.
private  void closeStreamGraph()
           
 Object contentsAsArray(String qualifier, String tableName)
          In theory, this method returns the contents of tableName as an array; in practice, it is a placeholder recognized by the optimizer to do something much more efficient.
 void detachMdrSession()
          Detaches the current MDR session from the running thread.
 Object dummyArray(Object[] dummyArray)
          Stupid helper for code generated by FennelMultipleRel.
 Object dummyPair(Object dummy1, Object dummy2)
          Stupid helper for code generated by FennelDoubleRel.
 FarragoTransform findFarragoTransform(String key)
           
 boolean forgetAllocation(ClosableAllocation allocation)
          Forgets an allocation without closing it.
 String getContextVariable_CURRENT_CATALOG()
          Called from generated code.
 Date getContextVariable_CURRENT_DATE()
          Called from generated code.
 String getContextVariable_CURRENT_PATH()
          Called from generated code.
 String getContextVariable_CURRENT_ROLE()
          Called from generated code.
 String getContextVariable_CURRENT_SCHEMA()
          Called from generated code.
 Time getContextVariable_CURRENT_TIME()
          Called from generated code.
 Timestamp getContextVariable_CURRENT_TIMESTAMP()
          Called from generated code.
 String getContextVariable_CURRENT_USER()
          Called from generated code.
 Time getContextVariable_LOCALTIME()
          Called from generated code.
 Timestamp getContextVariable_LOCALTIMESTAMP()
          Called from generated code.
 String getContextVariable_SESSION_USER()
          Called from generated code.
 String getContextVariable_SYSTEM_USER()
          Called from generated code.
 String getContextVariable_USER()
          Called from generated code.
protected  long getCurrentTime()
           
 Object getDataServerRuntimeSupport(String serverMofId, Object param)
          Gets an object needed to support the implementation of foreign data access.
 Object getDynamicParamValue(int paramIndex)
          Gets the value bound to a dynamic parameter.
 FennelDbHandle getFennelDbHandle()
           
 FennelStreamGraph getFennelStreamGraph()
           
 FennelTxnContext getFennelTxnContext()
           
 long getIndexRoot(long pageOwnerId)
          Looks up the root PageId of an index.
private static List<FarragoUdrInvocationFrame> getInvocationStack()
           
 long getJavaStreamHandle(int streamId)
          Looks up the handle of a JavaTupleStream by its ID.
 String getRefMofId(RefBaseObject refObj)
          Gets the MofId for a RefBaseObject, or null if the object is null.
 RelOptSchema getRelOptSchema()
          Returns the schema underlying this connection.
 FarragoRepos getRepos()
           
 RelDataType getRowTypeForResultSet(String resultSetName)
          Gets the row type for instantiating a result set.
 FarragoSequenceAccessor getSequenceAccessor(String mofId)
           
 FarragoSession getSession()
           
protected  FennelStreamGraph getStreamGraph()
          Returns the stream graph.
 FennelStreamHandle getStreamHandle(String globalStreamName, boolean isInput)
          Retrieves the FennelStreamHandle corresponding to a stream
(package private) static FarragoUdrInvocationFrame getUdrInvocationFrame()
           
 FarragoWarningQueue getWarningQueue()
           
 RuntimeException handleRoutineInvocationException(Throwable ex, String methodName)
          Handles an exception caught by invocation of a routine.
 Object handleRowError(String[] columnNames, Object[] columnValues, RuntimeException ex, int columnIndex, String tag, boolean isWarning)
          Handles a runtime exception based on an array of column values rather than on a SyntheticObject
 Object handleRowError(String[] columnNames, Object[] columnValues, RuntimeException ex, int columnIndex, String tag, boolean isWarning, String errorCode, String columnName)
          Handles runtime exception; if errorCode is non-null, exceptions are deferred until all errors on a row are processed; not currently implemented
 Object handleRowError(String source, boolean isWarning, String msg, ByteBuffer byteBuffer, int index)
          Handles a Fennel row exception
 Object handleRowError(SyntheticObject row, RuntimeException ex, int columnIndex, String tag)
          Handles an exception encountered by a stream while processing an input row.
 Object handleRowError(SyntheticObject row, RuntimeException ex, int columnIndex, String tag, boolean isWarning)
          Handles a runtime exception, but allows warnings as well.
 void handleRowErrorCompletion(RuntimeException ex, String tag)
          Handles exception for row errors with deferred exceptions; not currently implemented
private  EigenbaseException handleRowErrorHelper(String row, RuntimeException ex, int columnIndex, String tag, boolean isWarning)
          Helper for various handleRowError methods
 boolean hasAllocations()
           
static boolean inUdr()
           
 void loadFennelPlan(String xmiFennelPlan)
          Loads the Fennel portion of an execution plan (either creating a new XO graph or reusing a cached instance).
protected  EigenbaseException makeRowError(RuntimeException ex, String row, int index, String field)
          Makes a row error based on conventions for column index
static Connection newConnection()
          Creates a new default connection attached to the session of the current thread.
 TupleIter newFennelTransformTupleIter(FennelTupleReader tupleReader, String streamName, String inputStreamName, FarragoTransform.InputBinding[] inputBindings, Object dummies)
          Creates a FennelTupleIter for executing a plan represented as XML.
 TupleIter newFennelTupleIter(FennelTupleReader tupleReader, String streamName, int streamId, Object dummies)
          Creates a FennelTupleIter for executing a plan represented as XML.
 void openStreams()
          Opens all streams, including the Fennel portion of the execution plan.
private static FarragoUdrInvocationFrame peekStackFrame(List<FarragoUdrInvocationFrame> stack)
           
 void popRoutineInvocation()
          Pops a routine invocation from the context stack.
protected  FennelStreamGraph prepareStreamGraph(String xmiFennelPlan)
           
 void pushRoutineInvocation(FarragoSessionUdrContext udrContext, boolean allowSql)
          Pushes a routine invocation onto the context stack.
 void reattachMdrSession()
          Re-attaches a detached MDR session to the currently running thread, if any was previously detached.
 void registerFarragoTransform(String key, FarragoTransform xform)
          Associates a FarragoTransform instance with its class name, so that it can be retrieved by a native method later.
protected  void registerJavaStream(int streamId, Object stream)
          Associates a stream id with a java stream object, so that it can be retrieved by a native method later.
protected  void registerJavaStream(int streamId, Object stream, FarragoCompoundAllocation owner)
          Associates a stream id with a java stream object, so that it can be retrieved by a native method later.
 void setCursorState(boolean active)
          Sets the state of the top-level cursor associated with this context.
 void setExecutionHandle(FennelExecutionHandle execHandle)
          Associates an execution handle with the runtime context.
 void setStatementClassLoader(ClassLoader statementClassLoader)
          Configures a custom class loader used to load extra classes that may be needed during statement runtime.
 Class statementClassForName(String statementClassName)
           
 void waitForCursor()
          Waits for cursor state to be reset to active=false (returns immediately if cursor is not currently active).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tracer

protected static final Logger tracer

threadInvocationStack

private static final ThreadLocal<List<FarragoUdrInvocationFrame>> threadInvocationStack

session

private final FarragoSession session

repos

private final FarragoRepos repos

codeCache

protected final FarragoObjectCache codeCache

txnCodeCache

private final Map<String,FarragoObjectCache.Entry> txnCodeCache

fennelTxnContext

private final FennelTxnContext fennelTxnContext

warningQueue

private final FarragoWarningQueue warningQueue

cursorMonitor

protected final Object cursorMonitor

cursorActive

private boolean cursorActive

execHandle

private FennelExecutionHandle execHandle

streamIdToHandleMap

private final Map<Integer,FennelJavaHandle> streamIdToHandleMap
Maps stream id to the corresponding java object.


transformMap

private final Map<String,FarragoTransform> transformMap

dynamicParamValues

protected final Object[] dynamicParamValues

streamGraph

protected FennelStreamGraph streamGraph

streamOwner

protected final FarragoCompoundAllocation streamOwner
responsible for closing the FennelStreamGraph


indexMap

private final FarragoSessionIndexMap indexMap

sessionVariables

private final FarragoSessionVariables sessionVariables

dataWrapperCache

protected final FarragoDataWrapperCache dataWrapperCache

streamFactoryProvider

private final FarragoStreamFactoryProvider streamFactoryProvider

isDml

private final boolean isDml

currentTime

private long currentTime

isCanceled

private boolean isCanceled

isClosed

protected boolean isClosed

statementClassLoader

private ClassLoader statementClassLoader

resultSetTypeMap

protected Map<String,RelDataType> resultSetTypeMap

stmtId

protected long stmtId

nativeContext

private NativeRuntimeContext nativeContext

detachedSession

private EnkiMDSession detachedSession
Constructor Detail

FarragoRuntimeContext

public FarragoRuntimeContext(FarragoSessionRuntimeParams params)
Creates a new FarragoRuntimeContext.

Parameters:
params - constructor params
Method Detail

getWarningQueue

public FarragoWarningQueue getWarningQueue()
Specified by:
getWarningQueue in interface FarragoSessionRuntimeContext
Returns:
queue of warnings posted to this runtime context

getStreamGraph

protected FennelStreamGraph getStreamGraph()
Returns the stream graph.


getRelOptSchema

public RelOptSchema getRelOptSchema()
Description copied from interface: RelOptConnection
Returns the schema underlying this connection. Non-abstract classes implementing this interface must also provide public static Schema getRelOptSchemaStatic().

Specified by:
getRelOptSchema in interface RelOptConnection

closeAllocation

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

Specified by:
closeAllocation in interface ClosableAllocation
Overrides:
closeAllocation in class CompoundClosableAllocation

closeStreamGraph

private void closeStreamGraph()

addAllocation

public void addAllocation(ClosableAllocation allocation)
Description copied from interface: ClosableAllocationOwner
Assigns ownership of a ClosableAllocation to this owner.

Specified by:
addAllocation in interface ClosableAllocationOwner
Overrides:
addAllocation in class CompoundClosableAllocation
Parameters:
allocation - the ClosableAllocation to take over

forgetAllocation

public boolean forgetAllocation(ClosableAllocation allocation)
Description copied from class: CompoundClosableAllocation
Forgets an allocation without closing it.

Overrides:
forgetAllocation in class CompoundClosableAllocation
Parameters:
allocation - the allocation to forget
Returns:
whether the allocation was known

hasAllocations

public boolean hasAllocations()
Overrides:
hasAllocations in class CompoundClosableAllocation
Returns:
whether any allocations remain unclosed

contentsAsArray

public Object contentsAsArray(String qualifier,
                              String tableName)
Description copied from interface: RelOptConnection
In theory, this method returns the contents of tableName as an array; in practice, it is a placeholder recognized by the optimizer to do something much more efficient. This involves calling RelOptSchema.getTableForMember(java.lang.String[])(qualifier,tableName).RelOptTable.toRel(org.eigenbase.relopt.RelOptCluster, org.eigenbase.relopt.RelOptConnection)(cluster, exp).

Specified by:
contentsAsArray in interface RelOptConnection

getDataServerRuntimeSupport

public Object getDataServerRuntimeSupport(String serverMofId,
                                          Object param)
Gets an object needed to support the implementation of foreign data access.

Parameters:
serverMofId - MOFID of foreign server being accessed
param - server-specific runtime parameter
Returns:
server-specific runtime support object

getRefMofId

public String getRefMofId(RefBaseObject refObj)
Gets the MofId for a RefBaseObject, or null if the object is null. This is called at execution from code generated by MdrTable.

Parameters:
refObj - RefBaseObject for which to get the MofId
Returns:
MofId or null

getDynamicParamValue

public Object getDynamicParamValue(int paramIndex)
Gets the value bound to a dynamic parameter.

Parameters:
paramIndex - 0-based index of parameter
Returns:
bound value

getContextVariable_USER

public String getContextVariable_USER()
Called from generated code.

Returns:
the value of context variable USER.

getContextVariable_CURRENT_USER

public String getContextVariable_CURRENT_USER()
Called from generated code.

Returns:
the value of context variable CURRENT_USER.

getContextVariable_SYSTEM_USER

public String getContextVariable_SYSTEM_USER()
Called from generated code.

Returns:
the value of context variable SYSTEM_USER.

getContextVariable_SESSION_USER

public String getContextVariable_SESSION_USER()
Called from generated code.

Returns:
the value of context variable SESSION_USER.

getContextVariable_CURRENT_ROLE

public String getContextVariable_CURRENT_ROLE()
Called from generated code.

Returns:
the value of context variable CURRENT_ROLE.

getContextVariable_CURRENT_CATALOG

public String getContextVariable_CURRENT_CATALOG()
Called from generated code.

Returns:
the value of context variable CURRENT_CATALOG.

getContextVariable_CURRENT_SCHEMA

public String getContextVariable_CURRENT_SCHEMA()
Called from generated code.

Returns:
the value of context variable CURRENT_SCHEMA.

getContextVariable_CURRENT_PATH

public String getContextVariable_CURRENT_PATH()
Called from generated code.

Returns:
the value of context variable CURRENT_PATH.
Reference to SQL:1999 standard:
Part 2 Section 6.3 General Rule 10

getCurrentTime

protected long getCurrentTime()

getContextVariable_CURRENT_DATE

public Date getContextVariable_CURRENT_DATE()
Called from generated code.

Returns:
the value of context variable CURRENT_DATE.

getContextVariable_CURRENT_TIME

public Time getContextVariable_CURRENT_TIME()
Called from generated code.

Returns:
the value of context variable CURRENT_TIME.

getContextVariable_CURRENT_TIMESTAMP

public Timestamp getContextVariable_CURRENT_TIMESTAMP()
Called from generated code.

Returns:
the value of context variable CURRENT_TIMESTAMP.

getContextVariable_LOCALTIME

public Time getContextVariable_LOCALTIME()
Called from generated code.

Returns:
the value of context variable LOCALTIME.

getContextVariable_LOCALTIMESTAMP

public Timestamp getContextVariable_LOCALTIMESTAMP()
Called from generated code.

Returns:
the value of context variable LOCALTIMESTAMP.

registerJavaStream

protected void registerJavaStream(int streamId,
                                  Object stream)
Associates a stream id with a java stream object, so that it can be retrieved by a native method later.


registerJavaStream

protected void registerJavaStream(int streamId,
                                  Object stream,
                                  FarragoCompoundAllocation owner)
Associates a stream id with a java stream object, so that it can be retrieved by a native method later. Binds the stream to a specific owner (that will eventually close it).


registerFarragoTransform

public void registerFarragoTransform(String key,
                                     FarragoTransform xform)
Associates a FarragoTransform instance with its class name, so that it can be retrieved by a native method later. Binds the stream to a specific owner (that will eventually close it).


findFarragoTransform

public FarragoTransform findFarragoTransform(String key)

dummyPair

public Object dummyPair(Object dummy1,
                        Object dummy2)
Stupid helper for code generated by FennelDoubleRel.

Parameters:
dummy1 - a dummy
dummy2 - another dummy
Returns:
yet another dummy

dummyArray

public Object dummyArray(Object[] dummyArray)
Stupid helper for code generated by FennelMultipleRel.

Parameters:
dummyArray - array of dummies
Returns:
yet another dummy

loadFennelPlan

public void loadFennelPlan(String xmiFennelPlan)
Description copied from interface: FarragoSessionRuntimeContext
Loads the Fennel portion of an execution plan (either creating a new XO graph or reusing a cached instance).

Specified by:
loadFennelPlan in interface FarragoSessionRuntimeContext
Parameters:
xmiFennelPlan - XMI representation of plan definition

openStreams

public void openStreams()
Description copied from interface: FarragoSessionRuntimeContext
Opens all streams, including the Fennel portion of the execution plan. This should only be called after all Java TupleStreams have been created.

Specified by:
openStreams in interface FarragoSessionRuntimeContext

getFennelStreamGraph

public FennelStreamGraph getFennelStreamGraph()
Specified by:
getFennelStreamGraph in interface FarragoSessionRuntimeContext
Returns:
FennelStreamGraph pinned by loadFennelPlan

newFennelTupleIter

public TupleIter newFennelTupleIter(FennelTupleReader tupleReader,
                                    String streamName,
                                    int streamId,
                                    Object dummies)
Creates a FennelTupleIter for executing a plan represented as XML. This is called at execution from code generated by FennelToIteratorConverter. The FennelTupleIter is registered as the java peer of streamId.

Parameters:
tupleReader - object providing FennelTupleReader implementation
streamName - name of stream from which to read (globally unique)
streamId - id of stream from which to read (unique within statement)
dummies - a dummy parameter to give non-Fennel children a place to generate code
Returns:
tuple iterator

newFennelTransformTupleIter

public TupleIter newFennelTransformTupleIter(FennelTupleReader tupleReader,
                                             String streamName,
                                             String inputStreamName,
                                             FarragoTransform.InputBinding[] inputBindings,
                                             Object dummies)
Creates a FennelTupleIter for executing a plan represented as XML. This iterator is used during execution in Fennel's JavaTransformExecStream from code generated by FennelToIteratorConverter.

Note: The semantics of streamName and streamId differ from newFennelTupleIter(FennelTupleReader, String, int, Object). The iter is not registered as the java peer of the fennel stream; the registered peer of the stream is instead the specially generated FarragoTransform. (See FarragoTransformDef.init(net.sf.farrago.session.FarragoSessionRuntimeContext).)

Parameters:
tupleReader - object providing FennelTupleReader implementation
streamName - name of the JavaExecTransformStream we're reading on behalf of
inputStreamName - the global name of a stream to read
dummies - a dummy parameter to give non-Fennel children a place to generate code
Returns:
tuple iterator

getStreamHandle

public FennelStreamHandle getStreamHandle(String globalStreamName,
                                          boolean isInput)
Description copied from interface: FarragoSessionRuntimeContext
Retrieves the FennelStreamHandle corresponding to a stream

Specified by:
getStreamHandle in interface FarragoSessionRuntimeContext
Parameters:
globalStreamName - name of the stream that you are searching for
Returns:
FennelStreamHandle corresponding to the stream specified by the name parameter

prepareStreamGraph

protected FennelStreamGraph prepareStreamGraph(String xmiFennelPlan)

getJavaStreamHandle

public long getJavaStreamHandle(int streamId)
Description copied from interface: FennelJavaStreamMap
Looks up the handle of a JavaTupleStream by its ID. This is called by native code when a TupleStream is opened. The ID is a placeholder in the TupleStream definition; each open may result in a different handle.

Specified by:
getJavaStreamHandle in interface FennelJavaStreamMap
Parameters:
streamId - ID of stream to find
Returns:
JavaTupleStream handle

getIndexRoot

public long getIndexRoot(long pageOwnerId)
Description copied from interface: FennelJavaStreamMap
Looks up the root PageId of an index. This is called by native code when a TupleStream accessing a temporary BTree is opened.

Specified by:
getIndexRoot in interface FennelJavaStreamMap
Parameters:
pageOwnerId - the identifier for the index

getFennelDbHandle

public FennelDbHandle getFennelDbHandle()
Returns:
handle to Fennel database being accessed

getFennelTxnContext

public FennelTxnContext getFennelTxnContext()
Returns:
handle to current Fennel Transaction

getRepos

public FarragoRepos getRepos()
Specified by:
getRepos in interface FarragoSessionRuntimeContext
Returns:
FarragoRepos for use by extension projects

checkNotNull

public void checkNotNull(String targetName,
                         NullableValue nullableValue)
Called when a nullable value is cast to a NOT NULL type.

Parameters:
targetName - target expression
nullableValue - source value

checkNotNull

public void checkNotNull(String targetName,
                         Object obj)
Called when a nullable value is cast to a NOT NULL type.

Parameters:
targetName - target expression
obj - source value

pushRoutineInvocation

public void pushRoutineInvocation(FarragoSessionUdrContext udrContext,
                                  boolean allowSql)
Description copied from interface: FarragoSessionRuntimeContext
Pushes a routine invocation onto the context stack.

Specified by:
pushRoutineInvocation in interface FarragoSessionRuntimeContext
Parameters:
udrContext - context holder for routine invocation instance within statement being executed
allowSql - whether SQL execution should be allowed in this routine

popRoutineInvocation

public void popRoutineInvocation()
Description copied from interface: FarragoSessionRuntimeContext
Pops a routine invocation from the context stack.

Specified by:
popRoutineInvocation in interface FarragoSessionRuntimeContext

cancel

public void cancel()
Description copied from interface: FarragoSessionRuntimeContext
Requests cancellation of this execution (either for asynchronous abort, or because execution has ended).

Specified by:
cancel in interface FarragoSessionRuntimeContext

checkCancel

public void checkCancel()
Description copied from interface: FarragoSessionRuntimeContext
Throws an exception if execution has been canceled.

Specified by:
checkCancel in interface FarragoSessionRuntimeContext

setExecutionHandle

public void setExecutionHandle(FennelExecutionHandle execHandle)
Description copied from interface: FarragoSessionRuntimeContext
Associates an execution handle with the runtime context.

Specified by:
setExecutionHandle in interface FarragoSessionRuntimeContext
Parameters:
execHandle - the execution handle

setCursorState

public void setCursorState(boolean active)
Description copied from interface: FarragoSessionRuntimeContext
Sets the state of the top-level cursor associated with this context. FarragoSessionRuntimeContext.checkCancel() is called both before the fetch request (active=true) and after the fetch (active=false). Not called for internal cursors such as UDX inputs and cursors opened via reentrant SQL from UDRs.

Specified by:
setCursorState in interface FarragoSessionRuntimeContext
Parameters:
active - true if cursor is beginning a fetch request; false if cursor is ending a fetch request

waitForCursor

public void waitForCursor()
Description copied from interface: FarragoSessionRuntimeContext
Waits for cursor state to be reset to active=false (returns immediately if cursor is not currently active).

Specified by:
waitForCursor in interface FarragoSessionRuntimeContext

handleRoutineInvocationException

public RuntimeException handleRoutineInvocationException(Throwable ex,
                                                         String methodName)
Description copied from interface: FarragoSessionRuntimeContext
Handles an exception caught by invocation of a routine.

Specified by:
handleRoutineInvocationException in interface FarragoSessionRuntimeContext
Parameters:
ex - exception
methodName - name of external Java method
Returns:
exception to be re-thrown

getInvocationStack

private static List<FarragoUdrInvocationFrame> getInvocationStack()

getUdrInvocationFrame

static FarragoUdrInvocationFrame getUdrInvocationFrame()

peekStackFrame

private static FarragoUdrInvocationFrame peekStackFrame(List<FarragoUdrInvocationFrame> stack)

newConnection

public static Connection newConnection()
Creates a new default connection attached to the session of the current thread.


setStatementClassLoader

public void setStatementClassLoader(ClassLoader statementClassLoader)
Description copied from interface: FarragoSessionRuntimeContext
Configures a custom class loader used to load extra classes that may be needed during statement runtime. Specifically, allows Fennel to load implementations of FarragoTransform.

Specified by:
setStatementClassLoader in interface FarragoSessionRuntimeContext

statementClassForName

public Class statementClassForName(String statementClassName)

getRowTypeForResultSet

public RelDataType getRowTypeForResultSet(String resultSetName)
Description copied from interface: FarragoSessionRuntimeContext
Gets the row type for instantiating a result set.

Specified by:
getRowTypeForResultSet in interface FarragoSessionRuntimeContext
Parameters:
resultSetName - name of result set stored by optimizer
Returns:
corresponding row type

getSequenceAccessor

public FarragoSequenceAccessor getSequenceAccessor(String mofId)

getSession

public FarragoSession getSession()
Specified by:
getSession in interface FarragoSessionRuntimeContext
Returns:
session on behalf of which this runtime context is executing

handleRowError

public Object handleRowError(SyntheticObject row,
                             RuntimeException ex,
                             int columnIndex,
                             String tag)
Handles an exception encountered by a stream while processing an input row. The default implementation logs exceptions to the server trace file.

Parameters:
row - the input row object
ex - the exception encountered
columnIndex - index for the output column being calculated when an exception was encountered, or zero if the filter condition was being evaluated. This parameter may be -1 if not appropriate for the exception
tag - an error handling tag specific to the runtime context. This parameter may also be null
Returns:
the status of the error handler. While the default implementation returns null, Farrago extensions may return more informative values, such as TupleIter.NoDataReason.

handleRowError

public Object handleRowError(SyntheticObject row,
                             RuntimeException ex,
                             int columnIndex,
                             String tag,
                             boolean isWarning)
Handles a runtime exception, but allows warnings as well.

See Also:
handleRowError(SyntheticObject, RuntimeException, int, String)

handleRowError

public Object handleRowError(String[] columnNames,
                             Object[] columnValues,
                             RuntimeException ex,
                             int columnIndex,
                             String tag,
                             boolean isWarning)
Handles a runtime exception based on an array of column values rather than on a SyntheticObject


handleRowError

public Object handleRowError(String[] columnNames,
                             Object[] columnValues,
                             RuntimeException ex,
                             int columnIndex,
                             String tag,
                             boolean isWarning,
                             String errorCode,
                             String columnName)
Handles runtime exception; if errorCode is non-null, exceptions are deferred until all errors on a row are processed; not currently implemented


handleRowErrorCompletion

public void handleRowErrorCompletion(RuntimeException ex,
                                     String tag)
Handles exception for row errors with deferred exceptions; not currently implemented


handleRowErrorHelper

private EigenbaseException handleRowErrorHelper(String row,
                                                RuntimeException ex,
                                                int columnIndex,
                                                String tag,
                                                boolean isWarning)
Helper for various handleRowError methods


makeRowError

protected EigenbaseException makeRowError(RuntimeException ex,
                                          String row,
                                          int index,
                                          String field)
Makes a row error based on conventions for column index

Parameters:
ex - the runtime exception encountered
row - string representing the row on which an exception occurred
index - index of the column being processed at the time the exception was encountered, or 0 for an error processing a conditional expression, or -1 for a non-specific error
field - optional column name, used in constructing the error message when columnIndex > 0
Returns:
a non-nested exception summarizing the row error

handleRowError

public Object handleRowError(String source,
                             boolean isWarning,
                             String msg,
                             ByteBuffer byteBuffer,
                             int index)
Description copied from interface: FennelJavaErrorTarget
Handles a Fennel row exception

Specified by:
handleRowError in interface FennelJavaErrorTarget
Parameters:
source - the unique Fennel stream name
isWarning - true if the exception is only a warning
msg - the exception string
byteBuffer - the Fennel format byte buffer containing an error record for the row that failed. The error record must conform to the row type specified for the source with FennelRelImplementor.setErrorRecordType(net.sf.farrago.query.FennelRel, net.sf.farrago.fem.fennel.FemExecutionStreamDef, org.eigenbase.reltype.RelDataType)
index - position of the column whose processing caused the exception to occur. -1 indicates that no column was culpable. 0 indicates that a filter condition was being processed. Otherwise this parameter should be a 1-indexed column position.

inUdr

public static boolean inUdr()
Returns:
true if a UDR is currently being executed

detachMdrSession

public void detachMdrSession()
Description copied from interface: FarragoSessionRuntimeContext
Detaches the current MDR session from the running thread. The detached session is stored for later re-attachment and is automatically re-attached and closed if when the runtime context is closed.

Specified by:
detachMdrSession in interface FarragoSessionRuntimeContext

reattachMdrSession

public void reattachMdrSession()
Description copied from interface: FarragoSessionRuntimeContext
Re-attaches a detached MDR session to the currently running thread, if any was previously detached.

Specified by:
reattachMdrSession in interface FarragoSessionRuntimeContext