net.sf.farrago.db
Class FarragoDbStmtContext

java.lang.Object
  extended by net.sf.farrago.db.FarragoDbStmtContextBase
      extended by net.sf.farrago.db.FarragoDbStmtContext
All Implemented Interfaces:
FarragoSessionStmtContext, FarragoAllocation, ClosableAllocation

public class FarragoDbStmtContext
extends FarragoDbStmtContextBase
implements FarragoSessionStmtContext

FarragoDbStmtContext implements the FarragoSessionStmtContext interface in terms of a FarragoDbSession.

Most non-trivial public methods on this class must be synchronized on the parent session; see superclass for details.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/db/FarragoDbStmtContext.java#57 $
Author:
John V. Sichi

Field Summary
private  FarragoCompoundAllocation allocations
           
private  FarragoSessionExecutableStmt executableStmt
           
private  boolean isExecDirect
           
private  int queryTimeoutMillis
          query timeout in seconds, default to 0.
private  ResultSet resultSet
           
private  FarragoSessionRuntimeContext runningContext
           
private  long updateCount
           
private  FarragoWarningQueue warningQueue
           
 
Fields inherited from class net.sf.farrago.db.FarragoDbStmtContextBase
cancelFlag, childrenStmtContexts, daemon, dynamicParamDefs, dynamicParamValues, dynamicParamValuesSet, paramDefFactory, rootStmtContext, saveFirstCsn, session, snapshotCsn, sql, tracer
 
Constructor Summary
FarragoDbStmtContext(FarragoDbSession session, FarragoSessionStmtParamDefFactory paramDefFactory, FarragoDdlLockManager ddlLockManager)
          Creates a new FarragoDbStmtContext object.
FarragoDbStmtContext(FarragoDbSession session, FarragoSessionStmtParamDefFactory paramDefFactory, FarragoDdlLockManager ddlLockManager, FarragoSessionStmtContext rootStmtContext)
          Creates a new FarragoDbStmtContext object.
 
Method Summary
 void cancel()
          Cancels execution.
private  void cancel(boolean wait)
           
 void closeResultSet()
          Closes any result set associated with this statement context.
 void execute()
          Executes the currently prepared statement.
private  void executeImpl()
           
private  void finishPrepare()
           
private  List<String> getDmlTarget()
           
 RelDataType getPreparedParamType()
           
 RelDataType getPreparedRowType()
           
 int getQueryTimeout()
           
 ResultSet getResultSet()
           
 long getUpdateCount()
          Obtains an update count produced by execute(), clearing this information as a side effect.
 FarragoWarningQueue getWarningQueue()
          Gets the warning queue for this statement.
 boolean isPrepared()
           
 boolean isPreparedDml()
           
 void kill()
          Cancels execution and destroys the statement.
 void prepare(RelNode plan, SqlKind kind, boolean logical, FarragoSessionPreparingStmt prep)
          Prepares a query or DML statement (not DDL), provided as a query plan.
 void prepare(String sql, boolean isExecDirect)
          Prepares an SQL statement.
 void setQueryTimeout(int millis)
           
 void unprepare()
          Releases any resources (including result sets) associated with this statement context.
private  long updateRowCounts(List<Long> rowCounts, FarragoSessionRuntimeContext runningContext)
          Update catalog row counts
 
Methods inherited from class net.sf.farrago.db.FarragoDbStmtContextBase
accessTable, accessTables, addChildStmtContext, checkDynamicParamsSet, clearExecutingStmtInfo, clearParameters, closeAllocation, daemonize, getCancelFlag, getExecutingStmtInfo, getSession, getSql, getStmtCurrentTime, initDynamicParams, initExecutingStmtInfo, lockObjectInUse, lockObjectsInUse, needToSaveFirstTxnCsn, saveFirstTxnCsn, setDynamicParam, setDynamicParam, setSaveFirstTxnCsn, startAutocommitTxn, traceExecute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.farrago.session.FarragoSessionStmtContext
addChildStmtContext, clearParameters, daemonize, getCancelFlag, getExecutingStmtInfo, getSession, getSql, getStmtCurrentTime, needToSaveFirstTxnCsn, saveFirstTxnCsn, setDynamicParam, setDynamicParam, setSaveFirstTxnCsn
 
Methods inherited from interface org.eigenbase.util.ClosableAllocation
closeAllocation
 

Field Detail

updateCount

private long updateCount

resultSet

private ResultSet resultSet

executableStmt

private FarragoSessionExecutableStmt executableStmt

allocations

private FarragoCompoundAllocation allocations

runningContext

private FarragoSessionRuntimeContext runningContext

warningQueue

private final FarragoWarningQueue warningQueue

isExecDirect

private boolean isExecDirect

queryTimeoutMillis

private int queryTimeoutMillis
query timeout in seconds, default to 0.

Constructor Detail

FarragoDbStmtContext

public FarragoDbStmtContext(FarragoDbSession session,
                            FarragoSessionStmtParamDefFactory paramDefFactory,
                            FarragoDdlLockManager ddlLockManager)
Creates a new FarragoDbStmtContext object.

Parameters:
session - the session creating this statement

FarragoDbStmtContext

public FarragoDbStmtContext(FarragoDbSession session,
                            FarragoSessionStmtParamDefFactory paramDefFactory,
                            FarragoDdlLockManager ddlLockManager,
                            FarragoSessionStmtContext rootStmtContext)
Creates a new FarragoDbStmtContext object.

Parameters:
session - the session creating this statement
Method Detail

isPrepared

public boolean isPrepared()
Specified by:
isPrepared in interface FarragoSessionStmtContext
Returns:
whether this context currently has a statement prepared

isPreparedDml

public boolean isPreparedDml()
Specified by:
isPreparedDml in interface FarragoSessionStmtContext
Returns:
whether this context currently has a DML statement prepared

prepare

public void prepare(String sql,
                    boolean isExecDirect)
Description copied from interface: FarragoSessionStmtContext
Prepares an SQL statement.

Specified by:
prepare in interface FarragoSessionStmtContext
Parameters:
sql - text of statement to be prepared
isExecDirect - whether the statement is being prepared as part of direct execution

finishPrepare

private void finishPrepare()

prepare

public void prepare(RelNode plan,
                    SqlKind kind,
                    boolean logical,
                    FarragoSessionPreparingStmt prep)
Description copied from interface: FarragoSessionStmtContext
Prepares a query or DML statement (not DDL), provided as a query plan. The system uses this to prepare and execute internal statements. As with FarragoSessionStmtContext.prepare(String,boolean), the statement can be executed by FarragoSessionStmtContext.execute().

Specified by:
prepare in interface FarragoSessionStmtContext
Parameters:
plan - a query plan (ie a relational expression).
kind - SqlKind value that characterized the statement.
logical - true when the query plan is logical (needs to be optimized), false when it is physical (already optimized).
prep - the FarragoSessionPreparingStatement that is managing the query plan.

getPreparedRowType

public RelDataType getPreparedRowType()
Specified by:
getPreparedRowType in interface FarragoSessionStmtContext
Returns:
the output row type for the currently prepared statement

getPreparedParamType

public RelDataType getPreparedParamType()
Specified by:
getPreparedParamType in interface FarragoSessionStmtContext
Returns:
the input parameter row type for the currently prepared statement

setQueryTimeout

public void setQueryTimeout(int millis)
Specified by:
setQueryTimeout in interface FarragoSessionStmtContext

getQueryTimeout

public int getQueryTimeout()
Specified by:
getQueryTimeout in interface FarragoSessionStmtContext

execute

public void execute()
Description copied from interface: FarragoSessionStmtContext
Executes the currently prepared statement.

Specified by:
execute in interface FarragoSessionStmtContext

executeImpl

private void executeImpl()

getResultSet

public ResultSet getResultSet()
Specified by:
getResultSet in interface FarragoSessionStmtContext
Returns:
the result set produced by execute(), or null if the statement was not a query

getUpdateCount

public long getUpdateCount()
Description copied from interface: FarragoSessionStmtContext
Obtains an update count produced by execute(), clearing this information as a side effect.

Specified by:
getUpdateCount in interface FarragoSessionStmtContext
Returns:
number of rows affected, or -1 if statement is non-DML or its update count was already returned

cancel

public void cancel()
Description copied from interface: FarragoSessionStmtContext
Cancels execution.

Specified by:
cancel in interface FarragoSessionStmtContext

cancel

private void cancel(boolean wait)

kill

public void kill()
Description copied from interface: FarragoSessionStmtContext
Cancels execution and destroys the statement.

Specified by:
kill in interface FarragoSessionStmtContext

closeResultSet

public void closeResultSet()
Description copied from interface: FarragoSessionStmtContext
Closes any result set associated with this statement context.

Specified by:
closeResultSet in interface FarragoSessionStmtContext

unprepare

public void unprepare()
Description copied from interface: FarragoSessionStmtContext
Releases any resources (including result sets) associated with this statement context.

Specified by:
unprepare in interface FarragoSessionStmtContext
Overrides:
unprepare in class FarragoDbStmtContextBase

getWarningQueue

public FarragoWarningQueue getWarningQueue()
Description copied from interface: FarragoSessionStmtContext
Gets the warning queue for this statement.

Specified by:
getWarningQueue in interface FarragoSessionStmtContext
Returns:
warning queue

updateRowCounts

private long updateRowCounts(List<Long> rowCounts,
                             FarragoSessionRuntimeContext runningContext)
Update catalog row counts

Parameters:
rowCounts - row counts returned by the DML operation
Returns:
rowcount affected by the DML operation

getDmlTarget

private List<String> getDmlTarget()