private class SchemaDictionary.Scope
extends java.lang.Object
Each scope contains the following three global namespaces:
findNode(com.goldencode.p2j.schema.EntityName, boolean)
method for search
implementation details.Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Integer,Namespace> |
globals
Global namespaces indexed by entity type (database, table, field)
|
private int |
id
Unique identifier for this scope.
|
private boolean |
internal
Marks this scope as an internal procedure, function or trigger.
|
private java.util.Set<NameNode> |
preferredNodes
Set of preferred nodes.
|
private java.util.Set<NameNode> |
promoted
Stores the list of name nodes that have been promoted
|
private NameNode |
weak
A weak reference that is associated with this scope.
|
Constructor and Description |
---|
Scope(int id,
boolean internal)
Default constructor which initializes the database, table, and field
level global namespaces.
|
Scope(SchemaDictionary.Scope other)
Copy constructor which makes a new instance with the same data
as the given instance.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
addNode(NameNode node,
int type,
boolean exclude)
Add a name node to the appropriate global namespace, determined by
type . |
(package private) void |
addOrReplaceNode(NameNode node,
int type,
boolean exclude,
boolean qualifiedFind)
Add a new name node or replace any existing name node (of the same
name) in the appropriate global namespace, determined by
type . |
(package private) boolean |
containsNode(NameNode node,
int type)
Indicate whether the global namespace indicated by
type
within this scope contains a reference to node . |
(package private) void |
dump(java.io.PrintStream stream)
Debug method to dump the contents of all global namespaces managed
by this scope object to a stream.
|
private void |
dumpNamespace(java.io.PrintStream stream,
Namespace namespace)
Debug method to dump the contents of the specified namespace to a
stream.
|
protected NameNode |
findDatabaseNode(Namespace namespace,
java.lang.String name)
Find the name node, if any, corresponding with the database named or
aliased by
name . |
protected NameNode |
findFieldNode(Namespace namespace,
java.lang.String name,
java.util.Set<NameNode> preferred)
Find the name node, if any, for the field associated with
name . |
(package private) NameNode |
findNode(EntityName name,
boolean exact)
Find the name node entry, if any, associated with the specified
entity name.
|
protected NameNode |
findRecordNode(Namespace namespace,
java.lang.String name,
boolean exact)
Find a matching node for a table-like record entity.
|
(package private) Namespace |
getNamespace(int type)
Get the global namespace associated with the specified
EntityName type. |
(package private) NameNode |
getWeakReference()
Obtains the buffer that associated with a weak reference, which
is a block defined by a
FOR statement,
DO PRESELECT statement or a
REPEAT PRESELECT statement. |
(package private) boolean |
isInternal()
Reports if this instance is marked as an internal procedure,
user-defined function or trigger.
|
(package private) boolean |
isWeak()
Reports if this instance is marked as a weak scope.
|
private void |
noLooseEnds(java.util.List<NameNode> nodes)
Given a list of name nodes that have been removed from their global namespace, sever all
of their connections with private namespaces and remove their associated ASTs from the
larger tree.
|
(package private) void |
removeAllNodes(java.util.Set<NameNode> except,
int type)
Remove all name nodes of the given type from all namespaces in which they reside, and
purge their descendants from all namespaces and the corresponding AST branches from
their ASTs.
|
(package private) void |
setWeakReference(NameNode weak)
Sets a node as the weak reference associated with a block created
created by a
FOR statement, DO PRESELECT
statement or a REPEAT PRESELECT statement. |
private java.util.Set<NameNode> promoted
private int id
private boolean internal
private NameNode weak
private java.util.Map<java.lang.Integer,Namespace> globals
private java.util.Set<NameNode> preferredNodes
Scope(int id, boolean internal)
id
- Unique identifier for this scope.internal
- true
to mark this scope as one which is an
internal procedure, user-defined function or trigger.
false
for any other case including external
procedures and inner blocks.Scope(SchemaDictionary.Scope other)
other
- The instance from which to copy.protected NameNode findDatabaseNode(Namespace namespace, java.lang.String name) throws AmbiguousSchemaNameException
name
. name
is assumed to be an
alias for a logical database name. A lookup is done in the aliases
map maintained at the SchemaDictionary
level. If the
lookup returns a name, the alias is replaced with this name. Logical
database names are artificially aliases to themselves, so this
substitution is always safe.namespace
- Namespace in which to search for this database name node.name
- Logical name or alias for a database. May not be
abbreviated.null
if not found.AmbiguousSchemaNameException
- if name
matches more than one entry in the
dictionary.protected NameNode findRecordNode(Namespace namespace, java.lang.String name, boolean exact) throws AmbiguousSchemaNameException
null
is always returned, since no record entries
will be present.
namespace
- Namespace in which to search for this field name node.name
- A record name which may be abbreviated if it represents a
regular table, but may not be abbreviated if it represents
a buffer, temp table, or work table.exact
- Overrides the abbreviation rule for a regular table. If
false
, a regular table name may be abbreviated,
as normal; if true
, it can not.null
if not found.AmbiguousSchemaNameException
- if name
matches more than one entry in the
dictionary.protected NameNode findFieldNode(Namespace namespace, java.lang.String name, java.util.Set<NameNode> preferred) throws AmbiguousSchemaNameException
name
.namespace
- Namespace in which to search for this field name node.name
- Name of a field. May be abbreviated.preferred
- A set of priority nodes used to disambiguate abbreviated fields. This set is
populated with the fields for the tables which have weak references.null
if not found.AmbiguousSchemaNameException
- if name
matches more than one entry in the
dictionary.boolean isInternal()
true
if this is an internal scope.boolean isWeak()
true
if this is a weak scope.NameNode getWeakReference()
FOR
statement,
DO PRESELECT
statement or a
REPEAT PRESELECT
statement.void setWeakReference(NameNode weak)
FOR
statement, DO PRESELECT
statement or a REPEAT PRESELECT
statement.weak
- Buffer node.boolean containsNode(NameNode node, int type)
type
within this scope contains a reference to node
.node
- Name node to check.type
- EntityName
constant indicating whether
node
represents a DATABASE
,
TABLE
, or FIELD
.true
if the node already exists in this scope,
else false
.void addNode(NameNode node, int type, boolean exclude)
type
.node
- Node to be added to a global namespace of this scope.type
- EntityName
constant indicating whether
node
represents a DATABASE
,
TABLE
, or FIELD
.exclude
- true
to mark this node as one that can be
optionally excluded from an iterator.void addOrReplaceNode(NameNode node, int type, boolean exclude, boolean qualifiedFind)
type
.node
- Node to be added to or replaced in a global namespace of
this scope.type
- EntityName
constant indicating whether
node
represents a DATABASE
,
TABLE
, or FIELD
.exclude
- true
to mark this node as one that can be
optionally excluded from an iterator.qualifiedFind
- true
to match only on a qualified node name before replacing an
existing node; else just use the unqualified name.void removeAllNodes(java.util.Set<NameNode> except, int type)
except
- Set of name nodes to keep.type
- Entity type of the nodes to be removed.NameNode findNode(EntityName name, boolean exact) throws AmbiguousSchemaNameException
null
is returned. When all parts of the name have
been looked up in the appropriate namespace, the search is complete,
and the last found name node is returned.
The lookup logic for each name part follows different rules,
depending upon whether that part represents a database qualifier,
record qualifier, or field qualifier. This function is delegated to
the findXXXXNode
methods listed below.
name
- Entity name for which to search.exact
- true
to require an exact match;
false
to allow an exact or abbreviated name to
match.null
if name
could not be
matched against any entry in this scope.AmbiguousSchemaNameException
- if name
matches more than one entry in this
scope, based upon the lookup rules applied.findDatabaseNode(com.goldencode.p2j.schema.Namespace, java.lang.String)
,
findRecordNode(com.goldencode.p2j.schema.Namespace, java.lang.String, boolean)
,
findFieldNode(com.goldencode.p2j.schema.Namespace, java.lang.String, java.util.Set<com.goldencode.p2j.schema.NameNode>)
Namespace getNamespace(int type)
EntityName
type.type
- EntityName
constant indicating whether
to return the global DATABASE
,
TABLE
, or FIELD
namespace.void dump(java.io.PrintStream stream)
stream
- Destination stream.private void noLooseEnds(java.util.List<NameNode> nodes)
nodes
- Nodes to be purged.private void dumpNamespace(java.io.PrintStream stream, Namespace namespace)
stream
- Destination stream.namespace
- Target namespace.