Methods Summary |
---|
public void | addGroupingToQuery(oracle.toplink.essentials.queryframework.ObjectLevelReadQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Add the grouping to the passed query
if (hasGroupBy()) {
((GroupByNode)getGroupByNode()).addGroupingToQuery(theQuery, generationContext);
}
|
public void | addHavingToQuery(oracle.toplink.essentials.queryframework.ObjectLevelReadQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Add the having to the passed query
if (hasHaving()) {
((HavingNode)getHavingNode()).addHavingToQuery(theQuery, generationContext);
}
|
public void | addNonFetchJoinAttributes(oracle.toplink.essentials.queryframework.ObjectLevelReadQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
ParseTreeContext context = generationContext.getParseTreeContext();
for (Iterator i = unusedVariables.iterator(); i.hasNext();) {
String variable = (String)i.next();
Expression expr = null;
if (!context.isRangeVariable(variable)) {
Node path = context.pathForVariable(variable);
expr = path.generateExpression(generationContext);
theQuery.addNonFetchJoinedAttribute(expr);
} else {
// unused range variable => not supported yet
throw EJBQLException.notYetImplemented(context.getQueryInfo(),
"Variable [" + variable + "] is defined in a range variable declaration, but not used in the rest of the query.");
}
}
|
public void | addOrderingToQuery(oracle.toplink.essentials.queryframework.ObjectLevelReadQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Add the ordering to the passed query
if (hasOrderBy()) {
((OrderByNode)getOrderByNode()).addOrderingToQuery(theQuery, generationContext);
}
|
public void | addParametersToQuery(oracle.toplink.essentials.queryframework.DatabaseQuery query)INTERNAL
Add parameters to the 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);
}
}
|
public void | addUpdatesToQuery(oracle.toplink.essentials.queryframework.UpdateAllQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Add the updates to the passed query
if (getSetNode() != null) {
((SetNode)getSetNode()).addUpdatesToQuery(theQuery, generationContext);
}
|
public void | adjustReferenceClassForQuery(oracle.toplink.essentials.queryframework.DatabaseQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Adjust the reference class of the passed query if necessary
Need to test this for Employee, employee.getAddress(), report query
Class referenceClass = getReferenceClass(theQuery, generationContext);
if ((referenceClass != null) && (referenceClass != theQuery.getReferenceClass())) {
if (theQuery.isObjectLevelReadQuery()) {
// The referenceClass needs to be changed.
// This should only happen in an ejbSelect...
((ObjectLevelReadQuery)theQuery).setReferenceClass(referenceClass);
generationContext.setBaseQueryClass(referenceClass);
((ObjectLevelReadQuery)theQuery).changeDescriptor(generationContext.getSession());
} else if (theQuery.isUpdateAllQuery()) {
((UpdateAllQuery)theQuery).setReferenceClass(referenceClass);
} else if (theQuery.isDeleteAllQuery()) {
((DeleteAllQuery)theQuery).setReferenceClass(referenceClass);
}
}
|
public void | applyQueryNodeToQuery(oracle.toplink.essentials.queryframework.DatabaseQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Apply the select or update to the passed query.
If there is a single attribute being selected, add it to the query result set
If an aggregate is being used, add it to the query result set
getQueryNode().applyToQuery(theQuery, generationContext);
|
public oracle.toplink.essentials.internal.parsing.GenerationContext | buildContext(oracle.toplink.essentials.queryframework.DatabaseQuery query, oracle.toplink.essentials.internal.sessions.AbstractSession sessionForContext)INTERNAL
Build the context to be used when generating the expression from the parse tree
if (query.isObjectLevelReadQuery()) {
return buildContextForReadQuery(sessionForContext);
} else if (query.isUpdateAllQuery() || query.isDeleteAllQuery()) {
return new GenerationContext(getContext(), sessionForContext, this);
}
return null;
|
public oracle.toplink.essentials.internal.parsing.GenerationContext | buildContextForReadQuery(oracle.toplink.essentials.internal.sessions.AbstractSession sessionForContext)INTERNAL
Build the context to be used when generating the expression from the parse tree
return new SelectGenerationContext(getContext(), sessionForContext, this);
|
public oracle.toplink.essentials.queryframework.DatabaseQuery | createDatabaseQuery()INTERNAL
Returns a DatabaseQuery instance for this ParseTree.
return (queryNode == null) ? null :
queryNode.createDatabaseQuery(context);
|
public oracle.toplink.essentials.expressions.Expression | generateExpression(oracle.toplink.essentials.queryframework.DatabaseQuery readQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Build a context for the expression generation
Expression selectExpression = getQueryNode().generateExpression(generationContext);
if (getWhereNode() == null) {
return selectExpression;
}
Expression whereExpression = getWhereNode().generateExpression(generationContext);
selectExpression = getQueryNode().generateExpression(generationContext);
if (selectExpression != null) {
whereExpression = selectExpression.and(whereExpression);
}
return whereExpression;
|
private java.lang.Class | getBaseExpressionClass(oracle.toplink.essentials.internal.parsing.Node node, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)
ParseTreeContext context = generationContext.getParseTreeContext();
Class clazz = null;
if (node == null) {
clazz = null;
} else if (node.isDotNode()) {
// DotNode: delegate to left
clazz = getBaseExpressionClass(node.getLeft(), generationContext);
} else if (node.isVariableNode()) {
// VariableNode
String variable = ((VariableNode)node).getVariableName();
if (!context.isRangeVariable(variable)) {
Node path = context.pathForVariable(variable);
// Variable is defined in JOIN/IN clause =>
// return the Class from its definition
clazz = getBaseExpressionClass(path, generationContext);
} else {
// Variable is defined in range variable decl =>
// return its class
String schema = context.schemaForVariable(variable);
if (schema != null) {
clazz = context.classForSchemaName(schema, generationContext);
}
}
}
return clazz;
|
public java.lang.ClassLoader | getClassLoader()INTERNAL
Return a class loader
if (classLoader == null) {
return oracle.toplink.essentials.internal.helper.ConversionManager.getDefaultManager().getLoader();
} else {
return classLoader;
}
|
public oracle.toplink.essentials.internal.parsing.ParseTreeContext | getContext()Return the context for this parse tree
return context;
|
public short | getDistinctState()INTERNAL
Return the DISTINCT state for the tree
return distinctState;
|
public oracle.toplink.essentials.internal.parsing.FromNode | getFromNode()INTERNAL
Return the FROM Node
return fromNode;
|
public oracle.toplink.essentials.internal.parsing.GroupByNode | getGroupByNode()INTERNAL
Return the GroupByNode
return groupByNode;
|
public oracle.toplink.essentials.internal.parsing.HavingNode | getHavingNode()INTERNAL
Return the HavingNode
return havingNode;
|
public oracle.toplink.essentials.internal.parsing.OrderByNode | getOrderByNode()INTERNAL
Return the OrderByNode
return orderByNode;
|
public oracle.toplink.essentials.internal.parsing.QueryNode | getQueryNode()INTERNAL
Return the root node for the tree
return queryNode;
|
public java.lang.Class | getReferenceClass(oracle.toplink.essentials.queryframework.DatabaseQuery query, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)getReferenceClass(): Answer the class which will be the reference class for the query.
Resolve this using the node parsed from the "SELECT" of the EJBQL query string
if (getQueryNode() == null) {
return null;
}
return getQueryNode().getReferenceClass(generationContext);
|
public oracle.toplink.essentials.internal.parsing.SetNode | getSetNode()INTERNAL
Return the set node for the tree
return setNode;
|
public oracle.toplink.essentials.internal.parsing.WhereNode | getWhereNode()INTERNAL
Return the Where node
return whereNode;
|
public boolean | hasGroupBy()INTERNAL
Does this EJBQL have a Grouping Clause
return getGroupByNode() != null;
|
public boolean | hasHaving()INTERNAL
Does this EJBQL have a Having Clause
return getHavingNode() != null;
|
public boolean | hasOrderBy()INTERNAL
Does this EJBQL have an Ordering Clause
return getOrderByNode() != null;
|
public void | initBaseExpression(oracle.toplink.essentials.queryframework.ObjectLevelReadQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Initialize the base expression in the generation context.
String variable = getFromNode().getFirstVariable();
ParseTreeContext context = generationContext.getParseTreeContext();
if (context.isRangeVariable(variable)) {
Class referenceClass = theQuery.getReferenceClass();
// Create a new expression builder for the reference class
ExpressionBuilder builder = new ExpressionBuilder(referenceClass);
// Use the expression builder as the default expression builder for the query
theQuery.setExpressionBuilder(builder);
// Add the expression builder to the expression cache in the context
generationContext.setBaseExpression(variable, builder);
} else {
// Get the declaring node for the variable
Node path = context.pathForVariable(variable);
// Get the ExpressionBuilder of the range variable for the path
Class baseClass = getBaseExpressionClass(path, generationContext);
// Use the base ExpressionBuilder as the default for the query
theQuery.setExpressionBuilder(new ExpressionBuilder(baseClass));
// and change the reference class accordingly
theQuery.setReferenceClass(baseClass);
theQuery.changeDescriptor(generationContext.getSession());
generationContext.setBaseQueryClass(baseClass);
// Set the node expression as base expression
generationContext.setBaseExpression(
variable, path.generateExpression(generationContext));
}
|
public void | initBaseExpression(oracle.toplink.essentials.queryframework.ModifyAllQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Initialize the base expression in the generation context.
ModifyNode queryNode = (ModifyNode)getQueryNode();
String variable = queryNode.getCanonicalAbstractSchemaIdentifier();
Class referenceClass = theQuery.getReferenceClass();
// Create a new expression builder for the reference class
ExpressionBuilder builder = new ExpressionBuilder(referenceClass);
// Use the expression builder as the default expression builder for the query
theQuery.setExpressionBuilder(builder);
// Add the expression builder to the expression cache in the context
generationContext.setBaseExpression(variable, builder);
|
protected void | qualifyAttributeAccess(oracle.toplink.essentials.internal.parsing.ParseTreeContext context)INTERNAL
This method handles any unqualified field access in bulk UPDATE and
DELETE statements. A UPDATE or DELETE statement may not define an
identification variable. In this case any field accessed from the
current class is not qualified with an identification variable, e.g.
UPDATE Customer SET name = :newname
The method goes through the expressions of the SET clause and the WHERE
clause of such an DELETE and UPDATE statement and qualifies the field
access using the abstract schema name as qualifier.
if ((queryNode.isUpdateNode() || queryNode.isDeleteNode()) &&
((ModifyNode)queryNode).getAbstractSchemaIdentifier() == null) {
if (setNode != null) {
setNode.qualifyAttributeAccess(context);
}
if (whereNode != null) {
whereNode.qualifyAttributeAccess(context);
}
}
|
public void | setClassLoader(java.lang.ClassLoader loader)INTERNAL:
Set the class loader for this parse tree
this.classLoader = loader;
|
public void | setContext(oracle.toplink.essentials.internal.parsing.ParseTreeContext newContext)INTERNAL
Set the context for this parse tree
context = newContext;
|
public void | setDistinctState(short newDistinctState)INTERNAL
Set the DISTINCT state for the tree
distinctState = newDistinctState;
|
public void | setFromNode(oracle.toplink.essentials.internal.parsing.FromNode fromNode)INTERNAL
Set the FROM node for the query
this.fromNode = fromNode;
|
public void | setGroupByNode(oracle.toplink.essentials.internal.parsing.GroupByNode newGroupByNode)INTERNAL
Set the Group by node
groupByNode = newGroupByNode;
|
public void | setHavingNode(oracle.toplink.essentials.internal.parsing.HavingNode newHavingNode)INTERNAL
Set the Having node
havingNode = newHavingNode;
|
public void | setOrderByNode(oracle.toplink.essentials.internal.parsing.OrderByNode newOrderByNode)INTERNAL
Set the Order by node
orderByNode = newOrderByNode;
|
public void | setQueryNode(oracle.toplink.essentials.internal.parsing.QueryNode newQueryNode)INTERNAL
Set the Select node
queryNode = newQueryNode;
|
public void | setSelectionCriteriaForQuery(oracle.toplink.essentials.queryframework.DatabaseQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)
theQuery.setSelectionCriteria(generateExpression(theQuery, generationContext));
|
public void | setSetNode(oracle.toplink.essentials.internal.parsing.SetNode newSetNode)INTERNAL
Set the Where node
setNode = newSetNode;
|
public void | setWhereNode(oracle.toplink.essentials.internal.parsing.WhereNode newWhereNode)INTERNAL
Set the Where node
whereNode = newWhereNode;
|
public java.lang.String | toString()INTERNAL
Print the contents of the parse tree on a string
StringBuffer buffer = new StringBuffer();
buffer.append(getContext().toString());
return ToStringLocalization.buildMessage("context", (Object[])null) + " " + buffer.toString();
|
public boolean | usesDistinct()INTERNAL
Answer true if DISTINCT has been chosen.
return distinctState == ObjectLevelReadQuery.USE_DISTINCT;
|
protected void | validate(oracle.toplink.essentials.internal.sessions.AbstractSession session, java.lang.ClassLoader classLoader)INTERNAL
Validate the parse tree.
validate(new TypeHelperImpl(session, classLoader));
|
public void | validate(oracle.toplink.essentials.internal.parsing.TypeHelper typeHelper)INTERNAL
Validate the parse tree.
ParseTreeContext context = getContext();
context.setTypeHelper(typeHelper);
validate(context);
|
public void | validate(oracle.toplink.essentials.internal.parsing.ParseTreeContext context)INTERNAL
Validate the parse tree.
if (validated) {
// already validated => return
return;
}
validated = true;
context.enterScope();
if (fromNode != null) {
fromNode.validate(context);
}
queryNode.validate(context);
qualifyAttributeAccess(context);
if (setNode != null) {
setNode.validate(context);
}
if (whereNode != null) {
whereNode.validate(context);
}
if (hasOrderBy()) {
orderByNode.validate(context, (SelectNode)queryNode);
}
if (hasGroupBy()) {
groupByNode.validate(context, (SelectNode)queryNode);
}
if (hasHaving()) {
havingNode.validate(context, groupByNode);
}
// store the set od unused variable for later use
unusedVariables = context.getUnusedVariables();
context.leaveScope();
|
public void | verifySelect(oracle.toplink.essentials.queryframework.DatabaseQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext generationContext)INTERNAL
Verify that the alias in the SELECT is valid.
Invalid: SELECT OBJECT(badAlias) FROM Employee employee....
Valid: SELECT OBJECT(employee) FROM Employee employee....
if (theQuery.isObjectLevelReadQuery()) {
//verify the selected alias,
//this will throw an error if the alias is bad
((SelectNode)getQueryNode()).verifySelectedAlias(generationContext);
}
|