/** No-arg Constructor */ public NodeFactoryImpl(String queryInfo) { this.context = new ParseTreeContext(this, queryInfo); }
private Class getClassOfFirstVariable(GenerationContext context) { Class clazz = null; String variable = getParseTree().getFromNode().getFirstVariable(); ParseTreeContext parseTreeContext = context.getParseTreeContext(); if (parseTreeContext.isRangeVariable(variable)) { String schema = parseTreeContext.schemaForVariable(variable); // variables is defines in a range variable declaration, so there // is a schema name for this variable clazz = parseTreeContext.classForSchemaName(schema, context); } else { // variable is defined in a JOIN clause, so there is a a defining // node for the variable Node path = parseTreeContext.pathForVariable(variable); clazz = path.resolveClass(context); } return clazz; }
/** * INTERNAL */ public void validateParameter(ParseTreeContext context, Object contextType) { context.defineParameterType(name, contextType, getLine(), getColumn()); setType(context.getParameterType(name)); }
/** * INTERNAL * Add parameters to the query */ public void addParametersToQuery(DatabaseQuery query) { //Bug#4646580 Add arguments to query if (context.hasParameters()) { TypeHelper typeHelper = context.getTypeHelper(); for (Iterator i = context.getParameterNames().iterator(); i.hasNext();) { String param = (String)i.next(); Object type = context.getParameterType(param); Class clazz = typeHelper.getJavaClass(type); if (clazz == null) { clazz = Object.class; } query.addArgument(param, clazz); } } }
/** * INTERNAL * This node represent an unqualified field access in the case the method * is called and the variableName is not defined as identification variable. * The method returns a DotNode representing a qualified field access with * the base variable as left child node. The right child node is an * AttributeNode using the variableName as field name. */ public Node qualifyAttributeAccess(ParseTreeContext context) { return context.isVariable(variableName) ? this : (Node)context.getNodeFactory().newQualifiedAttribute( getLine(), getColumn(), context.getBaseVariable(), variableName); }
/** * INTERNAL * If called this AttributeNode represents an unqualified field access. * The method returns a DotNode representing a qualified field access with * the base variable as left child node and the attribute as right child * node. */ public Node qualifyAttributeAccess(ParseTreeContext context) { return (Node)context.getNodeFactory().newQualifiedAttribute( getLine(), getColumn(), context.getBaseVariable(), name); }
/** * INTERNAL * Check for an unqualified field access. If abstractSchemaName does not * define a valid abstract schema name treat it as unqualified field * access. Then method qualifies the field access and use it as the path * expression of a new join variable declaration node returned by the * method. */ public Node qualifyAttributeAccess(ParseTreeContext context) { TypeHelper typeHelper = context.getTypeHelper(); String name = abstractSchemaName; if (typeHelper.resolveSchema(name) == null) { // not a known abstract schema name => make it a join node with a // qualified attribute access as path expression context.unregisterVariable(getCanonicalVariableName()); NodeFactory factory = context.getNodeFactory(); Node path = (Node)factory.newQualifiedAttribute( getLine(), getColumn(), context.getBaseVariable(), name); return (Node)factory.newVariableDecl( getLine(), getColumn(), path, getVariableName()); } return this; }
/** * INTERNAL * Validate node and calculate its type. */ public void validate(ParseTreeContext context) { Set saved = context.getOuterScopeVariables(); if (left != null) { context.resetOuterScopeVariables(); left.validate(context); leftOuterScopeVariables = context.getOuterScopeVariables(); } if (right != null) { context.resetOuterScopeVariables(); right.validate(context); rightOuterScopeVariables = context.getOuterScopeVariables(); } context.resetOuterScopeVariables(saved); if ((left != null) && (right != null)) { left.validateParameter(context, right.getType()); right.validateParameter(context, left.getType()); } TypeHelper typeHelper = context.getTypeHelper(); setType(typeHelper.getBooleanType()); }
context.enterScope(); if (fromNode != null) { fromNode.validate(context); unusedVariables = context.getUnusedVariables(); context.leaveScope();
/** */ public Object newPositionalParameter(int line, int column, String position) { ParameterNode node = new ParameterNode(position); context.addParameter(position); setPosition(node, line, column); return node; }
/** * INTERNAL * Add the variable as ReportQuery item. The method checks for any JOIN * FETCH nodes of the current variable and adds them as part of the * ReportQuery item. */ private void addAttributeWithFetchJoins(ReportQuery reportQuery, Expression expression, GenerationContext context) { String name = getCanonicalVariableName(); List fetchJoinNodes = context.getParseTreeContext().getFetchJoins(name); if (fetchJoinNodes == null) { reportQuery.addAttribute(name, expression); } else { List fetchJoinExprs = new ArrayList(fetchJoinNodes.size()); for (Iterator i = fetchJoinNodes.iterator(); i.hasNext(); ) { Node node = (Node)i.next(); fetchJoinExprs.add(node.generateExpression(context)); } reportQuery.addItem(name, expression, fetchJoinExprs); } }
/** * INTERNAL * Validate node and calculate its type. */ public void validate(ParseTreeContext context) { subqueryParseTree.validate(context); outerVars = context.getOuterScopeVariables(); SelectNode selectNode = (SelectNode)subqueryParseTree.getQueryNode(); // Get the select expression, subqueries only have one Node selectExpr = (Node)selectNode.getSelectExpressions().get(0); setType(selectExpr.getType()); }
/** * INTERNAL * getVariableNameForClass(): * Answer the name mapped to the specified class. Answer null if none found. * SELECT OBJECT (emp) FROM Employee emp * getVariableNameForClass(Employee.class) => "emp" */ public String getVariableNameForClass(Class theClass, GenerationContext context) { for (Iterator i = variableDecls.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry)i.next(); String nextVariable = (String)entry.getKey(); VariableDecl decl = (VariableDecl)entry.getValue(); if ((decl.schema != null) && (theClass == this.classForSchemaName(decl.schema, context))) { return nextVariable; } } return null; }
/** * INTERNAL * Add parameters to the query */ public void addParametersToQuery(DatabaseQuery query) { //Bug#4646580 Add arguments to query if (context.hasParameters()) { TypeHelper typeHelper = context.getTypeHelper(); for (Iterator i = context.getParameterNames().iterator(); i.hasNext();) { String param = (String)i.next(); Object type = context.getParameterType(param); Class clazz = typeHelper.getJavaClass(type); if (clazz == null) { clazz = Object.class; } query.addArgument(param, clazz); } } }
/** * INTERNAL * Check for an unqualified field access. If abstractSchemaName does not * define a valid abstract schema name treat it as unqualified field * access. Then method qualifies the field access and use it as the path * expression of a new join variable declaration node returned by the * method. */ public Node qualifyAttributeAccess(ParseTreeContext context) { TypeHelper typeHelper = context.getTypeHelper(); String name = abstractSchemaName; if (typeHelper.resolveSchema(name) == null) { // not a known abstract schema name => make it a join node with a // qualified attribute access as path expression context.unregisterVariable(getCanonicalVariableName()); NodeFactory factory = context.getNodeFactory(); Node path = (Node)factory.newQualifiedAttribute( getLine(), getColumn(), context.getBaseVariable(), name); return (Node)factory.newVariableDecl( getLine(), getColumn(), path, getVariableName()); } return this; }
/** * INTERNAL * This node represent an unqualified field access in the case the method * is called and the variableName is not defined as identification variable. * The method returns a DotNode representing a qualified field access with * the base variable as left child node. The right child node is an * AttributeNode using the variableName as field name. */ public Node qualifyAttributeAccess(ParseTreeContext context) { return context.isVariable(variableName) ? this : (Node)context.getNodeFactory().newQualifiedAttribute( getLine(), getColumn(), context.getBaseVariable(), variableName); }
/** * INTERNAL * Validate node and calculate its type. */ public void validate(ParseTreeContext context) { Set saved = context.getOuterScopeVariables(); if (left != null) { context.resetOuterScopeVariables(); left.validate(context); leftOuterScopeVariables = context.getOuterScopeVariables(); } if (right != null) { context.resetOuterScopeVariables(); right.validate(context); rightOuterScopeVariables = context.getOuterScopeVariables(); } context.resetOuterScopeVariables(saved); if ((left != null) && (right != null)) { left.validateParameter(context, right.getType()); right.validateParameter(context, left.getType()); } TypeHelper typeHelper = context.getTypeHelper(); setType(typeHelper.getBooleanType()); }
context.enterScope(); if (fromNode != null) { fromNode.validate(context); unusedVariables = context.getUnusedVariables(); context.leaveScope();
/** * INTERNAL * If called this AttributeNode represents an unqualified field access. * The method returns a DotNode representing a qualified field access with * the base variable as left child node and the attribute as right child * node. */ public Node qualifyAttributeAccess(ParseTreeContext context) { return (Node)context.getNodeFactory().newQualifiedAttribute( getLine(), getColumn(), context.getBaseVariable(), name); }
/** */ public Object newNamedParameter(int line, int column, String name) { ParameterNode node = new ParameterNode(name); context.addParameter(name); setPosition(node, line, column); return node; }