|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.util.CompoundClosableAllocation net.sf.farrago.util.FarragoCompoundAllocation net.sf.farrago.ddl.DdlValidator
public class DdlValidator
DdlValidator validates the process of applying a DDL statement to the catalog. By implementing MDRPreChangeListener, it is able to automatically collect references to all objects modified by the statement. (MDRChangeListener isn't suitable since it's asynchronous.)
Generic validation support is implemented in this class, but object-specific rules should be implemented in handler classes for the appropriate catalog objects.
NOTE: all validation activity must take place in the same thread in which DdlValidator's constructor is called.
Nested Class Summary | |
---|---|
private static class |
DdlValidator.DeferredException
DeferredException allows an exception's creation to be deferred. |
private class |
DdlValidator.RefObjectPositionComparator
RefObjectPositionComparator compares RefObjects based on their position within the owning DdlValidator's parserContextMap . |
private static class |
DdlValidator.SchedulingDetail
|
private static class |
DdlValidator.ValidatedOp
|
Field Summary | |
---|---|
protected List<DdlHandler> |
actionHandlers
List of handlers to be invoked. |
private Thread |
activeThread
Thread binding to prevent cross-talk. |
private FemAuthId |
currentUserAuthId
|
protected FarragoSessionDdlStmt |
ddlStmt
DDL statement being validated. |
private Set<RefObject> |
deleteQueue
Set of objects which a DROP CASCADE has encountered but not yet processed. |
protected ReflectiveVisitDispatcher<DdlHandler,CwmModelElement> |
dispatcher
|
private MultiMap<Class<?>,FarragoSessionDdlDropRule> |
dropRules
Map (from RefAssociation.Class to FarragoSessionDdlDropRule) of associations for which special handling is required during DROP. |
private DdlValidator.DeferredException |
enqueuedValidationExcn
Queue of excns detected during plannedChange. |
private Map<Object,SqlParserPos> |
parserContextMap
Map from catalog object to SqlParserPos for beginning of definition. |
private Map<RefObject,SqlParserPos> |
parserOffsetMap
Map from catalog object to SqlParserPos for offset of body. |
private CwmModelElement |
replacementTarget
Object to be replaced if CREATE OR REPLACE |
private Set<CwmModelElement> |
revalidateQueue
Set of objects to be revalidated (CREATE OR REPLACE) |
private Map<String,DdlValidator.SchedulingDetail> |
schedulingMap
Map containing scheduled validation actions. |
private Map<RefObject,SqlNode> |
sqlMap
Map from catalog object to associated SQL definition (not all objects have these). |
private FarragoSessionStmtValidator |
stmtValidator
|
private FemAuthId |
systemUserAuthId
|
private String |
timestamp
|
private static Logger |
tracer
|
private Map<String,DdlValidator.SchedulingDetail> |
transitMap
Map of objects in transition between schedulingMap and validatedMap. |
private boolean |
usePreviewDelete
|
private Map<RefObject,DdlValidator.ValidatedOp> |
validatedMap
Map of object validations which have already taken place. |
Fields inherited from class org.eigenbase.util.CompoundClosableAllocation |
---|
allocations |
Constructor Summary | |
---|---|
DdlValidator(FarragoSessionStmtValidator stmtValidator)
Creates a new validator. |
Method Summary | ||
---|---|---|
void |
change(MDRChangeEvent event)
|
|
void |
changeCancelled(MDRChangeEvent event)
|
|
private void |
checkInUse(String mofId)
Checks if an object is in use by a running statement. |
|
private void |
checkJmiConstraints(RefObject obj)
|
|
private void |
checkStringLength(AttributeEvent event)
|
|
private void |
checkValidationExcnQueue()
|
|
void |
closeAllocation()
Closes this object. |
|
private boolean |
containsCycle(CwmModelElement rootElement)
Check transitive closure of dependencies of an element for cycles. |
|
|
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 |
deleteReplacementTarget(CwmModelElement newElement)
Delete the existing object of a CREATE OR REPLACE statement, saving its dependencies for later revalidation. |
|
void |
discardDataWrapper(CwmModelElement wrapper)
Discards a data wrapper or server from the shared cache (called when it is dropped). |
|
private void |
enqueueValidationExcn(DdlValidator.DeferredException excn)
|
|
void |
executeStorage()
Executes storage management commands for any model elements encountered during validation. |
|
private CwmModelElement |
findDuplicate(CwmModelElement target)
Searches an element's namespace's owned elements and returns the first duplicate found (by name, type). |
|
private void |
fireDropRule(FarragoSessionDdlDropRule rule,
RefObject droppedEnd,
RefObject otherEnd)
|
|
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()
|
|
private String |
getNameKey(CwmModelElement element,
boolean includeType)
|
|
private SqlIdentifier |
getNewName()
Returns RENAME TO argument of CREATE OR REPLACE. |
|
private DdlValidator.ValidatedOp |
getObjectStatusFromMap(Map<String,DdlValidator.SchedulingDetail> map,
RefObject refObject)
|
|
FarragoSessionParser |
getParser()
|
|
SqlParserPos |
getParserOffset(RefObject obj)
Retrieves the parser offset for the body of a given object. |
|
private SqlParserPos |
getParserPos(RefObject obj)
|
|
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 FarragoSessionDdlValidator.setSqlDefinition(javax.jmi.reflect.RefObject, org.eigenbase.sql.SqlNode) . |
|
FarragoSessionStmtValidator |
getStmtValidator()
|
|
FarragoTypeFactory |
getTypeFactory()
|
|
(package private) void |
handlePostCommit(CwmModelElement modelElement,
String command)
|
|
protected boolean |
invokeHandler(CwmModelElement modelElement,
String action)
|
|
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()
|
|
private boolean |
isNewObject(CwmModelElement modelElement)
Determines whether a catalog object has had its visibility set yet. |
|
boolean |
isReplace()
Tests if DDL statement is CREATE OR REPLACE. |
|
boolean |
isReplacingType(CwmModelElement object)
Tests if DDL statement is CREATE OR REPLACE and the target object (to be replaced) is of the specified type. |
|
private void |
mapParserPosition(RefObject obj)
|
|
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 |
plannedChange(MDRChangeEvent event)
|
|
void |
releaseReentrantSession(FarragoSession session)
Releases a FarragoSession acquired with newReentrantSession(). |
|
private void |
replaceDependencies(CwmModelElement oldElement,
CwmModelElement newElement)
Removes dependency associations on oldElement so that it may be deleted without cascading side effects. |
|
private void |
rollbackDeletions()
|
|
private void |
scheduleDeletion(RefObject obj)
|
|
private void |
scheduleModification(RefObject obj)
|
|
private void |
scheduleRevalidation(Set<CwmModelElement> elements)
|
|
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)
Handle an exception encountered during validation of dependencies of an object replaced via CREATE OR REPLACE (a.k.a. |
|
void |
setSchemaObjectName(CwmModelElement schemaElement,
SqlIdentifier qualifiedName)
Sets the name of a new object being defined, and adds the object to the correct schema. |
|
private void |
setSourceInContext(EigenbaseException e,
String sourceString)
|
|
void |
setSqlDefinition(RefObject obj,
SqlNode sqlNode)
Associates an SQL definition with a catalog object. |
|
private void |
startListening()
|
|
private void |
stopListening()
|
|
private boolean |
testObjectStatus(RefObject refObject,
DdlValidator.ValidatedOp status)
|
|
private void |
updateObjectTimestamp(CwmModelElement element)
|
|
void |
validate(FarragoSessionDdlStmt ddlStmt)
Validates all scheduled operations. |
|
private boolean |
validateAction(CwmModelElement modelElement,
DdlValidator.ValidatedOp action)
|
|
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 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 |
---|
private static final Logger tracer
private final FarragoSessionStmtValidator stmtValidator
private DdlValidator.DeferredException enqueuedValidationExcn
private MultiMap<Class<?>,FarragoSessionDdlDropRule> dropRules
private final Map<Object,SqlParserPos> parserContextMap
private final Map<RefObject,SqlParserPos> parserOffsetMap
private final Map<RefObject,SqlNode> sqlMap
private Map<String,DdlValidator.SchedulingDetail> schedulingMap
private Map<String,DdlValidator.SchedulingDetail> transitMap
private Map<RefObject,DdlValidator.ValidatedOp> validatedMap
private Set<RefObject> deleteQueue
private Thread activeThread
protected FarragoSessionDdlStmt ddlStmt
protected List<DdlHandler> actionHandlers
private CwmModelElement replacementTarget
private Set<CwmModelElement> revalidateQueue
private String timestamp
protected final ReflectiveVisitDispatcher<DdlHandler,CwmModelElement> dispatcher
private FemAuthId systemUserAuthId
private FemAuthId currentUserAuthId
private boolean usePreviewDelete
Constructor Detail |
---|
public DdlValidator(FarragoSessionStmtValidator stmtValidator)
stmtValidator
- generic stmt validatorMethod Detail |
---|
public FarragoSessionStmtValidator getStmtValidator()
getStmtValidator
in interface FarragoSessionDdlValidator
public FarragoRepos getRepos()
getRepos
in interface FarragoSessionDdlValidator
public FennelDbHandle getFennelDbHandle()
getFennelDbHandle
in interface FarragoSessionDdlValidator
public FarragoTypeFactory getTypeFactory()
getTypeFactory
in interface FarragoSessionDdlValidator
public FarragoSessionIndexMap getIndexMap()
getIndexMap
in interface FarragoSessionDdlValidator
public FarragoDataWrapperCache getDataWrapperCache()
getDataWrapperCache
in interface FarragoSessionDdlValidator
public FarragoSession newReentrantSession()
FarragoSessionDdlValidator
newReentrantSession
in interface FarragoSessionDdlValidator
public FarragoSession getInvokingSession()
getInvokingSession
in interface FarragoSessionDdlValidator
public void releaseReentrantSession(FarragoSession session)
FarragoSessionDdlValidator
releaseReentrantSession
in interface FarragoSessionDdlValidator
session
- the session to releasepublic FarragoSessionParser getParser()
getParser
in interface FarragoSessionDdlValidator
public boolean isDeletedObject(RefObject refObject)
FarragoSessionDdlValidator
isDeletedObject
in interface FarragoSessionDdlValidator
refObject
- object in question
public boolean isCreatedObject(RefObject refObject)
FarragoSessionDdlValidator
isCreatedObject
in interface FarragoSessionDdlValidator
refObject
- object in question
private boolean testObjectStatus(RefObject refObject, DdlValidator.ValidatedOp status)
private DdlValidator.ValidatedOp getObjectStatusFromMap(Map<String,DdlValidator.SchedulingDetail> map, RefObject refObject)
public boolean isDropRestrict()
isDropRestrict
in interface FarragoSessionDdlValidator
private boolean isNewObject(CwmModelElement modelElement)
modelElement
- object in question
public String getParserPosString(RefObject obj)
FarragoSessionDdlValidator
getParserPosString
in interface FarragoSessionDdlValidator
obj
- the affected object
private SqlParserPos getParserPos(RefObject obj)
public String setParserOffset(RefObject obj, SqlParserPos pos, String body)
FarragoSessionDdlValidator
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.
setParserOffset
in interface FarragoSessionDdlValidator
obj
- object being definedpos
- parser offsetbody
- text of body
public SqlParserPos getParserOffset(RefObject obj)
FarragoSessionDdlValidator
getParserOffset
in interface FarragoSessionDdlValidator
obj
- object to look up
public void setSqlDefinition(RefObject obj, SqlNode sqlNode)
FarragoSessionDdlValidator
FarragoSessionDdlValidator.getSqlDefinition(javax.jmi.reflect.RefObject)
.
setSqlDefinition
in interface FarragoSessionDdlValidator
obj
- object being definedsqlNode
- SQL definitionpublic SqlNode getSqlDefinition(RefObject obj)
FarragoSessionDdlValidator
FarragoSessionDdlValidator.setSqlDefinition(javax.jmi.reflect.RefObject, org.eigenbase.sql.SqlNode)
. As a side effect, also restores parser
context for this object if available.
getSqlDefinition
in interface FarragoSessionDdlValidator
obj
- object being validated
public void setSchemaObjectName(CwmModelElement schemaElement, SqlIdentifier qualifiedName)
FarragoSessionDdlValidator
setSchemaObjectName
in interface FarragoSessionDdlValidator
schemaElement
- the object being namedqualifiedName
- the (possibly) qualified name of the objectpublic void change(MDRChangeEvent event)
change
in interface MDRChangeListener
public void changeCancelled(MDRChangeEvent event)
changeCancelled
in interface MDRPreChangeListener
public void closeAllocation()
ClosableAllocation
closeAllocation
in interface ClosableAllocation
closeAllocation
in class CompoundClosableAllocation
public boolean isReplace()
private SqlIdentifier getNewName()
public boolean isReplacingType(CwmModelElement object)
object
- Object type to test for
public void deleteReplacementTarget(CwmModelElement newElement)
public void executeStorage()
FarragoSessionDdlValidator
executeStorage
in interface FarragoSessionDdlValidator
private void checkJmiConstraints(RefObject obj)
private void updateObjectTimestamp(CwmModelElement element)
public void plannedChange(MDRChangeEvent event)
plannedChange
in interface MDRPreChangeListener
public void validate(FarragoSessionDdlStmt ddlStmt)
FarragoSessionDdlValidator
validate
in interface FarragoSessionDdlValidator
ddlStmt
- DDL statement to be validatedprivate void setSourceInContext(EigenbaseException e, String sourceString)
public void setRevalidationResult(CwmModelElement element, EigenbaseException ex)
setRevalidationResult
in interface FarragoSessionDdlValidator
element
- Catalog object causing revalidation exceptionex
- Revalidation exceptionpublic void validateUniqueNames(CwmModelElement container, Collection<? extends CwmModelElement> collection, boolean includeType)
FarragoSessionDdlValidator
validateUniqueNames
in interface FarragoSessionDdlValidator
container
- namespace object for use in error messagecollection
- Collection of CwmModelElements representing namespace
contentsincludeType
- if true, include type in name; if false, ignoreprivate String getNameKey(CwmModelElement element, boolean includeType)
public <T extends CwmModelElement> CwmDependency createDependency(CwmNamespace client, Collection<T> suppliers)
FarragoSessionDdlValidator
createDependency
in interface FarragoSessionDdlValidator
client
- element which depends on others; we require this to be a
CwmNamespace
so that it can own the CwmDependency
createdsuppliers
- collection of elements on which client depends
public void discardDataWrapper(CwmModelElement wrapper)
FarragoSessionDdlValidator
discardDataWrapper
in interface FarragoSessionDdlValidator
wrapper
- definition of wrapper to discardpublic void setCreatedSchemaContext(FemLocalSchema schema)
FarragoSessionDdlValidator
setCreatedSchemaContext
in interface FarragoSessionDdlValidator
schema
- new schema being createdpublic EigenbaseException newPositionalError(RefObject refObj, SqlValidatorException ex)
FarragoSessionDdlValidator
newPositionalError
in interface FarragoSessionDdlValidator
refObj
- object whose definition should be used for position
informationex
- exception to be wrapped
public void deleteObject(RefObject obj)
FarragoSessionDdlValidator
deleteObject
in interface FarragoSessionDdlValidator
obj
- object to deletepublic void defineDropRule(RefAssociation refAssoc, FarragoSessionDdlDropRule dropRule)
FarragoSessionDdlValidator
FarragoSessionDdlDropRule
.
defineDropRule
in interface FarragoSessionDdlValidator
refAssoc
- model association to which the rule relatesdropRule
- rule to addprivate void enqueueValidationExcn(DdlValidator.DeferredException excn)
private void checkValidationExcnQueue()
private void fireDropRule(FarragoSessionDdlDropRule rule, RefObject droppedEnd, RefObject otherEnd)
private void mapParserPosition(RefObject obj)
private void rollbackDeletions()
private void scheduleDeletion(RefObject obj)
private void scheduleModification(RefObject obj)
private void checkStringLength(AttributeEvent event)
private void startListening()
private void stopListening()
private boolean validateAction(CwmModelElement modelElement, DdlValidator.ValidatedOp action)
void handlePostCommit(CwmModelElement modelElement, String command)
protected boolean invokeHandler(CwmModelElement modelElement, String action)
private boolean containsCycle(CwmModelElement rootElement)
rootElement
- Starting element for dependency search
private void scheduleRevalidation(Set<CwmModelElement> elements)
public Set<CwmModelElement> getDependencies(CwmModelElement rootElement)
FarragoSessionDdlValidator
getDependencies
in interface FarragoSessionDdlValidator
rootElement
- Starting element for dependency search
public void fixupView(FemLocalView view, FarragoSessionAnalyzedSql analyzedSql)
FarragoSessionDdlValidator
fixupView
in interface FarragoSessionDdlValidator
view
- View definitionanalyzedSql
- Analyzed SQL for the view definitionprivate void replaceDependencies(CwmModelElement oldElement, CwmModelElement newElement)
oldElement
- Element to remove dependencies fromnewElement
- Element to add dependencies toprivate CwmModelElement findDuplicate(CwmModelElement target)
target
- Target of search
public String obtainTimestamp()
FarragoSessionDdlValidator
obtainTimestamp
in interface FarragoSessionDdlValidator
public void validateViewColumnList(Collection<?> collection)
FarragoSessionDdlValidator
validateViewColumnList
in interface FarragoSessionDdlValidator
collection
- Collection of CwmModelElements representing the
explicitly named columnsprivate void checkInUse(String mofId)
mofId
- Object MOFID being dropped
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |