net.sf.farrago.session
Interface FarragoSessionDdlValidator

All Superinterfaces:
ClosableAllocation, FarragoAllocation
All Known Implementing Classes:
DdlValidator

public interface FarragoSessionDdlValidator
extends FarragoAllocation

FarragoSessionDdlValidator represents an object capable of validating a DDL statement.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/session/FarragoSessionDdlValidator.java#33 $
Author:
John V. Sichi

Method Summary
<T extends CwmModelElement>
CwmDependency
createDependency(CwmNamespace client, Collection<T> suppliers)
          Creates a new dependency.
 void defineDropRule(RefAssociation refAssoc, FarragoSessionDdlDropRule dropRule)
          Adds a FarragoSessionDdlDropRule.
 void deleteObject(RefObject obj)
          Deletes the given object and cascades deletion as necessary to subordinate objects.
 void discardDataWrapper(CwmModelElement wrapper)
          Discards a data wrapper or server from the shared cache (called when it is dropped).
 void executeStorage()
          Executes storage management commands for any model elements encountered during validation.
 void fixupView(FemLocalView view, FarragoSessionAnalyzedSql analyzedSql)
          Modifies the analyzed SQL for a view definition, to take into account any system columns which a personality may need to have in the view.
 FarragoDataWrapperCache getDataWrapperCache()
           
 Set<CwmModelElement> getDependencies(CwmModelElement rootElement)
          Returns immediate dependencies of an of element.
 FennelDbHandle getFennelDbHandle()
           
 FarragoSessionIndexMap getIndexMap()
           
 FarragoSession getInvokingSession()
           
 FarragoSessionParser getParser()
           
 SqlParserPos getParserOffset(RefObject obj)
          Retrieves the parser offset for the body of a given object.
 String getParserPosString(RefObject obj)
          Finds the parse position for an object affected by DDL.
 FarragoRepos getRepos()
           
 SqlNode getSqlDefinition(RefObject obj)
          Retrieves an SQL definition previously associated with a catalog object via setSqlDefinition(javax.jmi.reflect.RefObject, org.eigenbase.sql.SqlNode).
 FarragoSessionStmtValidator getStmtValidator()
           
 FarragoTypeFactory getTypeFactory()
           
 boolean isCreatedObject(RefObject refObject)
          Determines whether a catalog object is being created by this DDL statement.
 boolean isDeletedObject(RefObject refObject)
          Determines whether a catalog object is being deleted by this DDL statement.
 boolean isDropRestrict()
           
 EigenbaseException newPositionalError(RefObject refObj, SqlValidatorException ex)
          Wraps a validation error with position information.
 FarragoSession newReentrantSession()
          Creates a new reentrant session; this is required during validation of some DDL commands (e.g.
 String obtainTimestamp()
          Obtains the single consistent timestamp for this DDL transaction.
 void releaseReentrantSession(FarragoSession session)
          Releases a FarragoSession acquired with newReentrantSession().
 void setCreatedSchemaContext(FemLocalSchema schema)
          Sets the context for a compound CREATE SCHEMA statement to be used by all object definitions in the new schema.
 String setParserOffset(RefObject obj, SqlParserPos pos, String body)
          Sets the parser offset for the body of a given object.
 void setRevalidationResult(CwmModelElement element, EigenbaseException ex)
          Called after revalidation (validation of dependencies during a CREATE OR REPLACE) is successful (ex is null), or upon failure (ex is not null).
 void setSchemaObjectName(CwmModelElement schemaElement, SqlIdentifier qualifiedName)
          Sets the name of a new object being defined, and adds the object to the correct schema.
 void setSqlDefinition(RefObject obj, SqlNode sqlNode)
          Associates an SQL definition with a catalog object.
 void validate(FarragoSessionDdlStmt ddlStmt)
          Validates all scheduled operations.
 void validateUniqueNames(CwmModelElement container, Collection<? extends CwmModelElement> collection, boolean includeType)
          Determines whether all of the objects in a collection have distinct names, throwing an appropriate exception if not.
 void validateViewColumnList(Collection<?> collection)
          validate the names provided in a VIEW's explicit column list.
 
Methods inherited from interface org.eigenbase.util.ClosableAllocation
closeAllocation
 

Method Detail

getStmtValidator

FarragoSessionStmtValidator getStmtValidator()
Returns:
generic stmt validator

getRepos

FarragoRepos getRepos()
Returns:
repos storing object definitions being validated

getFennelDbHandle

FennelDbHandle getFennelDbHandle()
Returns:
Handle to Fennel database accessed by this stmt

getTypeFactory

FarragoTypeFactory getTypeFactory()
Returns:
type factory to be used for any type-checking during validation

getIndexMap

FarragoSessionIndexMap getIndexMap()
Returns:
the FarragoSessionIndexMap to use for managing index storage

getDataWrapperCache

FarragoDataWrapperCache getDataWrapperCache()
Returns:
cache for loaded data wrappers

getInvokingSession

FarragoSession getInvokingSession()
Returns:
the FarragoSession which invoked this DDL

getParser

FarragoSessionParser getParser()
Returns:
the parser whose statement is being validated

isDropRestrict

boolean isDropRestrict()
Returns:
is a DROP RESTRICT being executed?

newReentrantSession

FarragoSession newReentrantSession()
Creates a new reentrant session; this is required during validation of some DDL commands (e.g. view creation) for preparation or execution of internal SQL statements.

Returns:
a FarragoSession to use for reentrant SQL; when done, this session must be released by calling releaseReentrantSession

releaseReentrantSession

void releaseReentrantSession(FarragoSession session)
Releases a FarragoSession acquired with newReentrantSession().

Parameters:
session - the session to release

isDeletedObject

boolean isDeletedObject(RefObject refObject)
Determines whether a catalog object is being deleted by this DDL statement.

Parameters:
refObject - object in question
Returns:
true if refObject is being deleted

isCreatedObject

boolean isCreatedObject(RefObject refObject)
Determines whether a catalog object is being created by this DDL statement.

Parameters:
refObject - object in question
Returns:
true if refObject is being created

getParserPosString

String getParserPosString(RefObject obj)
Finds the parse position for an object affected by DDL. Not all objects have parse positions (e.g. when a table is dropped, referencing views are implicitly affected).

Parameters:
obj - the affected object
Returns:
the parse position string associated with the given object, or null if the object was not encountered by parsing

setParserOffset

String setParserOffset(RefObject obj,
                       SqlParserPos pos,
                       String body)
Sets the parser offset for the body of a given object.

If the body text has preceding whitespace, trims the whitespace and advances the position by the number of whitespace characters removed. Returns the trimmed body.

Parameters:
obj - object being defined
pos - parser offset
body - text of body
Returns:
body text with preceding whitespace removed

getParserOffset

SqlParserPos getParserOffset(RefObject obj)
Retrieves the parser offset for the body of a given object.

Parameters:
obj - object to look up
Returns:
parser offset, or null if none recorded

setSqlDefinition

void setSqlDefinition(RefObject obj,
                      SqlNode sqlNode)
Associates an SQL definition with a catalog object. This is called from the parser; later, this information is retrieved during validation via getSqlDefinition(javax.jmi.reflect.RefObject).

Parameters:
obj - object being defined
sqlNode - SQL definition

getSqlDefinition

SqlNode getSqlDefinition(RefObject obj)
Retrieves an SQL definition previously associated with a catalog object via setSqlDefinition(javax.jmi.reflect.RefObject, org.eigenbase.sql.SqlNode). As a side effect, also restores parser context for this object if available.

Parameters:
obj - object being validated
Returns:
SQL definition

setSchemaObjectName

void setSchemaObjectName(CwmModelElement schemaElement,
                         SqlIdentifier qualifiedName)
Sets the name of a new object being defined, and adds the object to the correct schema.

Parameters:
schemaElement - the object being named
qualifiedName - the (possibly) qualified name of the object

executeStorage

void executeStorage()
Executes storage management commands for any model elements encountered during validation.


validate

void validate(FarragoSessionDdlStmt ddlStmt)
Validates all scheduled operations. Validation may cause other objects to be changed, so the process continues until a fixpoint is reached.

Parameters:
ddlStmt - DDL statement to be validated

validateUniqueNames

void validateUniqueNames(CwmModelElement container,
                         Collection<? extends CwmModelElement> collection,
                         boolean includeType)
Determines whether all of the objects in a collection have distinct names, throwing an appropriate exception if not.

Parameters:
container - namespace object for use in error message
collection - Collection of CwmModelElements representing namespace contents
includeType - if true, include type in name; if false, ignore

validateViewColumnList

void validateViewColumnList(Collection<?> collection)
validate the names provided in a VIEW's explicit column list.

Parameters:
collection - Collection of CwmModelElements representing the explicitly named columns

createDependency

<T extends CwmModelElement> CwmDependency createDependency(CwmNamespace client,
                                                           Collection<T> suppliers)
Creates a new dependency.

Parameters:
client - element which depends on others; we require this to be a CwmNamespace so that it can own the CwmDependency created
suppliers - collection of elements on which client depends
Returns:
new dependency

discardDataWrapper

void discardDataWrapper(CwmModelElement wrapper)
Discards a data wrapper or server from the shared cache (called when it is dropped).

Parameters:
wrapper - definition of wrapper to discard

setCreatedSchemaContext

void setCreatedSchemaContext(FemLocalSchema schema)
Sets the context for a compound CREATE SCHEMA statement to be used by all object definitions in the new schema.

Parameters:
schema - new schema being created

newPositionalError

EigenbaseException newPositionalError(RefObject refObj,
                                      SqlValidatorException ex)
Wraps a validation error with position information.

Parameters:
refObj - object whose definition should be used for position information
ex - exception to be wrapped
Returns:
wrapping exception

deleteObject

void deleteObject(RefObject obj)
Deletes the given object and cascades deletion as necessary to subordinate objects. Implementation of deletion is handled with the highest performance possible given the underlying repository implementation.

Parameters:
obj - object to delete

defineDropRule

void defineDropRule(RefAssociation refAssoc,
                    FarragoSessionDdlDropRule dropRule)
Adds a FarragoSessionDdlDropRule.

Parameters:
refAssoc - model association to which the rule relates
dropRule - rule to add

setRevalidationResult

void setRevalidationResult(CwmModelElement element,
                           EigenbaseException ex)
Called after revalidation (validation of dependencies during a CREATE OR REPLACE) is successful (ex is null), or upon failure (ex is not null).

Parameters:
element - object impacted by replacement
ex - exception to be handled, may be null

getDependencies

Set<CwmModelElement> getDependencies(CwmModelElement rootElement)
Returns immediate dependencies of an of element.

Parameters:
rootElement - Starting element for dependency search
Returns:
Set of CwmModelElement, immediate dependencies of rootElement

fixupView

void fixupView(FemLocalView view,
               FarragoSessionAnalyzedSql analyzedSql)
Modifies the analyzed SQL for a view definition, to take into account any system columns which a personality may need to have in the view. In particular, makes sure that the analyzed SQL returns the same number and type of columns as the view definition.

Parameters:
view - View definition
analyzedSql - Analyzed SQL for the view definition

obtainTimestamp

String obtainTimestamp()
Obtains the single consistent timestamp for this DDL transaction.

Returns:
the timestamp for this DDL transaction