net.sf.farrago.query
Class ReposDefaultValueFactory

java.lang.Object
  extended by net.sf.farrago.query.ReposDefaultValueFactory
All Implemented Interfaces:
FarragoObjectCache.CachedObjectFactory, DefaultValueFactory

public class ReposDefaultValueFactory
extends Object
implements DefaultValueFactory, FarragoObjectCache.CachedObjectFactory

DefaultValueFactory looks up a default value stored in the catalog, parses it, and converts it to an Expression. Processed expressions are cached for use by subsequent calls. The CwmExpression's MofId is used as the cache key.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/query/ReposDefaultValueFactory.java#14 $
Author:
John V. Sichi

Field Summary
private  Map<FemRoutine,SqlNodeList> constructorToSqlMap
           
protected  FarragoPreparingStmt farragoPreparingStmt
           
 
Constructor Summary
ReposDefaultValueFactory(FarragoPreparingStmt farragoPreparingStmt)
          Creates a ReposDefaultValueFactory.
 
Method Summary
private  RexNode convertConstructorAssignment(FarragoUserDefinedRoutine constructor, FemSqltypeAttribute attribute, RexNode[] constructorArgs)
           
private  RexNode convertExpression(CwmExpression cwmExp)
          Converts an expression definition from the repository into RexNode format.
 void initializeEntry(Object key, FarragoObjectCache.UninitializedEntry entry)
          Initializes a cache entry.
 boolean isGeneratedAlways(RelOptTable table, int iColumn)
          Whether a column is always generated.
 boolean isStale(Object value)
          Tests a cached object for staleness.
 RexNode newAttributeInitializer(RelDataType type, SqlFunction constructor, int iAttribute, RexNode[] constructorArgs)
          Creates an expression which evaluates to the initializer expression for a particular attribute of a structured type.
 RexNode newColumnDefaultValue(RelOptTable table, int iColumn)
          Creates an expression which evaluates to the default value for a particular column.
private  RexNode sequenceValue(FemSequenceGenerator sequence)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constructorToSqlMap

private Map<FemRoutine,SqlNodeList> constructorToSqlMap

farragoPreparingStmt

protected FarragoPreparingStmt farragoPreparingStmt
Constructor Detail

ReposDefaultValueFactory

public ReposDefaultValueFactory(FarragoPreparingStmt farragoPreparingStmt)
Creates a ReposDefaultValueFactory.

Parameters:
farragoPreparingStmt - Statement preparation context
Method Detail

isGeneratedAlways

public boolean isGeneratedAlways(RelOptTable table,
                                 int iColumn)
Description copied from interface: DefaultValueFactory
Whether a column is always generated. If a column is always generated, then non-generated values cannot be inserted into the column.

Specified by:
isGeneratedAlways in interface DefaultValueFactory

newColumnDefaultValue

public RexNode newColumnDefaultValue(RelOptTable table,
                                     int iColumn)
Description copied from interface: DefaultValueFactory
Creates an expression which evaluates to the default value for a particular column.

Specified by:
newColumnDefaultValue in interface DefaultValueFactory
Parameters:
table - the table containing the column
iColumn - the 0-based offset of the column in the table
Returns:
default value expression

newAttributeInitializer

public RexNode newAttributeInitializer(RelDataType type,
                                       SqlFunction constructor,
                                       int iAttribute,
                                       RexNode[] constructorArgs)
Description copied from interface: DefaultValueFactory
Creates an expression which evaluates to the initializer expression for a particular attribute of a structured type.

Specified by:
newAttributeInitializer in interface DefaultValueFactory
Parameters:
type - the structured type
constructor - the constructor invoked to initialize the type
iAttribute - the 0-based offset of the attribute in the type
constructorArgs - arguments passed to the constructor invocation
Returns:
default value expression

convertConstructorAssignment

private RexNode convertConstructorAssignment(FarragoUserDefinedRoutine constructor,
                                             FemSqltypeAttribute attribute,
                                             RexNode[] constructorArgs)

convertExpression

private RexNode convertExpression(CwmExpression cwmExp)
Converts an expression definition from the repository into RexNode format.

Parameters:
cwmExp - Repository object representing an expression
Returns:
Rex expression

sequenceValue

private RexNode sequenceValue(FemSequenceGenerator sequence)

initializeEntry

public void initializeEntry(Object key,
                            FarragoObjectCache.UninitializedEntry entry)
Description copied from interface: FarragoObjectCache.CachedObjectFactory
Initializes a cache entry.

Specified by:
initializeEntry in interface FarragoObjectCache.CachedObjectFactory
Parameters:
key - key of the object to be constructed
entry - to initialize by calling its FarragoObjectCache.UninitializedEntry.initialize(java.lang.Object, long, boolean) method; failing to call initialize will lead to a subsequent assertion (unless an exception is thrown to indicate initialization failure)

isStale

public boolean isStale(Object value)
Description copied from interface: FarragoObjectCache.CachedObjectFactory
Tests a cached object for staleness.

Specified by:
isStale in interface FarragoObjectCache.CachedObjectFactory
Returns:
true if object is stale, meaning it must not be returned from a pin call, and should be discarded from the cache when detected