net.wgen.op
Class Op

java.lang.Object
  extended bynet.wgen.op.Op
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DummyOp, LoginOp, MultiRsOp, ProjectListOp, ProjectTimesheetsOp, SleepyOp, TestOp.TopOp

public abstract class Op
extends java.lang.Object
implements java.io.Serializable

Command-pattern object that encapsulates some database operations or business logic.

Version:
$Id: Op.html,v 1.2 2007/01/28 04:09:36 paulfeuer Exp $
Author:
Paul Feuer, Wireless Generation, Inc.
See Also:
Serialized Form

Field Summary
private  java.lang.Long _callersUserId
          The userID of the end-user responsible for causing the instantiation of this Op.
private  java.lang.String _defaultDataSourceName
          The default DataSource name for DatabaseCall objects instantiated by the Op's helper methods.
protected  OpExecutor _opExecutor
          The executor of the Op.
protected  java.util.Map _options
          Options for this Op's execution.
protected  Op _rootOp
          The Op, if any, that may have been responsible for this Op's instantiation.
private  TraceKey _traceKey
          The trace key for the request creating this Op.
protected  org.apache.log4j.Logger LOG
          Logger for the implementation class.
private static long serialVersionUID
          UID for serialization compatibility.
 
Constructor Summary
protected Op(Op callingOp)
          Constructor to be used by an Op that needs to instantiate another Op.
  Op(TraceKey traceKey)
          Default constructor must use a TraceKey object.
 
Method Summary
protected abstract  void _execute(CallExecutor exec)
          Execute the body of the Op.
 Op execute()
          Invoke the OpExecutor, or if the OpExecutor is null, use the OpExecutorFactory to create one.
 java.lang.String getAmountOfWorkDone()
          Characterizes the amount of work done by the Op, such as number of records retrieved.
 java.lang.Long getCallersUserId()
          The ID of the end-user responsible for the instantiation and execution of this Op.
 java.lang.String getDefaultDataSourceName()
          The datasource to be used for new DatabaseCalls provided by this Op.
 org.apache.log4j.Logger getLogger()
          The Logger associated with the implementation class.
 java.util.Map getOptions()
          The execution options for this Op.
 Op getRootOp()
          The top-most Op in the execution.
 TraceKey getTraceKey()
          The traceKey for this Op identifying the request responsible for the Op's instantiation and execution.
protected  DatabaseCall makeFunction(java.lang.String callText)
          Convenience method to create a call declared as a database function with the Op's defaultDataSourceName.
protected  DatabaseCall makeProcedure(java.lang.String callText)
          Convenience method to create a call declared as a database procedure with the Op's defaultDataSourceName.
protected  DatabaseCall makeQuery(java.lang.String callText)
          Convenience method to create a call declared as a SQL query with the Op's defaultDataSourceName.
 void setDefaultDataSourceName(java.lang.String defaultDataSourceName)
          Change the datasource to be used for new DatabaseCalls created in the make* convenience methods.
 void setOpExecutor(OpExecutor executor)
          The executor for this Op.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
UID for serialization compatibility.

See Also:
Constant Field Values

LOG

protected transient org.apache.log4j.Logger LOG
Logger for the implementation class.


_traceKey

private final TraceKey _traceKey
The trace key for the request creating this Op.


_opExecutor

protected transient OpExecutor _opExecutor
The executor of the Op.


_rootOp

protected final Op _rootOp
The Op, if any, that may have been responsible for this Op's instantiation.


_callersUserId

private final java.lang.Long _callersUserId
The userID of the end-user responsible for causing the instantiation of this Op.


_options

protected java.util.Map _options
Options for this Op's execution.


_defaultDataSourceName

private java.lang.String _defaultDataSourceName
The default DataSource name for DatabaseCall objects instantiated by the Op's helper methods.

Constructor Detail

Op

public Op(TraceKey traceKey)
Default constructor must use a TraceKey object. During initialization, the Op's options will be retrieved from the TraceKey's userData map at key ParamTriggerState.TRACE_KEY_USER_DATA_KEY. The defaultDataSourceName will also be initialized using the dataSourceName of the OpModule in the TraceKey. The defaultDataSourceName is used to initialize the dataSourceName of the DatabaseCalls created by the Op's DatabaseCall convenience methods.

Parameters:
traceKey - the traceKey identifying the request responsible for the instantiation and execution of this Op
Throws:
java.lang.NullPointerException - if traceKey or traceKey.getUserId() is null
See Also:
ParamTriggerState.TRACE_KEY_USER_DATA_KEY, OpModule.getDataSourceName()

Op

protected Op(Op callingOp)
Constructor to be used by an Op that needs to instantiate another Op. This constructor is used to associate nested Ops with some entry point. During initialization, the TraceKey, defaultDataSourceName, callersUserId, and options will all be copied from the callingOp. This new Op's rootOp is the callingOp unless the callingOp itself has a rootOp, i.e. the rootOp is the ROOT and not the parent.

Parameters:
callingOp - the Op responsible for this Op's instantiation and execution
Throws:
java.lang.NullPointerException - if the callingOp is null
Method Detail

getCallersUserId

public final java.lang.Long getCallersUserId()
The ID of the end-user responsible for the instantiation and execution of this Op.


getTraceKey

public final TraceKey getTraceKey()
The traceKey for this Op identifying the request responsible for the Op's instantiation and execution.


getRootOp

public final Op getRootOp()
The top-most Op in the execution.


setDefaultDataSourceName

public void setDefaultDataSourceName(java.lang.String defaultDataSourceName)
Change the datasource to be used for new DatabaseCalls created in the make* convenience methods.

Parameters:
defaultDataSourceName - the name of the datasource to be used for new DatabaseCalls instantiated by the make* convenience methods.
See Also:
makeFunction(java.lang.String), makeProcedure(java.lang.String), makeQuery(java.lang.String)

getDefaultDataSourceName

public java.lang.String getDefaultDataSourceName()
The datasource to be used for new DatabaseCalls provided by this Op.


getOptions

public java.util.Map getOptions()
The execution options for this Op. They are initialized during the constructor either from the TraceKey userData, or the parent Op's options.

See Also:
Op(net.wgen.op.logging.TraceKey), ParamTriggerState.TRACE_KEY_USER_DATA_KEY

getLogger

public org.apache.log4j.Logger getLogger()
The Logger associated with the implementation class.


setOpExecutor

public void setOpExecutor(OpExecutor executor)
The executor for this Op. This need not be called. When execute() is invoked, if the OpExecutor is null, the OpExecutorFactory creates one to use.

Parameters:
executor - the executor to use for execution

execute

public Op execute()
           throws OpException
Invoke the OpExecutor, or if the OpExecutor is null, use the OpExecutorFactory to create one.

Returns:
the Op itself, if never serialized, or the Op as it was returned after serialization in some remote container
Throws:
OpException

_execute

protected abstract void _execute(CallExecutor exec)
                          throws OpException
Execute the body of the Op.

Parameters:
exec - what will perform DB or other calls
Throws:
OpException

getAmountOfWorkDone

public java.lang.String getAmountOfWorkDone()
Characterizes the amount of work done by the Op, such as number of records retrieved. This is an optional string that, when not null, allows the Op implementer to add log information to the framework-invoked logging statement.

Returns:
characterization of the amount of work done by the Op, or null, if the value was not set

makeFunction

protected DatabaseCall makeFunction(java.lang.String callText)
Convenience method to create a call declared as a database function with the Op's defaultDataSourceName.

Parameters:
callText - the function name
Returns:
a call declared a database function with the Op's defaultDataSourceName

makeProcedure

protected DatabaseCall makeProcedure(java.lang.String callText)
Convenience method to create a call declared as a database procedure with the Op's defaultDataSourceName.

Parameters:
callText - the procedure name
Returns:
a call declared a database function with the Op's defaultDataSourceName

makeQuery

protected DatabaseCall makeQuery(java.lang.String callText)
Convenience method to create a call declared as a SQL query with the Op's defaultDataSourceName.

Parameters:
callText - the parameterized query text
Returns:
a call declared a SQL query with the Op's defaultDataSourceName