net.sf.farrago.query
Class FarragoStmtValidator

java.lang.Object
  extended by org.eigenbase.util.CompoundClosableAllocation
      extended by net.sf.farrago.util.FarragoCompoundAllocation
          extended by net.sf.farrago.query.FarragoStmtValidator
All Implemented Interfaces:
FarragoSessionStmtValidator, FarragoAllocation, FarragoAllocationOwner, ClosableAllocation, ClosableAllocationOwner

public class FarragoStmtValidator
extends FarragoCompoundAllocation
implements FarragoSessionStmtValidator

FarragoStmtValidator is a default implementation of the FarragoSessionStmtValidator interface.

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

Field Summary
private  FarragoObjectCache codeCache
           
private  FemRole currentRole
           
private  FemUser currentUser
           
private  FarragoDataWrapperCache dataWrapperCache
           
private  FarragoDdlLockManager ddlLockManager
           
private  FennelDbHandle fennelDbHandle
           
private  FarragoSessionIndexMap indexMap
           
private  FarragoSessionParser parser
           
private  SqlParserPos parserPos
           
private  FarragoSessionPrivilegeChecker privilegeChecker
           
private  FarragoRepos repos
           
private  FarragoReposTxnContext reposTxnContext
           
private  FarragoSession session
           
private  FarragoSessionVariables sessionVariables
           
private  FarragoObjectCache sharedDataWrapperCache
           
private  Map<String,CwmSqldataType> sqldataTypeCache
           
private  EigenbaseTimingTracer timingTracer
           
private  FarragoTypeFactory typeFactory
           
private  FarragoWarningQueue warningQueue
           
 
Fields inherited from class org.eigenbase.util.CompoundClosableAllocation
allocations
 
Constructor Summary
FarragoStmtValidator(FarragoRepos repos, FennelDbHandle fennelDbHandle, FarragoSession session, FarragoObjectCache codeCache, FarragoObjectCache sharedDataWrapperCache, FarragoSessionIndexMap indexMap, FarragoDdlLockManager ddlLockManager)
          Creates a new FarragoStmtValidator object.
 
Method Summary
private  void checkValidated(CwmModelElement element)
           
 void closeAllocation()
          Closes this object.
 CwmCatalog findCatalog(String catalogName)
          Looks up a catalog by name, throwing a validation error if not found.
 CwmColumn findColumn(CwmNamedColumnSet namedColumnSet, String columnName)
          Looks up a table's column by name, throwing a validation error if not found.
 FemDataServer findDataServer(SqlIdentifier serverName)
          Looks up a data server by name, throwing a validation error if not found.
 FemDataWrapper findDataWrapper(SqlIdentifier wrapperName, boolean isForeign)
          Looks up a data wrapper by name, throwing a validation error if not found.
 FemJar findJarFromLiteralName(String jarName)
          Looks up a jar from a string literal representing its name (typically from a LIBRARY clause), throwing an exception if not found.
private  RefClass findRefClass(Class<? extends RefObject> clazz)
           
 List<FemRoutine> findRoutineOverloads(SqlIdentifier invocationName, ProcedureType routineType)
          Looks up all matching routine overloads by invocation name.
 FemLocalSchema findSchema(SqlIdentifier schemaName)
          Looks up a schema by name, throwing a validation error if not found.
<T extends CwmModelElement>
T
findSchemaObject(SqlIdentifier qualifiedName, Class<T> clazz)
          Looks up a schema object by name, throwing a validation error if not found.
 CwmSqldataType findSqldataType(SqlIdentifier typeName)
          Looks up a SQL datatype by name, throwing an exception if not found.
private  CwmSqldataType findSqldataTypeImpl(SqlIdentifier typeName)
           
<T extends CwmModelElement>
T
findUnqualifiedObject(SqlIdentifier unqualifiedName, Class<T> clazz)
          Looks up a top-level object (e.g.
private  List<SqlMoniker> getAllObjectNamesByType(Collection<CwmModelElement> collection, Class<? extends CwmModelElement> type)
          Returns a list of all object names of a given type in a collection.
 List<SqlMoniker> getAllSchemaObjectNames(List<String> names)
          Gets schema object names as specified.
 FarragoObjectCache getCodeCache()
           
 FarragoDataWrapperCache getDataWrapperCache()
           
 FarragoDdlLockManager getDdlLockManager()
           
 CwmCatalog getDefaultCatalog()
          Gets the default catalog for unqualified schema names.
 FemDataServer getDefaultLocalDataServer()
           
 FennelDbHandle getFennelDbHandle()
           
 FarragoSessionIndexMap getIndexMap()
           
 FarragoSessionParser getParser()
           
 FarragoSessionPrivilegeChecker getPrivilegeChecker()
           
 FarragoRepos getRepos()
           
 FarragoReposTxnContext getReposTxnContext()
           
 CwmNamedColumnSet getSampleDataset(CwmNamedColumnSet columnSet, String datasetName)
          Looks up a sample dataset for a given schema object, or returns null if none is found.
 FarragoSession getSession()
           
 FarragoSessionVariables getSessionVariables()
           
 FarragoObjectCache getSharedDataWrapperCache()
           
 EigenbaseTimingTracer getTimingTracer()
           
 FarragoTypeFactory getTypeFactory()
           
 FarragoWarningQueue getWarningQueue()
          Gets the warning queue to be used by this validator
private  CwmCatalog lookupCatalog(String catalogName, boolean throwIfNotFound)
           
private  FemLocalSchema lookupSchema(SqlIdentifier schemaName, boolean throwIfNotFound)
           
private  EigenbaseException newPositionalError(SqlValidatorException ex)
           
 void requestPrivilege(CwmModelElement obj, String action)
          Submits a request for access from the current user and/or role to a catalog object via this validator's privilege checker.
<T extends CwmModelElement>
FarragoSessionResolvedObject<T>
resolveSchemaObjectName(String[] names, Class<T> clazz)
          Resolve a (possibly qualified) name of a schema object.
 void setParserPosition(SqlParserPos pos)
          Sets the parser position to use for context in error messages.
 void setReposTxnContext(FarragoReposTxnContext reposTxnContext)
          Sets the repository transaction context associated with this statement.
 void setTimingTracer(EigenbaseTimingTracer timingTracer)
          Sets the timing tracer associated with this statement
 void setWarningQueue(FarragoWarningQueue warningQueue)
          Sets the warning queue to be used by this validator
 void validateDataType(SqlDataTypeSpec dataType)
          Validates a data type expression.
 void validateFeature(org.eigenbase.resgen.ResourceDefinition feature, SqlParserPos context)
          Validates that a particular feature is enabled.
 
Methods inherited from class org.eigenbase.util.CompoundClosableAllocation
addAllocation, forgetAllocation, hasAllocations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eigenbase.util.ClosableAllocationOwner
addAllocation
 

Field Detail

repos

private final FarragoRepos repos

fennelDbHandle

private final FennelDbHandle fennelDbHandle

session

private final FarragoSession session

typeFactory

private final FarragoTypeFactory typeFactory

sessionVariables

private final FarragoSessionVariables sessionVariables

codeCache

private final FarragoObjectCache codeCache

dataWrapperCache

private final FarragoDataWrapperCache dataWrapperCache

indexMap

private final FarragoSessionIndexMap indexMap

sharedDataWrapperCache

private final FarragoObjectCache sharedDataWrapperCache

parser

private final FarragoSessionParser parser

privilegeChecker

private final FarragoSessionPrivilegeChecker privilegeChecker

ddlLockManager

private final FarragoDdlLockManager ddlLockManager

parserPos

private SqlParserPos parserPos

timingTracer

private EigenbaseTimingTracer timingTracer

reposTxnContext

private FarragoReposTxnContext reposTxnContext

warningQueue

private FarragoWarningQueue warningQueue

currentUser

private FemUser currentUser

currentRole

private FemRole currentRole

sqldataTypeCache

private Map<String,CwmSqldataType> sqldataTypeCache
Constructor Detail

FarragoStmtValidator

public FarragoStmtValidator(FarragoRepos repos,
                            FennelDbHandle fennelDbHandle,
                            FarragoSession session,
                            FarragoObjectCache codeCache,
                            FarragoObjectCache sharedDataWrapperCache,
                            FarragoSessionIndexMap indexMap,
                            FarragoDdlLockManager ddlLockManager)
Creates a new FarragoStmtValidator object.

Parameters:
repos - repos to use for object definitions
fennelDbHandle - handle to Fennel database to access
session - invoking session
codeCache - FarragoObjectCache to use for caching code snippets needed during preparation
sharedDataWrapperCache - FarragoObjectCache to use for caching FarragoMedDataWrapper instances
ddlLockManager - FarragoDdlLockManager to use for protecting catalog objects in use from modification
indexMap - FarragoSessionIndexMap to use for index access
Method Detail

getParser

public FarragoSessionParser getParser()
Specified by:
getParser in interface FarragoSessionStmtValidator
Returns:
the parser parsing the statement being validated

getRepos

public FarragoRepos getRepos()
Specified by:
getRepos in interface FarragoSessionStmtValidator
Returns:
repos to use for validating object references

getFennelDbHandle

public FennelDbHandle getFennelDbHandle()
Specified by:
getFennelDbHandle in interface FarragoSessionStmtValidator
Returns:
FennelDbHandle storing local data to be accessed by validated stmt

getSession

public FarragoSession getSession()
Specified by:
getSession in interface FarragoSessionStmtValidator
Returns:
session invoking stmt to be validated

getTypeFactory

public FarragoTypeFactory getTypeFactory()
Specified by:
getTypeFactory in interface FarragoSessionStmtValidator
Returns:
type factory to use for validation

getSessionVariables

public FarragoSessionVariables getSessionVariables()
Specified by:
getSessionVariables in interface FarragoSessionStmtValidator
Returns:
connection defaults to use for validation

getCodeCache

public FarragoObjectCache getCodeCache()
Specified by:
getCodeCache in interface FarragoSessionStmtValidator
Returns:
cache to use for code lookups during validation

getDataWrapperCache

public FarragoDataWrapperCache getDataWrapperCache()
Specified by:
getDataWrapperCache in interface FarragoSessionStmtValidator
Returns:
private cache to use for validating references to data wrappers

getIndexMap

public FarragoSessionIndexMap getIndexMap()
Specified by:
getIndexMap in interface FarragoSessionStmtValidator
Returns:
index map to use for validation

getSharedDataWrapperCache

public FarragoObjectCache getSharedDataWrapperCache()
Specified by:
getSharedDataWrapperCache in interface FarragoSessionStmtValidator
Returns:
shared cache to use for validating references to data wrappers

getPrivilegeChecker

public FarragoSessionPrivilegeChecker getPrivilegeChecker()
Specified by:
getPrivilegeChecker in interface FarragoSessionStmtValidator
Returns:
the privilege checker for this validator

getDdlLockManager

public FarragoDdlLockManager getDdlLockManager()
Specified by:
getDdlLockManager in interface FarragoSessionStmtValidator
Returns:
the DDL lock manager for this validator

getWarningQueue

public FarragoWarningQueue getWarningQueue()
Description copied from interface: FarragoSessionStmtValidator
Gets the warning queue to be used by this validator

Specified by:
getWarningQueue in interface FarragoSessionStmtValidator
Returns:
warning queue

setWarningQueue

public void setWarningQueue(FarragoWarningQueue warningQueue)
Description copied from interface: FarragoSessionStmtValidator
Sets the warning queue to be used by this validator

Specified by:
setWarningQueue in interface FarragoSessionStmtValidator
Parameters:
warningQueue - target queue to use

requestPrivilege

public void requestPrivilege(CwmModelElement obj,
                             String action)
Description copied from interface: FarragoSessionStmtValidator
Submits a request for access from the current user and/or role to a catalog object via this validator's privilege checker. Actual checking of the request may be deferred.

Specified by:
requestPrivilege in interface FarragoSessionStmtValidator
Parameters:
obj - object to be accessed
action - the action to be performed on obj (see PrivilegedActionEnum for base set)

findColumn

public CwmColumn findColumn(CwmNamedColumnSet namedColumnSet,
                            String columnName)
Description copied from interface: FarragoSessionStmtValidator
Looks up a table's column by name, throwing a validation error if not found.

Specified by:
findColumn in interface FarragoSessionStmtValidator
Parameters:
namedColumnSet - the table to search
columnName - name of column to find
Returns:
column found

findCatalog

public CwmCatalog findCatalog(String catalogName)
Description copied from interface: FarragoSessionStmtValidator
Looks up a catalog by name, throwing a validation error if not found.

Specified by:
findCatalog in interface FarragoSessionStmtValidator
Parameters:
catalogName - name of catalog to look up
Returns:
catalog found

getAllSchemaObjectNames

public List<SqlMoniker> getAllSchemaObjectNames(List<String> names)
Description copied from interface: FarragoSessionStmtValidator
Gets schema object names as specified. They can be schema or table object. If names array contain 1 element, return all schema names and all table names under the default schema (if that is set) If names array contain 2 elements, treat 1st element as schema name and return all table names in this schema

Specified by:
getAllSchemaObjectNames in interface FarragoSessionStmtValidator
Parameters:
names - the array contains either 2 elements representing a partially qualified object name in the format of 'schema.object', or an unqualified name in the format of 'object'
Returns:
the list of all SqlMoniker object (schema and table) names under the above criteria

getAllObjectNamesByType

private List<SqlMoniker> getAllObjectNamesByType(Collection<CwmModelElement> collection,
                                                 Class<? extends CwmModelElement> type)
Returns a list of all object names of a given type in a collection.

Parameters:
collection - Collection
type - Type of object to return
Returns:
list of object names

lookupCatalog

private CwmCatalog lookupCatalog(String catalogName,
                                 boolean throwIfNotFound)

getDefaultCatalog

public CwmCatalog getDefaultCatalog()
Description copied from interface: FarragoSessionStmtValidator
Gets the default catalog for unqualified schema names.

Specified by:
getDefaultCatalog in interface FarragoSessionStmtValidator
Returns:
default catalog

findSchema

public FemLocalSchema findSchema(SqlIdentifier schemaName)
Description copied from interface: FarragoSessionStmtValidator
Looks up a schema by name, throwing a validation error if not found.

Specified by:
findSchema in interface FarragoSessionStmtValidator
Parameters:
schemaName - name of schema to look up
Returns:
schema found

lookupSchema

private FemLocalSchema lookupSchema(SqlIdentifier schemaName,
                                    boolean throwIfNotFound)

findDataWrapper

public FemDataWrapper findDataWrapper(SqlIdentifier wrapperName,
                                      boolean isForeign)
Description copied from interface: FarragoSessionStmtValidator
Looks up a data wrapper by name, throwing a validation error if not found.

Specified by:
findDataWrapper in interface FarragoSessionStmtValidator
Parameters:
wrapperName - name of wrapper to look up (must be simple)
isForeign - true for foreign data wrapper; false for local data wrapper
Returns:
wrapper found

findDataServer

public FemDataServer findDataServer(SqlIdentifier serverName)
Description copied from interface: FarragoSessionStmtValidator
Looks up a data server by name, throwing a validation error if not found.

Specified by:
findDataServer in interface FarragoSessionStmtValidator
Parameters:
serverName - name of server to look up (must be simple)
Returns:
server found

getDefaultLocalDataServer

public FemDataServer getDefaultLocalDataServer()
Specified by:
getDefaultLocalDataServer in interface FarragoSessionStmtValidator
Returns:
default data server to use if none specified in local table definition

findSchemaObject

public <T extends CwmModelElement> T findSchemaObject(SqlIdentifier qualifiedName,
                                                      Class<T> clazz)
Description copied from interface: FarragoSessionStmtValidator
Looks up a schema object by name, throwing a validation error if not found.

Specified by:
findSchemaObject in interface FarragoSessionStmtValidator
Parameters:
qualifiedName - name of object to look up
clazz - expected class of object; if the object exists with a different class, it will be treated as if it did not exist
Returns:
schema object found

findRefClass

private RefClass findRefClass(Class<? extends RefObject> clazz)

findUnqualifiedObject

public <T extends CwmModelElement> T findUnqualifiedObject(SqlIdentifier unqualifiedName,
                                                           Class<T> clazz)
Description copied from interface: FarragoSessionStmtValidator
Looks up a top-level object (e.g. a catalog) by name, throwing a validation error if not found.

Specified by:
findUnqualifiedObject in interface FarragoSessionStmtValidator
Parameters:
unqualifiedName - SqlIdentifier which returns true for isSimple()
clazz - class of object to find
Returns:
object found

findRoutineOverloads

public List<FemRoutine> findRoutineOverloads(SqlIdentifier invocationName,
                                             ProcedureType routineType)
Description copied from interface: FarragoSessionStmtValidator
Looks up all matching routine overloads by invocation name.

Specified by:
findRoutineOverloads in interface FarragoSessionStmtValidator
Parameters:
invocationName - invocation name of routine to look up
routineType - type of routine to look up, or null for any type
Returns:
list of matching FemRoutine objects (empty if no matches)

findSqldataType

public CwmSqldataType findSqldataType(SqlIdentifier typeName)
Description copied from interface: FarragoSessionStmtValidator
Looks up a SQL datatype by name, throwing an exception if not found.

Specified by:
findSqldataType in interface FarragoSessionStmtValidator
Parameters:
typeName - name of type to find
Returns:
type definition

findSqldataTypeImpl

private CwmSqldataType findSqldataTypeImpl(SqlIdentifier typeName)

findJarFromLiteralName

public FemJar findJarFromLiteralName(String jarName)
Description copied from interface: FarragoSessionStmtValidator
Looks up a jar from a string literal representing its name (typically from a LIBRARY clause), throwing an exception if not found.

Specified by:
findJarFromLiteralName in interface FarragoSessionStmtValidator
Parameters:
jarName - string literal representing name of jar
Returns:
jar found

checkValidated

private void checkValidated(CwmModelElement element)

resolveSchemaObjectName

public <T extends CwmModelElement> FarragoSessionResolvedObject<T> resolveSchemaObjectName(String[] names,
                                                                                           Class<T> clazz)
Description copied from interface: FarragoSessionStmtValidator
Resolve a (possibly qualified) name of a schema object.

Specified by:
resolveSchemaObjectName in interface FarragoSessionStmtValidator
Parameters:
names - array of 1 or more name components, from most general to most specific
clazz - type of object to resolve
Returns:
FarragoSessionResolvedObject, or null if object definitely doesn't exist

getSampleDataset

public CwmNamedColumnSet getSampleDataset(CwmNamedColumnSet columnSet,
                                          String datasetName)
Description copied from interface: FarragoSessionStmtValidator
Looks up a sample dataset for a given schema object, or returns null if none is found.

Specified by:
getSampleDataset in interface FarragoSessionStmtValidator
Parameters:
columnSet - Schema object
datasetName - Name of dataset, not null
Returns:
Sample dataset, or null if not found

setParserPosition

public void setParserPosition(SqlParserPos pos)
Description copied from interface: FarragoSessionStmtValidator
Sets the parser position to use for context in error messages.

Specified by:
setParserPosition in interface FarragoSessionStmtValidator
Parameters:
pos - new position to set, or null to clear

newPositionalError

private EigenbaseException newPositionalError(SqlValidatorException ex)

validateFeature

public void validateFeature(org.eigenbase.resgen.ResourceDefinition feature,
                            SqlParserPos context)
Description copied from interface: FarragoSessionStmtValidator
Validates that a particular feature is enabled.

Specified by:
validateFeature in interface FarragoSessionStmtValidator
Parameters:
feature - feature being used, represented as a resource definition from EigenbaseResource
context - parser position context for error reporting, or null if none available

setTimingTracer

public void setTimingTracer(EigenbaseTimingTracer timingTracer)
Description copied from interface: FarragoSessionStmtValidator
Sets the timing tracer associated with this statement

Specified by:
setTimingTracer in interface FarragoSessionStmtValidator
Parameters:
timingTracer - tracer to use

getTimingTracer

public EigenbaseTimingTracer getTimingTracer()
Specified by:
getTimingTracer in interface FarragoSessionStmtValidator
Returns:
the timing tracer associated with this statement

setReposTxnContext

public void setReposTxnContext(FarragoReposTxnContext reposTxnContext)
Description copied from interface: FarragoSessionStmtValidator
Sets the repository transaction context associated with this statement.

Specified by:
setReposTxnContext in interface FarragoSessionStmtValidator
Parameters:
reposTxnContext - repos txn context to use

getReposTxnContext

public FarragoReposTxnContext getReposTxnContext()
Specified by:
getReposTxnContext in interface FarragoSessionStmtValidator
Returns:
the repository transaction context associated with this statement.

validateDataType

public void validateDataType(SqlDataTypeSpec dataType)
                      throws SqlValidatorException
Description copied from interface: FarragoSessionStmtValidator
Validates a data type expression.

Specified by:
validateDataType in interface FarragoSessionStmtValidator
Throws:
SqlValidatorException

closeAllocation

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

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