feat(jsqlparser): 首次提交

This commit is contained in:
2026-01-21 20:50:35 +08:00
commit dc8ea30850
461 changed files with 61538 additions and 0 deletions

View File

@@ -0,0 +1 @@
Dual licensed under GNU LGPL 2.1 or Apache License 2.0

View File

@@ -0,0 +1,710 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
(This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.)
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random
Hacker.
{signature of Ty Coon}, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!
*********************************************************************************************
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,10 @@
###
# #%L
# JSQLParser library
# %%
# Copyright (C) 2004 - 2019 JSQLParser
# %%
# Dual licensed under GNU LGPL 2.1 or Apache License 2.0
# #L%
###
dual_lgpl_ap2=Dual License GNU LGPL 2.1 or Apache License 2.0

View File

@@ -0,0 +1,55 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2024 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
module net.sf.jsqlparser {
requires java.sql;
requires java.logging;
exports net.sf.jsqlparser;
exports net.sf.jsqlparser.expression;
exports net.sf.jsqlparser.expression.operators.arithmetic;
exports net.sf.jsqlparser.expression.operators.conditional;
exports net.sf.jsqlparser.expression.operators.relational;
exports net.sf.jsqlparser.parser;
exports net.sf.jsqlparser.parser.feature;
exports net.sf.jsqlparser.schema;
exports net.sf.jsqlparser.statement;
exports net.sf.jsqlparser.statement.alter;
exports net.sf.jsqlparser.statement.alter.sequence;
exports net.sf.jsqlparser.statement.analyze;
exports net.sf.jsqlparser.statement.comment;
exports net.sf.jsqlparser.statement.create.function;
exports net.sf.jsqlparser.statement.create.index;
exports net.sf.jsqlparser.statement.create.procedure;
exports net.sf.jsqlparser.statement.create.schema;
exports net.sf.jsqlparser.statement.create.sequence;
exports net.sf.jsqlparser.statement.create.synonym;
exports net.sf.jsqlparser.statement.create.table;
exports net.sf.jsqlparser.statement.create.view;
exports net.sf.jsqlparser.statement.delete;
exports net.sf.jsqlparser.statement.drop;
exports net.sf.jsqlparser.statement.execute;
exports net.sf.jsqlparser.statement.grant;
exports net.sf.jsqlparser.statement.insert;
exports net.sf.jsqlparser.statement.merge;
exports net.sf.jsqlparser.statement.refresh;
exports net.sf.jsqlparser.statement.select;
exports net.sf.jsqlparser.statement.show;
exports net.sf.jsqlparser.statement.truncate;
exports net.sf.jsqlparser.statement.update;
exports net.sf.jsqlparser.statement.upsert;
exports net.sf.jsqlparser.util;
exports net.sf.jsqlparser.util.cnfexpression;
exports net.sf.jsqlparser.util.deparser;
exports net.sf.jsqlparser.util.validation;
exports net.sf.jsqlparser.util.validation.allowedtypes;
exports net.sf.jsqlparser.util.validation.feature;
exports net.sf.jsqlparser.util.validation.metadata;
exports net.sf.jsqlparser.util.validation.validator;
}

View File

@@ -0,0 +1,32 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser;
public class JSQLParserException extends Exception {
private static final long serialVersionUID = -4200894355696788796L;
public JSQLParserException() {
super();
}
public JSQLParserException(String message, Throwable cause) {
super(message, cause);
}
public JSQLParserException(String message) {
super(message);
}
public JSQLParserException(Throwable cause) {
super(cause == null ? null : cause.getMessage(), cause);
}
}

View File

@@ -0,0 +1,24 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2020 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser;
import java.io.Serializable;
/**
* <p>
* A marker interface for jsqlparser-model-classes.
* </p>
* <p>
* The datastructure where the sql syntax is represented by a tree consists of {@link Model}'s
* </p>
*/
public interface Model extends Serializable {
}

View File

@@ -0,0 +1,126 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import net.sf.jsqlparser.statement.create.table.ColDataType;
public class Alias implements Serializable {
private String name;
private boolean useAs = true;
private List<AliasColumn> aliasColumns;
public Alias(String name) {
this.name = name;
}
public Alias(String name, boolean useAs) {
this.name = name;
this.useAs = useAs;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isUseAs() {
return useAs;
}
public void setUseAs(boolean useAs) {
this.useAs = useAs;
}
public List<AliasColumn> getAliasColumns() {
return aliasColumns;
}
public void setAliasColumns(List<AliasColumn> aliasColumns) {
this.aliasColumns = aliasColumns;
}
@Override
public String toString() {
String alias = (useAs ? " AS " : " ") + name;
if (aliasColumns != null && !aliasColumns.isEmpty()) {
StringBuilder ac = new StringBuilder();
for (AliasColumn col : aliasColumns) {
if (ac.length() > 0) {
ac.append(", ");
}
ac.append(col.name);
if (col.colDataType != null) {
ac.append(" ").append(col.colDataType.toString());
}
}
alias += "(" + ac + ")";
}
return alias;
}
public Alias withName(String name) {
this.setName(name);
return this;
}
public Alias withUseAs(boolean useAs) {
this.setUseAs(useAs);
return this;
}
public Alias withAliasColumns(List<AliasColumn> aliasColumns) {
this.setAliasColumns(aliasColumns);
return this;
}
public Alias addAliasColumns(AliasColumn... aliasColumns) {
List<AliasColumn> collection =
Optional.ofNullable(getAliasColumns()).orElseGet(ArrayList::new);
Collections.addAll(collection, aliasColumns);
return this.withAliasColumns(collection);
}
public Alias addAliasColumns(Collection<? extends AliasColumn> aliasColumns) {
List<AliasColumn> collection =
Optional.ofNullable(getAliasColumns()).orElseGet(ArrayList::new);
collection.addAll(aliasColumns);
return this.withAliasColumns(collection);
}
public static class AliasColumn implements Serializable {
public final String name;
public final ColDataType colDataType;
public AliasColumn(String name, ColDataType colDataType) {
Objects.requireNonNull(name);
this.name = name;
this.colDataType = colDataType;
}
public AliasColumn(String name) {
this(name, null);
}
}
}

View File

@@ -0,0 +1,25 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class AllValue extends ASTNodeAccessImpl implements Expression {
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return "ALL";
}
}

View File

@@ -0,0 +1,452 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.select.Limit;
import net.sf.jsqlparser.statement.select.OrderByElement;
import java.util.List;
import static java.util.stream.Collectors.joining;
/**
* Analytic function. The name of the function is variable but the parameters following the special
* analytic function path. e.g. row_number() over (order by test). Additionally, there can be an
* expression for an analytical aggregate like sum(col) or the "all columns" wildcard like count(*).
*
* @author tw
*/
public class AnalyticExpression extends ASTNodeAccessImpl implements Expression {
private String name;
private Expression expression;
private Expression offset;
private Expression defaultValue;
private boolean allColumns = false;
private KeepExpression keep = null;
private AnalyticType type = AnalyticType.OVER;
private boolean distinct = false;
private boolean unique = false;
private boolean ignoreNullsOutside = false; // IGNORE NULLS outside function parameters
private Expression filterExpression = null;
private List<OrderByElement> funcOrderBy = null;
private String windowName = null; // refers to an external window definition (paritionBy,
// orderBy, windowElement)
private WindowDefinition windowDef = new WindowDefinition();
private Function.HavingClause havingClause;
private Function.NullHandling nullHandling = null;
private Limit limit = null;
public AnalyticExpression() {}
public AnalyticExpression(Function function) {
this.name = String.join(" ", function.getMultipartName());
this.allColumns = function.isAllColumns();
this.distinct = function.isDistinct();
this.unique = function.isUnique();
ExpressionList<? extends Expression> list = function.getParameters();
if (list != null) {
if (list.size() > 3) {
throw new IllegalArgumentException(
"function object not valid to initialize analytic expression");
}
expression = list.get(0);
if (list.size() > 1) {
offset = list.get(1);
}
if (list.size() > 2) {
defaultValue = list.get(2);
}
}
this.havingClause = function.getHavingClause();
this.ignoreNullsOutside = function.isIgnoreNullsOutside();
this.nullHandling = function.getNullHandling();
this.funcOrderBy = function.getOrderByElements();
this.limit = function.getLimit();
this.keep = function.getKeep();
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public List<OrderByElement> getOrderByElements() {
return windowDef.orderBy.getOrderByElements();
}
public void setOrderByElements(List<OrderByElement> orderByElements) {
windowDef.orderBy.setOrderByElements(orderByElements);
}
public KeepExpression getKeep() {
return keep;
}
public void setKeep(KeepExpression keep) {
this.keep = keep;
}
public ExpressionList<?> getPartitionExpressionList() {
return windowDef.partitionBy.getPartitionExpressionList();
}
public void setPartitionExpressionList(ExpressionList<?> partitionExpressionList) {
setPartitionExpressionList(partitionExpressionList, false);
}
public void setPartitionExpressionList(ExpressionList<?> partitionExpressionList,
boolean brackets) {
windowDef.partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
}
public boolean isPartitionByBrackets() {
return windowDef.partitionBy.isBrackets();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
public Expression getOffset() {
return offset;
}
public void setOffset(Expression offset) {
this.offset = offset;
}
public Expression getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(Expression defaultValue) {
this.defaultValue = defaultValue;
}
public WindowElement getWindowElement() {
return windowDef.windowElement;
}
public void setWindowElement(WindowElement windowElement) {
windowDef.windowElement = windowElement;
}
public AnalyticType getType() {
return type;
}
public void setType(AnalyticType type) {
this.type = type;
}
public boolean isDistinct() {
return distinct;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isUnique() {
return unique;
}
public void setUnique(boolean unique) {
this.unique = unique;
}
public boolean isIgnoreNulls() {
return this.nullHandling == Function.NullHandling.IGNORE_NULLS;
}
public void setIgnoreNulls(boolean ignoreNulls) {
this.nullHandling = ignoreNulls ? Function.NullHandling.IGNORE_NULLS : null;
}
public boolean isIgnoreNullsOutside() {
return ignoreNullsOutside;
}
public void setIgnoreNullsOutside(boolean ignoreNullsOutside) {
this.ignoreNullsOutside = ignoreNullsOutside;
}
public String getWindowName() {
return windowName;
}
public void setWindowName(String windowName) {
this.windowName = windowName;
}
public WindowDefinition getWindowDefinition() {
return windowDef;
}
public void setWindowDefinition(WindowDefinition windowDef) {
this.windowDef = windowDef;
}
public Function.HavingClause getHavingClause() {
return havingClause;
}
public AnalyticExpression setHavingClause(Function.HavingClause havingClause) {
this.havingClause = havingClause;
return this;
}
public AnalyticExpression setHavingClause(String havingType, Expression expression) {
this.havingClause = new Function.HavingClause(
Function.HavingClause.HavingType.valueOf(havingType.trim().toUpperCase()),
expression);
return this;
}
public Function.NullHandling getNullHandling() {
return nullHandling;
}
public AnalyticExpression setNullHandling(Function.NullHandling nullHandling) {
this.nullHandling = nullHandling;
return this;
}
public Limit getLimit() {
return limit;
}
public AnalyticExpression setLimit(Limit limit) {
this.limit = limit;
return this;
}
@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity",
"PMD.MissingBreakInSwitch"})
public String toString() {
StringBuilder b = new StringBuilder();
b.append(name).append("(");
if (isDistinct()) {
b.append("DISTINCT ");
}
if (expression != null) {
b.append(expression);
if (offset != null) {
b.append(", ").append(offset);
if (defaultValue != null) {
b.append(", ").append(defaultValue);
}
}
} else if (isAllColumns()) {
b.append("*");
}
if (havingClause != null) {
havingClause.appendTo(b);
}
if (nullHandling != null && !ignoreNullsOutside) {
switch (nullHandling) {
case IGNORE_NULLS:
b.append(" IGNORE NULLS");
break;
case RESPECT_NULLS:
b.append(" RESPECT NULLS");
break;
}
}
if (funcOrderBy != null) {
b.append(" ORDER BY ");
b.append(funcOrderBy.stream().map(OrderByElement::toString).collect(joining(", ")));
}
if (limit != null) {
b.append(limit);
}
b.append(") ");
if (keep != null) {
b.append(keep).append(" ");
}
if (filterExpression != null) {
b.append("FILTER (WHERE ");
b.append(filterExpression);
b.append(")");
if (type != AnalyticType.FILTER_ONLY) {
b.append(" ");
}
}
if (nullHandling != null && ignoreNullsOutside) {
switch (nullHandling) {
case IGNORE_NULLS:
b.append(" IGNORE NULLS ");
break;
case RESPECT_NULLS:
b.append(" RESPECT NULLS ");
break;
}
}
switch (type) {
case FILTER_ONLY:
return b.toString();
case WITHIN_GROUP:
b.append("WITHIN GROUP");
break;
case WITHIN_GROUP_OVER:
b.append("WITHIN GROUP (");
windowDef.orderBy.toStringOrderByElements(b);
b.append(") OVER (");
windowDef.partitionBy.toStringPartitionBy(b);
b.append(")");
break;
default:
b.append("OVER");
}
if (windowName != null) {
b.append(" ").append(windowName);
} else if (type != AnalyticType.WITHIN_GROUP_OVER) {
b.append(" ");
b.append(windowDef.toString());
}
return b.toString();
}
public boolean isAllColumns() {
return allColumns;
}
public void setAllColumns(boolean allColumns) {
this.allColumns = allColumns;
}
public Expression getFilterExpression() {
return filterExpression;
}
public void setFilterExpression(Expression filterExpression) {
this.filterExpression = filterExpression;
}
public AnalyticExpression withName(String name) {
this.setName(name);
return this;
}
public AnalyticExpression withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public AnalyticExpression withOffset(Expression offset) {
this.setOffset(offset);
return this;
}
public AnalyticExpression withDefaultValue(Expression defaultValue) {
this.setDefaultValue(defaultValue);
return this;
}
public AnalyticExpression withAllColumns(boolean allColumns) {
this.setAllColumns(allColumns);
return this;
}
public AnalyticExpression withKeep(KeepExpression keep) {
this.setKeep(keep);
return this;
}
public AnalyticExpression withType(AnalyticType type) {
this.setType(type);
return this;
}
public AnalyticExpression withDistinct(boolean distinct) {
this.setDistinct(distinct);
return this;
}
public AnalyticExpression withUnique(boolean unique) {
this.setUnique(unique);
return this;
}
public AnalyticExpression withIgnoreNulls(boolean ignoreNulls) {
this.setIgnoreNulls(ignoreNulls);
return this;
}
public AnalyticExpression withFilterExpression(Expression filterExpression) {
this.setFilterExpression(filterExpression);
return this;
}
public AnalyticExpression withWindowElement(WindowElement windowElement) {
this.setWindowElement(windowElement);
return this;
}
public <E extends Expression> E getExpression(Class<E> type) {
return type.cast(getExpression());
}
public <E extends Expression> E getOffset(Class<E> type) {
return type.cast(getOffset());
}
public <E extends Expression> E getDefaultValue(Class<E> type) {
return type.cast(getDefaultValue());
}
public <E extends Expression> E getFilterExpression(Class<E> type) {
return type.cast(getFilterExpression());
}
public List<OrderByElement> getFuncOrderBy() {
return funcOrderBy;
}
public void setFuncOrderBy(List<OrderByElement> funcOrderBy) {
this.funcOrderBy = funcOrderBy;
}
}

View File

@@ -0,0 +1,18 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
public enum AnalyticType {
OVER, WITHIN_GROUP, WITHIN_GROUP_OVER, FILTER_ONLY;
public static AnalyticType from(String type) {
return Enum.valueOf(AnalyticType.class, type.toUpperCase());
}
}

View File

@@ -0,0 +1,48 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.select.Select;
/**
* Combines ANY and SOME expressions.
*
* @author toben
*/
public class AnyComparisonExpression extends ASTNodeAccessImpl implements Expression {
private final Select select;
private final AnyType anyType;
public AnyComparisonExpression(AnyType anyType, Select select) {
this.anyType = anyType;
this.select = select;
}
public Select getSelect() {
return select;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public AnyType getAnyType() {
return anyType;
}
@Override
public String toString() {
String s = anyType.name() + select;
return s;
}
}

View File

@@ -0,0 +1,18 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
public enum AnyType {
ANY, SOME, ALL;
public static AnyType from(String type) {
return Enum.valueOf(AnyType.class, type.toUpperCase());
}
}

View File

@@ -0,0 +1,60 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class ArrayConstructor extends ASTNodeAccessImpl implements Expression {
private ExpressionList<?> expressions;
private boolean arrayKeyword;
public ArrayConstructor(ExpressionList<?> expressions, boolean arrayKeyword) {
this.expressions = expressions;
this.arrayKeyword = arrayKeyword;
}
public ArrayConstructor(Expression... expressions) {
this(new ExpressionList<Expression>(expressions), false);
}
public ExpressionList<?> getExpressions() {
return expressions;
}
public void setExpressions(ExpressionList<?> expressions) {
this.expressions = expressions;
}
public boolean isArrayKeyword() {
return arrayKeyword;
}
public void setArrayKeyword(boolean arrayKeyword) {
this.arrayKeyword = arrayKeyword;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (arrayKeyword) {
sb.append("ARRAY");
}
sb.append("[");
sb.append(expressions.toString());
sb.append("]");
return sb.toString();
}
}

View File

@@ -0,0 +1,117 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class ArrayExpression extends ASTNodeAccessImpl implements Expression {
private Expression objExpression;
private Expression indexExpression;
private Expression startIndexExpression;
private Expression stopIndexExpression;
public ArrayExpression() {
// empty constructor
}
public ArrayExpression(Expression objExpression, Expression indexExpression,
Expression startIndexExpression, Expression stopIndexExpression) {
this.objExpression = objExpression;
this.indexExpression = indexExpression;
this.startIndexExpression = startIndexExpression;
this.stopIndexExpression = stopIndexExpression;
}
public ArrayExpression(Expression objExpression, Expression indexExpression) {
this(objExpression, indexExpression, null, null);
}
public ArrayExpression(Expression objExpression, Expression startIndexExpression,
Expression stopIndexExpression) {
this(objExpression, null, startIndexExpression, stopIndexExpression);
}
public Expression getObjExpression() {
return objExpression;
}
public void setObjExpression(Expression objExpression) {
this.objExpression = objExpression;
}
public Expression getIndexExpression() {
return indexExpression;
}
public void setIndexExpression(Expression indexExpression) {
this.indexExpression = indexExpression;
}
public Expression getStartIndexExpression() {
return startIndexExpression;
}
public void setStartIndexExpression(Expression startIndexExpression) {
this.startIndexExpression = startIndexExpression;
}
public Expression getStopIndexExpression() {
return stopIndexExpression;
}
public void setStopIndexExpression(Expression stopIndexExpression) {
this.stopIndexExpression = stopIndexExpression;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
if (indexExpression != null) {
return objExpression.toString() + "[" + indexExpression.toString() + "]";
} else {
return objExpression.toString() + "[" +
(startIndexExpression == null ? "" : startIndexExpression.toString()) +
":" +
(stopIndexExpression == null ? "" : stopIndexExpression.toString()) +
"]";
}
}
public ArrayExpression withObjExpression(Expression objExpression) {
this.setObjExpression(objExpression);
return this;
}
public ArrayExpression withIndexExpression(Expression indexExpression) {
this.setIndexExpression(indexExpression);
return this;
}
public ArrayExpression withRangeExpression(Expression startIndexExpression,
Expression stopIndexExpression) {
this.setStartIndexExpression(startIndexExpression);
this.setStopIndexExpression(stopIndexExpression);
return this;
}
public <E extends Expression> E getObjExpression(Class<E> type) {
return type.cast(getObjExpression());
}
public <E extends Expression> E getIndexExpression(Class<E> type) {
return type.cast(getIndexExpression());
}
}

View File

@@ -0,0 +1,266 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseLeftShift;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseRightShift;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor;
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
import net.sf.jsqlparser.expression.operators.arithmetic.IntegerDivision;
import net.sf.jsqlparser.expression.operators.arithmetic.Modulo;
import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication;
import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.conditional.XorExpression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Iterator;
/**
* A basic class for binary expressions, that is expressions having a left member and a right member
* which are in turn expressions.
*/
public abstract class BinaryExpression extends ASTNodeAccessImpl implements Expression {
private Expression leftExpression;
private Expression rightExpression;
public BinaryExpression() {}
public BinaryExpression(Expression leftExpression, Expression rightExpression) {
this.leftExpression = leftExpression;
this.rightExpression = rightExpression;
}
public static Expression build(Class<? extends BinaryExpression> clz, Expression... expressions)
throws NoSuchMethodException, InvocationTargetException, InstantiationException,
IllegalAccessException {
switch (expressions.length) {
case 0:
return new NullValue();
case 1:
return expressions[0];
default:
Iterator<Expression> it = Arrays.stream(expressions).iterator();
Expression leftExpression = it.next();
Expression rightExpression = it.next();
BinaryExpression binaryExpression =
clz.getConstructor(Expression.class, Expression.class)
.newInstance(leftExpression, rightExpression);
while (it.hasNext()) {
rightExpression = it.next();
binaryExpression = clz.getConstructor(Expression.class, Expression.class)
.newInstance(binaryExpression, rightExpression);
}
return binaryExpression;
}
}
public static Expression add(Expression... expressions) {
try {
return build(Addition.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression bitAnd(Expression... expressions) {
try {
return build(BitwiseAnd.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression bitShiftLeft(Expression... expressions) {
try {
return build(BitwiseLeftShift.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression multiply(Expression... expressions) {
try {
return build(Multiplication.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression bitOr(Expression... expressions) {
try {
return build(BitwiseOr.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression bitShiftRight(Expression... expressions) {
try {
return build(BitwiseRightShift.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression bitXor(Expression... expressions) {
try {
return build(BitwiseXor.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression concat(Expression... expressions) {
try {
return build(Concat.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression divide(Expression... expressions) {
try {
return build(Division.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression divideInt(Expression... expressions) {
try {
return build(IntegerDivision.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression modulo(Expression... expressions) {
try {
return build(Modulo.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression subtract(Expression... expressions) {
try {
return build(Subtraction.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression or(Expression... expressions) {
try {
return build(OrExpression.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression xor(Expression... expressions) {
try {
return build(XorExpression.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public static Expression and(Expression... expressions) {
try {
return build(AndExpression.class, expressions);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) {
// this should never happen, at least I don't see how
throw new RuntimeException(e);
}
}
public Expression getLeftExpression() {
return leftExpression;
}
public void setLeftExpression(Expression expression) {
leftExpression = expression;
}
public Expression getRightExpression() {
return rightExpression;
}
public void setRightExpression(Expression expression) {
rightExpression = expression;
}
public BinaryExpression withLeftExpression(Expression expression) {
setLeftExpression(expression);
return this;
}
public BinaryExpression withRightExpression(Expression expression) {
setRightExpression(expression);
return this;
}
@Override
public String toString() {
return // (not ? "NOT " : "") +
getLeftExpression() + " " + getStringExpression() + " " + getRightExpression();
}
public abstract String getStringExpression();
public <E extends Expression> E getLeftExpression(Class<E> type) {
return type.cast(getLeftExpression());
}
public <E extends Expression> E getRightExpression(Class<E> type) {
return type.cast(getRightExpression());
}
}

View File

@@ -0,0 +1,182 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.select.PlainSelect;
/**
* CASE/WHEN expression.
* <p>
* Syntax:
*
* <pre>
* <code>
* CASE
* WHEN condition THEN expression
* [WHEN condition THEN expression]...
* [ELSE expression]
* END
* </code>
* </pre>
*
* <br>
* or <br>
* <br>
*
* <pre>
* <code>
* CASE expression
* WHEN condition THEN expression
* [WHEN condition THEN expression]...
* [ELSE expression]
* END
* </code>
* </pre>
*/
public class CaseExpression extends ASTNodeAccessImpl implements Expression {
private boolean usingBrackets = false;
private Expression switchExpression;
private List<WhenClause> whenClauses;
private Expression elseExpression;
public CaseExpression() {}
public CaseExpression(WhenClause... whenClauses) {
this.whenClauses = Arrays.asList(whenClauses);
}
public CaseExpression(Expression elseExpression, WhenClause... whenClauses) {
this.elseExpression = elseExpression;
this.whenClauses = Arrays.asList(whenClauses);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public Expression getSwitchExpression() {
return switchExpression;
}
public void setSwitchExpression(Expression switchExpression) {
this.switchExpression = switchExpression;
}
/**
* @return Returns the elseExpression.
*/
public Expression getElseExpression() {
return elseExpression;
}
/**
* @param elseExpression The elseExpression to set.
*/
public void setElseExpression(Expression elseExpression) {
this.elseExpression = elseExpression;
}
/**
* @return Returns the whenClauses.
*/
public List<WhenClause> getWhenClauses() {
return whenClauses;
}
/**
* @param whenClauses The whenClauses to set.
*/
public void setWhenClauses(List<WhenClause> whenClauses) {
this.whenClauses = whenClauses;
}
@Override
public String toString() {
return (usingBrackets ? "(" : "") + "CASE "
+ ((switchExpression != null) ? switchExpression + " " : "")
+ PlainSelect.getStringList(whenClauses, false, false) + " "
+ ((elseExpression != null) ? "ELSE " + elseExpression + " " : "") + "END"
+ (usingBrackets ? ")" : "");
}
public CaseExpression withSwitchExpression(Expression switchExpression) {
this.setSwitchExpression(switchExpression);
return this;
}
public CaseExpression withWhenClauses(WhenClause... whenClauses) {
return this.withWhenClauses(Arrays.asList(whenClauses));
}
public CaseExpression withWhenClauses(List<WhenClause> whenClauses) {
this.setWhenClauses(whenClauses);
return this;
}
public CaseExpression withElseExpression(Expression elseExpression) {
this.setElseExpression(elseExpression);
return this;
}
public CaseExpression addWhenClauses(WhenClause... whenClauses) {
List<WhenClause> collection =
Optional.ofNullable(getWhenClauses()).orElseGet(ArrayList::new);
Collections.addAll(collection, whenClauses);
return this.withWhenClauses(collection);
}
public CaseExpression addWhenClauses(Collection<? extends WhenClause> whenClauses) {
List<WhenClause> collection =
Optional.ofNullable(getWhenClauses()).orElseGet(ArrayList::new);
collection.addAll(whenClauses);
return this.withWhenClauses(collection);
}
public <E extends Expression> E getSwitchExpression(Class<E> type) {
return type.cast(getSwitchExpression());
}
public <E extends Expression> E getElseExpression(Class<E> type) {
return type.cast(getElseExpression());
}
/**
* @return the usingBrackets
*/
public boolean isUsingBrackets() {
return usingBrackets;
}
/**
* @param usingBrackets the usingBrackets to set
*/
public void setUsingBrackets(boolean usingBrackets) {
this.usingBrackets = usingBrackets;
}
/**
* @param usingBrackets the usingBrackets to set
*/
public CaseExpression withUsingBrackets(boolean usingBrackets) {
this.usingBrackets = usingBrackets;
return this;
}
}

View File

@@ -0,0 +1,295 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.create.table.ColDataType;
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
import net.sf.jsqlparser.statement.select.Select;
import java.util.ArrayList;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CastExpression extends ASTNodeAccessImpl implements Expression {
private final static Pattern PATTERN =
Pattern.compile("(^[a-z0-9_]*){1}", Pattern.CASE_INSENSITIVE);
public String keyword;
private Expression leftExpression;
private ColDataType colDataType = null;
private ArrayList<ColumnDefinition> columnDefinitions = new ArrayList<>();
private boolean isImplicitCast = false;
// BigQuery specific FORMAT clause:
// https://cloud.google.com/bigquery/docs/reference/standard-sql/conversion_functions#cast_as_date
private String format = null;
public CastExpression(String keyword, Expression leftExpression, String dataType) {
this.keyword = keyword;
this.leftExpression = leftExpression;
this.colDataType = new ColDataType(dataType);
}
// Implicit Cast
public CastExpression(String dataType, String value) {
this.keyword = null;
this.isImplicitCast = true;
this.colDataType = new ColDataType(dataType);
this.leftExpression = new StringValue(value);
}
public CastExpression(ColDataType colDataType, String value) {
this.keyword = null;
this.isImplicitCast = true;
this.colDataType = colDataType;
this.leftExpression = new StringValue(value);
}
public CastExpression(ColDataType colDataType, Long value) {
this.keyword = null;
this.isImplicitCast = true;
this.colDataType = colDataType;
this.leftExpression = new LongValue(value);
}
public CastExpression(ColDataType colDataType, Double value) {
this.keyword = null;
this.isImplicitCast = true;
this.colDataType = colDataType;
this.leftExpression = new DoubleValue(value);
}
public CastExpression(Expression leftExpression, String dataType) {
this.keyword = null;
this.leftExpression = leftExpression;
this.colDataType = new ColDataType(dataType);
}
public CastExpression(String keyword) {
this.keyword = keyword;
}
public CastExpression() {
this("CAST");
}
public static boolean isOf(ColDataType colDataType, DataType... types) {
return Set.of(types).contains(DataType.from(colDataType.getDataType()));
}
public static boolean isTime(ColDataType colDataType) {
return isOf(colDataType, DataType.TIME, DataType.TIME_WITH_TIME_ZONE,
DataType.TIME_WITHOUT_TIME_ZONE);
}
public static boolean isTimeStamp(ColDataType colDataType) {
return isOf(colDataType, DataType.TIMESTAMP_NS, DataType.TIMESTAMP,
DataType.TIMESTAMP_WITHOUT_TIME_ZONE,
DataType.DATETIME, DataType.TIMESTAMP_MS, DataType.TIMESTAMP_S,
DataType.TIMESTAMPTZ, DataType.TIMESTAMP_WITH_TIME_ZONE);
}
public static boolean isDate(ColDataType colDataType) {
return isOf(colDataType, DataType.DATE);
}
public static boolean isBLOB(ColDataType colDataType) {
return isOf(colDataType, DataType.BLOB, DataType.BYTEA, DataType.BINARY, DataType.VARBINARY,
DataType.BYTES, DataType.VARBYTE);
}
public static boolean isFloat(ColDataType colDataType) {
return isOf(colDataType, DataType.REAL, DataType.FLOAT4, DataType.FLOAT, DataType.DOUBLE,
DataType.DOUBLE_PRECISION, DataType.FLOAT8);
}
public static boolean isInteger(ColDataType colDataType) {
return isOf(colDataType, DataType.TINYINT, DataType.INT1, DataType.SMALLINT, DataType.INT2,
DataType.SHORT, DataType.INTEGER, DataType.INT4, DataType.INT, DataType.SIGNED,
DataType.BIGINT, DataType.INT8, DataType.LONG, DataType.HUGEINT, DataType.UTINYINT,
DataType.USMALLINT, DataType.UINTEGER, DataType.UBIGINT, DataType.UHUGEINT);
}
public static boolean isDecimal(ColDataType colDataType) {
return isOf(colDataType, DataType.DECIMAL, DataType.NUMBER, DataType.NUMERIC);
}
public static boolean isText(ColDataType colDataType) {
return isOf(colDataType, DataType.VARCHAR, DataType.NVARCHAR, DataType.CHAR, DataType.NCHAR,
DataType.BPCHAR, DataType.STRING, DataType.TEXT, DataType.CLOB);
}
public ColDataType getColDataType() {
return colDataType;
}
public void setColDataType(ColDataType colDataType) {
this.colDataType = colDataType;
}
public ArrayList<ColumnDefinition> getColumnDefinitions() {
return columnDefinitions;
}
public void addColumnDefinition(ColumnDefinition columnDefinition) {
this.columnDefinitions.add(columnDefinition);
}
public Expression getLeftExpression() {
return leftExpression;
}
public void setLeftExpression(Expression expression) {
leftExpression = expression;
}
public boolean isImplicitCast() {
return isImplicitCast;
}
public CastExpression setImplicitCast(boolean implicitCast) {
isImplicitCast = implicitCast;
return this;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Deprecated
public boolean isUseCastKeyword() {
return keyword != null && !keyword.isEmpty();
}
@Deprecated
public void setUseCastKeyword(boolean useCastKeyword) {
if (useCastKeyword) {
if (keyword == null || keyword.isEmpty()) {
keyword = "CAST";
}
} else {
keyword = null;
}
}
public String getFormat() {
return format;
}
public CastExpression setFormat(String format) {
this.format = format;
return this;
}
@Override
public String toString() {
String formatStr = format != null && !format.isEmpty()
? " FORMAT " + format
: "";
if (isImplicitCast) {
return colDataType + " " + leftExpression;
} else if (keyword != null && !keyword.isEmpty()) {
return columnDefinitions.size() > 1
? keyword + "(" + leftExpression + " AS ROW("
+ Select.getStringList(columnDefinitions) + ")" + formatStr + ")"
: keyword + "(" + leftExpression + " AS " + colDataType.toString() + formatStr
+ ")";
} else {
return leftExpression + "::" + colDataType.toString();
}
}
public CastExpression withType(ColDataType type) {
this.setColDataType(type);
return this;
}
public CastExpression withUseCastKeyword(boolean useCastKeyword) {
this.setUseCastKeyword(useCastKeyword);
return this;
}
public CastExpression withLeftExpression(Expression leftExpression) {
this.setLeftExpression(leftExpression);
return this;
}
public <E extends Expression> E getLeftExpression(Class<E> type) {
return type.cast(getLeftExpression());
}
public boolean isOf(CastExpression anotherCast) {
return this.colDataType.equals(anotherCast.colDataType);
}
public boolean isOf(DataType... types) {
return Set.of(types).contains(DataType.from(colDataType.getDataType()));
}
public boolean isTime() {
return isTime(this.colDataType);
}
public boolean isTimeStamp() {
return isTimeStamp(this.colDataType);
}
public boolean isDate() {
return isDate(this.colDataType);
}
public boolean isBLOB() {
return isBLOB(this.colDataType);
}
public boolean isFloat() {
return isFloat(this.colDataType);
}
public boolean isInteger() {
return isInteger(this.colDataType);
}
public boolean isDecimal() {
return isDecimal(this.colDataType);
}
public boolean isText() {
return isText(this.colDataType);
}
public enum DataType {
ARRAY, BIT, BITSTRING, BLOB, BYTEA, BINARY, VARBINARY, BYTES, BOOLEAN, BOOL, ENUM, INTERVAL, LIST, MAP, STRUCT, TINYINT, INT1, SMALLINT, INT2, SHORT, INTEGER, INT4, INT, SIGNED, BIGINT, INT8, LONG, HUGEINT, UTINYINT, USMALLINT, UINTEGER, UBIGINT, UHUGEINT, DECIMAL, NUMBER, NUMERIC, REAL, FLOAT4, FLOAT, DOUBLE, DOUBLE_PRECISION, FLOAT8, FLOAT64, UUID, VARCHAR, NVARCHAR, CHAR, NCHAR, BPCHAR, STRING, TEXT, CLOB, DATE, TIME, TIME_WITHOUT_TIME_ZONE, TIMETZ, TIME_WITH_TIME_ZONE, TIMESTAMP_NS, TIMESTAMP, TIMESTAMP_WITHOUT_TIME_ZONE, DATETIME, TIMESTAMP_MS, TIMESTAMP_S, TIMESTAMPTZ, TIMESTAMP_WITH_TIME_ZONE, UNKNOWN, VARBYTE;
public static DataType from(String typeStr) {
Matcher matcher = PATTERN.matcher(typeStr.trim().replaceAll("\\s+", "_").toUpperCase());
if (matcher.find()) {
try {
return Enum.valueOf(DataType.class, matcher.group(0));
} catch (Exception ex) {
Logger.getLogger(CastExpression.class.getName()).log(Level.FINE,
"Type " + typeStr + " unknown", ex);
return DataType.UNKNOWN;
}
} else {
Logger.getLogger(CastExpression.class.getName()).log(Level.FINE,
"Type " + typeStr + " unknown");
return DataType.UNKNOWN;
}
}
}
}

View File

@@ -0,0 +1,67 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class CollateExpression extends ASTNodeAccessImpl implements Expression {
private Expression leftExpression;
private String collate;
public CollateExpression() {
// empty constructor
}
public CollateExpression(Expression leftExpression, String collate) {
this.leftExpression = leftExpression;
this.collate = collate;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public Expression getLeftExpression() {
return leftExpression;
}
public void setLeftExpression(Expression leftExpression) {
this.leftExpression = leftExpression;
}
public String getCollate() {
return collate;
}
public void setCollate(String collate) {
this.collate = collate;
}
@Override
public String toString() {
return leftExpression.toString() + " COLLATE " + collate;
}
public CollateExpression withLeftExpression(Expression leftExpression) {
this.setLeftExpression(leftExpression);
return this;
}
public CollateExpression withCollate(String collate) {
this.setCollate(collate);
return this;
}
public <E extends Expression> E getLeftExpression(Class<E> type) {
return type.cast(getLeftExpression());
}
}

View File

@@ -0,0 +1,63 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
/*
* Copyright (C) 2021 JSQLParser.
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
package net.sf.jsqlparser.expression;
import java.util.Objects;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.schema.Column;
/**
* @author are
*/
public class ConnectByRootOperator extends ASTNodeAccessImpl implements Expression {
private final Column column;
public ConnectByRootOperator(Column column) {
this.column = Objects.requireNonNull(column,
"The COLUMN of the ConnectByRoot Operator must not be null");
}
public Column getColumn() {
return column;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public StringBuilder appendTo(StringBuilder builder) {
builder.append("CONNECT_BY_ROOT ").append(column);
return builder;
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
}

View File

@@ -0,0 +1,62 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class DateTimeLiteralExpression extends ASTNodeAccessImpl implements Expression {
private String value;
private DateTime type;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public DateTime getType() {
return type;
}
public void setType(DateTime type) {
this.type = type;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return type.name() + " " + value;
}
public DateTimeLiteralExpression withValue(String value) {
this.setValue(value);
return this;
}
public DateTimeLiteralExpression withType(DateTime type) {
this.setType(type);
return this;
}
public enum DateTime {
DATE, DATETIME, TIME, TIMESTAMP, TIMESTAMPTZ;
public static DateTime from(String dateTimeStr) {
return Enum.valueOf(DateTime.class, dateTimeStr.toUpperCase());
}
}
}

View File

@@ -0,0 +1,62 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.sql.Date;
/**
* A Date in the form {d 'yyyy-mm-dd'}
*/
public class DateValue extends ASTNodeAccessImpl implements Expression {
private Date value;
public DateValue() {
// empty constructor
}
public DateValue(Date value) {
this.value = value;
}
/**
* A Date in the form {d 'yyyy-mm-dd'}
*
* @param value The text presentation of the Date to be parsed.
*/
public DateValue(String value) {
this(Date.valueOf(value.substring(1, value.length() - 1)));
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public Date getValue() {
return value;
}
public void setValue(Date d) {
value = d;
}
@Override
public String toString() {
return "{d '" + value.toString() + "'}";
}
public DateValue withValue(Date value) {
this.setValue(value);
return this;
}
}

View File

@@ -0,0 +1,66 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* Every number with a point or a exponential format is a DoubleValue
*/
public class DoubleValue extends ASTNodeAccessImpl implements Expression {
private Double value;
private String stringValue;
public DoubleValue() {
// empty constructor
}
public DoubleValue(final String value) {
if (value == null || value.length() == 0) {
throw new IllegalArgumentException("value can neither be null nor empty.");
}
String val = value;
if (val.charAt(0) == '+') {
val = val.substring(1);
}
this.value = Double.parseDouble(val);
this.stringValue = val;
}
public DoubleValue(final double value) {
this.value = value;
this.stringValue = String.valueOf(value);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public double getValue() {
return value;
}
public void setValue(Double d) {
value = d;
stringValue = String.valueOf(value);
}
@Override
public String toString() {
return stringValue;
}
public DoubleValue withValue(Double value) {
this.setValue(value);
return this;
}
}

View File

@@ -0,0 +1,26 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.Model;
import net.sf.jsqlparser.parser.ASTNodeAccess;
public interface Expression extends ASTNodeAccess, Model {
<T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context);
default <T> void accept(ExpressionVisitor<T> expressionVisitor) {
this.accept(expressionVisitor, null);
}
;
}

View File

@@ -0,0 +1,644 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseLeftShift;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseRightShift;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor;
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
import net.sf.jsqlparser.expression.operators.arithmetic.IntegerDivision;
import net.sf.jsqlparser.expression.operators.arithmetic.Modulo;
import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication;
import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.conditional.XorExpression;
import net.sf.jsqlparser.expression.operators.relational.Between;
import net.sf.jsqlparser.expression.operators.relational.ContainedBy;
import net.sf.jsqlparser.expression.operators.relational.Contains;
import net.sf.jsqlparser.expression.operators.relational.DoubleAnd;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.ExcludesExpression;
import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.FullTextSearch;
import net.sf.jsqlparser.expression.operators.relational.GeometryDistance;
import net.sf.jsqlparser.expression.operators.relational.GreaterThan;
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
import net.sf.jsqlparser.expression.operators.relational.InExpression;
import net.sf.jsqlparser.expression.operators.relational.IncludesExpression;
import net.sf.jsqlparser.expression.operators.relational.IsBooleanExpression;
import net.sf.jsqlparser.expression.operators.relational.IsDistinctExpression;
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
import net.sf.jsqlparser.expression.operators.relational.LikeExpression;
import net.sf.jsqlparser.expression.operators.relational.Matches;
import net.sf.jsqlparser.expression.operators.relational.MemberOfExpression;
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.AllColumns;
import net.sf.jsqlparser.statement.select.AllTableColumns;
import net.sf.jsqlparser.statement.select.ParenthesedSelect;
import net.sf.jsqlparser.statement.select.Select;
public interface ExpressionVisitor<T> {
<S> T visit(BitwiseRightShift bitwiseRightShift, S context);
default void visit(BitwiseRightShift bitwiseRightShift) {
this.visit(bitwiseRightShift, null);
}
<S> T visit(BitwiseLeftShift bitwiseLeftShift, S context);
default void visit(BitwiseLeftShift bitwiseLeftShift) {
this.visit(bitwiseLeftShift, null);
}
<S> T visit(NullValue nullValue, S context);
default void visit(NullValue nullValue) {
this.visit(nullValue, null);
}
<S> T visit(Function function, S context);
default void visit(Function function) {
this.visit(function, null);
}
<S> T visit(SignedExpression signedExpression, S context);
default void visit(SignedExpression signedExpression) {
this.visit(signedExpression, null);
}
<S> T visit(JdbcParameter jdbcParameter, S context);
default void visit(JdbcParameter jdbcParameter) {
this.visit(jdbcParameter, null);
}
<S> T visit(JdbcNamedParameter jdbcNamedParameter, S context);
default void visit(JdbcNamedParameter jdbcNamedParameter) {
this.visit(jdbcNamedParameter, null);
}
<S> T visit(DoubleValue doubleValue, S context);
default void visit(DoubleValue doubleValue) {
this.visit(doubleValue, null);
}
<S> T visit(LongValue longValue, S context);
default void visit(LongValue longValue) {
this.visit(longValue, null);
}
<S> T visit(HexValue hexValue, S context);
default void visit(HexValue hexValue) {
this.visit(hexValue, null);
}
<S> T visit(DateValue dateValue, S context);
default void visit(DateValue dateValue) {
this.visit(dateValue, null);
}
<S> T visit(TimeValue timeValue, S context);
default void visit(TimeValue timeValue) {
this.visit(timeValue, null);
}
<S> T visit(TimestampValue timestampValue, S context);
default void visit(TimestampValue timestampValue) {
this.visit(timestampValue, null);
}
<S> T visit(StringValue stringValue, S context);
default void visit(StringValue stringValue) {
this.visit(stringValue, null);
}
<S> T visit(Addition addition, S context);
default void visit(Addition addition) {
this.visit(addition, null);
}
<S> T visit(Division division, S context);
default void visit(Division division) {
this.visit(division, null);
}
<S> T visit(IntegerDivision integerDivision, S context);
default void visit(IntegerDivision integerDivision) {
this.visit(integerDivision, null);
}
<S> T visit(Multiplication multiplication, S context);
default void visit(Multiplication multiplication) {
this.visit(multiplication, null);
}
<S> T visit(Subtraction subtraction, S context);
default void visit(Subtraction subtraction) {
this.visit(subtraction, null);
}
<S> T visit(AndExpression andExpression, S context);
default void visit(AndExpression andExpression) {
this.visit(andExpression, null);
}
<S> T visit(OrExpression orExpression, S context);
default void visit(OrExpression orExpression) {
this.visit(orExpression, null);
}
<S> T visit(XorExpression xorExpression, S context);
default void visit(XorExpression xorExpression) {
this.visit(xorExpression, null);
}
<S> T visit(Between between, S context);
default void visit(Between between) {
this.visit(between, null);
}
<S> T visit(OverlapsCondition overlapsCondition, S context);
default void visit(OverlapsCondition overlapsCondition) {
this.visit(overlapsCondition, null);
}
<S> T visit(EqualsTo equalsTo, S context);
default void visit(EqualsTo equalsTo) {
this.visit(equalsTo, null);
}
<S> T visit(GreaterThan greaterThan, S context);
default void visit(GreaterThan greaterThan) {
this.visit(greaterThan, null);
}
<S> T visit(GreaterThanEquals greaterThanEquals, S context);
default void visit(GreaterThanEquals greaterThanEquals) {
this.visit(greaterThanEquals, null);
}
<S> T visit(InExpression inExpression, S context);
default void visit(InExpression inExpression) {
this.visit(inExpression, null);
}
<S> T visit(IncludesExpression includesExpression, S context);
default void visit(IncludesExpression includesExpression) {
this.visit(includesExpression, null);
}
<S> T visit(ExcludesExpression excludesExpression, S context);
default void visit(ExcludesExpression excludesExpression) {
this.visit(excludesExpression, null);
}
<S> T visit(FullTextSearch fullTextSearch, S context);
default void visit(FullTextSearch fullTextSearch) {
this.visit(fullTextSearch, null);
}
<S> T visit(IsNullExpression isNullExpression, S context);
default void visit(IsNullExpression isNullExpression) {
this.visit(isNullExpression, null);
}
<S> T visit(IsBooleanExpression isBooleanExpression, S context);
default void visit(IsBooleanExpression isBooleanExpression) {
this.visit(isBooleanExpression, null);
}
<S> T visit(LikeExpression likeExpression, S context);
default void visit(LikeExpression likeExpression) {
this.visit(likeExpression, null);
}
<S> T visit(MinorThan minorThan, S context);
default void visit(MinorThan minorThan) {
this.visit(minorThan, null);
}
<S> T visit(MinorThanEquals minorThanEquals, S context);
default void visit(MinorThanEquals minorThanEquals) {
this.visit(minorThanEquals, null);
}
<S> T visit(NotEqualsTo notEqualsTo, S context);
default void visit(NotEqualsTo notEqualsTo) {
this.visit(notEqualsTo, null);
}
<S> T visit(DoubleAnd doubleAnd, S context);
default void visit(DoubleAnd doubleAnd) {
this.visit(doubleAnd, null);
}
<S> T visit(Contains contains, S context);
default void visit(Contains contains) {
this.visit(contains, null);
}
<S> T visit(ContainedBy containedBy, S context);
default void visit(ContainedBy containedBy) {
this.visit(containedBy, null);
}
<S> T visit(ParenthesedSelect select, S context);
default void visit(ParenthesedSelect select) {
this.visit(select, null);
}
<S> T visit(Column column, S context);
default void visit(Column column) {
this.visit(column, null);
}
<S> T visit(CaseExpression caseExpression, S context);
default void visit(CaseExpression caseExpression) {
this.visit(caseExpression, null);
}
<S> T visit(WhenClause whenClause, S context);
default void visit(WhenClause whenClause) {
this.visit(whenClause, null);
}
<S> T visit(ExistsExpression existsExpression, S context);
default void visit(ExistsExpression existsExpression) {
this.visit(existsExpression, null);
}
<S> T visit(MemberOfExpression memberOfExpression, S context);
default void visit(MemberOfExpression memberOfExpression) {
this.visit(memberOfExpression, null);
}
<S> T visit(AnyComparisonExpression anyComparisonExpression, S context);
default void visit(AnyComparisonExpression anyComparisonExpression) {
this.visit(anyComparisonExpression, null);
}
<S> T visit(Concat concat, S context);
default void visit(Concat concat) {
this.visit(concat, null);
}
<S> T visit(Matches matches, S context);
default void visit(Matches matches) {
this.visit(matches, null);
}
<S> T visit(BitwiseAnd bitwiseAnd, S context);
default void visit(BitwiseAnd bitwiseAnd) {
this.visit(bitwiseAnd, null);
}
<S> T visit(BitwiseOr bitwiseOr, S context);
default void visit(BitwiseOr bitwiseOr) {
this.visit(bitwiseOr, null);
}
<S> T visit(BitwiseXor bitwiseXor, S context);
default void visit(BitwiseXor bitwiseXor) {
this.visit(bitwiseXor, null);
}
<S> T visit(CastExpression castExpression, S context);
default void visit(CastExpression castExpression) {
this.visit(castExpression, null);
}
<S> T visit(Modulo modulo, S context);
default void visit(Modulo modulo) {
this.visit(modulo, null);
}
<S> T visit(AnalyticExpression analyticExpression, S context);
default void visit(AnalyticExpression analyticExpression) {
this.visit(analyticExpression, null);
}
<S> T visit(ExtractExpression extractExpression, S context);
default void visit(ExtractExpression extractExpression) {
this.visit(extractExpression, null);
}
<S> T visit(IntervalExpression intervalExpression, S context);
default void visit(IntervalExpression intervalExpression) {
this.visit(intervalExpression, null);
}
<S> T visit(OracleHierarchicalExpression hierarchicalExpression, S context);
default void visit(OracleHierarchicalExpression hierarchicalExpression) {
this.visit(hierarchicalExpression, null);
}
<S> T visit(RegExpMatchOperator regExpMatchOperator, S context);
default void visit(RegExpMatchOperator regExpMatchOperator) {
this.visit(regExpMatchOperator, null);
}
<S> T visit(JsonExpression jsonExpression, S context);
default void visit(JsonExpression jsonExpression) {
this.visit(jsonExpression, null);
}
<S> T visit(JsonOperator jsonOperator, S context);
default void visit(JsonOperator jsonOperator) {
this.visit(jsonOperator, null);
}
<S> T visit(UserVariable userVariable, S context);
default void visit(UserVariable userVariable) {
this.visit(userVariable, null);
}
<S> T visit(NumericBind numericBind, S context);
default void visit(NumericBind numericBind) {
this.visit(numericBind, null);
}
<S> T visit(KeepExpression keepExpression, S context);
default void visit(KeepExpression keepExpression) {
this.visit(keepExpression, null);
}
<S> T visit(MySQLGroupConcat groupConcat, S context);
default void visit(MySQLGroupConcat groupConcat) {
this.visit(groupConcat, null);
}
<S> T visit(ExpressionList<? extends Expression> expressionList, S context);
default void visit(ExpressionList<? extends Expression> expressionList) {
this.visit(expressionList, null);
}
<S> T visit(RowConstructor<? extends Expression> rowConstructor, S context);
default void visit(RowConstructor<? extends Expression> rowConstructor) {
this.visit(rowConstructor, null);
}
<S> T visit(RowGetExpression rowGetExpression, S context);
default void visit(RowGetExpression rowGetExpression) {
this.visit(rowGetExpression, null);
}
<S> T visit(OracleHint hint, S context);
default void visit(OracleHint hint) {
this.visit(hint, null);
}
<S> T visit(TimeKeyExpression timeKeyExpression, S context);
default void visit(TimeKeyExpression timeKeyExpression) {
this.visit(timeKeyExpression, null);
}
<S> T visit(DateTimeLiteralExpression dateTimeLiteralExpression, S context);
default void visit(DateTimeLiteralExpression dateTimeLiteralExpression) {
this.visit(dateTimeLiteralExpression, null);
}
<S> T visit(NotExpression notExpression, S context);
default void visit(NotExpression notExpression) {
this.visit(notExpression, null);
}
<S> T visit(NextValExpression nextValExpression, S context);
default void visit(NextValExpression nextValExpression) {
this.visit(nextValExpression, null);
}
<S> T visit(CollateExpression collateExpression, S context);
default void visit(CollateExpression collateExpression) {
this.visit(collateExpression, null);
}
<S> T visit(SimilarToExpression similarToExpression, S context);
default void visit(SimilarToExpression similarToExpression) {
this.visit(similarToExpression, null);
}
<S> T visit(ArrayExpression arrayExpression, S context);
default void visit(ArrayExpression arrayExpression) {
this.visit(arrayExpression, null);
}
<S> T visit(ArrayConstructor arrayConstructor, S context);
default void visit(ArrayConstructor arrayConstructor) {
this.visit(arrayConstructor, null);
}
<S> T visit(VariableAssignment variableAssignment, S context);
default void visit(VariableAssignment variableAssignment) {
this.visit(variableAssignment, null);
}
<S> T visit(XMLSerializeExpr xmlSerializeExpr, S context);
default void visit(XMLSerializeExpr xmlSerializeExpr) {
this.visit(xmlSerializeExpr, null);
}
<S> T visit(TimezoneExpression timezoneExpression, S context);
default void visit(TimezoneExpression timezoneExpression) {
this.visit(timezoneExpression, null);
}
<S> T visit(JsonAggregateFunction jsonAggregateFunction, S context);
default void visit(JsonAggregateFunction jsonAggregateFunction) {
this.visit(jsonAggregateFunction, null);
}
<S> T visit(JsonFunction jsonFunction, S context);
default void visit(JsonFunction jsonFunction) {
this.visit(jsonFunction, null);
}
<S> T visit(ConnectByRootOperator connectByRootOperator, S context);
default void visit(ConnectByRootOperator connectByRootOperator) {
this.visit(connectByRootOperator, null);
}
<S> T visit(OracleNamedFunctionParameter oracleNamedFunctionParameter, S context);
default void visit(OracleNamedFunctionParameter oracleNamedFunctionParameter) {
this.visit(oracleNamedFunctionParameter, null);
}
<S> T visit(AllColumns allColumns, S context);
default void visit(AllColumns allColumns) {
this.visit(allColumns, null);
}
<S> T visit(AllTableColumns allTableColumns, S context);
default void visit(AllTableColumns allTableColumns) {
this.visit(allTableColumns, null);
}
<S> T visit(AllValue allValue, S context);
default void visit(AllValue allValue) {
this.visit(allValue, null);
}
<S> T visit(IsDistinctExpression isDistinctExpression, S context);
default void visit(IsDistinctExpression isDistinctExpression) {
this.visit(isDistinctExpression, null);
}
<S> T visit(GeometryDistance geometryDistance, S context);
default void visit(GeometryDistance geometryDistance) {
this.visit(geometryDistance, null);
}
<S> T visit(Select select, S context);
default void visit(Select select) {
this.visit(select, null);
}
<S> T visit(TranscodingFunction transcodingFunction, S context);
default void visit(TranscodingFunction transcodingFunction) {
this.visit(transcodingFunction, null);
}
<S> T visit(TrimFunction trimFunction, S context);
default void visit(TrimFunction trimFunction) {
this.visit(trimFunction, null);
}
<S> T visit(RangeExpression rangeExpression, S context);
default void visit(RangeExpression rangeExpression) {
this.visit(rangeExpression, null);
}
<S> T visit(TSQLLeftJoin tsqlLeftJoin, S context);
default void visit(TSQLLeftJoin tsqlLeftJoin) {
this.visit(tsqlLeftJoin, null);
}
<S> T visit(TSQLRightJoin tsqlRightJoin, S context);
default void visit(TSQLRightJoin tsqlRightJoin) {
this.visit(tsqlRightJoin, null);
}
<S> T visit(StructType structType, S context);
default void visit(StructType structType) {
this.visit(structType, null);
}
<S> T visit(LambdaExpression lambdaExpression, S context);
default void visit(LambdaExpression lambdaExpression) {
this.visit(lambdaExpression, null);
}
}

View File

@@ -0,0 +1,827 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseLeftShift;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseRightShift;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor;
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
import net.sf.jsqlparser.expression.operators.arithmetic.IntegerDivision;
import net.sf.jsqlparser.expression.operators.arithmetic.Modulo;
import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication;
import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.conditional.XorExpression;
import net.sf.jsqlparser.expression.operators.relational.Between;
import net.sf.jsqlparser.expression.operators.relational.ContainedBy;
import net.sf.jsqlparser.expression.operators.relational.Contains;
import net.sf.jsqlparser.expression.operators.relational.DoubleAnd;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.FullTextSearch;
import net.sf.jsqlparser.expression.operators.relational.GeometryDistance;
import net.sf.jsqlparser.expression.operators.relational.GreaterThan;
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
import net.sf.jsqlparser.expression.operators.relational.InExpression;
import net.sf.jsqlparser.expression.operators.relational.IsBooleanExpression;
import net.sf.jsqlparser.expression.operators.relational.IsDistinctExpression;
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
import net.sf.jsqlparser.expression.operators.relational.LikeExpression;
import net.sf.jsqlparser.expression.operators.relational.Matches;
import net.sf.jsqlparser.expression.operators.relational.MemberOfExpression;
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.AllColumns;
import net.sf.jsqlparser.statement.select.AllTableColumns;
import net.sf.jsqlparser.statement.select.OrderByElement;
import net.sf.jsqlparser.statement.select.ParenthesedSelect;
import net.sf.jsqlparser.statement.select.Pivot;
import net.sf.jsqlparser.statement.select.PivotVisitor;
import net.sf.jsqlparser.statement.select.PivotXml;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.select.SelectItem;
import net.sf.jsqlparser.statement.select.SelectItemVisitor;
import net.sf.jsqlparser.statement.select.SelectVisitor;
import net.sf.jsqlparser.statement.select.UnPivot;
import net.sf.jsqlparser.statement.select.WithItem;
import java.util.Optional;
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.UncommentedEmptyMethodBody"})
public class ExpressionVisitorAdapter<T>
implements ExpressionVisitor<T>, PivotVisitor<T>, SelectItemVisitor<T> {
private SelectVisitor<T> selectVisitor;
public SelectVisitor<T> getSelectVisitor() {
return selectVisitor;
}
public void setSelectVisitor(SelectVisitor<T> selectVisitor) {
this.selectVisitor = selectVisitor;
}
@Override
public <S> T visit(NullValue nullValue, S context) {
return null;
}
@Override
public <S> T visit(Function function, S context) {
if (function.getParameters() != null) {
function.getParameters().accept(this, context);
}
if (function.getKeep() != null) {
function.getKeep().accept(this, context);
}
if (function.getOrderByElements() != null) {
for (OrderByElement orderByElement : function.getOrderByElements()) {
orderByElement.getExpression().accept(this, context);
}
}
return null;
}
@Override
public <S> T visit(SignedExpression signedExpression, S context) {
signedExpression.getExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(JdbcParameter jdbcParameter, S context) {
return null;
}
@Override
public <S> T visit(JdbcNamedParameter jdbcNamedParameter, S context) {
return null;
}
@Override
public <S> T visit(DoubleValue doubleValue, S context) {
return null;
}
@Override
public <S> T visit(LongValue longValue, S context) {
return null;
}
@Override
public <S> T visit(DateValue dateValue, S context) {
return null;
}
@Override
public <S> T visit(TimeValue timeValue, S context) {
return null;
}
@Override
public <S> T visit(TimestampValue timestampValue, S context) {
return null;
}
@Override
public <S> T visit(StringValue stringValue, S context) {
return null;
}
@Override
public <S> T visit(Addition addition, S context) {
visitBinaryExpression(addition, context);
return null;
}
@Override
public <S> T visit(Division division, S context) {
visitBinaryExpression(division, context);
return null;
}
@Override
public <S> T visit(IntegerDivision integerDivision, S context) {
visitBinaryExpression(integerDivision, context);
return null;
}
@Override
public <S> T visit(Multiplication multiplication, S context) {
visitBinaryExpression(multiplication, context);
return null;
}
@Override
public <S> T visit(Subtraction subtraction, S context) {
visitBinaryExpression(subtraction, context);
return null;
}
@Override
public <S> T visit(AndExpression andExpression, S context) {
visitBinaryExpression(andExpression, context);
return null;
}
@Override
public <S> T visit(OrExpression orExpression, S context) {
visitBinaryExpression(orExpression, context);
return null;
}
@Override
public <S> T visit(XorExpression xorExpression, S context) {
visitBinaryExpression(xorExpression, context);
return null;
}
@Override
public <S> T visit(Between between, S context) {
between.getLeftExpression().accept(this, context);
between.getBetweenExpressionStart().accept(this, context);
between.getBetweenExpressionEnd().accept(this, context);
return null;
}
public <S> T visit(OverlapsCondition overlapsCondition, S context) {
overlapsCondition.getLeft().accept(this, context);
overlapsCondition.getRight().accept(this, context);
return null;
}
@Override
public <S> T visit(EqualsTo equalsTo, S context) {
visitBinaryExpression(equalsTo, context);
return null;
}
@Override
public <S> T visit(GreaterThan greaterThan, S context) {
visitBinaryExpression(greaterThan, context);
return null;
}
@Override
public <S> T visit(GreaterThanEquals greaterThanEquals, S context) {
visitBinaryExpression(greaterThanEquals, context);
return null;
}
@Override
public <S> T visit(InExpression inExpression, S context) {
inExpression.getLeftExpression().accept(this, context);
inExpression.getRightExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(IncludesExpression includesExpression, S context) {
includesExpression.getLeftExpression().accept(this, context);
includesExpression.getRightExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(ExcludesExpression excludesExpression, S context) {
excludesExpression.getLeftExpression().accept(this, context);
excludesExpression.getRightExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(IsNullExpression isNullExpression, S context) {
isNullExpression.getLeftExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(FullTextSearch fullTextSearch, S context) {
for (Column col : fullTextSearch.getMatchColumns()) {
col.accept(this, context);
}
return null;
}
@Override
public <S> T visit(IsBooleanExpression isBooleanExpression, S context) {
isBooleanExpression.getLeftExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(LikeExpression likeExpression, S context) {
visitBinaryExpression(likeExpression, context);
return null;
}
@Override
public <S> T visit(MinorThan minorThan, S context) {
visitBinaryExpression(minorThan, context);
return null;
}
@Override
public <S> T visit(MinorThanEquals minorThanEquals, S context) {
visitBinaryExpression(minorThanEquals, context);
return null;
}
@Override
public <S> T visit(NotEqualsTo notEqualsTo, S context) {
visitBinaryExpression(notEqualsTo, context);
return null;
}
@Override
public <S> T visit(DoubleAnd doubleAnd, S context) {
visitBinaryExpression(doubleAnd, context);
return null;
}
@Override
public <S> T visit(Contains contains, S context) {
visitBinaryExpression(contains, context);
return null;
}
@Override
public <S> T visit(ContainedBy containedBy, S context) {
visitBinaryExpression(containedBy, context);
return null;
}
@Override
public <S> T visit(Column column, S context) {
return null;
}
@Override
public <S> T visit(ParenthesedSelect select, S context) {
visit((Select) select, context);
if (select.getPivot() != null) {
select.getPivot().accept(this, context);
}
return null;
}
@Override
public <S> T visit(CaseExpression caseExpression, S context) {
if (caseExpression.getSwitchExpression() != null) {
caseExpression.getSwitchExpression().accept(this, context);
}
for (Expression x : caseExpression.getWhenClauses()) {
x.accept(this, context);
}
if (caseExpression.getElseExpression() != null) {
caseExpression.getElseExpression().accept(this, context);
}
return null;
}
@Override
public <S> T visit(WhenClause whenClause, S context) {
whenClause.getWhenExpression().accept(this, context);
whenClause.getThenExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(ExistsExpression existsExpression, S context) {
existsExpression.getRightExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(MemberOfExpression memberOfExpression, S context) {
memberOfExpression.getRightExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(AnyComparisonExpression anyComparisonExpression, S context) {
return null;
}
@Override
public <S> T visit(Concat concat, S context) {
visitBinaryExpression(concat, context);
return null;
}
@Override
public <S> T visit(Matches matches, S context) {
visitBinaryExpression(matches, context);
return null;
}
@Override
public <S> T visit(BitwiseAnd bitwiseAnd, S context) {
visitBinaryExpression(bitwiseAnd, context);
return null;
}
@Override
public <S> T visit(BitwiseOr bitwiseOr, S context) {
visitBinaryExpression(bitwiseOr, context);
return null;
}
@Override
public <S> T visit(BitwiseXor bitwiseXor, S context) {
visitBinaryExpression(bitwiseXor, context);
return null;
}
@Override
public <S> T visit(CastExpression castExpression, S context) {
castExpression.getLeftExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(Modulo modulo, S context) {
visitBinaryExpression(modulo, context);
return null;
}
@Override
public <S> T visit(AnalyticExpression analyticExpression, S context) {
if (analyticExpression.getExpression() != null) {
analyticExpression.getExpression().accept(this, context);
}
if (analyticExpression.getDefaultValue() != null) {
analyticExpression.getDefaultValue().accept(this, context);
}
if (analyticExpression.getOffset() != null) {
analyticExpression.getOffset().accept(this, context);
}
if (analyticExpression.getKeep() != null) {
analyticExpression.getKeep().accept(this, context);
}
if (analyticExpression.getFuncOrderBy() != null) {
for (OrderByElement element : analyticExpression.getOrderByElements()) {
element.getExpression().accept(this, context);
}
}
if (analyticExpression.getWindowElement() != null) {
/*
* Visit expressions from the range and offset of the window element. Do this using
* optional chains, because several things down the tree can be null e.g. the
* expression. So, null-safe versions of e.g.:
* analyticExpression.getWindowElement().getOffset().getExpression().accept(this,
* parameters);
*/
Optional.ofNullable(analyticExpression.getWindowElement().getRange())
.map(WindowRange::getStart)
.map(WindowOffset::getExpression).ifPresent(e -> e.accept(this, context));
Optional.ofNullable(analyticExpression.getWindowElement().getRange())
.map(WindowRange::getEnd)
.map(WindowOffset::getExpression).ifPresent(e -> e.accept(this, context));
Optional.ofNullable(analyticExpression.getWindowElement().getOffset())
.map(WindowOffset::getExpression).ifPresent(e -> e.accept(this, context));
}
return null;
}
@Override
public <S> T visit(ExtractExpression extractExpression, S context) {
extractExpression.getExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(IntervalExpression intervalExpression, S context) {
return null;
}
@Override
public <S> T visit(OracleHierarchicalExpression hierarchicalExpression, S context) {
hierarchicalExpression.getConnectExpression().accept(this, context);
hierarchicalExpression.getStartExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(RegExpMatchOperator regExpMatchOperator, S context) {
visitBinaryExpression(regExpMatchOperator, context);
return null;
}
@Override
public <S> T visit(ExpressionList<? extends Expression> expressionList, S context) {
for (Expression expr : expressionList) {
expr.accept(this, context);
}
return null;
}
@Override
public <S> T visit(RowConstructor<? extends Expression> rowConstructor, S context) {
for (Expression expr : rowConstructor) {
expr.accept(this, context);
}
return null;
}
@Override
public <S> T visit(NotExpression notExpr, S context) {
notExpr.getExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(BitwiseRightShift bitwiseRightShift, S context) {
visitBinaryExpression(bitwiseRightShift, context);
return null;
}
@Override
public <S> T visit(BitwiseLeftShift bitwiseLeftShift, S context) {
visitBinaryExpression(bitwiseLeftShift, context);
return null;
}
protected <S> T visitBinaryExpression(BinaryExpression binaryExpression, S context) {
binaryExpression.getLeftExpression().accept(this, context);
binaryExpression.getRightExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(JsonExpression jsonExpr, S context) {
jsonExpr.getExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(JsonOperator jsonOperator, S context) {
visitBinaryExpression(jsonOperator, context);
return null;
}
@Override
public <S> T visit(UserVariable userVariable, S context) {
return null;
}
@Override
public <S> T visit(NumericBind numericBind, S context) {
return null;
}
@Override
public <S> T visit(KeepExpression keepExpression, S context) {
for (OrderByElement element : keepExpression.getOrderByElements()) {
element.getExpression().accept(this, context);
}
return null;
}
@Override
public <S> T visit(MySQLGroupConcat groupConcat, S context) {
for (Expression expr : groupConcat.getExpressionList()) {
expr.accept(this, context);
}
if (groupConcat.getOrderByElements() != null) {
for (OrderByElement element : groupConcat.getOrderByElements()) {
element.getExpression().accept(this, context);
}
}
return null;
}
@Override
public <S> T visit(Pivot pivot, S context) {
for (SelectItem<?> item : pivot.getFunctionItems()) {
item.getExpression().accept(this, context);
}
for (Column col : pivot.getForColumns()) {
col.accept(this, context);
}
if (pivot.getSingleInItems() != null) {
for (SelectItem<?> item : pivot.getSingleInItems()) {
item.getExpression().accept(this, context);
}
}
if (pivot.getMultiInItems() != null) {
for (SelectItem<ExpressionList<?>> item : pivot.getMultiInItems()) {
item.getExpression().accept(this, context);
}
}
return null;
}
@Override
public <S> T visit(PivotXml pivotXml, S context) {
for (SelectItem<?> item : pivotXml.getFunctionItems()) {
item.getExpression().accept(this, context);
}
for (Column col : pivotXml.getForColumns()) {
col.accept(this, context);
}
if (pivotXml.getInSelect() != null && selectVisitor != null) {
pivotXml.getInSelect().accept(selectVisitor, context);
}
return null;
}
@Override
public <S> T visit(UnPivot unpivot, S context) {
unpivot.accept(this, context);
return null;
}
@Override
public <S> T visit(AllColumns allColumns, S context) {
return null;
}
@Override
public <S> T visit(AllTableColumns allTableColumns, S context) {
return null;
}
@Override
public <S> T visit(AllValue allValue, S context) {
return null;
}
@Override
public <S> T visit(IsDistinctExpression isDistinctExpression, S context) {
visitBinaryExpression(isDistinctExpression, context);
return null;
}
@Override
public <S> T visit(SelectItem<? extends Expression> selectItem, S context) {
selectItem.getExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(RowGetExpression rowGetExpression, S context) {
rowGetExpression.getExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(HexValue hexValue, S context) {
return null;
}
@Override
public <S> T visit(OracleHint hint, S context) {
return null;
}
@Override
public <S> T visit(TimeKeyExpression timeKeyExpression, S context) {
return null;
}
@Override
public <S> T visit(DateTimeLiteralExpression dateTimeLiteralExpression, S context) {
return null;
}
@Override
public <S> T visit(NextValExpression nextValExpression, S context) {
return null;
}
@Override
public <S> T visit(CollateExpression collateExpression, S context) {
collateExpression.getLeftExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(SimilarToExpression similarToExpression, S context) {
visitBinaryExpression(similarToExpression, context);
return null;
}
@Override
public <S> T visit(ArrayExpression arrayExpression, S context) {
arrayExpression.getObjExpression().accept(this, context);
if (arrayExpression.getIndexExpression() != null) {
arrayExpression.getIndexExpression().accept(this, context);
}
if (arrayExpression.getStartIndexExpression() != null) {
arrayExpression.getStartIndexExpression().accept(this, context);
}
if (arrayExpression.getStopIndexExpression() != null) {
arrayExpression.getStopIndexExpression().accept(this, context);
}
return null;
}
@Override
public <S> T visit(ArrayConstructor arrayConstructor, S context) {
for (Expression expression : arrayConstructor.getExpressions()) {
expression.accept(this, context);
}
return null;
}
@Override
public <S> T visit(VariableAssignment variableAssignment, S context) {
variableAssignment.getVariable().accept(this, context);
variableAssignment.getExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(XMLSerializeExpr xmlSerializeExpr, S context) {
xmlSerializeExpr.getExpression().accept(this, context);
for (OrderByElement elm : xmlSerializeExpr.getOrderByElements()) {
elm.getExpression().accept(this, context);
}
return null;
}
@Override
public <S> T visit(TimezoneExpression timezoneExpression, S context) {
timezoneExpression.getLeftExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(JsonAggregateFunction jsonAggregateFunction, S context) {
Expression expr = jsonAggregateFunction.getExpression();
if (expr != null) {
expr.accept(this, context);
}
expr = jsonAggregateFunction.getFilterExpression();
if (expr != null) {
expr.accept(this, context);
}
return null;
}
@Override
public <S> T visit(JsonFunction jsonFunction, S context) {
for (JsonFunctionExpression expr : jsonFunction.getExpressions()) {
expr.getExpression().accept(this, context);
}
return null;
}
@Override
public <S> T visit(ConnectByRootOperator connectByRootOperator, S context) {
connectByRootOperator.getColumn().accept(this, context);
return null;
}
@Override
public <S> T visit(OracleNamedFunctionParameter oracleNamedFunctionParameter, S context) {
oracleNamedFunctionParameter.getExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(GeometryDistance geometryDistance, S context) {
visitBinaryExpression(geometryDistance, context);
return null;
}
@Override
public <S> T visit(Select select, S context) {
if (selectVisitor != null) {
if (select.getWithItemsList() != null) {
for (WithItem item : select.getWithItemsList()) {
item.accept(selectVisitor, context);
}
}
select.accept(selectVisitor, context);
}
return null;
}
@Override
public <S> T visit(TranscodingFunction transcodingFunction, S context) {
return null;
}
@Override
public <S> T visit(TrimFunction trimFunction, S context) {
return null;
}
@Override
public <S> T visit(RangeExpression rangeExpression, S context) {
rangeExpression.getStartExpression().accept(this, context);
rangeExpression.getEndExpression().accept(this, context);
return null;
}
@Override
public <S> T visit(TSQLLeftJoin tsqlLeftJoin, S context) {
visitBinaryExpression(tsqlLeftJoin, context);
return null;
}
@Override
public <S> T visit(TSQLRightJoin tsqlRightJoin, S context) {
visitBinaryExpression(tsqlRightJoin, context);
return null;
}
@Override
public <S> T visit(StructType structType, S context) {
// @todo: visit the ColType also
if (structType.getArguments() != null) {
for (SelectItem<?> selectItem : structType.getArguments()) {
visit(selectItem, context);
}
}
return null;
}
@Override
public <S> T visit(LambdaExpression lambdaExpression, S context) {
lambdaExpression.getExpression().accept(this, context);
return null;
}
}

View File

@@ -0,0 +1,64 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* Extract value from date/time expression. The name stores the part - name to get from the
* following date/time expression.
*
* @author tw
*/
public class ExtractExpression extends ASTNodeAccessImpl implements Expression {
private String name;
private Expression expression;
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
@Override
public String toString() {
return "EXTRACT(" + name + " FROM " + expression + ')';
}
public ExtractExpression withName(String name) {
this.setName(name);
return this;
}
public ExtractExpression withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public <E extends Expression> E getExpression(Class<E> type) {
return type.cast(getExpression());
}
}

View File

@@ -0,0 +1,142 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.util.List;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.select.OrderByElement;
/**
* @author tw
*/
public class FilterOverImpl extends ASTNodeAccessImpl {
private final OrderByClause orderBy = new OrderByClause();
private final PartitionByClause partitionBy = new PartitionByClause();
private AnalyticType analyticType = AnalyticType.FILTER_ONLY;
private Expression filterExpression = null;
private WindowElement windowElement = null;
public AnalyticType getAnalyticType() {
return analyticType;
}
public void setAnalyticType(AnalyticType analyticType) {
this.analyticType = analyticType;
}
public FilterOverImpl withAnalyticType(AnalyticType analyticType) {
this.setAnalyticType(analyticType);
return this;
}
public List<OrderByElement> getOrderByElements() {
return orderBy.getOrderByElements();
}
public void setOrderByElements(List<OrderByElement> orderByElements) {
orderBy.setOrderByElements(orderByElements);
}
public FilterOverImpl withOrderByElements(List<OrderByElement> orderByElements) {
this.setOrderByElements(orderByElements);
return this;
}
public ExpressionList getPartitionExpressionList() {
return partitionBy.getPartitionExpressionList();
}
public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
setPartitionExpressionList(partitionExpressionList, false);
}
public void setPartitionExpressionList(ExpressionList partitionExpressionList,
boolean brackets) {
partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
}
public boolean isPartitionByBrackets() {
return partitionBy.isBrackets();
}
public Expression getFilterExpression() {
return filterExpression;
}
public void setFilterExpression(Expression filterExpression) {
this.filterExpression = filterExpression;
}
public FilterOverImpl withFilterExpression(Expression filterExpression) {
this.setFilterExpression(filterExpression);
return this;
}
public WindowElement getWindowElement() {
return windowElement;
}
public void setWindowElement(WindowElement windowElement) {
this.windowElement = windowElement;
}
public FilterOverImpl withWindowElement(WindowElement windowElement) {
this.setWindowElement(windowElement);
return this;
}
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity",
"PMD.MissingBreakInSwitch"})
public StringBuilder append(StringBuilder builder) {
if (filterExpression != null) {
builder.append("FILTER (WHERE ");
builder.append(filterExpression.toString());
builder.append(")");
if (analyticType != AnalyticType.FILTER_ONLY) {
builder.append(" ");
}
}
switch (analyticType) {
case FILTER_ONLY:
return builder;
case WITHIN_GROUP:
builder.append("WITHIN GROUP");
break;
default:
builder.append("OVER");
}
builder.append(" (");
partitionBy.toStringPartitionBy(builder);
orderBy.toStringOrderByElements(builder);
if (windowElement != null) {
if (orderBy.getOrderByElements() != null) {
builder.append(' ');
}
builder.append(windowElement);
}
builder.append(")");
return builder;
}
@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {
StringBuilder builder = new StringBuilder();
return append(builder).toString();
}
}

View File

@@ -0,0 +1,456 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.NamedExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.Limit;
import net.sf.jsqlparser.statement.select.OrderByElement;
import java.util.Arrays;
import java.util.List;
/**
* A function as MAX,COUNT...
*/
public class Function extends ASTNodeAccessImpl implements Expression {
private List<String> nameparts;
private ExpressionList<?> parameters;
private NamedExpressionList<?> namedParameters;
private boolean allColumns = false;
private boolean distinct = false;
private boolean unique = false;
private boolean isEscaped = false;
private Expression attributeExpression;
private HavingClause havingClause;
private Column attributeColumn = null;
private List<OrderByElement> orderByElements;
private NullHandling nullHandling = null;
private boolean ignoreNullsOutside = false; // IGNORE NULLS outside function parameters
private Limit limit = null;
private KeepExpression keep = null;
public Function() {}
public Function(String name, Expression... parameters) {
this.nameparts = Arrays.asList(name);
this.parameters = new ExpressionList<>(parameters);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public String getName() {
return nameparts == null ? null
: String.join(nameparts.get(0).equalsIgnoreCase("APPROXIMATE") ? " " : ".",
nameparts);
}
public void setName(String string) {
nameparts = Arrays.asList(string);
}
public void setName(List<String> string) {
nameparts = string;
}
public List<String> getMultipartName() {
return nameparts;
}
public Function withName(String name) {
this.setName(name);
return this;
}
public Function withName(List<String> nameparts) {
this.nameparts = nameparts;
return this;
}
public boolean isAllColumns() {
return allColumns;
}
public void setAllColumns(boolean b) {
allColumns = b;
}
public NullHandling getNullHandling() {
return nullHandling;
}
public Function setNullHandling(NullHandling nullHandling) {
this.nullHandling = nullHandling;
return this;
}
public boolean isIgnoreNullsOutside() {
return ignoreNullsOutside;
}
public Function setIgnoreNullsOutside(boolean ignoreNullsOutside) {
this.ignoreNullsOutside = ignoreNullsOutside;
return this;
}
public Limit getLimit() {
return limit;
}
public Function setLimit(Limit limit) {
this.limit = limit;
return this;
}
public boolean isIgnoreNulls() {
return nullHandling != null && nullHandling == NullHandling.IGNORE_NULLS;
}
/**
* This is at the moment only necessary for AnalyticExpression initialization and not for normal
* functions. Therefore there is no deparsing for it for normal functions.
*/
public void setIgnoreNulls(boolean ignoreNulls) {
this.nullHandling = ignoreNulls ? NullHandling.IGNORE_NULLS : null;
}
public HavingClause getHavingClause() {
return havingClause;
}
public Function setHavingClause(HavingClause havingClause) {
this.havingClause = havingClause;
return this;
}
public Function setHavingClause(String havingType, Expression expression) {
this.havingClause = new HavingClause(
HavingClause.HavingType.valueOf(havingType.trim().toUpperCase()), expression);
return this;
}
/**
* true if the function is "distinct"
*
* @return true if the function is "distinct"
*/
public boolean isDistinct() {
return distinct;
}
public void setDistinct(boolean b) {
distinct = b;
}
/**
* true if the function is "unique"
*
* @return true if the function is "unique"
*/
public boolean isUnique() {
return unique;
}
public void setUnique(boolean b) {
unique = b;
}
/**
* The list of parameters of the function (if any, else null) If the parameter is "*",
* allColumns is set to true
*
* @return the list of parameters of the function (if any, else null)
*/
public ExpressionList<?> getParameters() {
return parameters;
}
public void setParameters(Expression... expressions) {
if (expressions.length == 1 && expressions[0] instanceof ExpressionList) {
parameters = (ExpressionList<?>) expressions[0];
} else {
parameters = new ExpressionList<>(expressions);
}
}
public void setParameters(ExpressionList<?> list) {
parameters = list;
}
/**
* the parameters might be named parameters, e.g. substring('foobar' from 2 for 3)
*
* @return the list of named parameters of the function (if any, else null)
*/
public NamedExpressionList<?> getNamedParameters() {
return namedParameters;
}
public void setNamedParameters(NamedExpressionList<?> list) {
namedParameters = list;
}
/**
* Return true if it's in the form "{fn function_body() }"
*
* @return true if it's java-escaped
*/
public boolean isEscaped() {
return isEscaped;
}
public void setEscaped(boolean isEscaped) {
this.isEscaped = isEscaped;
}
public Object getAttribute() {
return attributeExpression != null ? attributeExpression : attributeColumn;
}
public void setAttribute(Expression attributeExpression) {
this.attributeExpression = attributeExpression;
}
public void setAttribute(Column attributeColumn) {
attributeExpression = null;
this.attributeColumn = attributeColumn;
}
@Deprecated
public String getAttributeName() {
return attributeColumn.toString();
}
public void setAttributeName(String attributeName) {
this.attributeColumn = new Column().withColumnName(attributeName);
}
public Column getAttributeColumn() {
return attributeColumn;
}
public Function withAttribute(Column attributeColumn) {
setAttribute(attributeColumn);
return this;
}
public KeepExpression getKeep() {
return keep;
}
public void setKeep(KeepExpression keep) {
this.keep = keep;
}
@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {
String params;
if (parameters != null || namedParameters != null) {
if (parameters != null) {
StringBuilder b = new StringBuilder();
b.append("(");
if (isDistinct()) {
b.append("DISTINCT ");
} else if (isUnique()) {
b.append("UNIQUE ");
}
if (isAllColumns()) {
b.append("ALL ");
}
b.append(parameters);
if (havingClause != null) {
havingClause.appendTo(b);
}
if (nullHandling != null && !isIgnoreNullsOutside()) {
switch (nullHandling) {
case IGNORE_NULLS:
b.append(" IGNORE NULLS");
break;
case RESPECT_NULLS:
b.append(" RESPECT NULLS");
break;
}
}
if (orderByElements != null) {
b.append(" ORDER BY ");
boolean comma = false;
for (OrderByElement orderByElement : orderByElements) {
if (comma) {
b.append(", ");
} else {
comma = true;
}
b.append(orderByElement);
}
}
if (limit != null) {
b.append(limit);
}
b.append(")");
params = b.toString();
} else {
params = namedParameters.toString();
}
} else {
params = "()";
}
String ans = getName() + params;
if (nullHandling != null && isIgnoreNullsOutside()) {
switch (nullHandling) {
case IGNORE_NULLS:
ans += " IGNORE NULLS";
break;
case RESPECT_NULLS:
ans += " RESPECT NULLS";
break;
}
}
if (attributeExpression != null) {
ans += "." + attributeExpression;
} else if (attributeColumn != null) {
ans += "." + attributeColumn;
}
if (keep != null) {
ans += " " + keep;
}
if (isEscaped) {
ans = "{fn " + ans + "}";
}
return ans;
}
public Function withAttribute(Expression attribute) {
this.setAttribute(attribute);
return this;
}
@Deprecated
public Function withAttributeName(String attributeName) {
this.setAttributeName(attributeName);
return this;
}
public Function withKeep(KeepExpression keep) {
this.setKeep(keep);
return this;
}
public Function withIgnoreNulls(boolean ignoreNulls) {
this.setIgnoreNulls(ignoreNulls);
return this;
}
public Function withParameters(ExpressionList<?> parameters) {
this.setParameters(parameters);
return this;
}
public Function withParameters(Expression... parameters) {
return withParameters(new ExpressionList<>(parameters));
}
public Function withNamedParameters(NamedExpressionList<?> namedParameters) {
this.setNamedParameters(namedParameters);
return this;
}
public Function withAllColumns(boolean allColumns) {
this.setAllColumns(allColumns);
return this;
}
public Function withDistinct(boolean distinct) {
this.setDistinct(distinct);
return this;
}
public Function withUnique(boolean unique) {
this.setUnique(unique);
return this;
}
public List<OrderByElement> getOrderByElements() {
return orderByElements;
}
public void setOrderByElements(List<OrderByElement> orderByElements) {
this.orderByElements = orderByElements;
}
public <E extends Expression> E getAttribute(Class<E> type) {
return type.cast(getAttribute());
}
public enum NullHandling {
IGNORE_NULLS, RESPECT_NULLS;
}
public static class HavingClause extends ASTNodeAccessImpl implements Expression {
HavingType havingType;
Expression expression;
public HavingClause(HavingType havingType, Expression expression) {
this.havingType = havingType;
this.expression = expression;
}
public HavingType getHavingType() {
return havingType;
}
public HavingClause setHavingType(HavingType havingType) {
this.havingType = havingType;
return this;
}
public Expression getExpression() {
return expression;
}
public HavingClause setExpression(Expression expression) {
this.expression = expression;
return this;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expression.accept(expressionVisitor, context);
}
public StringBuilder appendTo(StringBuilder builder) {
builder.append(" HAVING ").append(havingType.name()).append(" ").append(expression);
return builder;
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
enum HavingType {
MAX, MIN;
}
}
}

View File

@@ -0,0 +1,93 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.nio.charset.StandardCharsets;
public class HexValue extends ASTNodeAccessImpl implements Expression {
private String value;
public HexValue() {
// empty constructor
}
public HexValue(final String value) {
String val = value;
this.value = val;
}
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i + 1), 16));
}
return data;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public HexValue withValue(String value) {
this.setValue(value);
return this;
}
@Override
public String toString() {
return value;
}
public String getDigits() {
return value.toUpperCase().startsWith("0X")
? value.substring(2)
: value.substring(2, value.length() - 1);
}
public Long getLong() {
return Long.parseLong(
getDigits(), 16);
}
public LongValue getLongValue() {
return new LongValue(getLong());
}
// `X'C3BC'` --> `'ü'`
public StringValue getStringValue() {
return new StringValue(
new String(hexStringToByteArray(getDigits()), StandardCharsets.UTF_8));
}
// `X'C3BC'` --> `\xC3\xBC`
public StringValue getBlob() {
StringBuilder builder = new StringBuilder();
String digits = getDigits();
int len = digits.length();
for (int i = 0; i < len; i += 2) {
builder.append("\\x").append(digits.charAt(i)).append(digits.charAt(i + 1));
}
return new StringValue(builder.toString());
}
}

View File

@@ -0,0 +1,96 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.util.Objects;
public class IntervalExpression extends ASTNodeAccessImpl implements Expression {
private final boolean intervalKeyword;
private String parameter = null;
private String intervalType = null;
private Expression expression = null;
public IntervalExpression() {
this(true);
}
public IntervalExpression(boolean intervalKeyword) {
this.intervalKeyword = intervalKeyword;
}
public IntervalExpression(int value, String type) {
this.parameter = null;
this.intervalKeyword = true;
this.expression = new LongValue(value);
this.intervalType = type;
}
public boolean isUsingIntervalKeyword() {
return intervalKeyword;
}
public String getParameter() {
return parameter;
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
public String getIntervalType() {
return intervalType;
}
public void setIntervalType(String intervalType) {
this.intervalType = intervalType;
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
@Override
public String toString() {
return (intervalKeyword ? "INTERVAL " : "")
+ Objects.toString(expression, parameter)
+ (intervalType != null ? " " + intervalType : "");
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public IntervalExpression withParameter(String parameter) {
this.setParameter(parameter);
return this;
}
public IntervalExpression withIntervalType(String intervalType) {
this.setIntervalType(intervalType);
return this;
}
public IntervalExpression withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public <E extends Expression> E getExpression(Class<E> type) {
return type.cast(getExpression());
}
}

View File

@@ -0,0 +1,55 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class JdbcNamedParameter extends ASTNodeAccessImpl implements Expression {
private String parameterCharacter = ":";
private String name;
public JdbcNamedParameter() {}
public JdbcNamedParameter(String name) {
this.name = name;
}
public String getParameterCharacter() {
return parameterCharacter;
}
public JdbcNamedParameter setParameterCharacter(String parameterCharacter) {
this.parameterCharacter = parameterCharacter;
return this;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return parameterCharacter + name;
}
public JdbcNamedParameter withName(String name) {
this.setName(name);
return this;
}
}

View File

@@ -0,0 +1,88 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A '?' in a statement or a ?&lt;number&gt; e.g. ?4
*/
public class JdbcParameter extends ASTNodeAccessImpl implements Expression {
private String parameterCharacter = "?";
private Integer index;
private boolean useFixedIndex = false;
public JdbcParameter() {}
public JdbcParameter(Integer index, boolean useFixedIndex, String parameterCharacter) {
this.index = index;
this.useFixedIndex = useFixedIndex;
this.parameterCharacter = parameterCharacter;
// This is needed for Parameters starting with "$" like "$2"
// Those will contain the index in the parameterCharacter
final Pattern pattern = Pattern.compile("(\\$)(\\d*)");
final Matcher matcher = pattern.matcher(parameterCharacter);
if (matcher.find() && matcher.groupCount() == 2) {
this.useFixedIndex = true;
this.parameterCharacter = matcher.group(1);
this.index = Integer.valueOf(matcher.group(2));
}
}
public String getParameterCharacter() {
return parameterCharacter;
}
public JdbcParameter setParameterCharacter(String parameterCharacter) {
this.parameterCharacter = parameterCharacter;
return this;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
public boolean isUseFixedIndex() {
return useFixedIndex;
}
public void setUseFixedIndex(boolean useFixedIndex) {
this.useFixedIndex = useFixedIndex;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return useFixedIndex ? parameterCharacter + index : parameterCharacter;
}
public JdbcParameter withIndex(Integer index) {
this.setIndex(index);
return this;
}
public JdbcParameter withUseFixedIndex(boolean useFixedIndex) {
this.setUseFixedIndex(useFixedIndex);
return this;
}
}

View File

@@ -0,0 +1,292 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.util.List;
import java.util.Objects;
import net.sf.jsqlparser.statement.select.OrderByElement;
/**
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public class JsonAggregateFunction extends FilterOverImpl implements Expression {
private final OrderByClause expressionOrderBy = new OrderByClause();
private JsonFunctionType functionType;
private Expression expression = null;
private boolean usingKeyKeyword = false;
private String key;
private boolean usingValueKeyword = false;
private Object value;
private boolean usingFormatJson = false;
private JsonAggregateOnNullType onNullType;
private JsonAggregateUniqueKeysType uniqueKeysType;
public JsonAggregateOnNullType getOnNullType() {
return onNullType;
}
public void setOnNullType(JsonAggregateOnNullType onNullType) {
this.onNullType = onNullType;
}
public JsonAggregateFunction withOnNullType(JsonAggregateOnNullType onNullType) {
this.setOnNullType(onNullType);
return this;
}
public JsonAggregateUniqueKeysType getUniqueKeysType() {
return uniqueKeysType;
}
public void setUniqueKeysType(JsonAggregateUniqueKeysType uniqueKeysType) {
this.uniqueKeysType = uniqueKeysType;
}
public JsonAggregateFunction withUniqueKeysType(JsonAggregateUniqueKeysType uniqueKeysType) {
this.setUniqueKeysType(uniqueKeysType);
return this;
}
public JsonFunctionType getType() {
return functionType;
}
public void setType(JsonFunctionType type) {
this.functionType = Objects.requireNonNull(type,
"The Type of the JSON Aggregate Function must not be null");
}
public void setType(String typeName) {
this.functionType = JsonFunctionType
.valueOf(Objects
.requireNonNull(typeName,
"The Type of the JSON Aggregate Function must not be null")
.toUpperCase());
}
public JsonAggregateFunction withType(JsonFunctionType type) {
this.setType(type);
return this;
}
public JsonAggregateFunction withType(String typeName) {
this.setType(typeName);
return this;
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
public JsonAggregateFunction withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public boolean isUsingKeyKeyword() {
return usingKeyKeyword;
}
public void setUsingKeyKeyword(boolean usingKeyKeyword) {
this.usingKeyKeyword = usingKeyKeyword;
}
public JsonAggregateFunction withUsingKeyKeyword(boolean usingKeyKeyword) {
this.setUsingKeyKeyword(usingKeyKeyword);
return this;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public JsonAggregateFunction withKey(String key) {
this.setKey(key);
return this;
}
public boolean isUsingValueKeyword() {
return usingValueKeyword;
}
public void setUsingValueKeyword(boolean usingValueKeyword) {
this.usingValueKeyword = usingValueKeyword;
}
public JsonAggregateFunction withUsingValueKeyword(boolean usingValueKeyword) {
this.setUsingValueKeyword(usingValueKeyword);
return this;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public JsonAggregateFunction withValue(Object value) {
this.setValue(value);
return this;
}
public boolean isUsingFormatJson() {
return usingFormatJson;
}
public void setUsingFormatJson(boolean usingFormatJson) {
this.usingFormatJson = usingFormatJson;
}
public JsonAggregateFunction withUsingFormatJson(boolean usingFormatJson) {
this.setUsingFormatJson(usingFormatJson);
return this;
}
public List<OrderByElement> getExpressionOrderByElements() {
return expressionOrderBy.getOrderByElements();
}
public void setExpressionOrderByElements(List<OrderByElement> orderByElements) {
expressionOrderBy.setOrderByElements(orderByElements);
}
public JsonAggregateFunction withExpressionOrderByElements(
List<OrderByElement> orderByElements) {
this.setExpressionOrderByElements(orderByElements);
return this;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
// avoid countless Builder --> String conversion
@Override
public StringBuilder append(StringBuilder builder) {
switch (functionType) {
case OBJECT:
appendObject(builder);
break;
case ARRAY:
appendArray(builder);
break;
default:
// this should never happen really
throw new UnsupportedOperationException("JSON Aggregate Function of the type "
+ functionType.name() + " has not been implemented yet.");
}
return builder;
}
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public StringBuilder appendObject(StringBuilder builder) {
builder.append("JSON_OBJECTAGG( ");
if (usingValueKeyword) {
if (usingKeyKeyword) {
builder.append("KEY ");
}
builder.append(key).append(" VALUE ").append(value);
} else {
builder.append(key).append(":").append(value);
}
if (usingFormatJson) {
builder.append(" FORMAT JSON");
}
if (onNullType != null) {
switch (onNullType) {
case NULL:
builder.append(" NULL ON NULL");
break;
case ABSENT:
builder.append(" ABSENT On NULL");
break;
default:
// this should never happen
}
}
if (uniqueKeysType != null) {
switch (uniqueKeysType) {
case WITH:
builder.append(" WITH UNIQUE KEYS");
break;
case WITHOUT:
builder.append(" WITHOUT UNIQUE KEYS");
break;
default:
// this should never happen
}
}
builder.append(" ) ");
// FILTER( WHERE expression ) OVER windowNameOrSpecification
super.append(builder);
return builder;
}
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public StringBuilder appendArray(StringBuilder builder) {
builder.append("JSON_ARRAYAGG( ");
builder.append(expression).append(" ");
if (usingFormatJson) {
builder.append("FORMAT JSON ");
}
expressionOrderBy.toStringOrderByElements(builder);
if (onNullType != null) {
switch (onNullType) {
case NULL:
builder.append(" NULL ON NULL ");
break;
case ABSENT:
builder.append(" ABSENT On NULL ");
break;
default:
// "ON NULL" was ommitted
}
}
builder.append(") ");
// FILTER( WHERE expression ) OVER windowNameOrSpecification
super.append(builder);
return builder;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
return append(builder).toString();
}
}

View File

@@ -0,0 +1,37 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
/*
* Copyright (C) 2021 JSQLParser.
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
package net.sf.jsqlparser.expression;
/**
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public enum JsonAggregateOnNullType {
NULL, ABSENT;
public static JsonAggregateOnNullType from(String type) {
return Enum.valueOf(JsonAggregateOnNullType.class, type.toUpperCase());
}
}

View File

@@ -0,0 +1,37 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
/*
* Copyright (C) 2021 JSQLParser.
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
package net.sf.jsqlparser.expression;
/**
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public enum JsonAggregateUniqueKeysType {
WITH, WITHOUT;
public static JsonAggregateUniqueKeysType from(String type) {
return Enum.valueOf(JsonAggregateUniqueKeysType.class, type.toUpperCase());
}
}

View File

@@ -0,0 +1,99 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class JsonExpression extends ASTNodeAccessImpl implements Expression {
private final List<Map.Entry<String, String>> idents = new ArrayList<>();
private Expression expr;
public JsonExpression() {
}
public JsonExpression(Expression expr) {
this.expr = expr;
}
public JsonExpression(Expression expr, List<Map.Entry<String, String>> idents) {
this.expr = expr;
this.idents.addAll(idents);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public Expression getExpression() {
return expr;
}
public void setExpression(Expression expr) {
this.expr = expr;
}
public void addIdent(String ident, String operator) {
idents.add(new AbstractMap.SimpleEntry<>(ident, operator));
}
public void addAllIdents(Collection<Map.Entry<String, String>> idents) {
this.idents.addAll(idents);
}
public List<Map.Entry<String, String>> getIdentList() {
return idents;
}
public Map.Entry<String, String> getIdent(int index) {
return idents.get(index);
}
@Deprecated
public List<String> getIdents() {
ArrayList<String> l = new ArrayList<>();
for (Map.Entry<String, String> ident : idents) {
l.add(ident.getKey());
}
return l;
}
@Deprecated
public List<String> getOperators() {
ArrayList<String> l = new ArrayList<>();
for (Map.Entry<String, String> ident : idents) {
l.add(ident.getValue());
}
return l;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append(expr.toString());
for (Map.Entry<String, String> ident : idents) {
b.append(ident.getValue()).append(ident.getKey());
}
return b.toString();
}
public JsonExpression withExpression(Expression expr) {
this.setExpression(expr);
return this;
}
}

View File

@@ -0,0 +1,264 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.util.ArrayList;
import java.util.Objects;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public class JsonFunction extends ASTNodeAccessImpl implements Expression {
private final ArrayList<JsonKeyValuePair> keyValuePairs = new ArrayList<>();
private final ArrayList<JsonFunctionExpression> expressions = new ArrayList<>();
private JsonFunctionType functionType;
private JsonAggregateOnNullType onNullType;
private JsonAggregateUniqueKeysType uniqueKeysType;
public ArrayList<JsonKeyValuePair> getKeyValuePairs() {
return keyValuePairs;
}
public ArrayList<JsonFunctionExpression> getExpressions() {
return expressions;
}
public JsonKeyValuePair getKeyValuePair(int i) {
return keyValuePairs.get(i);
}
public JsonFunctionExpression getExpression(int i) {
return expressions.get(i);
}
public boolean add(JsonKeyValuePair keyValuePair) {
return keyValuePairs.add(keyValuePair);
}
public void add(int i, JsonKeyValuePair keyValuePair) {
keyValuePairs.add(i, keyValuePair);
}
public boolean add(JsonFunctionExpression expression) {
return expressions.add(expression);
}
public void add(int i, JsonFunctionExpression expression) {
expressions.add(i, expression);
}
public boolean isEmpty() {
return keyValuePairs.isEmpty();
}
public JsonAggregateOnNullType getOnNullType() {
return onNullType;
}
public void setOnNullType(JsonAggregateOnNullType onNullType) {
this.onNullType = onNullType;
}
public JsonFunction withOnNullType(JsonAggregateOnNullType onNullType) {
this.setOnNullType(onNullType);
return this;
}
public JsonAggregateUniqueKeysType getUniqueKeysType() {
return uniqueKeysType;
}
public void setUniqueKeysType(JsonAggregateUniqueKeysType uniqueKeysType) {
this.uniqueKeysType = uniqueKeysType;
}
public JsonFunction withUniqueKeysType(JsonAggregateUniqueKeysType uniqueKeysType) {
this.setUniqueKeysType(uniqueKeysType);
return this;
}
public JsonFunctionType getType() {
return functionType;
}
public void setType(JsonFunctionType type) {
this.functionType =
Objects.requireNonNull(type,
"The Type of the JSON Aggregate Function must not be null");
}
public void setType(String typeName) {
this.functionType = JsonFunctionType.valueOf(
Objects.requireNonNull(typeName,
"The Type of the JSON Aggregate Function must not be null")
.toUpperCase());
}
public JsonFunction withType(JsonFunctionType type) {
this.setType(type);
return this;
}
public JsonFunction withType(String typeName) {
this.setType(typeName);
return this;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
// avoid countless Builder --> String conversion
public StringBuilder append(StringBuilder builder) {
switch (functionType) {
case OBJECT:
appendObject(builder);
break;
case POSTGRES_OBJECT:
appendPostgresObject(builder);
break;
case MYSQL_OBJECT:
appendMySqlObject(builder);
break;
case ARRAY:
appendArray(builder);
break;
default:
// this should never happen really
}
return builder;
}
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public StringBuilder appendObject(StringBuilder builder) {
builder.append("JSON_OBJECT( ");
int i = 0;
for (JsonKeyValuePair keyValuePair : keyValuePairs) {
if (i > 0) {
builder.append(", ");
}
if (keyValuePair.isUsingValueKeyword()) {
if (keyValuePair.isUsingKeyKeyword()) {
builder.append("KEY ");
}
builder.append(keyValuePair.getKey()).append(" VALUE ")
.append(keyValuePair.getValue());
} else {
builder.append(keyValuePair.getKey()).append(":").append(keyValuePair.getValue());
}
if (keyValuePair.isUsingFormatJson()) {
builder.append(" FORMAT JSON");
}
i++;
}
if (onNullType != null) {
switch (onNullType) {
case NULL:
builder.append(" NULL ON NULL");
break;
case ABSENT:
builder.append(" ABSENT On NULL");
break;
default:
// this should never happen
}
}
if (uniqueKeysType != null) {
switch (uniqueKeysType) {
case WITH:
builder.append(" WITH UNIQUE KEYS");
break;
case WITHOUT:
builder.append(" WITHOUT UNIQUE KEYS");
break;
default:
// this should never happen
}
}
builder.append(" ) ");
return builder;
}
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public StringBuilder appendPostgresObject(StringBuilder builder) {
builder.append("JSON_OBJECT( ");
for (JsonKeyValuePair keyValuePair : keyValuePairs) {
builder.append(keyValuePair.getKey());
if (keyValuePair.getValue() != null) {
builder.append(", ").append(keyValuePair.getValue());
}
}
builder.append(" ) ");
return builder;
}
public StringBuilder appendMySqlObject(StringBuilder builder) {
builder.append("JSON_OBJECT( ");
int i = 0;
for (JsonKeyValuePair keyValuePair : keyValuePairs) {
if (i > 0) {
builder.append(", ");
}
builder.append(keyValuePair.getKey());
builder.append(", ").append(keyValuePair.getValue());
i++;
}
builder.append(" ) ");
return builder;
}
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public StringBuilder appendArray(StringBuilder builder) {
builder.append("JSON_ARRAY( ");
int i = 0;
for (JsonFunctionExpression expr : expressions) {
if (i > 0) {
builder.append(", ");
}
expr.append(builder);
i++;
}
if (onNullType != null) {
switch (onNullType) {
case NULL:
builder.append(" NULL ON NULL ");
break;
case ABSENT:
builder.append(" ABSENT ON NULL ");
break;
default:
// "ON NULL" was omitted
}
}
builder.append(") ");
return builder;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
return append(builder).toString();
}
}

View File

@@ -0,0 +1,54 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
import java.util.Objects;
/**
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public class JsonFunctionExpression implements Serializable {
private final Expression expression;
private boolean usingFormatJson = false;
public JsonFunctionExpression(Expression expression) {
this.expression = Objects.requireNonNull(expression, "The EXPRESSION must not be null");
}
public Expression getExpression() {
return expression;
}
public boolean isUsingFormatJson() {
return usingFormatJson;
}
public void setUsingFormatJson(boolean usingFormatJson) {
this.usingFormatJson = usingFormatJson;
}
public JsonFunctionExpression withUsingFormatJson(boolean usingFormatJson) {
this.setUsingFormatJson(usingFormatJson);
return this;
}
public StringBuilder append(StringBuilder builder) {
return builder.append(getExpression()).append(isUsingFormatJson() ? " FORMAT JSON" : "");
}
@Override
public String toString() {
return append(new StringBuilder()).toString();
}
}

View File

@@ -0,0 +1,22 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
/**
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public enum JsonFunctionType {
OBJECT, ARRAY, POSTGRES_OBJECT, MYSQL_OBJECT;
public static JsonFunctionType from(String type) {
return Enum.valueOf(JsonFunctionType.class, type.toUpperCase());
}
}

View File

@@ -0,0 +1,126 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
import java.util.Objects;
/**
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public class JsonKeyValuePair implements Serializable {
private final String key;
private final Object value;
private boolean usingKeyKeyword = false;
private boolean usingValueKeyword = false;
private boolean usingFormatJson = false;
public JsonKeyValuePair(String key, Object value, boolean usingKeyKeyword,
boolean usingValueKeyword) {
this.key = Objects.requireNonNull(key, "The KEY of the Pair must not be null");
this.value = value;
this.usingKeyKeyword = usingKeyKeyword;
this.usingValueKeyword = usingValueKeyword;
}
public boolean isUsingKeyKeyword() {
return usingKeyKeyword;
}
public void setUsingKeyKeyword(boolean usingKeyKeyword) {
this.usingKeyKeyword = usingKeyKeyword;
}
public JsonKeyValuePair withUsingKeyKeyword(boolean usingKeyKeyword) {
this.setUsingKeyKeyword(usingKeyKeyword);
return this;
}
public boolean isUsingValueKeyword() {
return usingValueKeyword;
}
public void setUsingValueKeyword(boolean usingValueKeyword) {
this.usingValueKeyword = usingValueKeyword;
}
public JsonKeyValuePair withUsingValueKeyword(boolean usingValueKeyword) {
this.setUsingValueKeyword(usingValueKeyword);
return this;
}
public boolean isUsingFormatJson() {
return usingFormatJson;
}
public void setUsingFormatJson(boolean usingFormatJson) {
this.usingFormatJson = usingFormatJson;
}
public JsonKeyValuePair withUsingFormatJson(boolean usingFormatJson) {
this.setUsingFormatJson(usingFormatJson);
return this;
}
@Override
public int hashCode() {
int hash = 7;
hash = 83 * hash + Objects.hashCode(this.key);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final JsonKeyValuePair other = (JsonKeyValuePair) obj;
return Objects.equals(this.key, other.key);
}
public String getKey() {
return key;
}
public Object getValue() {
return value;
}
public StringBuilder append(StringBuilder builder) {
if (isUsingValueKeyword()) {
if (isUsingKeyKeyword()) {
builder.append("KEY ");
}
builder.append(getKey()).append(" VALUE ").append(getValue());
} else {
builder.append(getKey()).append(":").append(getValue());
}
if (isUsingFormatJson()) {
builder.append(" FORMAT JSON");
}
return builder;
}
@Override
public String toString() {
return append(new StringBuilder()).toString();
}
}

View File

@@ -0,0 +1,110 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.select.OrderByElement;
public class KeepExpression extends ASTNodeAccessImpl implements Expression {
private String name;
private List<OrderByElement> orderByElements;
private boolean first = false;
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public List<OrderByElement> getOrderByElements() {
return orderByElements;
}
public void setOrderByElements(List<OrderByElement> orderByElements) {
this.orderByElements = orderByElements;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isFirst() {
return first;
}
public void setFirst(boolean first) {
this.first = first;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("KEEP (").append(name);
b.append(" ").append(first ? "FIRST" : "LAST").append(" ");
toStringOrderByElements(b);
b.append(")");
return b.toString();
}
private void toStringOrderByElements(StringBuilder b) {
if (orderByElements != null && !orderByElements.isEmpty()) {
b.append("ORDER BY ");
for (int i = 0; i < orderByElements.size(); i++) {
if (i > 0) {
b.append(", ");
}
b.append(orderByElements.get(i).toString());
}
}
}
public KeepExpression withName(String name) {
this.setName(name);
return this;
}
public KeepExpression withOrderByElements(List<OrderByElement> orderByElements) {
this.setOrderByElements(orderByElements);
return this;
}
public KeepExpression withFirst(boolean first) {
this.setFirst(first);
return this;
}
public KeepExpression addOrderByElements(OrderByElement... orderByElements) {
List<OrderByElement> collection =
Optional.ofNullable(getOrderByElements()).orElseGet(ArrayList::new);
Collections.addAll(collection, orderByElements);
return this.withOrderByElements(collection);
}
public KeepExpression addOrderByElements(Collection<? extends OrderByElement> orderByElements) {
List<OrderByElement> collection =
Optional.ofNullable(getOrderByElements()).orElseGet(ArrayList::new);
collection.addAll(orderByElements);
return this.withOrderByElements(collection);
}
}

View File

@@ -0,0 +1,72 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2024 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.util.Arrays;
import java.util.List;
public class LambdaExpression extends ASTNodeAccessImpl implements Expression {
private List<String> identifiers;
private Expression expression;
public LambdaExpression(String identifier, Expression expression) {
this.identifiers = Arrays.asList(identifier);
this.expression = expression;
}
public LambdaExpression(List<String> identifiers, Expression expression) {
this.identifiers = identifiers;
this.expression = expression;
}
public List<String> getIdentifiers() {
return identifiers;
}
public LambdaExpression setIdentifiers(List<String> identifiers) {
this.identifiers = identifiers;
return this;
}
public Expression getExpression() {
return expression;
}
public LambdaExpression setExpression(Expression expression) {
this.expression = expression;
return this;
}
public StringBuilder appendTo(StringBuilder builder) {
if (identifiers.size() == 1) {
builder.append(identifiers.get(0));
} else {
int i = 0;
builder.append("( ");
for (String s : identifiers) {
builder.append(i++ > 0 ? ", " : "").append(s);
}
builder.append(" )");
}
return builder.append(" -> ").append(expression);
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}

View File

@@ -0,0 +1,99 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.math.BigInteger;
import java.util.Objects;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* Every number without a point or an exponential format is a LongValue.
*/
public class LongValue extends ASTNodeAccessImpl implements Expression {
private String stringValue;
public LongValue() {
// empty constructor
}
public LongValue(final String value) {
if (value == null || value.length() == 0) {
throw new IllegalArgumentException("value can neither be null nor empty.");
}
String val = value;
if (val.charAt(0) == '+') {
val = val.substring(1);
}
this.stringValue = val;
}
public LongValue(long value) {
stringValue = String.valueOf(value);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public long getValue() {
return Long.parseLong(stringValue);
}
public void setValue(long d) {
stringValue = String.valueOf(d);
}
public BigInteger getBigIntegerValue() {
return new BigInteger(stringValue);
}
public LongValue withValue(long d) {
setValue(d);
return this;
}
public String getStringValue() {
return stringValue;
}
public void setStringValue(String string) {
stringValue = string;
}
@Override
public String toString() {
return getStringValue();
}
public LongValue withStringValue(String stringValue) {
this.setStringValue(stringValue);
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
LongValue longValue = (LongValue) o;
return stringValue.equals(longValue.stringValue);
}
@Override
public int hashCode() {
return Objects.hash(stringValue);
}
}

View File

@@ -0,0 +1,124 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.select.OrderByElement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
public class MySQLGroupConcat extends ASTNodeAccessImpl implements Expression {
private ExpressionList expressionList;
private boolean distinct = false;
private List<OrderByElement> orderByElements;
private String separator;
public ExpressionList<?> getExpressionList() {
return expressionList;
}
public void setExpressionList(ExpressionList expressionList) {
this.expressionList = expressionList;
}
public boolean isDistinct() {
return distinct;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public List<OrderByElement> getOrderByElements() {
return orderByElements;
}
public void setOrderByElements(List<OrderByElement> orderByElements) {
this.orderByElements = orderByElements;
}
public String getSeparator() {
return separator;
}
public void setSeparator(String separator) {
this.separator = separator;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("GROUP_CONCAT(");
if (isDistinct()) {
b.append("DISTINCT ");
}
b.append(expressionList);
if (orderByElements != null && !orderByElements.isEmpty()) {
b.append(" ORDER BY ");
for (int i = 0; i < orderByElements.size(); i++) {
if (i > 0) {
b.append(", ");
}
b.append(orderByElements.get(i).toString());
}
}
if (separator != null) {
b.append(" SEPARATOR ").append(separator);
}
b.append(")");
return b.toString();
}
public MySQLGroupConcat withExpressionList(ExpressionList expressionList) {
this.setExpressionList(expressionList);
return this;
}
public MySQLGroupConcat withDistinct(boolean distinct) {
this.setDistinct(distinct);
return this;
}
public MySQLGroupConcat withOrderByElements(List<OrderByElement> orderByElements) {
this.setOrderByElements(orderByElements);
return this;
}
public MySQLGroupConcat withSeparator(String separator) {
this.setSeparator(separator);
return this;
}
public MySQLGroupConcat addOrderByElements(OrderByElement... orderByElements) {
List<OrderByElement> collection =
Optional.ofNullable(getOrderByElements()).orElseGet(ArrayList::new);
Collections.addAll(collection, orderByElements);
return this.withOrderByElements(collection);
}
public MySQLGroupConcat addOrderByElements(
Collection<? extends OrderByElement> orderByElements) {
List<OrderByElement> collection =
Optional.ofNullable(getOrderByElements()).orElseGet(ArrayList::new);
collection.addAll(orderByElements);
return this.withOrderByElements(collection);
}
}

View File

@@ -0,0 +1,53 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
import java.util.List;
public class MySQLIndexHint implements Serializable {
private final String action;
private final String indexQualifier;
private final List<String> indexNames;
public MySQLIndexHint(String action, String indexQualifier, List<String> indexNames) {
this.action = action;
this.indexQualifier = indexQualifier;
this.indexNames = indexNames;
}
public String getAction() {
return action;
}
public String getIndexQualifier() {
return indexQualifier;
}
public List<String> getIndexNames() {
return indexNames;
}
@Override
public String toString() {
// use|ignore|force key|index (index1,...,indexN)
StringBuilder buffer = new StringBuilder();
buffer.append(" ").append(action).append(" ").append(indexQualifier).append(" (");
for (int i = 0; i < indexNames.size(); i++) {
if (i > 0) {
buffer.append(",");
}
buffer.append(indexNames.get(i));
}
buffer.append(")");
return buffer.toString();
}
}

View File

@@ -0,0 +1,66 @@
/*
* - #%L JSQLParser library %% Copyright (C) 2004 - 2019 JSQLParser %% Dual licensed under GNU LGPL
* 2.1 or Apache License 2.0 #L%
*/
package net.sf.jsqlparser.expression;
import java.util.List;
import java.util.regex.Pattern;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class NextValExpression extends ASTNodeAccessImpl implements Expression {
public static final Pattern NEXT_VALUE_PATTERN =
Pattern.compile("NEXT\\s+VALUE\\s+FOR", Pattern.CASE_INSENSITIVE);
private final List<String> nameList;
private boolean usingNextValueFor = false;
public NextValExpression(List<String> nameList, String image) {
this.nameList = nameList;
// Test if we shall use NEXT VALUE FOR instead of NEXTVAL FOR
if (NEXT_VALUE_PATTERN.matcher(image).matches()) {
usingNextValueFor = true;
}
}
public boolean isUsingNextValueFor() {
return usingNextValueFor;
}
public void setUsingNextValueFor(boolean usingNextValueFor) {
this.usingNextValueFor = usingNextValueFor;
}
public NextValExpression withNextValueFor(boolean usingNextValueFor) {
setUsingNextValueFor(usingNextValueFor);
return this;
}
public List<String> getNameList() {
return nameList;
}
public String getName() {
StringBuilder b = new StringBuilder();
for (String name : nameList) {
if (b.length() > 0) {
b.append(".");
}
b.append(name);
}
return b.toString();
}
@Override
public String toString() {
return (usingNextValueFor
? "NEXT VALUE FOR "
: "NEXTVAL FOR ") + getName();
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}

View File

@@ -0,0 +1,75 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* It represents a "not " or "!" before an expression.
*/
public class NotExpression extends ASTNodeAccessImpl implements Expression {
private Expression expression;
private boolean exclamationMark = false;
public NotExpression() {
// empty constructor
}
public NotExpression(Expression expression) {
this(expression, false);
}
public NotExpression(Expression expression, boolean useExclamationMark) {
setExpression(expression);
this.exclamationMark = useExclamationMark;
}
public Expression getExpression() {
return expression;
}
public final void setExpression(Expression expression) {
this.expression = expression;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return (exclamationMark ? "! " : "NOT ") + expression.toString();
}
public boolean isExclamationMark() {
return exclamationMark;
}
public void setExclamationMark(boolean exclamationMark) {
this.exclamationMark = exclamationMark;
}
public NotExpression withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public NotExpression withExclamationMark(boolean exclamationMark) {
this.setExclamationMark(exclamationMark);
return this;
}
public <E extends Expression> E getExpression(Class<E> type) {
return type.cast(getExpression());
}
}

View File

@@ -0,0 +1,25 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class NullValue extends ASTNodeAccessImpl implements Expression {
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return "NULL";
}
}

View File

@@ -0,0 +1,40 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class NumericBind extends ASTNodeAccessImpl implements Expression {
private int bindId;
public int getBindId() {
return bindId;
}
public void setBindId(int bindId) {
this.bindId = bindId;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return ":" + bindId;
}
public NumericBind withBindId(int bindId) {
this.setBindId(bindId);
return this;
}
}

View File

@@ -0,0 +1,110 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class OracleHierarchicalExpression extends ASTNodeAccessImpl implements Expression {
boolean connectFirst = false;
private Expression startExpression;
private Expression connectExpression;
private boolean noCycle = false;
public Expression getStartExpression() {
return startExpression;
}
public void setStartExpression(Expression startExpression) {
this.startExpression = startExpression;
}
public Expression getConnectExpression() {
return connectExpression;
}
public void setConnectExpression(Expression connectExpression) {
this.connectExpression = connectExpression;
}
public boolean isNoCycle() {
return noCycle;
}
public void setNoCycle(boolean noCycle) {
this.noCycle = noCycle;
}
public boolean isConnectFirst() {
return connectFirst;
}
public void setConnectFirst(boolean connectFirst) {
this.connectFirst = connectFirst;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
if (isConnectFirst()) {
b.append(" CONNECT BY ");
if (isNoCycle()) {
b.append("NOCYCLE ");
}
b.append(connectExpression.toString());
if (startExpression != null) {
b.append(" START WITH ").append(startExpression.toString());
}
} else {
if (startExpression != null) {
b.append(" START WITH ").append(startExpression.toString());
}
b.append(" CONNECT BY ");
if (isNoCycle()) {
b.append("NOCYCLE ");
}
b.append(connectExpression.toString());
}
return b.toString();
}
public OracleHierarchicalExpression withStartExpression(Expression startExpression) {
this.setStartExpression(startExpression);
return this;
}
public OracleHierarchicalExpression withConnectExpression(Expression connectExpression) {
this.setConnectExpression(connectExpression);
return this;
}
public OracleHierarchicalExpression withNoCycle(boolean noCycle) {
this.setNoCycle(noCycle);
return this;
}
public OracleHierarchicalExpression withConnectFirst(boolean connectFirst) {
this.setConnectFirst(connectFirst);
return this;
}
public <E extends Expression> E getStartExpression(Class<E> type) {
return type.cast(getStartExpression());
}
public <E extends Expression> E getConnectExpression(Class<E> type) {
return type.cast(getConnectExpression());
}
}

View File

@@ -0,0 +1,101 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.select.ParenthesedSelect;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Oracle Hint Expression
*/
public class OracleHint extends ASTNodeAccessImpl implements Expression {
private static final Pattern SINGLE_LINE = Pattern.compile("--\\+ *([^ ].*[^ ])");
private static final Pattern MULTI_LINE =
Pattern.compile("\\/\\*\\+ *([^ ].*[^ ]) *\\*+\\/", Pattern.MULTILINE | Pattern.DOTALL);
private String value;
private boolean singleLine = false;
public static boolean isHintMatch(String comment) {
return SINGLE_LINE.matcher(comment).find() || MULTI_LINE.matcher(comment).find();
}
public static OracleHint getHintFromSelectBody(Select selectBody) {
if (selectBody instanceof PlainSelect) {
return ((PlainSelect) selectBody).getOracleHint();
} else if (selectBody instanceof ParenthesedSelect) {
return getHintFromSelectBody(((ParenthesedSelect) selectBody).getSelect());
} else {
return null;
}
}
public final void setComment(String comment) {
Matcher m;
m = SINGLE_LINE.matcher(comment);
if (m.find()) {
this.value = m.group(1);
this.singleLine = true;
return;
}
m = MULTI_LINE.matcher(comment);
if (m.find()) {
this.value = m.group(1);
this.singleLine = false;
}
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public boolean isSingleLine() {
return singleLine;
}
public void setSingleLine(boolean singleLine) {
this.singleLine = singleLine;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
if (singleLine) {
return "--+ " + value + "\n";
} else {
return "/*+ " + value + " */";
}
}
public OracleHint withValue(String value) {
this.setValue(value);
return this;
}
public OracleHint withSingleLine(boolean singleLine) {
this.setSingleLine(singleLine);
return this;
}
}

View File

@@ -0,0 +1,55 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.util.Objects;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public class OracleNamedFunctionParameter extends ASTNodeAccessImpl implements Expression {
private final String name;
private final Expression expression;
public OracleNamedFunctionParameter(String name, Expression expression) {
this.name = Objects.requireNonNull(name,
"The NAME of the OracleNamedFunctionParameter must not be null.");
this.expression = Objects.requireNonNull(expression,
"The EXPRESSION of the OracleNamedFunctionParameter must not be null.");
}
public String getName() {
return name;
}
public Expression getExpression() {
return expression;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public StringBuilder appendTo(StringBuilder builder) {
builder.append(name)
.append(" => ")
.append(expression);
return builder;
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
}

View File

@@ -0,0 +1,62 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import net.sf.jsqlparser.statement.select.OrderByElement;
public class OrderByClause implements Serializable {
private List<OrderByElement> orderByElements;
public List<OrderByElement> getOrderByElements() {
return orderByElements;
}
public void setOrderByElements(List<OrderByElement> orderByElements) {
this.orderByElements = orderByElements;
}
public void toStringOrderByElements(StringBuilder b) {
if (orderByElements != null && !orderByElements.isEmpty()) {
b.append("ORDER BY ");
for (int i = 0; i < orderByElements.size(); i++) {
if (i > 0) {
b.append(", ");
}
b.append(orderByElements.get(i).toString());
}
}
}
public OrderByClause withOrderByElements(List<OrderByElement> orderByElements) {
this.setOrderByElements(orderByElements);
return this;
}
public OrderByClause addOrderByElements(OrderByElement... orderByElements) {
List<OrderByElement> collection =
Optional.ofNullable(getOrderByElements()).orElseGet(ArrayList::new);
Collections.addAll(collection, orderByElements);
return this.withOrderByElements(collection);
}
public OrderByClause addOrderByElements(Collection<? extends OrderByElement> orderByElements) {
List<OrderByElement> collection =
Optional.ofNullable(getOrderByElements()).orElseGet(ArrayList::new);
collection.addAll(orderByElements);
return this.withOrderByElements(collection);
}
}

View File

@@ -0,0 +1,41 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2022 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class OverlapsCondition extends ASTNodeAccessImpl implements Expression {
private final ExpressionList<?> left;
private final ExpressionList<?> right;
public OverlapsCondition(ExpressionList<?> left, ExpressionList<?> right) {
this.left = left;
this.right = right;
}
public ExpressionList<?> getLeft() {
return left;
}
public ExpressionList<?> getRight() {
return right;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return String.format("%s OVERLAPS %s", left.toString(), right.toString());
}
}

View File

@@ -0,0 +1,37 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList;
/**
* @deprecated This class is deprecated since version 5.0. Use {@link ParenthesedExpressionList}
* instead. The reason for deprecation is the ambiguity and redundancy.
*/
@Deprecated(since = "5.0", forRemoval = true)
public class Parenthesis extends ParenthesedExpressionList<Expression> {
public Expression getExpression() {
return isEmpty() ? null : get(0);
}
public Parenthesis setExpression(Expression expression) {
this.set(0, expression);
return this;
}
public Parenthesis withExpression(Expression expression) {
return this.setExpression(expression);
}
public <E extends Expression> E getExpression(Class<E> type) {
return type.cast(getExpression());
}
}

View File

@@ -0,0 +1,53 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.statement.select.PlainSelect;
import java.io.Serializable;
public class PartitionByClause implements Serializable {
ExpressionList partitionExpressionList;
boolean brackets = false;
public ExpressionList getPartitionExpressionList() {
return partitionExpressionList;
}
public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
setPartitionExpressionList(partitionExpressionList, false);
}
public void setPartitionExpressionList(ExpressionList partitionExpressionList,
boolean brackets) {
this.partitionExpressionList = partitionExpressionList;
this.brackets = brackets;
}
public void toStringPartitionBy(StringBuilder b) {
if (partitionExpressionList != null
&& !partitionExpressionList.getExpressions().isEmpty()) {
b.append("PARTITION BY ");
b.append(PlainSelect.getStringList(partitionExpressionList.getExpressions(), true,
brackets));
b.append(" ");
}
}
public boolean isBrackets() {
return brackets;
}
public PartitionByClause withPartitionExpressionList(ExpressionList partitionExpressionList) {
this.setPartitionExpressionList(partitionExpressionList);
return this;
}
}

View File

@@ -0,0 +1,50 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2023 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class RangeExpression extends ASTNodeAccessImpl implements Expression {
private Expression startExpression;
private Expression endExpression;
public RangeExpression(Expression startExpression, Expression endExpression) {
this.startExpression = startExpression;
this.endExpression = endExpression;
}
public Expression getStartExpression() {
return startExpression;
}
public RangeExpression setStartExpression(Expression startExpression) {
this.startExpression = startExpression;
return this;
}
public Expression getEndExpression() {
return endExpression;
}
public RangeExpression setEndExpression(Expression endExpression) {
this.endExpression = endExpression;
return this;
}
@Override
public String toString() {
return startExpression + ":" + endExpression;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}

View File

@@ -0,0 +1,48 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList;
public class RowConstructor<T extends Expression> extends ParenthesedExpressionList<T>
implements Expression {
private String name = null;
public RowConstructor() {}
public RowConstructor(String name, ExpressionList<T> expressionList) {
this.name = name;
addAll(expressionList);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return (name != null ? name : "") + super.toString();
}
public RowConstructor<?> withName(String name) {
this.setName(name);
return this;
}
@Override
public <K, S> K accept(ExpressionVisitor<K> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}

View File

@@ -0,0 +1,48 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public final class RowGetExpression extends ASTNodeAccessImpl implements Expression {
private Expression expression;
private String columnName;
public RowGetExpression(Expression expression, String columnName) {
this.expression = expression;
this.columnName = columnName;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return expression + "." + columnName;
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
}

View File

@@ -0,0 +1,67 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class SQLServerHints implements Serializable {
private Boolean noLock;
private String indexName;
public SQLServerHints() {}
public SQLServerHints withNoLock() {
this.noLock = true;
return this;
}
public Boolean getNoLock() {
return noLock;
}
public void setNoLock(Boolean noLock) {
this.noLock = noLock;
}
public String getIndexName() {
return indexName;
}
public void setIndexName(String indexName) {
this.indexName = indexName;
}
@Override
public String toString() {
List<String> hints = new ArrayList<>();
if (indexName != null) {
hints.add("INDEX (" + indexName + ")");
}
if (Boolean.TRUE.equals(noLock)) {
hints.add("NOLOCK");
}
return " WITH ("
+ String.join(", ", hints)
+ ")";
}
public SQLServerHints withNoLock(Boolean noLock) {
this.setNoLock(noLock);
return this;
}
public SQLServerHints withIndexName(String indexName) {
this.setIndexName(indexName);
return this;
}
}

View File

@@ -0,0 +1,73 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* It represents a "-" or "+" or "~" before an expression
*/
public class SignedExpression extends ASTNodeAccessImpl implements Expression {
private char sign;
private Expression expression;
public SignedExpression() {
// empty constructor
}
public SignedExpression(char sign, Expression expression) {
setSign(sign);
setExpression(expression);
}
public char getSign() {
return sign;
}
public final void setSign(char sign) {
this.sign = sign;
if (sign != '+' && sign != '-' && sign != '~') {
throw new IllegalArgumentException("illegal sign character, only + - ~ allowed");
}
}
public Expression getExpression() {
return expression;
}
public final void setExpression(Expression expression) {
this.expression = expression;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return getSign() + expression.toString();
}
public SignedExpression withSign(char sign) {
this.setSign(sign);
return this;
}
public SignedExpression withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public <E extends Expression> E getExpression(Class<E> type) {
return type.cast(getExpression());
}
}

View File

@@ -0,0 +1,80 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.schema.Table;
import java.util.Collections;
import java.util.List;
public class SpannerInterleaveIn {
private Table table;
private OnDelete onDelete;
public SpannerInterleaveIn() {
}
public SpannerInterleaveIn(Table table, OnDelete action) {
setTable(table);
setOnDelete(action);
}
public SpannerInterleaveIn(List<String> nameParts) {
this(new Table(nameParts), null);
}
public SpannerInterleaveIn(String tableName) {
this(Collections.singletonList(tableName));
}
public Table getTable() {
return table;
}
public void setTable(Table table) {
this.table = table;
}
public OnDelete getOnDelete() {
return onDelete;
}
public void setOnDelete(OnDelete action) {
this.onDelete = action;
}
@Override
public String toString() {
return "INTERLEAVE IN PARENT " + getTable().getName() +
(getOnDelete() == null ? ""
: " ON DELETE "
+ (getOnDelete() == OnDelete.CASCADE ? "CASCADE" : "NO ACTION"));
}
public SpannerInterleaveIn withTable(Table table) {
this.setTable(table);
return this;
}
public SpannerInterleaveIn withOnDelete(OnDelete action) {
this.setOnDelete(action);
return this;
}
public enum OnDelete {
CASCADE, NO_ACTION;
public static OnDelete from(String action) {
return Enum.valueOf(OnDelete.class, action.toUpperCase());
}
}
}

View File

@@ -0,0 +1,119 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* A string as in 'example_string'
*/
public final class StringValue extends ASTNodeAccessImpl implements Expression {
public static final List<String> ALLOWED_PREFIXES =
Arrays.asList("N", "U", "E", "R", "B", "RB", "_utf8", "Q");
private String value = "";
private String prefix = null;
public StringValue() {
// empty constructor
}
public StringValue(String escapedValue) {
// removing "'" at the start and at the end
if (escapedValue.length() >= 2 && escapedValue.startsWith("'")
&& escapedValue.endsWith("'")) {
value = escapedValue.substring(1, escapedValue.length() - 1);
return;
}
if (escapedValue.length() > 2) {
for (String p : ALLOWED_PREFIXES) {
if (escapedValue.length() > p.length()
&& escapedValue.substring(0, p.length()).equalsIgnoreCase(p)
&& escapedValue.charAt(p.length()) == '\'') {
this.prefix = p;
value = escapedValue.substring(p.length() + 1, escapedValue.length() - 1);
return;
}
}
}
value = escapedValue;
}
public String getValue() {
return value;
}
public void setValue(String string) {
value = string;
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getNotExcapedValue() {
StringBuilder buffer = new StringBuilder(value);
int index = 0;
int deletesNum = 0;
while ((index = value.indexOf("''", index)) != -1) {
buffer.deleteCharAt(index - deletesNum);
index += 2;
deletesNum++;
}
return buffer.toString();
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return (prefix != null ? prefix : "") + "'" + value + "'";
}
public StringValue withPrefix(String prefix) {
this.setPrefix(prefix);
return this;
}
public StringValue withValue(String value) {
this.setValue(value);
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
StringValue that = (StringValue) o;
return Objects.equals(value, that.value) && Objects.equals(prefix, that.prefix);
}
@Override
public int hashCode() {
return Objects.hash(value, prefix);
}
}

View File

@@ -0,0 +1,198 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2024 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.create.table.ColDataType;
import net.sf.jsqlparser.statement.select.SelectItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/*
* STRUCT<T>
*
* Type Declaration Meaning STRUCT<INT64> Simple struct with a single unnamed 64-bit integer field.
* STRUCT<x STRING(10)> Simple struct with a single parameterized string field named x. STRUCT<x
* STRUCT<y INT64, z INT64>> A struct with a nested struct named x inside it. The struct x has two
* fields, y and z, both of which are 64-bit integers. STRUCT<inner_array ARRAY<INT64>> A struct
* containing an array named inner_array that holds 64-bit integer elements.
*
* STRUCT( expr1 [AS field_name] [, ... ])
*
* Syntax Output Type STRUCT(1,2,3) STRUCT<int64,int64,int64> STRUCT() STRUCT<> STRUCT('abc')
* STRUCT<string> STRUCT(1, t.str_col) STRUCT<int64, str_col string> STRUCT(1 AS a, 'abc' AS b)
* STRUCT<a int64, b string> STRUCT(str_col AS abc) STRUCT<abc string>
*
*
* Struct Literals
*
* Example Output Type (1, 2, 3) STRUCT<INT64, INT64, INT64> (1, 'abc') STRUCT<INT64, STRING>
* STRUCT(1 AS foo, 'abc' AS bar) STRUCT<foo INT64, bar STRING> STRUCT<INT64, STRING>(1, 'abc')
* STRUCT<INT64, STRING> STRUCT(1) STRUCT<INT64> STRUCT<INT64>(1) STRUCT<INT64>
*
*/
public class StructType extends ASTNodeAccessImpl implements Expression {
private Dialect dialect = Dialect.BIG_QUERY;;
private String keyword;
private List<Map.Entry<String, ColDataType>> parameters;
private List<SelectItem<?>> arguments;
public StructType(Dialect dialect, String keyword,
List<Map.Entry<String, ColDataType>> parameters,
List<SelectItem<?>> arguments) {
this.dialect = dialect;
this.keyword = keyword;
this.parameters = parameters;
this.arguments = arguments;
}
public StructType(Dialect dialect, List<Map.Entry<String, ColDataType>> parameters,
List<SelectItem<?>> arguments) {
this.dialect = dialect;
this.parameters = parameters;
this.arguments = arguments;
}
public StructType(Dialect dialect, List<SelectItem<?>> arguments) {
this.dialect = dialect;
this.arguments = arguments;
}
public Dialect getDialect() {
return dialect;
}
public StructType setDialect(Dialect dialect) {
this.dialect = dialect;
return this;
}
public String getKeyword() {
return keyword;
}
public StructType setKeyword(String keyword) {
this.keyword = keyword;
return this;
}
public List<Map.Entry<String, ColDataType>> getParameters() {
return parameters;
}
public StructType setParameters(List<Map.Entry<String, ColDataType>> parameters) {
this.parameters = parameters;
return this;
}
public List<SelectItem<?>> getArguments() {
return arguments;
}
public StructType setArguments(List<SelectItem<?>> arguments) {
this.arguments = arguments;
return this;
}
public StructType add(Expression expression, String aliasName) {
if (arguments == null) {
arguments = new ArrayList<>();
}
arguments.add(new SelectItem<>(expression, aliasName));
return this;
}
public StringBuilder appendTo(StringBuilder builder) {
if (dialect != Dialect.DUCKDB && keyword != null) {
builder.append(keyword);
}
if (dialect != Dialect.DUCKDB && parameters != null && !parameters.isEmpty()) {
builder.append("<");
int i = 0;
for (Map.Entry<String, ColDataType> e : parameters) {
if (0 < i++) {
builder.append(",");
}
// optional name
if (e.getKey() != null && !e.getKey().isEmpty()) {
builder.append(e.getKey()).append(" ");
}
// mandatory type
builder.append(e.getValue());
}
builder.append(">");
}
if (arguments != null && !arguments.isEmpty()) {
if (dialect == Dialect.DUCKDB) {
builder.append("{ ");
int i = 0;
for (SelectItem<?> e : arguments) {
if (0 < i++) {
builder.append(",");
}
builder.append(e.getAlias().getName());
builder.append(":");
builder.append(e.getExpression());
}
builder.append(" }");
} else {
builder.append("(");
int i = 0;
for (SelectItem<?> e : arguments) {
if (0 < i++) {
builder.append(",");
}
e.appendTo(builder);
}
builder.append(")");
}
}
if (dialect == Dialect.DUCKDB && parameters != null && !parameters.isEmpty()) {
builder.append("::STRUCT( ");
int i = 0;
for (Map.Entry<String, ColDataType> e : parameters) {
if (0 < i++) {
builder.append(",");
}
builder.append(e.getKey()).append(" ");
builder.append(e.getValue());
}
builder.append(")");
}
return builder;
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public enum Dialect {
BIG_QUERY, DUCKDB
}
}

View File

@@ -0,0 +1,48 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class TimeKeyExpression extends ASTNodeAccessImpl implements Expression {
private String stringValue;
public TimeKeyExpression() {
// empty constructor
}
public TimeKeyExpression(final String value) {
this.stringValue = value;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public String getStringValue() {
return stringValue;
}
public void setStringValue(String string) {
stringValue = string;
}
@Override
public String toString() {
return getStringValue();
}
public TimeKeyExpression withStringValue(String stringValue) {
this.setStringValue(stringValue);
return this;
}
}

View File

@@ -0,0 +1,56 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.sql.Time;
/**
* A Time in the form {t 'hh:mm:ss'}
*/
public class TimeValue extends ASTNodeAccessImpl implements Expression {
private Time value;
public TimeValue() {
// empty constructor
}
public TimeValue(String value) {
if (value == null || value.isEmpty()) {
throw new IllegalArgumentException("value can neither be null nor empty.");
}
this.value = Time.valueOf(value.substring(1, value.length() - 1));
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public Time getValue() {
return value;
}
public void setValue(Time d) {
value = d;
}
@Override
public String toString() {
return "{t '" + value + "'}";
}
public TimeValue withValue(Time value) {
this.setValue(value);
return this;
}
}

View File

@@ -0,0 +1,74 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.sql.Timestamp;
import java.util.Objects;
/**
* A Timestamp in the form {ts 'yyyy-mm-dd hh:mm:ss.f . . .'}
*/
public final class TimestampValue extends ASTNodeAccessImpl implements Expression {
private static final char QUOTATION = '\'';
private Timestamp value;
private String rawValue;
public TimestampValue() {
// empty constructor
}
public TimestampValue(String value) {
// if (value == null) {
// throw new IllegalArgumentException("null string");
// } else {
// setRawValue(value);
// }
setRawValue(Objects.requireNonNull(value, "The Timestamp string value must not be null."));
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public Timestamp getValue() {
return value;
}
public void setValue(Timestamp d) {
value = d;
}
public String getRawValue() {
return rawValue;
}
public void setRawValue(String rawValue) {
this.rawValue = rawValue;
if (rawValue.charAt(0) == QUOTATION) {
this.value = Timestamp.valueOf(rawValue.substring(1, rawValue.length() - 1));
} else {
this.value = Timestamp.valueOf(rawValue.substring(0, rawValue.length()));
}
}
@Override
public String toString() {
return "{ts '" + value + "'}";
}
public TimestampValue withValue(Timestamp value) {
this.setValue(value);
return this;
}
}

View File

@@ -0,0 +1,63 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import java.util.Arrays;
import java.util.List;
public class TimezoneExpression extends ASTNodeAccessImpl implements Expression {
private final ExpressionList<Expression> timezoneExpressions = new ExpressionList<>();
private Expression leftExpression;
public TimezoneExpression() {
leftExpression = null;
}
public TimezoneExpression(Expression leftExpression, Expression... timezoneExpressions) {
this.leftExpression = leftExpression;
this.timezoneExpressions.addAll(Arrays.asList(timezoneExpressions));
}
public Expression getLeftExpression() {
return leftExpression;
}
public TimezoneExpression setLeftExpression(Expression expression) {
this.leftExpression = expression;
return this;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public List<Expression> getTimezoneExpressions() {
return timezoneExpressions;
}
public void addTimezoneExpression(Expression... timezoneExpr) {
this.timezoneExpressions.addAll(Arrays.asList(timezoneExpr));
}
@Override
public String toString() {
StringBuilder returnValue = new StringBuilder(leftExpression.toString());
for (Expression expr : timezoneExpressions) {
returnValue.append(" AT TIME ZONE ").append(expr.toString());
}
return returnValue.toString();
}
}

View File

@@ -0,0 +1,112 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2023 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.create.table.ColDataType;
public class TranscodingFunction extends ASTNodeAccessImpl implements Expression {
private boolean isTranscodeStyle = true;
private ColDataType colDataType;
private Expression expression;
private String transcodingName;
public TranscodingFunction(Expression expression, String transcodingName) {
this.expression = expression;
this.transcodingName = transcodingName;
}
public TranscodingFunction(ColDataType colDataType, Expression expression,
String transcodingName) {
this.colDataType = colDataType;
this.expression = expression;
this.transcodingName = transcodingName;
this.isTranscodeStyle = false;
}
public TranscodingFunction() {
this(null, null);
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
public TranscodingFunction withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public String getTranscodingName() {
return transcodingName;
}
public void setTranscodingName(String transcodingName) {
this.transcodingName = transcodingName;
}
public TranscodingFunction withTranscodingName(String transcodingName) {
this.setTranscodingName(transcodingName);
return this;
}
public ColDataType getColDataType() {
return colDataType;
}
public TranscodingFunction setColDataType(ColDataType colDataType) {
this.colDataType = colDataType;
return this;
}
public boolean isTranscodeStyle() {
return isTranscodeStyle;
}
public TranscodingFunction setTranscodeStyle(boolean transcodeStyle) {
isTranscodeStyle = transcodeStyle;
return this;
}
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public StringBuilder appendTo(StringBuilder builder) {
if (isTranscodeStyle) {
return builder
.append("CONVERT( ")
.append(expression)
.append(" USING ")
.append(transcodingName)
.append(" )");
} else {
return builder
.append("CONVERT( ")
.append(colDataType)
.append(", ")
.append(expression)
.append(transcodingName != null && !transcodingName.isEmpty()
? ", " + transcodingName
: "")
.append(" )");
}
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
}

View File

@@ -0,0 +1,124 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2023 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class TrimFunction extends ASTNodeAccessImpl implements Expression {
private TrimSpecification trimSpecification;
private Expression expression;
private Expression fromExpression;
private boolean isUsingFromKeyword;
public TrimFunction(TrimSpecification trimSpecification,
Expression expression,
Expression fromExpression,
boolean isUsingFromKeyword) {
this.trimSpecification = trimSpecification;
this.expression = expression;
this.fromExpression = fromExpression;
this.isUsingFromKeyword = isUsingFromKeyword;
}
public TrimFunction() {
this(null, null, null, false);
}
public TrimSpecification getTrimSpecification() {
return trimSpecification;
}
public void setTrimSpecification(TrimSpecification trimSpecification) {
this.trimSpecification = trimSpecification;
}
public TrimFunction withTrimSpecification(TrimSpecification trimSpecification) {
this.setTrimSpecification(trimSpecification);
return this;
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
public TrimFunction withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public Expression getFromExpression() {
return fromExpression;
}
public void setFromExpression(Expression fromExpression) {
if (fromExpression == null) {
setUsingFromKeyword(false);
}
this.fromExpression = fromExpression;
}
public TrimFunction withFromExpression(Expression fromExpression) {
this.setFromExpression(fromExpression);
return this;
}
public boolean isUsingFromKeyword() {
return isUsingFromKeyword;
}
public void setUsingFromKeyword(boolean useFromKeyword) {
isUsingFromKeyword = useFromKeyword;
}
public TrimFunction withUsingFromKeyword(boolean useFromKeyword) {
this.setUsingFromKeyword(useFromKeyword);
return this;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public StringBuilder appendTo(StringBuilder builder) {
builder.append("Trim(");
if (trimSpecification != null) {
builder.append(" ").append(trimSpecification.name());
}
if (expression != null) {
builder.append(" ").append(expression);
}
if (fromExpression != null) {
builder
.append(isUsingFromKeyword ? " FROM " : ", ")
.append(fromExpression);
}
builder.append(" )");
return builder;
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
public enum TrimSpecification {
LEADING, TRAILING, BOTH
}
}

View File

@@ -0,0 +1,65 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* Simple uservariables like @test.
*/
public class UserVariable extends ASTNodeAccessImpl implements Expression {
private String name;
private boolean doubleAdd = false;
public UserVariable() {
// empty constructor
}
public UserVariable(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public boolean isDoubleAdd() {
return doubleAdd;
}
public void setDoubleAdd(boolean doubleAdd) {
this.doubleAdd = doubleAdd;
}
@Override
public String toString() {
return "@" + (doubleAdd ? "@" : "") + name;
}
public UserVariable withName(String name) {
this.setName(name);
return this;
}
public UserVariable withDoubleAdd(boolean doubleAdd) {
this.setDoubleAdd(doubleAdd);
return this;
}
}

View File

@@ -0,0 +1,58 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* Assignment to a user variable like in select @a = 5.
*/
public class VariableAssignment extends ASTNodeAccessImpl implements Expression {
private UserVariable variable;
private String operation;
private Expression expression;
public UserVariable getVariable() {
return variable;
}
public void setVariable(UserVariable variable) {
this.variable = variable;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
@Override
public String toString() {
return variable.toString() + " " + operation + " " + expression.toString();
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}

View File

@@ -0,0 +1,78 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* A clause of following syntax: WHEN condition THEN expression. Which is part of a CaseExpression.
*/
public class WhenClause extends ASTNodeAccessImpl implements Expression {
private Expression whenExpression;
private Expression thenExpression;
public WhenClause() {}
public WhenClause(Expression whenExpression, Expression thenExpression) {
this.whenExpression = whenExpression;
this.thenExpression = thenExpression;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public Expression getThenExpression() {
return thenExpression;
}
public void setThenExpression(Expression thenExpression) {
this.thenExpression = thenExpression;
}
/**
* @return Returns the whenExpression.
*/
public Expression getWhenExpression() {
return whenExpression;
}
/**
* @param whenExpression The whenExpression to set.
*/
public void setWhenExpression(Expression whenExpression) {
this.whenExpression = whenExpression;
}
@Override
public String toString() {
return "WHEN " + whenExpression + " THEN " + thenExpression;
}
public WhenClause withWhenExpression(Expression whenExpression) {
this.setWhenExpression(whenExpression);
return this;
}
public WhenClause withThenExpression(Expression thenExpression) {
this.setThenExpression(thenExpression);
return this;
}
public <E extends Expression> E getThenExpression(Class<E> type) {
return type.cast(getThenExpression());
}
public <E extends Expression> E getWhenExpression(Class<E> type) {
return type.cast(getWhenExpression());
}
}

View File

@@ -0,0 +1,95 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2022 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
import java.util.List;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.statement.select.OrderByElement;
public class WindowDefinition implements Serializable {
final OrderByClause orderBy = new OrderByClause();
final PartitionByClause partitionBy = new PartitionByClause();
WindowElement windowElement = null;
private String windowName;
public OrderByClause getOrderBy() {
return orderBy;
}
public PartitionByClause getPartitionBy() {
return partitionBy;
}
public WindowElement getWindowElement() {
return windowElement;
}
public void setWindowElement(WindowElement windowElement) {
this.windowElement = windowElement;
}
public List<OrderByElement> getOrderByElements() {
return orderBy.getOrderByElements();
}
public void setOrderByElements(List<OrderByElement> orderByElements) {
orderBy.setOrderByElements(orderByElements);
}
public ExpressionList getPartitionExpressionList() {
return partitionBy.getPartitionExpressionList();
}
public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
setPartitionExpressionList(partitionExpressionList, false);
}
public void setPartitionExpressionList(ExpressionList partitionExpressionList,
boolean brackets) {
partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
}
public String getWindowName() {
return windowName;
}
public void setWindowName(String windowName) {
this.windowName = windowName;
}
public WindowDefinition withWindowName(String windowName) {
setWindowName(windowName);
return this;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
if (windowName != null) {
b.append(windowName).append(" AS ");
}
b.append("(");
partitionBy.toStringPartitionBy(b);
orderBy.toStringOrderByElements(b);
if (windowElement != null) {
if (orderBy.getOrderByElements() != null) {
b.append(' ');
}
b.append(windowElement);
}
b.append(")");
return b.toString();
}
}

View File

@@ -0,0 +1,80 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
public class WindowElement implements Serializable {
private Type type;
private WindowOffset offset;
private WindowRange range;
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public WindowOffset getOffset() {
return offset;
}
public void setOffset(WindowOffset offset) {
this.offset = offset;
}
public WindowRange getRange() {
return range;
}
public void setRange(WindowRange range) {
this.range = range;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder(type.toString());
if (offset != null) {
buffer.append(offset.toString());
} else if (range != null) {
buffer.append(range.toString());
}
return buffer.toString();
}
public WindowElement withType(Type type) {
this.setType(type);
return this;
}
public WindowElement withOffset(WindowOffset offset) {
this.setOffset(offset);
return this;
}
public WindowElement withRange(WindowRange range) {
this.setRange(range);
return this;
}
public enum Type {
ROWS, RANGE;
public static Type from(String type) {
return Enum.valueOf(Type.class, type.toUpperCase());
}
}
}

View File

@@ -0,0 +1,86 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
public class WindowOffset implements Serializable {
private Expression expression;
private Type type;
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
if (expression != null) {
buffer.append(' ').append(expression);
if (type != null) {
buffer.append(' ');
buffer.append(type);
}
} else {
if (type != null) {
switch (type) {
case PRECEDING:
buffer.append(" UNBOUNDED PRECEDING");
break;
case FOLLOWING:
buffer.append(" UNBOUNDED FOLLOWING");
break;
case CURRENT:
buffer.append(" CURRENT ROW");
break;
default:
break;
}
}
}
return buffer.toString();
}
public WindowOffset withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public WindowOffset withType(Type type) {
this.setType(type);
return this;
}
public <E extends Expression> E getExpression(Class<E> type) {
return type.cast(getExpression());
}
public enum Type {
PRECEDING, FOLLOWING, CURRENT, EXPR;
public static Type from(String type) {
return Enum.valueOf(Type.class, type.toUpperCase());
}
}
}

View File

@@ -0,0 +1,52 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
public class WindowRange implements Serializable {
private WindowOffset start;
private WindowOffset end;
public WindowOffset getEnd() {
return end;
}
public void setEnd(WindowOffset end) {
this.end = end;
}
public WindowOffset getStart() {
return start;
}
public void setStart(WindowOffset start) {
this.start = start;
}
@Override
public String toString() {
return " BETWEEN" +
start +
" AND" +
end;
}
public WindowRange withStart(WindowOffset start) {
this.setStart(start);
return this;
}
public WindowRange withEnd(WindowOffset end) {
this.setEnd(end);
return this;
}
}

View File

@@ -0,0 +1,62 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.util.List;
import static java.util.stream.Collectors.joining;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.create.table.ColDataType;
import net.sf.jsqlparser.statement.select.OrderByElement;
public class XMLSerializeExpr extends ASTNodeAccessImpl implements Expression {
private Expression expression;
private List<OrderByElement> orderByElements;
private ColDataType dataType;
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
public List<OrderByElement> getOrderByElements() {
return orderByElements;
}
public void setOrderByElements(List<OrderByElement> orderByElements) {
this.orderByElements = orderByElements;
}
public ColDataType getDataType() {
return dataType;
}
public void setDataType(ColDataType dataType) {
this.dataType = dataType;
}
@Override
public String toString() {
return "xmlserialize(xmlagg(xmltext(" + expression + ")"
+ (orderByElements != null ? " ORDER BY " + orderByElements.stream()
.map(OrderByElement::toString).collect(joining(", ")) : "")
+ ") AS " + dataType + ")";
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class Addition extends BinaryExpression {
public Addition() {}
public Addition(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "+";
}
@Override
public Addition withLeftExpression(Expression arg0) {
return (Addition) super.withLeftExpression(arg0);
}
@Override
public Addition withRightExpression(Expression arg0) {
return (Addition) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class BitwiseAnd extends BinaryExpression {
public BitwiseAnd() {}
public BitwiseAnd(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "&";
}
@Override
public BitwiseAnd withLeftExpression(Expression arg0) {
return (BitwiseAnd) super.withLeftExpression(arg0);
}
@Override
public BitwiseAnd withRightExpression(Expression arg0) {
return (BitwiseAnd) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class BitwiseLeftShift extends BinaryExpression {
public BitwiseLeftShift() {}
public BitwiseLeftShift(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "<<";
}
@Override
public BitwiseLeftShift withLeftExpression(Expression arg0) {
return (BitwiseLeftShift) super.withLeftExpression(arg0);
}
@Override
public BitwiseLeftShift withRightExpression(Expression arg0) {
return (BitwiseLeftShift) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class BitwiseOr extends BinaryExpression {
public BitwiseOr() {}
public BitwiseOr(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "|";
}
@Override
public BitwiseOr withLeftExpression(Expression arg0) {
return (BitwiseOr) super.withLeftExpression(arg0);
}
@Override
public BitwiseOr withRightExpression(Expression arg0) {
return (BitwiseOr) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class BitwiseRightShift extends BinaryExpression {
public BitwiseRightShift() {}
public BitwiseRightShift(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return ">>";
}
@Override
public BitwiseRightShift withLeftExpression(Expression arg0) {
return (BitwiseRightShift) super.withLeftExpression(arg0);
}
@Override
public BitwiseRightShift withRightExpression(Expression arg0) {
return (BitwiseRightShift) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class BitwiseXor extends BinaryExpression {
public BitwiseXor() {}
public BitwiseXor(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "^";
}
@Override
public BitwiseXor withLeftExpression(Expression arg0) {
return (BitwiseXor) super.withLeftExpression(arg0);
}
@Override
public BitwiseXor withRightExpression(Expression arg0) {
return (BitwiseXor) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class Concat extends BinaryExpression {
public Concat() {}
public Concat(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "||";
}
@Override
public Concat withLeftExpression(Expression arg0) {
return (Concat) super.withLeftExpression(arg0);
}
@Override
public Concat withRightExpression(Expression arg0) {
return (Concat) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class Division extends BinaryExpression {
public Division() {}
public Division(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "/";
}
@Override
public Division withLeftExpression(Expression arg0) {
return (Division) super.withLeftExpression(arg0);
}
@Override
public Division withRightExpression(Expression arg0) {
return (Division) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class IntegerDivision extends BinaryExpression {
public IntegerDivision() {}
public IntegerDivision(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "DIV";
}
@Override
public IntegerDivision withLeftExpression(Expression arg0) {
return (IntegerDivision) super.withLeftExpression(arg0);
}
@Override
public IntegerDivision withRightExpression(Expression arg0) {
return (IntegerDivision) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,46 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
/**
* Modulo expression (a % b).
*/
public class Modulo extends BinaryExpression {
public Modulo() {}
public Modulo(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "%";
}
@Override
public Modulo withLeftExpression(Expression arg0) {
return (Modulo) super.withLeftExpression(arg0);
}
@Override
public Modulo withRightExpression(Expression arg0) {
return (Modulo) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class Multiplication extends BinaryExpression {
public Multiplication() {}
public Multiplication(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "*";
}
@Override
public Multiplication withLeftExpression(Expression arg0) {
return (Multiplication) super.withLeftExpression(arg0);
}
@Override
public Multiplication withRightExpression(Expression arg0) {
return (Multiplication) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.arithmetic;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class Subtraction extends BinaryExpression {
public Subtraction() {}
public Subtraction(Expression leftExpression, Expression rightExpression) {
super(leftExpression, rightExpression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "-";
}
@Override
public Subtraction withLeftExpression(Expression arg0) {
return (Subtraction) super.withLeftExpression(arg0);
}
@Override
public Subtraction withRightExpression(Expression arg0) {
return (Subtraction) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,60 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.conditional;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class AndExpression extends BinaryExpression {
private boolean useOperator = false;
public AndExpression() {
// nothing
}
public AndExpression(Expression leftExpression, Expression rightExpression) {
setLeftExpression(leftExpression);
setRightExpression(rightExpression);
}
public boolean isUseOperator() {
return useOperator;
}
public void setUseOperator(boolean useOperator) {
this.useOperator = useOperator;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return useOperator ? "&&" : "AND";
}
public AndExpression withUseOperator(boolean useOperator) {
this.setUseOperator(useOperator);
return this;
}
@Override
public AndExpression withLeftExpression(Expression arg0) {
return (AndExpression) super.withLeftExpression(arg0);
}
@Override
public AndExpression withRightExpression(Expression arg0) {
return (AndExpression) super.withRightExpression(arg0);
}
}

View File

@@ -0,0 +1,47 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.conditional;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class OrExpression extends BinaryExpression {
public OrExpression() {
// nothing
}
public OrExpression(Expression leftExpression, Expression rightExpression) {
setLeftExpression(leftExpression);
setRightExpression(rightExpression);
}
@Override
public OrExpression withLeftExpression(Expression expression) {
return (OrExpression) super.withLeftExpression(expression);
}
@Override
public OrExpression withRightExpression(Expression expression) {
return (OrExpression) super.withRightExpression(expression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "OR";
}
}

View File

@@ -0,0 +1,47 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.conditional;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class XorExpression extends BinaryExpression {
public XorExpression() {
// nothing
}
public XorExpression(Expression leftExpression, Expression rightExpression) {
setLeftExpression(leftExpression);
setRightExpression(rightExpression);
}
@Override
public XorExpression withLeftExpression(Expression expression) {
return (XorExpression) super.withLeftExpression(expression);
}
@Override
public XorExpression withRightExpression(Expression expression) {
return (XorExpression) super.withRightExpression(expression);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String getStringExpression() {
return "XOR";
}
}

View File

@@ -0,0 +1,101 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* A "BETWEEN" expr1 expr2 statement
*/
public class Between extends ASTNodeAccessImpl implements Expression {
private Expression leftExpression;
private boolean not = false;
private Expression betweenExpressionStart;
private Expression betweenExpressionEnd;
public Expression getBetweenExpressionEnd() {
return betweenExpressionEnd;
}
public void setBetweenExpressionEnd(Expression expression) {
betweenExpressionEnd = expression;
}
public Expression getBetweenExpressionStart() {
return betweenExpressionStart;
}
public void setBetweenExpressionStart(Expression expression) {
betweenExpressionStart = expression;
}
public Expression getLeftExpression() {
return leftExpression;
}
public void setLeftExpression(Expression expression) {
leftExpression = expression;
}
public boolean isNot() {
return not;
}
public void setNot(boolean b) {
not = b;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
return leftExpression + " " + (not ? "NOT " : "") + "BETWEEN " + betweenExpressionStart
+ " AND "
+ betweenExpressionEnd;
}
public Between withLeftExpression(Expression leftExpression) {
this.setLeftExpression(leftExpression);
return this;
}
public Between withNot(boolean not) {
this.setNot(not);
return this;
}
public Between withBetweenExpressionStart(Expression betweenExpressionStart) {
this.setBetweenExpressionStart(betweenExpressionStart);
return this;
}
public Between withBetweenExpressionEnd(Expression betweenExpressionEnd) {
this.setBetweenExpressionEnd(betweenExpressionEnd);
return this;
}
public <E extends Expression> E getBetweenExpressionEnd(Class<E> type) {
return type.cast(getBetweenExpressionEnd());
}
public <E extends Expression> E getBetweenExpressionStart(Class<E> type) {
return type.cast(getBetweenExpressionStart());
}
public <E extends Expression> E getLeftExpression(Class<E> type) {
return type.cast(getLeftExpression());
}
}

View File

@@ -0,0 +1,52 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;
import net.sf.jsqlparser.expression.Expression;
public abstract class ComparisonOperator extends OldOracleJoinBinaryExpression {
private final String operator;
public ComparisonOperator(String operator) {
this.operator = operator;
}
public ComparisonOperator(String operator, Expression left, Expression right) {
this(operator);
setLeftExpression(left);
setRightExpression(right);
}
@Override
public String getStringExpression() {
return operator;
}
@Override
public ComparisonOperator withLeftExpression(Expression arg0) {
return (ComparisonOperator) super.withLeftExpression(arg0);
}
@Override
public ComparisonOperator withRightExpression(Expression arg0) {
return (ComparisonOperator) super.withRightExpression(arg0);
}
@Override
public ComparisonOperator withOldOracleJoinSyntax(int oldOracleJoinSyntax) {
return (ComparisonOperator) super.withOldOracleJoinSyntax(oldOracleJoinSyntax);
}
@Override
public ComparisonOperator withOraclePriorPosition(int oraclePriorPosition) {
return (ComparisonOperator) super.withOraclePriorPosition(oraclePriorPosition);
}
}

View File

@@ -0,0 +1,25 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2023 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class ContainedBy extends ComparisonOperator {
public ContainedBy() {
super("<&");
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}

View File

@@ -0,0 +1,25 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2023 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class Contains extends ComparisonOperator {
public Contains() {
super("&>");
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}

View File

@@ -0,0 +1,24 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2023 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class DoubleAnd extends ComparisonOperator {
public DoubleAnd() {
super("&&");
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
}

View File

@@ -0,0 +1,51 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
public class EqualsTo extends ComparisonOperator {
public EqualsTo() {
super("=");
}
public EqualsTo(Expression left, Expression right) {
this();
setLeftExpression(left);
setRightExpression(right);
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public EqualsTo withLeftExpression(Expression expression) {
return (EqualsTo) super.withLeftExpression(expression);
}
@Override
public EqualsTo withRightExpression(Expression expression) {
return (EqualsTo) super.withRightExpression(expression);
}
@Override
public EqualsTo withOldOracleJoinSyntax(int arg0) {
return (EqualsTo) super.withOldOracleJoinSyntax(arg0);
}
@Override
public EqualsTo withOraclePriorPosition(int arg0) {
return (EqualsTo) super.withOraclePriorPosition(arg0);
}
}

View File

@@ -0,0 +1,78 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
public class ExcludesExpression extends ASTNodeAccessImpl implements Expression {
private Expression leftExpression;
private Expression rightExpression;
public ExcludesExpression() {}
public ExcludesExpression(Expression leftExpression, Expression rightExpression) {
this.leftExpression = leftExpression;
this.rightExpression = rightExpression;
}
public Expression getLeftExpression() {
return leftExpression;
}
public final void setLeftExpression(Expression expression) {
leftExpression = expression;
}
public ExcludesExpression withLeftExpression(Expression expression) {
this.setLeftExpression(expression);
return this;
}
public Expression getRightExpression() {
return rightExpression;
}
public void setRightExpression(Expression rightExpression) {
this.rightExpression = rightExpression;
}
@Override
public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
StringBuilder statementBuilder = new StringBuilder();
statementBuilder.append(leftExpression);
statementBuilder.append(" ");
statementBuilder.append("EXCLUDES ");
statementBuilder.append(rightExpression);
return statementBuilder.toString();
}
public ExcludesExpression withRightExpression(Expression rightExpression) {
this.setRightExpression(rightExpression);
return this;
}
public <E extends Expression> E getLeftExpression(Class<E> type) {
return type.cast(getLeftExpression());
}
public <E extends Expression> E getRightExpression(Class<E> type) {
return type.cast(getRightExpression());
}
}

Some files were not shown because too many files have changed in this diff Show More