NodeFactoryImplpublic class NodeFactoryImpl extends Object implements NodeFactoryINTERNAL
Purpose: Implements a node factory used by the EJBQLParser
class.
Responsibilities:
- Create EJBQLParseTree instances for EJBQL SELECT-, UPDATE- and DELETE
statements (see methods newSelectStatement, newUpdateStatement and
newDeleteStatement).
- Any new method returns an instance of the appropriate Node
subclass.
- The relationship to the child nodes passed as arguments are
automatically initialized.
- Note, this implementation has a state managing the parse tree context
and a list of parameter names for the current parse tree. This state needs
to be initilized before the same node factory implementation instacne may
be used to create a second parse tree (see methods initContext and
initParameters).
- The implementation automatically adds the list of parameters to the
created parse tree.
- The implementation automatically sets the parse tree context for any
created major node.
|
Fields Summary |
---|
private ParseTreeContext | contextThe parse tree context. | private String | currentIdentificationVariable |
Constructors Summary |
---|
public NodeFactoryImpl(String queryInfo)No-arg Constructor
this.context = new ParseTreeContext(this, queryInfo);
|
Methods Summary |
---|
private java.lang.String | calculateCanonicalName(java.lang.String name)
return (name == null) ? null :
IdentificationVariableDeclNode.calculateCanonicalName(name);
| public java.lang.Object | newAbs(int line, int column, java.lang.Object arg)
AbsNode node = new AbsNode();
node.setLeft((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newAll(int line, int column, java.lang.Object subquery)
AllNode node = new AllNode();
node.setLeft((Node)subquery);
setPosition(node, line, column);
return node;
| public java.lang.Object | newAnd(int line, int column, java.lang.Object left, java.lang.Object right)
AndNode node = new AndNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newAny(int line, int column, java.lang.Object subquery)
AnyNode node = new AnyNode();
node.setLeft((Node)subquery);
setPosition(node, line, column);
return node;
| public java.lang.Object | newAscOrdering(int line, int column, java.lang.Object arg)
OrderByItemNode node = new OrderByItemNode();
SortDirectionNode sortDirection = new SortDirectionNode();
sortDirection.useAscending();
node.setDirection(sortDirection);
node.setOrderByItem((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newAttribute(int line, int column, java.lang.String identifier)
AttributeNode node = new AttributeNode(identifier);
setPosition(node, line, column);
return node;
| public java.lang.Object | newAvg(int line, int column, boolean distinct, java.lang.Object arg)
AvgNode node = new AvgNode();
node.setLeft((Node)arg);
node.setDistinct(distinct);
setPosition(node, line, column);
return node;
| public java.lang.Object | newBetween(int line, int column, boolean not, java.lang.Object arg, java.lang.Object lower, java.lang.Object upper)
BetweenNode node = new BetweenNode();
node.setLeft((Node)arg);
node.setRightForBetween((Node)lower);
node.setRightForAnd((Node)upper);
setPosition(node, line, column);
return not? newNot(line, column, node) : node;
| public java.lang.Object | newBooleanLiteral(int line, int column, java.lang.Object value)
BooleanLiteralNode node = new BooleanLiteralNode();
node.setLiteral(value);
setPosition(node, line, column);
return node;
| public java.lang.Object | newCollectionMemberVariableDecl(int line, int column, java.lang.Object path, java.lang.String variable)
DotNode dotNode = (DotNode)path;
AttributeNode rightNode = (AttributeNode)dotNode.getRight();
// The IN-clause expression must be a collection valued path expression
rightNode.setRequiresCollectionAttribute(true);
CollectionMemberDeclNode node = new CollectionMemberDeclNode();
node.setPath(dotNode);
node.setVariableName(variable);
setPosition(node, line, column);
context.registerJoinVariable(node.getCanonicalVariableName(), dotNode, line, column);
currentIdentificationVariable = variable;
return node;
| public java.lang.Object | newConcat(int line, int column, java.lang.Object left, java.lang.Object right)
ConcatNode node = new ConcatNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newConstructor(int line, int column, java.lang.String className, java.util.List args)
ConstructorNode node = new ConstructorNode(className);
node.setConstructorItems(args);
setPosition(node, line, column);
return node;
| public java.lang.Object | newCount(int line, int column, boolean distinct, java.lang.Object arg)
CountNode node = new CountNode();
node.setLeft((Node)arg);
node.setDistinct(distinct);
setPosition(node, line, column);
return node;
| public java.lang.Object | newCurrentDate(int line, int column)
DateFunctionNode node = new DateFunctionNode();
node.useCurrentDate();
setPosition(node, line, column);
return node;
| public java.lang.Object | newCurrentTime(int line, int column)
DateFunctionNode node = new DateFunctionNode();
node.useCurrentTime();
setPosition(node, line, column);
return node;
| public java.lang.Object | newCurrentTimestamp(int line, int column)
DateFunctionNode node = new DateFunctionNode();
node.useCurrentTimestamp();
setPosition(node, line, column);
return node;
| public java.lang.Object | newDeleteClause(int line, int column, java.lang.String schema, java.lang.String variable)
DeleteNode node = new DeleteNode();
node.setContext(context);
node.setAbstractSchemaName(schema);
node.setAbstractSchemaIdentifier(variable);
setPosition(node, line, column);
registerSchema(calculateCanonicalName(variable), schema, line, column);
return node;
| public java.lang.Object | newDeleteStatement(int line, int column, java.lang.Object delete, java.lang.Object where)
QueryNode queryNode = (QueryNode)delete;
EJBQLParseTree tree = new EJBQLParseTree();
queryNode.setParseTree(tree);
tree.setContext(context);
tree.setQueryNode(queryNode);
tree.setWhereNode((WhereNode)where);
return tree;
| public java.lang.Object | newDescOrdering(int line, int column, java.lang.Object arg)
OrderByItemNode node = new OrderByItemNode();
SortDirectionNode sortDirection = new SortDirectionNode();
sortDirection.useDescending();
node.setDirection(sortDirection);
node.setOrderByItem((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newDivide(int line, int column, java.lang.Object left, java.lang.Object right)
DivideNode node = new DivideNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newDot(int line, int column, java.lang.Object left, java.lang.Object right)
DotNode node = new DotNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newDoubleLiteral(int line, int column, java.lang.Object value)
DoubleLiteralNode node = new DoubleLiteralNode();
node.setLiteral(value);
setPosition(node, line, column);
return node;
| public java.lang.Object | newEquals(int line, int column, java.lang.Object left, java.lang.Object right)
EqualsNode node = new EqualsNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newEscape(int line, int column, java.lang.Object arg)
EscapeNode node = new EscapeNode();
node.setLeft((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newExists(int line, int column, boolean not, java.lang.Object subquery)
ExistsNode node = new ExistsNode();
if (not) node.indicateNot();
node.setLeft((Node)subquery);
setPosition(node, line, column);
return node;
| public java.lang.Object | newFetchJoin(int line, int column, boolean outerJoin, java.lang.Object path)
DotNode dotNode = (DotNode)path;
AttributeNode rightNode = (AttributeNode)dotNode.getRight();
rightNode.setOuterJoin(outerJoin);
// register the dot expression to be added as joined attribute
FetchJoinNode node = new FetchJoinNode();
node.setPath(dotNode);
node.setOuterJoin(outerJoin);
setPosition(node, line, column);
context.registerFetchJoin(currentIdentificationVariable, dotNode);
return node;
| public java.lang.Object | newFloatLiteral(int line, int column, java.lang.Object value)
FloatLiteralNode node = new FloatLiteralNode();
node.setLiteral(value);
setPosition(node, line, column);
return node;
| public java.lang.Object | newFromClause(int line, int column, java.util.List decls)
FromNode node = new FromNode();
node.setContext(context);
node.setDeclarations(decls);
setPosition(node, line, column);
return node;
| public java.lang.Object | newGreaterThan(int line, int column, java.lang.Object left, java.lang.Object right)
GreaterThanNode node = new GreaterThanNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newGreaterThanEqual(int line, int column, java.lang.Object left, java.lang.Object right)
GreaterThanEqualToNode node = new GreaterThanEqualToNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newGroupByClause(int line, int column, java.util.List items)
GroupByNode node = new GroupByNode();
node.setContext(context);
node.setGroupByItems(items);
setPosition(node, line, column);
return node;
| public java.lang.Object | newHavingClause(int line, int column, java.lang.Object arg)
HavingNode node = new HavingNode();
node.setContext(context);
node.setHaving((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newIn(int line, int column, boolean not, java.lang.Object expr, java.util.List items)
InNode node = new InNode();
if (not) node.indicateNot();
node.setLeft((Node)expr);
node.setTheObjects(items);
setPosition(node, line, column);
return node;
| public java.lang.Object | newIn(int line, int column, boolean not, java.lang.Object expr, java.lang.Object subquery)
InNode node = new InNode();
if (not) node.indicateNot();
node.setLeft((Node)expr);
node.addNodeToTheObjects((Node)subquery);
setPosition(node, line, column);
return node;
| public java.lang.Object | newIntegerLiteral(int line, int column, java.lang.Object value)
IntegerLiteralNode node = new IntegerLiteralNode();
node.setLiteral(value);
setPosition(node, line, column);
return node;
| public java.lang.Object | newIsEmpty(int line, int column, boolean not, java.lang.Object expr)
EmptyCollectionComparisonNode node =
new EmptyCollectionComparisonNode();
node.setLeft((Node)expr);
if (not) node.indicateNot();
setPosition(node, line, column);
return node;
| public java.lang.Object | newIsNull(int line, int column, boolean not, java.lang.Object expr)
NullComparisonNode node = new NullComparisonNode();
node.setLeft((Node)expr);
setPosition(node, line, column);
return not ? newNot(line, column, node) : node;
| public java.lang.Object | newJoinVariableDecl(int line, int column, boolean outerJoin, java.lang.Object path, java.lang.String variable)
DotNode dotNode = (DotNode)path;
AttributeNode rightNode = (AttributeNode)dotNode.getRight();
rightNode.setOuterJoin(outerJoin);
JoinDeclNode node = new JoinDeclNode();
node.setPath(dotNode);
node.setVariableName(variable);
node.setOuterJoin(outerJoin);
setPosition(node, line, column);
context.registerJoinVariable(node.getCanonicalVariableName(), dotNode, line, column);
currentIdentificationVariable = variable;
return node;
| public java.lang.Object | newLength(int line, int column, java.lang.Object arg)
LengthNode node = new LengthNode();
node.setLeft((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newLessThan(int line, int column, java.lang.Object left, java.lang.Object right)
LessThanNode node = new LessThanNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newLessThanEqual(int line, int column, java.lang.Object left, java.lang.Object right)
LessThanEqualToNode node = new LessThanEqualToNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newLike(int line, int column, boolean not, java.lang.Object string, java.lang.Object pattern, java.lang.Object escape)
LikeNode node = new LikeNode();
node.setLeft((Node)string);
node.setRight((Node)pattern);
node.setEscapeNode((EscapeNode)escape);
setPosition(node, line, column);
return not ? newNot(line, column, node) : node;
| public java.lang.Object | newLocate(int line, int column, java.lang.Object pattern, java.lang.Object arg, java.lang.Object startPos)
LocateNode node = new LocateNode();
node.setFind((Node)pattern);
node.setFindIn((Node)arg);
node.setStartPosition((Node)startPos);
setPosition(node, line, column);
return node;
| public java.lang.Object | newLongLiteral(int line, int column, java.lang.Object value)
LongLiteralNode node = new LongLiteralNode();
node.setLiteral(value);
setPosition(node, line, column);
return node;
| public java.lang.Object | newLower(int line, int column, java.lang.Object arg)
LowerNode node = new LowerNode();
node.setLeft((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newMax(int line, int column, boolean distinct, java.lang.Object arg)
MaxNode node = new MaxNode();
node.setLeft((Node)arg);
node.setDistinct(distinct);
setPosition(node, line, column);
return node;
| public java.lang.Object | newMemberOf(int line, int column, boolean not, java.lang.Object expr, java.lang.Object collection)
MemberOfNode node = new MemberOfNode();
node.setLeft((Node)expr);
node.setRight((Node)collection);
if (not) node.indicateNot();
setPosition(node, line, column);
return node;
| public java.lang.Object | newMin(int line, int column, boolean distinct, java.lang.Object arg)
MinNode node = new MinNode();
node.setLeft((Node)arg);
node.setDistinct(distinct);
setPosition(node, line, column);
return node;
| public java.lang.Object | newMinus(int line, int column, java.lang.Object left, java.lang.Object right)
MinusNode node = new MinusNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newMod(int line, int column, java.lang.Object left, java.lang.Object right)
ModNode node = new ModNode();
node.setLeft((Node)left);
node.setDenominator((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newMultiply(int line, int column, java.lang.Object left, java.lang.Object right)
MultiplyNode node = new MultiplyNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newNamedParameter(int line, int column, java.lang.String name)
ParameterNode node = new ParameterNode(name);
context.addParameter(name);
setPosition(node, line, column);
return node;
| public java.lang.Object | newNot(int line, int column, java.lang.Object arg)
NotNode node = new NotNode();
node.setLeft((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newNotEquals(int line, int column, java.lang.Object left, java.lang.Object right)
NotEqualsNode node = new NotEqualsNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newNullLiteral(int line, int column)
LiteralNode node = new LiteralNode();
node.setLiteral(null);
setPosition(node, line, column);
return node;
| public java.lang.Object | newOr(int line, int column, java.lang.Object left, java.lang.Object right)
OrNode node = new OrNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newOrderByClause(int line, int column, java.util.List items)
OrderByNode node = new OrderByNode();
node.setContext(context);
node.setOrderByItems(items);
setPosition(node, line, column);
return node;
| public java.lang.Object | newPlus(int line, int column, java.lang.Object left, java.lang.Object right)
PlusNode node = new PlusNode();
node.setLeft((Node)left);
node.setRight((Node)right);
setPosition(node, line, column);
return node;
| public java.lang.Object | newPositionalParameter(int line, int column, java.lang.String position)
ParameterNode node = new ParameterNode(position);
context.addParameter(position);
setPosition(node, line, column);
return node;
| public java.lang.Object | newQualifiedAttribute(int line, int column, java.lang.String variable, java.lang.String attribute)
Object varNode = newVariableAccess(line, column, variable);
Object attrNode = newAttribute(line, column, attribute);
return newDot(line, column, varNode, attrNode);
| public java.lang.Object | newRangeVariableDecl(int line, int column, java.lang.String schema, java.lang.String variable)
RangeDeclNode node = new RangeDeclNode();
node.setAbstractSchemaName(schema);
node.setVariableName(variable);
setPosition(node, line, column);
registerSchema(node.getCanonicalVariableName(), schema, line, column);
currentIdentificationVariable = variable;
return node;
| public java.lang.Object | newSelectClause(int line, int column, boolean distinct, java.util.List selectExprs)
SelectNode node = new SelectNode();
node.setContext(context);
node.setSelectExpressions(selectExprs);
node.setDistinct(distinct);
setPosition(node, line, column);
return node;
| public java.lang.Object | newSelectStatement(int line, int column, java.lang.Object select, java.lang.Object from, java.lang.Object where, java.lang.Object groupBy, java.lang.Object having, java.lang.Object orderBy)
QueryNode queryNode = (QueryNode)select;
EJBQLParseTree tree = new EJBQLParseTree();
queryNode.setParseTree(tree);
tree.setContext(context);
tree.setQueryNode(queryNode);
tree.setFromNode((FromNode)from);
tree.setWhereNode((WhereNode)where);
tree.setGroupByNode((GroupByNode)groupBy);
tree.setHavingNode((HavingNode)having);
tree.setOrderByNode((OrderByNode)orderBy);
return tree;
| public java.lang.Object | newSetAssignmentClause(int line, int column, java.lang.Object target, java.lang.Object value)
EqualsAssignmentNode node = new EqualsAssignmentNode();
node.setLeft((Node)target);
node.setRight((Node)value);
return node;
| public java.lang.Object | newSetClause(int line, int column, java.util.List assignments)
SetNode node = new SetNode();
node.setAssignmentNodes(assignments);
setPosition(node, line, column);
return node;
| public java.lang.Object | newSize(int line, int column, java.lang.Object arg)
SizeNode node = new SizeNode();
node.setLeft((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newSome(int line, int column, java.lang.Object subquery)
SomeNode node = new SomeNode();
node.setLeft((Node)subquery);
setPosition(node, line, column);
return node;
| public java.lang.Object | newSqrt(int line, int column, java.lang.Object arg)
SqrtNode node = new SqrtNode();
node.setLeft((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newStringLiteral(int line, int column, java.lang.Object value)
StringLiteralNode node = new StringLiteralNode();
node.setLiteral(value);
setPosition(node, line, column);
return node;
| public java.lang.Object | newSubquery(int line, int column, java.lang.Object select, java.lang.Object from, java.lang.Object where, java.lang.Object groupBy, java.lang.Object having)
QueryNode queryNode = (QueryNode)select;
EJBQLParseTree tree = new EJBQLParseTree();
queryNode.setParseTree(tree);
tree.setQueryNode(queryNode);
tree.setFromNode((FromNode)from);
tree.setWhereNode((WhereNode)where);
tree.setGroupByNode((GroupByNode)groupBy);
tree.setHavingNode((HavingNode)having);
tree.setContext(context);
SubqueryNode node = new SubqueryNode();
node.setParseTree(tree);
setPosition(node, line, column);
return node;
| public java.lang.Object | newSubstring(int line, int column, java.lang.Object string, java.lang.Object start, java.lang.Object length)
SubstringNode node = new SubstringNode();
node.setLeft((Node)string);
node.setStartPosition((Node)start);
node.setStringLength((Node)length);
setPosition(node, line, column);
return node;
| public java.lang.Object | newSum(int line, int column, boolean distinct, java.lang.Object arg)
SumNode node = new SumNode();
node.setLeft((Node)arg);
node.setDistinct(distinct);
setPosition(node, line, column);
return node;
| public java.lang.Object | newTrim(int line, int column, TrimSpecification trimSpec, java.lang.Object trimChar, java.lang.Object string)
TrimNode node = new TrimNode();
node.setLeft((Node)string);
node.setTrimChar((Node)trimChar);
switch (trimSpec) {
case LEADING:
node.setLeading(true);
break;
case TRAILING:
node.setTrailing(true);
break;
case BOTH:
node.setBoth(true);
break;
}
setPosition(node, line, column);
return node;
| public java.lang.Object | newUnaryMinus(int line, int column, java.lang.Object arg)
UnaryMinus node = new UnaryMinus();
node.setLeft((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newUnaryPlus(int line, int column, java.lang.Object arg)
return arg;
| public java.lang.Object | newUpdateClause(int line, int column, java.lang.String schema, java.lang.String variable)
UpdateNode node = new UpdateNode();
node.setContext(context);
node.setAbstractSchemaName(schema);
node.setAbstractSchemaIdentifier(variable);
setPosition(node, line, column);
registerSchema(calculateCanonicalName(variable), schema, line, column);
return node;
| public java.lang.Object | newUpdateStatement(int line, int column, java.lang.Object update, java.lang.Object set, java.lang.Object where)
QueryNode queryNode = (QueryNode)update;
EJBQLParseTree tree = new EJBQLParseTree();
queryNode.setParseTree(tree);
tree.setContext(context);
tree.setQueryNode(queryNode);
tree.setSetNode((SetNode)set);
tree.setWhereNode((WhereNode)where);
return tree;
| public java.lang.Object | newUpper(int line, int column, java.lang.Object arg)
UpperNode node = new UpperNode();
node.setLeft((Node)arg);
setPosition(node, line, column);
return node;
| public java.lang.Object | newVariableAccess(int line, int column, java.lang.String identifier)
VariableNode node = new VariableNode(identifier);
setPosition(node, line, column);
return node;
| public java.lang.Object | newVariableDecl(int line, int column, java.lang.Object path, java.lang.String variable)
DotNode dotNode = (DotNode)path;
AttributeNode rightNode = (AttributeNode)dotNode.getRight();
JoinDeclNode node = new JoinDeclNode();
node.setPath(dotNode);
node.setVariableName(variable);
setPosition(node, line, column);
context.registerJoinVariable(node.getCanonicalVariableName(), dotNode, line, column);
currentIdentificationVariable = variable;
return node;
| public java.lang.Object | newWhereClause(int line, int column, java.lang.Object condition)
WhereNode node = new WhereNode();
node.setContext(context);
node.setLeft((Node)condition);
setPosition(node, line, column);
return node;
| private void | registerSchema(java.lang.String variable, java.lang.String schema, int line, int column)
if (variable != null) {
context.registerSchema(variable, schema, line, column);
}
else {
// UPDATE and DELETE may not define a variable =>
// use schema name as variable
context.registerSchema(calculateCanonicalName(schema), schema, line, column);
}
| private void | setPosition(oracle.toplink.essentials.internal.parsing.Node node, int line, int column)
node.setLine(line);
node.setColumn(column);
|
|