|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttribble.parse.sql.QueryExpr
Query expression tree.
An object of this type is produced by a QueryParser object, which
parses an SQL-like expression (i.e., an expression similar to an SQL
'SELECT WHERE' clause) and produces an expression tree
in the form of a QueryExpr object.
Some example query expressions and the expression trees resulting from parsing them:
| Query | Expression Tree |
|---|---|
exists |
val "exists" |
not directory |
not
val
"directory"
|
not directory or writable |
or
not
val
"directory"
val
"writable"
|
name like "Sarah%Conner" and ( birth_date >= '1996-06-14' ) |
and
like
"name"
"\"Sarah%Conner\""
ge
"birth_date"
"'1996-06-14'"
|
interest >= 5.000 and interest < 10.000 |
and
ge
"interest"
"5.000"
lt
"interest"
"10.000"
|
rec.id between 'A000' and 'B999' |
between
"rec.id"
and
"'A000'"
"'B999'"
|
pay-type in ( 'WK' 'HR' 'YR' ) |
in
"pay-type"
list
"'WK'"
list
"'HR'"
list
"'YR'"
|
addr is not null |
not
is
"addr"
"null"
|
rec.pay[mon] |
subscr
member
"rec"
"pay"
"mon"
|
Copyright ©2001 by David R. Tribble, all rights reserved.
Permission is granted to any person or entity except those designated by
by the United States Department of State as a terrorist, or terrorist
government or agency, to use and distribute this source code provided
that the original copyright notice remains present and unaltered.
QueryParser| Field Summary | |
java.lang.Object |
m_arg1
First (left) argument, typically either a QueryExpr or a String. |
java.lang.Object |
m_arg2
Second (right) argument, typically either a QueryExpr or a String. |
java.lang.String |
m_op
Operator, one of the OP_XXX constants. |
static java.lang.String |
OP_ADD
|
static java.lang.String |
OP_AND
|
static java.lang.String |
OP_BETWEEN
|
static java.lang.String |
OP_CONCAT
|
static java.lang.String |
OP_CONTAINS
|
static java.lang.String |
OP_DIV
|
static java.lang.String |
OP_EQ
|
static java.lang.String |
OP_EXPO
|
static java.lang.String |
OP_GE
|
static java.lang.String |
OP_GT
|
static java.lang.String |
OP_IN
|
static java.lang.String |
OP_IS
|
static java.lang.String |
OP_LE
|
static java.lang.String |
OP_LIKE
|
static java.lang.String |
OP_LIKEFILE
|
static java.lang.String |
OP_LIST
|
static java.lang.String |
OP_LT
|
static java.lang.String |
OP_MEMBER
|
static java.lang.String |
OP_MOD
|
static java.lang.String |
OP_MUL
|
static java.lang.String |
OP_NE
|
static java.lang.String |
OP_NEG
|
static java.lang.String |
OP_NOP
|
static java.lang.String |
OP_NOT
|
static java.lang.String |
OP_NULL
|
static java.lang.String |
OP_OR
|
static java.lang.String |
OP_POS
|
static java.lang.String |
OP_SUB
|
static java.lang.String |
OP_SUBSCR
|
static java.lang.String |
OP_VALUE
|
static int |
SERIES
|
| Constructor Summary | |
QueryExpr()
Default constructor. |
|
| Method Summary | |
protected static java.lang.String |
asQuotedOperand(java.lang.String s)
Add enclosing quotes to a string if necessary to make it a valid SQL token. |
protected void |
buildString(java.lang.Object arg,
java.lang.StringBuffer text)
Format an operand, appending it to a string buffer. |
protected void |
buildString(java.lang.StringBuffer text)
Convert this expression subtree into a printable text string, appending it to a string buffer. |
java.lang.Object |
clone()
Create a duplicate of this query expression tree. |
void |
dump(java.io.OutputStream out)
Print the structure of this expression tree. |
void |
dump(java.io.Writer out)
Print the structure of this expression tree. |
protected void |
dumpTree(java.io.PrintWriter out,
java.lang.String indent)
Print the structure of this expression tree. |
static boolean |
matchPattern(java.lang.String pat,
java.lang.String s)
Determine if a string matches a pattern string. |
protected static int |
matchSubpattern(java.lang.String pat,
int patOff,
java.lang.String str,
int strOff)
Determine if a substring matches a pattern substring. |
void |
simplify()
Simplify this query expression tree. |
java.lang.String |
toString()
Convert this expression tree into a printable text string. |
protected void |
writeAsXml(java.io.BufferedWriter out,
java.lang.String indent)
Print this query expression tree as XML. |
void |
writeAsXml(java.io.Writer out)
Print this query expression tree as XML. |
protected void |
writeStringAsXml(java.io.BufferedWriter out,
java.lang.String indent,
java.lang.String arg)
Print a query expression string argument tree as XML. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int SERIES
public static final java.lang.String OP_NOP
public static final java.lang.String OP_VALUE
public static final java.lang.String OP_NOT
public static final java.lang.String OP_AND
public static final java.lang.String OP_OR
public static final java.lang.String OP_LIST
public static final java.lang.String OP_IS
public static final java.lang.String OP_EQ
public static final java.lang.String OP_NE
public static final java.lang.String OP_LT
public static final java.lang.String OP_LE
public static final java.lang.String OP_GT
public static final java.lang.String OP_GE
public static final java.lang.String OP_EXPO
public static final java.lang.String OP_MUL
public static final java.lang.String OP_DIV
public static final java.lang.String OP_MOD
public static final java.lang.String OP_ADD
public static final java.lang.String OP_SUB
public static final java.lang.String OP_CONCAT
public static final java.lang.String OP_POS
public static final java.lang.String OP_NEG
public static final java.lang.String OP_MEMBER
public static final java.lang.String OP_SUBSCR
public static final java.lang.String OP_CONTAINS
public static final java.lang.String OP_LIKE
public static final java.lang.String OP_LIKEFILE
public static final java.lang.String OP_IN
public static final java.lang.String OP_BETWEEN
public static final java.lang.String OP_NULL
public java.lang.String m_op
public java.lang.Object m_arg1
QueryExpr or a String.
public java.lang.Object m_arg2
QueryExpr or a String.
| Constructor Detail |
public QueryExpr()
| Method Detail |
public static boolean matchPattern(java.lang.String pat,
java.lang.String s)
pat - An SQL pattern string.
A pattern is composed of regular characters and
special pattern matching characters, which are:
s - A string to compare against pattern pat.
protected static int matchSubpattern(java.lang.String pat,
int patOff,
java.lang.String str,
int strOff)
pat - A pattern string.patOff - The index of the first (leftmost) character within pattern string
pat to match.str - A string to compare against pattern pat.strOff - The index of the first (leftmost) character within string str to
match.
matchPattern(java.lang.String, java.lang.String)protected static java.lang.String asQuotedOperand(java.lang.String s)
s - A string.
public java.lang.String toString()
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
java.lang.CloneNotSupportedException - Thrown if any of the node in this expression tree cannot be cloned.
public void writeAsXml(java.io.Writer out)
throws java.io.IOException
For example, given the query expression:
len > 80 and rec.type not = 'T'
the following XML is generated for it:
<query>
<and>
<gt>
<arg>len</arg>
<arg>80</arg>
</gt>
<not>
<eq>
<member>
<arg>rec</arg>
<arg>type</arg>
</member>
<arg>'T'</arg>
</eq>
</not>
</and>
</query>
out - Output stream to write to.
java.io.IOException - Thrown if an I/O (write) error occurs.public void dump(java.io.Writer out)
out - An output stream to write to.public void dump(java.io.OutputStream out)
out - An output stream to write to.
public void simplify()
throws java.lang.Exception
Replaces the following query subexpressions with equivalent, but simpler, subexpressions:
"X between A and B" replaced with "X >= A and X <= B"
"X in ( A, B, C )" replaced with "X = A or X = B or X = C"
"not X = A" replaced with "X <> A"
"not not X = A" replaced with "X = A"
In other words, the following subexpression trees are replaced with simpler equivalent subtrees:
| Before | After |
|---|---|
between
"rec_id"
and
"'A000'"
"'B999'"
|
and
ge
"rec_id"
"'A000'"
le
"rec_id"
"'B999'"
|
in
"pay-type"
list
"'WK'"
list
"'HR'"
list
"'YR'"
|
or
eq
"pay-type"
"'WK'"
or
eq
"pay-type"
"'HR'"
eq
"pay-type"
"'YR'"
|
not
gt
"Amt"
"25.00"
|
le "Amt" "25.00" |
not
not
eq
"Amt"
"50.00"
|
eq "Amt" "50.00" |
java.lang.Exception - Thrown if this expression tree is malformed.
protected void dumpTree(java.io.PrintWriter out,
java.lang.String indent)
This method is called by methods dump(Writer) and
dump(OutputStream).
Example
Parsing the expression:
name like "sarah%conner" and ( birth.date >= '1996-06-14' )
results in an expression tree that is printed like this:
and
like
name
"sarah%conner"
ge
birth.date
'1996-06-14'
out - An output stream to write to.indent - Leading indentation.dump(Writer),
dump(OutputStream)protected void buildString(java.lang.StringBuffer text)
This method is called by method toString().
text - A string buffer to append the text string representation of this
subexpression to.toString()
protected void buildString(java.lang.Object arg,
java.lang.StringBuffer text)
This method is called by method toString().
arg - An operand to append, which is either a String or an
QueryExpr subtree. if it is a String, it will be
delimited with quotes as necessary.text - A string buffer to append the text string representation of this
subexpression to.toString(),
buildString(StringBuffer)
protected void writeAsXml(java.io.BufferedWriter out,
java.lang.String indent)
throws java.io.IOException
This method is called by method writeAsXml().
out - Output stream to write to.indent - Indentation prefix for each line of XML text output.
java.io.IOException - Thrown if an I/O (write) error occurs.writeAsXml
protected void writeStringAsXml(java.io.BufferedWriter out,
java.lang.String indent,
java.lang.String arg)
throws java.io.IOException
This method is called by method writeAsXml().
out - Output stream to write to.indent - Indentation prefix for each line of XML text output.arg - An expression operand from a query expression tree.
java.io.IOException - Thrown if an I/O (write) error occurs.writeAsXml
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||