Java Doc for Expression.java in  » Database-DBMS » mckoi » com » mckoi » database » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » mckoi » com.mckoi.database 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.mckoi.database.Expression

Expression
final public class Expression implements java.io.Serializable,Cloneable(Code)
An expression that can be evaluated in a statement. This is used as a more complete and flexible version of 'Condition' as well as representing column and aggregate functions.

This class can represent constant expressions (expressions that have no variable input), as well as variable expressions. Optimizations may be possible when evaluating constant expressions.

Some examples of constant expressions;

 ( 9 + 3 ) * 90
 ( ? * 9 ) / 1
 lower("CaPS MUMma")
 40 & 0x0FF != 39
 
Some examples of variable expressions;

 upper(Part.description)
 Part.id >= 50
 VendorMakesPart.part_id == Part.id
 Part.value_of <= Part.cost_of / 4
 

NOTE: the expression is stored in postfix orientation. eg. "8 + 9 * 3" becomes "8,9,3,*,+"

NOTE: This class is NOT thread safe. Do not use an expression instance between threads.
author:
   Tobias Downer



Field Summary
final static  longserialVersionUID
     Serialization UID.

Constructor Summary
public  Expression()
     Constructs a new Expression.
public  Expression(Object ob)
     Constructs a new Expression with a single object element.
public  Expression(Expression exp)
     Constructs a copy of the given Expression.
public  Expression(Expression exp1, Operator op, Expression exp2)
     Constructs a new Expression from the concatination of expression1 and expression2 and the operator for them.

Method Summary
public  voidaddElement(Object ob)
     Adds a new element into the expression.
public  voidaddOperator(Operator op)
     Adds a new operator into the expression.
public  ListallElements()
     Returns a complete list of all element objects that are in this expression and in the parameters of the functions of this expression.
public  ListallVariables()
     Returns a complete List of Variable objects in this expression not including correlated variables.
public  ArrayListbreakByOperator(ArrayList list, String logical_op)
     Breaks this expression into a list of sub-expressions that are split by the given operator.
public  Objectclone()
     Performs a deep clone of this object, calling 'clone' on any elements that are mutable or shallow copying immutable members.
public  Expressionconcat(Expression expr)
     Merges an expression with this expression.
public  booleancontainsNotOperator()
     Returns true if the expression contains a NOT operator somewhere in it.
public  voidcopyTextFrom(Expression e)
     Copies the text from the given expression.
public  ArrayListdiscoverCorrelatedVariables(int level, ArrayList list)
     Discovers all the correlated variables in this expression.
public  ArrayListdiscoverTableNames(ArrayList list)
     Discovers all the tables in the sub-queries of this expression.
public  ObjectelementAt(int n)
     Returns the element at the given position in the postfix list.
public  TObjectevaluate(GroupResolver group, VariableResolver resolver, QueryContext context)
     Evaluates this expression and returns an Object that represents the result of the evaluation.
public  TObjectevaluate(VariableResolver resolver, QueryContext context)
     Evaluation without a grouping table.
public  ExpressiongetEndExpression()
     Returns the end Expression of this expression.
public  QueryPlanNodegetQueryPlanNode()
     Returns the QueryPlanNode object in this expression if it evaluates to a single QueryPlanNode, otherwise returns null.
public  VariablegetVariable()
     Returns the Variable if this expression evaluates to a single variable, otherwise returns null.
public  booleanhasAggregateFunction(QueryContext context)
     Cascades through the expression and if any aggregate functions are found returns true, otherwise returns false.
public  booleanhasSubQuery()
     Returns true if the expression has a subquery (eg 'in ( select ...
public  booleanisConstant()
     Returns true if the expression doesn't include any variables or non constant functions (is constant).
public  Objectlast()
     Returns the element at the end of the postfix list (the last element).
public static  Expressionparse(String expression)
     Static method that parses the given string which contains an expression into an Expression object.
public  voidprepare(ExpressionPreparer preparer)
     A general prepare that cascades through the expression and its parents and substitutes an elements that the preparer wants to substitute.

NOTE: This will not cascade through to the parameters of Function objects however it will cascade through FunctionDef parameters.

public  TTypereturnTType(VariableResolver resolver, QueryContext context)
     Determines the type of object this expression evaluates to.
public  voidsetElementAt(int n, Object ob)
     Sets the element at the given position in the postfix list.
public static  Expressionsimple(Object ob1, Operator op, Object ob2)
     Generates a simple expression from two objects and an operator.
public  intsize()
     Returns the number of elements and operators that are in this postfix list.
public  Expression[]split()
     Returns an array of two Expression objects that represent the left hand and right and side of the last operator in the post fix notation. For example, (a + b) - (c + d) will return { (a + b), (c + d) }.
public  StringBuffertext()
     Returns the StringBuffer that we can use to append plain text representation as we are parsing the expression.
public  StringtoString()
     Returns a string representation of this object for diagnostic purposes.

Field Detail
serialVersionUID
final static long serialVersionUID(Code)
Serialization UID.




Constructor Detail
Expression
public Expression()(Code)
Constructs a new Expression.



Expression
public Expression(Object ob)(Code)
Constructs a new Expression with a single object element.



Expression
public Expression(Expression exp)(Code)
Constructs a copy of the given Expression.



Expression
public Expression(Expression exp1, Operator op, Expression exp2)(Code)
Constructs a new Expression from the concatination of expression1 and expression2 and the operator for them.




Method Detail
addElement
public void addElement(Object ob)(Code)
Adds a new element into the expression. String, BigNumber, Boolean and Variable are the types of elements allowed.

Must be added in postfix order.




addOperator
public void addOperator(Operator op)(Code)
Adds a new operator into the expression. Operators are represented as an Operator (eg. ">", "+", "<<", "!=" )

Must be added in postfix order.




allElements
public List allElements()(Code)
Returns a complete list of all element objects that are in this expression and in the parameters of the functions of this expression.



allVariables
public List allVariables()(Code)
Returns a complete List of Variable objects in this expression not including correlated variables.



breakByOperator
public ArrayList breakByOperator(ArrayList list, String logical_op)(Code)
Breaks this expression into a list of sub-expressions that are split by the given operator. For example, given the expression;

 (a = b AND b = c AND (a = 2 OR c = 1))
 

Calling this method with logical_op = "and" will return a list of the three expressions.

This is a common function used to split up an expressions into logical components for processing.




clone
public Object clone() throws CloneNotSupportedException(Code)
Performs a deep clone of this object, calling 'clone' on any elements that are mutable or shallow copying immutable members.



concat
public Expression concat(Expression expr)(Code)
Merges an expression with this expression. For example, given the expression 'ab', if the expression 'abc+-' was added the expression would become 'ababc+-'.

This method is useful when copying parts of other expressions when forming an expression.

This always returns this expression. This does not change 'text()'.




containsNotOperator
public boolean containsNotOperator()(Code)
Returns true if the expression contains a NOT operator somewhere in it.



copyTextFrom
public void copyTextFrom(Expression e)(Code)
Copies the text from the given expression.



discoverCorrelatedVariables
public ArrayList discoverCorrelatedVariables(int level, ArrayList list)(Code)
Discovers all the correlated variables in this expression. If this expression contains a sub-query plan, we ask the plan to find the list of correlated variables. The discovery process increments the 'level' variable for each sub-plan.



discoverTableNames
public ArrayList discoverTableNames(ArrayList list)(Code)
Discovers all the tables in the sub-queries of this expression. This is used for determining all the tables that a query plan touches.



elementAt
public Object elementAt(int n)(Code)
Returns the element at the given position in the postfix list. Note, this can return Operator's.



evaluate
public TObject evaluate(GroupResolver group, VariableResolver resolver, QueryContext context)(Code)
Evaluates this expression and returns an Object that represents the result of the evaluation. The passed VariableResolver object is used to resolve the variable name to a value. The GroupResolver object is used if there are any aggregate functions in the evaluation - this can be null if evaluating an expression without grouping aggregates. The query context object contains contextual information about the environment of the query.

NOTE: This method is gonna be called a lot, so we need it to be optimal.

NOTE: This method is not thread safe! The reason it's not safe is because of the evaluation stack.




evaluate
public TObject evaluate(VariableResolver resolver, QueryContext context)(Code)
Evaluation without a grouping table.



getEndExpression
public Expression getEndExpression()(Code)
Returns the end Expression of this expression. For example, an expression of 'ab' has an end expression of 'b'. The expression 'abc+=' has an end expression of 'abc+='.

This is a useful method to call in the middle of an Expression object being formed. It allows for the last complete expression to be returned.

If this is called when an expression is completely formed it will always return the complete expression.




getQueryPlanNode
public QueryPlanNode getQueryPlanNode()(Code)
Returns the QueryPlanNode object in this expression if it evaluates to a single QueryPlanNode, otherwise returns null.



getVariable
public Variable getVariable()(Code)
Returns the Variable if this expression evaluates to a single variable, otherwise returns null. A correlated variable will not be returned.



hasAggregateFunction
public boolean hasAggregateFunction(QueryContext context)(Code)
Cascades through the expression and if any aggregate functions are found returns true, otherwise returns false.



hasSubQuery
public boolean hasSubQuery()(Code)
Returns true if the expression has a subquery (eg 'in ( select ... )') somewhere in it (this cascades through function parameters also).



isConstant
public boolean isConstant()(Code)
Returns true if the expression doesn't include any variables or non constant functions (is constant). Note that a correlated variable is considered a constant.



last
public Object last()(Code)
Returns the element at the end of the postfix list (the last element).



parse
public static Expression parse(String expression)(Code)
Static method that parses the given string which contains an expression into an Expression object. For example, this will parse strings such as '(a + 9) * 2 = b' or 'upper(concat('12', '56', id))'.

Care should be taken to not use this method inside an inner loop because it creates a lot of objects.




prepare
public void prepare(ExpressionPreparer preparer) throws DatabaseException(Code)
A general prepare that cascades through the expression and its parents and substitutes an elements that the preparer wants to substitute.

NOTE: This will not cascade through to the parameters of Function objects however it will cascade through FunctionDef parameters. For this reason you MUST call 'prepareFunctions' after this method.




returnTType
public TType returnTType(VariableResolver resolver, QueryContext context)(Code)
Determines the type of object this expression evaluates to. We determine this by looking at the last element of the expression. If the last element is a TType object, it returns the type. If the last element is a Function, Operator or Variable then it returns the type that these objects have set as their result type.



setElementAt
public void setElementAt(int n, Object ob)(Code)
Sets the element at the given position in the postfix list. This should be called after the expression has been setup to alter variable alias names, etc.



simple
public static Expression simple(Object ob1, Operator op, Object ob2)(Code)
Generates a simple expression from two objects and an operator.



size
public int size()(Code)
Returns the number of elements and operators that are in this postfix list.



split
public Expression[] split()(Code)
Returns an array of two Expression objects that represent the left hand and right and side of the last operator in the post fix notation. For example, (a + b) - (c + d) will return { (a + b), (c + d) }. Or more a more useful example is;

 id + 3 > part_id - 2 will return ( id + 3, part_id - 2 }
 



text
public StringBuffer text()(Code)
Returns the StringBuffer that we can use to append plain text representation as we are parsing the expression.



toString
public String toString()(Code)
Returns a string representation of this object for diagnostic purposes.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.