initial-commit
This commit is contained in:
commit
861783f713
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
|
@ -0,0 +1,11 @@
|
|||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="WorkoutDBDatesAutoUpdater:jar">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/WorkoutDBDatesAutoUpdater</output-path>
|
||||
<root id="archive" name="WorkoutDBDatesAutoUpdater.jar">
|
||||
<element id="module-output" name="WorkoutDBDatesAutoUpdater" />
|
||||
<element id="library" level="project" name="java" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/mysql-connector-j-8.0.31/mysql-connector-j-8.0.31.jar" path-in-jar="/" />
|
||||
<element id="library" level="project" name="mysql-connector-j-8.0" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
|
@ -0,0 +1,10 @@
|
|||
<component name="libraryTable">
|
||||
<library name="java">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/json-simple-master/src/main/java" />
|
||||
<root url="file://$PROJECT_DIR$/json-simple-master/src/test/java" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,21 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.0">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/build/java" />
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/demo/java" />
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/generated/java" />
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/legacy/java" />
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/main/core-api/java" />
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/main/core-impl/java" />
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/main/protocol-impl/java" />
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/main/user-api/java" />
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/main/user-impl/java" />
|
||||
<root url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31/src/test/java" />
|
||||
</SOURCES>
|
||||
<jarDirectory url="file://$PROJECT_DIR$/mysql-connector-j-8.0.31" recursive="false" />
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/WorkoutDBDatesAutoUpdater.iml" filepath="$PROJECT_DIR$/WorkoutDBDatesAutoUpdater.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="mysql-connector-j-8.0" level="project" />
|
||||
<orderEntry type="library" name="java" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"dbname" : "localhost",
|
||||
"dbuser" : "root",
|
||||
"dbport" : "3306" ,
|
||||
"dbpass" : "506763",
|
||||
"schemename" : "workout"
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,2 @@
|
|||
.settings/
|
||||
target/
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>json-simple</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,3 @@
|
|||
Yidong Fang
|
||||
Chris Nokleberg
|
||||
Dave Hughes
|
|
@ -0,0 +1,28 @@
|
|||
ChangeLog
|
||||
|
||||
Version 1.1.1 (2012/01/29)
|
||||
* Supports OSGi
|
||||
* Accepts a java.util.Map parameter in constructor of JSONObject
|
||||
|
||||
Version 1.1 (2009/01/23)
|
||||
* Supports stoppable SAX-like content handler for streaming of JSON text
|
||||
* Added JSONStreamAware to support streaming JSON text
|
||||
* Added ContainerFactory to support creating arbitrary Map and List as JSON object and JSON array container during decoding
|
||||
* Supports any Map and List as JSON object and JSON array container during encoding
|
||||
* Added interface JSONAware
|
||||
* Added ParseException to get detail error report while parsing
|
||||
* Added escaping for Unicode characters that cause problems for browser JS eval
|
||||
|
||||
Version 1.02 (2009/01/10)
|
||||
* Updated json.lex to improve performance of the lexer
|
||||
* Removed Rope.java and related junit test
|
||||
|
||||
Version 1.01 (2008/08/26)
|
||||
* License changed to a more commerce friendly and clear one, Apache License 2.0
|
||||
* Use JFlex to generate a faster Yylex.java
|
||||
* Added Rope.java to get faster string operations
|
||||
* Separate test codes from source codes
|
||||
* Added ant build file build.xml
|
||||
|
||||
Version 1.0 (2006/04/15)
|
||||
* Initial version
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
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.
|
|
@ -0,0 +1,2 @@
|
|||
Please visit:
|
||||
http://code.google.com/p/json-simple/
|
|
@ -0,0 +1 @@
|
|||
1.1.1
|
|
@ -0,0 +1,41 @@
|
|||
<project name="json-simple" default="main" basedir=".">
|
||||
<property name="current-version" value="1.1.1"/>
|
||||
<property name="targetDir" value="target"/>
|
||||
<property name="javaSourceDir" value="src/main/java"/>
|
||||
<property name="javaTargetDir" value="target/classes"/>
|
||||
|
||||
<target name="WorkoutDatesUpdater" depends="jar"></target>
|
||||
|
||||
<target name="clean">
|
||||
<delete includeemptydirs="true">
|
||||
<fileset dir="${targetDir}" includes="**/*"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="mkdir">
|
||||
<mkdir dir="${javaTargetDir}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="mkdir">
|
||||
<javac srcdir="${javaSourceDir}"
|
||||
destdir="${javaTargetDir}"
|
||||
includes="**/*.java"
|
||||
target="1.2"
|
||||
source="1.2"/>
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="compile">
|
||||
<jar destfile="${targetDir}/json-simple-${current-version}.jar"
|
||||
basedir="${javaTargetDir}"
|
||||
includes="**/*.class">
|
||||
<manifest>
|
||||
<attribute name="Bundle-Name" value="JSON.simple"/>
|
||||
<attribute name="Bundle-SymbolicName" value="com.googlecode.json-simple.json-simple"/>
|
||||
<attribute name="Bundle-Version" value="${current-version}"/>
|
||||
<attribute name="Bundle-License" value="http://www.apache.org/licenses/LICENSE-2.0.txt"/>
|
||||
<attribute name="Bundle-Description" value="A simple Java toolkit for JSON"/>
|
||||
<attribute name="Export-Package" value="org.json.simple, org.json.simple.parser"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
|
@ -0,0 +1,61 @@
|
|||
package org.json.simple.parser;
|
||||
|
||||
%%
|
||||
|
||||
%{
|
||||
private StringBuffer sb=new StringBuffer();
|
||||
|
||||
int getPosition(){
|
||||
return yychar;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%table
|
||||
%unicode
|
||||
%state STRING_BEGIN
|
||||
|
||||
%yylexthrow ParseException
|
||||
%char
|
||||
|
||||
HEX_D = [a-fA-F0-9]
|
||||
INT = [-]?[0-9]+
|
||||
DOUBLE = {INT}((\.[0-9]+)?([eE][-+]?[0-9]+)?)
|
||||
WS = [ \t\r\n]
|
||||
UNESCAPED_CH = [^\"\\]
|
||||
FALLBACK_CH = .
|
||||
%%
|
||||
|
||||
<STRING_BEGIN> \" { yybegin(YYINITIAL);return new Yytoken(Yytoken.TYPE_VALUE, sb.toString());}
|
||||
<STRING_BEGIN> {UNESCAPED_CH}+ { sb.append(yytext());}
|
||||
<STRING_BEGIN> \\\" {sb.append('"');}
|
||||
<STRING_BEGIN> \\\\ {sb.append('\\');}
|
||||
<STRING_BEGIN> \\\/ {sb.append('/');}
|
||||
<STRING_BEGIN> \\b {sb.append('\b');}
|
||||
<STRING_BEGIN> \\f {sb.append('\f');}
|
||||
<STRING_BEGIN> \\n {sb.append('\n');}
|
||||
<STRING_BEGIN> \\r {sb.append('\r');}
|
||||
<STRING_BEGIN> \\t {sb.append('\t');}
|
||||
<STRING_BEGIN> \\u{HEX_D}{HEX_D}{HEX_D}{HEX_D} { try{
|
||||
int ch=Integer.parseInt(yytext().substring(2),16);
|
||||
sb.append((char)ch);
|
||||
}
|
||||
catch(Exception e){
|
||||
throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_EXCEPTION, e);
|
||||
}
|
||||
}
|
||||
<STRING_BEGIN> \\ {sb.append('\\');}
|
||||
|
||||
<YYINITIAL> \" { sb = null; sb = new StringBuffer(); yybegin(STRING_BEGIN);}
|
||||
<YYINITIAL> {INT} { Long val=Long.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);}
|
||||
<YYINITIAL> {DOUBLE} { Double val=Double.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);}
|
||||
<YYINITIAL> "true"|"false" { Boolean val=Boolean.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);}
|
||||
<YYINITIAL> "null" { return new Yytoken(Yytoken.TYPE_VALUE, null);}
|
||||
<YYINITIAL> "{" { return new Yytoken(Yytoken.TYPE_LEFT_BRACE,null);}
|
||||
<YYINITIAL> "}" { return new Yytoken(Yytoken.TYPE_RIGHT_BRACE,null);}
|
||||
<YYINITIAL> "[" { return new Yytoken(Yytoken.TYPE_LEFT_SQUARE,null);}
|
||||
<YYINITIAL> "]" { return new Yytoken(Yytoken.TYPE_RIGHT_SQUARE,null);}
|
||||
<YYINITIAL> "," { return new Yytoken(Yytoken.TYPE_COMMA,null);}
|
||||
<YYINITIAL> ":" { return new Yytoken(Yytoken.TYPE_COLON,null);}
|
||||
<YYINITIAL> {WS}+ {}
|
||||
<YYINITIAL> {FALLBACK_CH} { throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_CHAR, new Character(yycharat(0)));}
|
|
@ -0,0 +1,110 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>JSON.simple</name>
|
||||
<version>1.1.1</version>
|
||||
<description>A simple Java toolkit for JSON</description>
|
||||
<url>http://code.google.com/p/json-simple/</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>Yidong</id>
|
||||
<name>Yidong Fang</name>
|
||||
<roles>
|
||||
<role>architect</role>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
<timezone>+8</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:svn:http://json-simple.googlecode.com/svn/trunk/</connection>
|
||||
<developerConnection>scm:svn:http://json-simple.googlecode.com/svn/trunk/</developerConnection>
|
||||
<url>http://json-simple.googlecode.com/svn/trunk/</url>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>5.1.1</version>
|
||||
<extensions>true</extensions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release-sign-artifacts</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>performRelease</name>
|
||||
<value>true</value>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* $Id: ItemList.java,v 1.1 2006/04/15 14:10:48 platform Exp $
|
||||
* Created on 2006-3-24
|
||||
*/
|
||||
package org.json.simple;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* |a:b:c| => |a|,|b|,|c|
|
||||
* |:| => ||,||
|
||||
* |a:| => |a|,||
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public class ItemList {
|
||||
private String sp=",";
|
||||
List items=new ArrayList();
|
||||
|
||||
|
||||
public ItemList(){}
|
||||
|
||||
|
||||
public ItemList(String s){
|
||||
this.split(s,sp,items);
|
||||
}
|
||||
|
||||
public ItemList(String s,String sp){
|
||||
this.sp=s;
|
||||
this.split(s,sp,items);
|
||||
}
|
||||
|
||||
public ItemList(String s,String sp,boolean isMultiToken){
|
||||
split(s,sp,items,isMultiToken);
|
||||
}
|
||||
|
||||
public List getItems(){
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public String[] getArray(){
|
||||
return (String[])this.items.toArray();
|
||||
}
|
||||
|
||||
public void split(String s,String sp,List append,boolean isMultiToken){
|
||||
if(s==null || sp==null)
|
||||
return;
|
||||
if(isMultiToken){
|
||||
StringTokenizer tokens=new StringTokenizer(s,sp);
|
||||
while(tokens.hasMoreTokens()){
|
||||
append.add(tokens.nextToken().trim());
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.split(s,sp,append);
|
||||
}
|
||||
}
|
||||
|
||||
public void split(String s,String sp,List append){
|
||||
if(s==null || sp==null)
|
||||
return;
|
||||
int pos=0;
|
||||
int prevPos=0;
|
||||
do{
|
||||
prevPos=pos;
|
||||
pos=s.indexOf(sp,pos);
|
||||
if(pos==-1)
|
||||
break;
|
||||
append.add(s.substring(prevPos,pos).trim());
|
||||
pos+=sp.length();
|
||||
}while(pos!=-1);
|
||||
append.add(s.substring(prevPos).trim());
|
||||
}
|
||||
|
||||
public void setSP(String sp){
|
||||
this.sp=sp;
|
||||
}
|
||||
|
||||
public void add(int i,String item){
|
||||
if(item==null)
|
||||
return;
|
||||
items.add(i,item.trim());
|
||||
}
|
||||
|
||||
public void add(String item){
|
||||
if(item==null)
|
||||
return;
|
||||
items.add(item.trim());
|
||||
}
|
||||
|
||||
public void addAll(ItemList list){
|
||||
items.addAll(list.items);
|
||||
}
|
||||
|
||||
public void addAll(String s){
|
||||
this.split(s,sp,items);
|
||||
}
|
||||
|
||||
public void addAll(String s,String sp){
|
||||
this.split(s,sp,items);
|
||||
}
|
||||
|
||||
public void addAll(String s,String sp,boolean isMultiToken){
|
||||
this.split(s,sp,items,isMultiToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param i 0-based
|
||||
* @return
|
||||
*/
|
||||
public String get(int i){
|
||||
return (String)items.get(i);
|
||||
}
|
||||
|
||||
public int size(){
|
||||
return items.size();
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return toString(sp);
|
||||
}
|
||||
|
||||
public String toString(String sp){
|
||||
StringBuffer sb=new StringBuffer();
|
||||
|
||||
for(int i=0;i<items.size();i++){
|
||||
if(i==0)
|
||||
sb.append(items.get(i));
|
||||
else{
|
||||
sb.append(sp);
|
||||
sb.append(items.get(i));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
items.clear();
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
sp=",";
|
||||
items.clear();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,381 @@
|
|||
/*
|
||||
* $Id: JSONArray.java,v 1.1 2006/04/15 14:10:48 platform Exp $
|
||||
* Created on 2006-4-10
|
||||
*/
|
||||
package org.json.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A JSON array. JSONObject supports java.util.List interface.
|
||||
*
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public class JSONArray extends ArrayList implements JSONAware, JSONStreamAware {
|
||||
private static final long serialVersionUID = 3957988303675231981L;
|
||||
|
||||
/**
|
||||
* Constructs an empty JSONArray.
|
||||
*/
|
||||
public JSONArray(){
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a JSONArray containing the elements of the specified
|
||||
* collection, in the order they are returned by the collection's iterator.
|
||||
*
|
||||
* @param c the collection whose elements are to be placed into this JSONArray
|
||||
*/
|
||||
public JSONArray(Collection c){
|
||||
super(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a list into JSON text and write it to out.
|
||||
* If this list is also a JSONStreamAware or a JSONAware, JSONStreamAware and JSONAware specific behaviours will be ignored at this top level.
|
||||
*
|
||||
* @see org.json.simple.JSONValue#writeJSONString(Object, Writer)
|
||||
*
|
||||
* @param collection
|
||||
* @param out
|
||||
*/
|
||||
public static void writeJSONString(Collection collection, Writer out) throws IOException{
|
||||
if(collection == null){
|
||||
out.write("null");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean first = true;
|
||||
Iterator iter=collection.iterator();
|
||||
|
||||
out.write('[');
|
||||
while(iter.hasNext()){
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
out.write(',');
|
||||
|
||||
Object value=iter.next();
|
||||
if(value == null){
|
||||
out.write("null");
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONValue.writeJSONString(value, out);
|
||||
}
|
||||
out.write(']');
|
||||
}
|
||||
|
||||
public void writeJSONString(Writer out) throws IOException{
|
||||
writeJSONString(this, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a list to JSON text. The result is a JSON array.
|
||||
* If this list is also a JSONAware, JSONAware specific behaviours will be omitted at this top level.
|
||||
*
|
||||
* @see org.json.simple.JSONValue#toJSONString(Object)
|
||||
*
|
||||
* @param collection
|
||||
* @return JSON text, or "null" if list is null.
|
||||
*/
|
||||
public static String toJSONString(Collection collection){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(collection, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeJSONString(byte[] array, Writer out) throws IOException{
|
||||
if(array == null){
|
||||
out.write("null");
|
||||
} else if(array.length == 0) {
|
||||
out.write("[]");
|
||||
} else {
|
||||
out.write("[");
|
||||
out.write(String.valueOf(array[0]));
|
||||
|
||||
for(int i = 1; i < array.length; i++){
|
||||
out.write(",");
|
||||
out.write(String.valueOf(array[i]));
|
||||
}
|
||||
|
||||
out.write("]");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJSONString(byte[] array){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(array, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeJSONString(short[] array, Writer out) throws IOException{
|
||||
if(array == null){
|
||||
out.write("null");
|
||||
} else if(array.length == 0) {
|
||||
out.write("[]");
|
||||
} else {
|
||||
out.write("[");
|
||||
out.write(String.valueOf(array[0]));
|
||||
|
||||
for(int i = 1; i < array.length; i++){
|
||||
out.write(",");
|
||||
out.write(String.valueOf(array[i]));
|
||||
}
|
||||
|
||||
out.write("]");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJSONString(short[] array){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(array, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeJSONString(int[] array, Writer out) throws IOException{
|
||||
if(array == null){
|
||||
out.write("null");
|
||||
} else if(array.length == 0) {
|
||||
out.write("[]");
|
||||
} else {
|
||||
out.write("[");
|
||||
out.write(String.valueOf(array[0]));
|
||||
|
||||
for(int i = 1; i < array.length; i++){
|
||||
out.write(",");
|
||||
out.write(String.valueOf(array[i]));
|
||||
}
|
||||
|
||||
out.write("]");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJSONString(int[] array){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(array, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeJSONString(long[] array, Writer out) throws IOException{
|
||||
if(array == null){
|
||||
out.write("null");
|
||||
} else if(array.length == 0) {
|
||||
out.write("[]");
|
||||
} else {
|
||||
out.write("[");
|
||||
out.write(String.valueOf(array[0]));
|
||||
|
||||
for(int i = 1; i < array.length; i++){
|
||||
out.write(",");
|
||||
out.write(String.valueOf(array[i]));
|
||||
}
|
||||
|
||||
out.write("]");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJSONString(long[] array){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(array, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeJSONString(float[] array, Writer out) throws IOException{
|
||||
if(array == null){
|
||||
out.write("null");
|
||||
} else if(array.length == 0) {
|
||||
out.write("[]");
|
||||
} else {
|
||||
out.write("[");
|
||||
out.write(String.valueOf(array[0]));
|
||||
|
||||
for(int i = 1; i < array.length; i++){
|
||||
out.write(",");
|
||||
out.write(String.valueOf(array[i]));
|
||||
}
|
||||
|
||||
out.write("]");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJSONString(float[] array){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(array, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeJSONString(double[] array, Writer out) throws IOException{
|
||||
if(array == null){
|
||||
out.write("null");
|
||||
} else if(array.length == 0) {
|
||||
out.write("[]");
|
||||
} else {
|
||||
out.write("[");
|
||||
out.write(String.valueOf(array[0]));
|
||||
|
||||
for(int i = 1; i < array.length; i++){
|
||||
out.write(",");
|
||||
out.write(String.valueOf(array[i]));
|
||||
}
|
||||
|
||||
out.write("]");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJSONString(double[] array){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(array, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeJSONString(boolean[] array, Writer out) throws IOException{
|
||||
if(array == null){
|
||||
out.write("null");
|
||||
} else if(array.length == 0) {
|
||||
out.write("[]");
|
||||
} else {
|
||||
out.write("[");
|
||||
out.write(String.valueOf(array[0]));
|
||||
|
||||
for(int i = 1; i < array.length; i++){
|
||||
out.write(",");
|
||||
out.write(String.valueOf(array[i]));
|
||||
}
|
||||
|
||||
out.write("]");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJSONString(boolean[] array){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(array, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeJSONString(char[] array, Writer out) throws IOException{
|
||||
if(array == null){
|
||||
out.write("null");
|
||||
} else if(array.length == 0) {
|
||||
out.write("[]");
|
||||
} else {
|
||||
out.write("[\"");
|
||||
out.write(String.valueOf(array[0]));
|
||||
|
||||
for(int i = 1; i < array.length; i++){
|
||||
out.write("\",\"");
|
||||
out.write(String.valueOf(array[i]));
|
||||
}
|
||||
|
||||
out.write("\"]");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJSONString(char[] array){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(array, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeJSONString(Object[] array, Writer out) throws IOException{
|
||||
if(array == null){
|
||||
out.write("null");
|
||||
} else if(array.length == 0) {
|
||||
out.write("[]");
|
||||
} else {
|
||||
out.write("[");
|
||||
JSONValue.writeJSONString(array[0], out);
|
||||
|
||||
for(int i = 1; i < array.length; i++){
|
||||
out.write(",");
|
||||
JSONValue.writeJSONString(array[i], out);
|
||||
}
|
||||
|
||||
out.write("]");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJSONString(Object[] array){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(array, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String toJSONString(){
|
||||
return toJSONString(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this array. This is equivalent to
|
||||
* calling {@link JSONArray#toJSONString()}.
|
||||
*/
|
||||
public String toString() {
|
||||
return toJSONString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.json.simple;
|
||||
|
||||
/**
|
||||
* Beans that support customized output of JSON text shall implement this interface.
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public interface JSONAware {
|
||||
/**
|
||||
* @return JSON text
|
||||
*/
|
||||
String toJSONString();
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* $Id: JSONObject.java,v 1.1 2006/04/15 14:10:48 platform Exp $
|
||||
* Created on 2006-4-10
|
||||
*/
|
||||
package org.json.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A JSON object. Key value pairs are unordered. JSONObject supports java.util.Map interface.
|
||||
*
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAware{
|
||||
|
||||
private static final long serialVersionUID = -503443796854799292L;
|
||||
|
||||
|
||||
public JSONObject() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows creation of a JSONObject from a Map. After that, both the
|
||||
* generated JSONObject and the Map can be modified independently.
|
||||
*
|
||||
* @param map
|
||||
*/
|
||||
public JSONObject(Map map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode a map into JSON text and write it to out.
|
||||
* If this map is also a JSONAware or JSONStreamAware, JSONAware or JSONStreamAware specific behaviours will be ignored at this top level.
|
||||
*
|
||||
* @see org.json.simple.JSONValue#writeJSONString(Object, Writer)
|
||||
*
|
||||
* @param map
|
||||
* @param out
|
||||
*/
|
||||
public static void writeJSONString(Map map, Writer out) throws IOException {
|
||||
if(map == null){
|
||||
out.write("null");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean first = true;
|
||||
Iterator iter=map.entrySet().iterator();
|
||||
|
||||
out.write('{');
|
||||
while(iter.hasNext()){
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
out.write(',');
|
||||
Map.Entry entry=(Map.Entry)iter.next();
|
||||
out.write('\"');
|
||||
out.write(escape(String.valueOf(entry.getKey())));
|
||||
out.write('\"');
|
||||
out.write(':');
|
||||
JSONValue.writeJSONString(entry.getValue(), out);
|
||||
}
|
||||
out.write('}');
|
||||
}
|
||||
|
||||
public void writeJSONString(Writer out) throws IOException{
|
||||
writeJSONString(this, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a map to JSON text. The result is a JSON object.
|
||||
* If this map is also a JSONAware, JSONAware specific behaviours will be omitted at this top level.
|
||||
*
|
||||
* @see org.json.simple.JSONValue#toJSONString(Object)
|
||||
*
|
||||
* @param map
|
||||
* @return JSON text, or "null" if map is null.
|
||||
*/
|
||||
public static String toJSONString(Map map){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
writeJSONString(map, writer);
|
||||
return writer.toString();
|
||||
} catch (IOException e) {
|
||||
// This should never happen with a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String toJSONString(){
|
||||
return toJSONString(this);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return toJSONString();
|
||||
}
|
||||
|
||||
public static String toString(String key,Object value){
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append('\"');
|
||||
if(key == null)
|
||||
sb.append("null");
|
||||
else
|
||||
JSONValue.escape(key, sb);
|
||||
sb.append('\"').append(':');
|
||||
|
||||
sb.append(JSONValue.toJSONString(value));
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).
|
||||
* It's the same as JSONValue.escape() only for compatibility here.
|
||||
*
|
||||
* @see org.json.simple.JSONValue#escape(String)
|
||||
*
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static String escape(String s){
|
||||
return JSONValue.escape(s);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.json.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Beans that support customized output of JSON text to a writer shall implement this interface.
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public interface JSONStreamAware {
|
||||
/**
|
||||
* write JSON string to out.
|
||||
*/
|
||||
void writeJSONString(Writer out) throws IOException;
|
||||
}
|
|
@ -0,0 +1,316 @@
|
|||
/*
|
||||
* $Id: JSONValue.java,v 1.1 2006/04/15 14:37:04 platform Exp $
|
||||
* Created on 2006-4-15
|
||||
*/
|
||||
package org.json.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Collection;
|
||||
// import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
|
||||
/**
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public class JSONValue {
|
||||
/**
|
||||
* Parse JSON text into java object from the input source.
|
||||
* Please use parseWithException() if you don't want to ignore the exception.
|
||||
*
|
||||
* @see org.json.simple.parser.JSONParser#parse(Reader)
|
||||
* @see #parseWithException(Reader)
|
||||
*
|
||||
* @param in
|
||||
* @return Instance of the following:
|
||||
* org.json.simple.JSONObject,
|
||||
* org.json.simple.JSONArray,
|
||||
* java.lang.String,
|
||||
* java.lang.Number,
|
||||
* java.lang.Boolean,
|
||||
* null
|
||||
*
|
||||
* @deprecated this method may throw an {@code Error} instead of returning
|
||||
* {@code null}; please use {@link JSONValue#parseWithException(Reader)}
|
||||
* instead
|
||||
*/
|
||||
public static Object parse(Reader in){
|
||||
try{
|
||||
JSONParser parser=new JSONParser();
|
||||
return parser.parse(in);
|
||||
}
|
||||
catch(Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse JSON text into java object from the given string.
|
||||
* Please use parseWithException() if you don't want to ignore the exception.
|
||||
*
|
||||
* @see org.json.simple.parser.JSONParser#parse(Reader)
|
||||
* @see #parseWithException(Reader)
|
||||
*
|
||||
* @param s
|
||||
* @return Instance of the following:
|
||||
* org.json.simple.JSONObject,
|
||||
* org.json.simple.JSONArray,
|
||||
* java.lang.String,
|
||||
* java.lang.Number,
|
||||
* java.lang.Boolean,
|
||||
* null
|
||||
*
|
||||
* @deprecated this method may throw an {@code Error} instead of returning
|
||||
* {@code null}; please use {@link JSONValue#parseWithException(String)}
|
||||
* instead
|
||||
*/
|
||||
public static Object parse(String s){
|
||||
StringReader in=new StringReader(s);
|
||||
return parse(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse JSON text into java object from the input source.
|
||||
*
|
||||
* @see org.json.simple.parser.JSONParser
|
||||
*
|
||||
* @param in
|
||||
* @return Instance of the following:
|
||||
* org.json.simple.JSONObject,
|
||||
* org.json.simple.JSONArray,
|
||||
* java.lang.String,
|
||||
* java.lang.Number,
|
||||
* java.lang.Boolean,
|
||||
* null
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static Object parseWithException(Reader in) throws IOException, ParseException{
|
||||
JSONParser parser=new JSONParser();
|
||||
return parser.parse(in);
|
||||
}
|
||||
|
||||
public static Object parseWithException(String s) throws ParseException{
|
||||
JSONParser parser=new JSONParser();
|
||||
return parser.parse(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode an object into JSON text and write it to out.
|
||||
* <p>
|
||||
* If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly.
|
||||
* <p>
|
||||
* DO NOT call this method from writeJSONString(Writer) of a class that implements both JSONStreamAware and (Map or List) with
|
||||
* "this" as the first parameter, use JSONObject.writeJSONString(Map, Writer) or JSONArray.writeJSONString(List, Writer) instead.
|
||||
*
|
||||
* @see org.json.simple.JSONObject#writeJSONString(Map, Writer)
|
||||
* @see org.json.simple.JSONArray#writeJSONString(List, Writer)
|
||||
*
|
||||
* @param value
|
||||
* @param writer
|
||||
*/
|
||||
public static void writeJSONString(Object value, Writer out) throws IOException {
|
||||
if(value == null){
|
||||
out.write("null");
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof String){
|
||||
out.write('\"');
|
||||
out.write(escape((String)value));
|
||||
out.write('\"');
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof Double){
|
||||
if(((Double)value).isInfinite() || ((Double)value).isNaN())
|
||||
out.write("null");
|
||||
else
|
||||
out.write(value.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof Float){
|
||||
if(((Float)value).isInfinite() || ((Float)value).isNaN())
|
||||
out.write("null");
|
||||
else
|
||||
out.write(value.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof Number){
|
||||
out.write(value.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof Boolean){
|
||||
out.write(value.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if((value instanceof JSONStreamAware)){
|
||||
((JSONStreamAware)value).writeJSONString(out);
|
||||
return;
|
||||
}
|
||||
|
||||
if((value instanceof JSONAware)){
|
||||
out.write(((JSONAware)value).toJSONString());
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof Map){
|
||||
JSONObject.writeJSONString((Map)value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof Collection){
|
||||
JSONArray.writeJSONString((Collection)value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof byte[]){
|
||||
JSONArray.writeJSONString((byte[])value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof short[]){
|
||||
JSONArray.writeJSONString((short[])value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof int[]){
|
||||
JSONArray.writeJSONString((int[])value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof long[]){
|
||||
JSONArray.writeJSONString((long[])value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof float[]){
|
||||
JSONArray.writeJSONString((float[])value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof double[]){
|
||||
JSONArray.writeJSONString((double[])value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof boolean[]){
|
||||
JSONArray.writeJSONString((boolean[])value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof char[]){
|
||||
JSONArray.writeJSONString((char[])value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value instanceof Object[]){
|
||||
JSONArray.writeJSONString((Object[])value, out);
|
||||
return;
|
||||
}
|
||||
|
||||
out.write(value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an object to JSON text.
|
||||
* <p>
|
||||
* If this object is a Map or a List, and it's also a JSONAware, JSONAware will be considered firstly.
|
||||
* <p>
|
||||
* DO NOT call this method from toJSONString() of a class that implements both JSONAware and Map or List with
|
||||
* "this" as the parameter, use JSONObject.toJSONString(Map) or JSONArray.toJSONString(List) instead.
|
||||
*
|
||||
* @see org.json.simple.JSONObject#toJSONString(Map)
|
||||
* @see org.json.simple.JSONArray#toJSONString(List)
|
||||
*
|
||||
* @param value
|
||||
* @return JSON text, or "null" if value is null or it's an NaN or an INF number.
|
||||
*/
|
||||
public static String toJSONString(Object value){
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try{
|
||||
writeJSONString(value, writer);
|
||||
return writer.toString();
|
||||
} catch(IOException e){
|
||||
// This should never happen for a StringWriter
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static String escape(String s){
|
||||
if(s==null)
|
||||
return null;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
escape(s, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param s - Must not be null.
|
||||
* @param sb
|
||||
*/
|
||||
static void escape(String s, StringBuffer sb) {
|
||||
final int len = s.length();
|
||||
for(int i=0;i<len;i++){
|
||||
char ch=s.charAt(i);
|
||||
switch(ch){
|
||||
case '"':
|
||||
sb.append("\\\"");
|
||||
break;
|
||||
case '\\':
|
||||
sb.append("\\\\");
|
||||
break;
|
||||
case '\b':
|
||||
sb.append("\\b");
|
||||
break;
|
||||
case '\f':
|
||||
sb.append("\\f");
|
||||
break;
|
||||
case '\n':
|
||||
sb.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
sb.append("\\r");
|
||||
break;
|
||||
case '\t':
|
||||
sb.append("\\t");
|
||||
break;
|
||||
case '/':
|
||||
sb.append("\\/");
|
||||
break;
|
||||
default:
|
||||
//Reference: http://www.unicode.org/versions/Unicode5.1.0/
|
||||
if((ch>='\u0000' && ch<='\u001F') || (ch>='\u007F' && ch<='\u009F') || (ch>='\u2000' && ch<='\u20FF')){
|
||||
String ss=Integer.toHexString(ch);
|
||||
sb.append("\\u");
|
||||
for(int k=0;k<4-ss.length();k++){
|
||||
sb.append('0');
|
||||
}
|
||||
sb.append(ss.toUpperCase());
|
||||
}
|
||||
else{
|
||||
sb.append(ch);
|
||||
}
|
||||
}
|
||||
}//for
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.json.simple.parser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Container factory for creating containers for JSON object and JSON array.
|
||||
*
|
||||
* @see org.json.simple.parser.JSONParser#parse(java.io.Reader, ContainerFactory)
|
||||
*
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public interface ContainerFactory {
|
||||
/**
|
||||
* @return A Map instance to store JSON object, or null if you want to use org.json.simple.JSONObject.
|
||||
*/
|
||||
Map createObjectContainer();
|
||||
|
||||
/**
|
||||
* @return A List instance to store JSON array, or null if you want to use org.json.simple.JSONArray.
|
||||
*/
|
||||
List creatArrayContainer();
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package org.json.simple.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A simplified and stoppable SAX-like content handler for stream processing of JSON text.
|
||||
*
|
||||
* @see org.xml.sax.ContentHandler
|
||||
* @see org.json.simple.parser.JSONParser#parse(java.io.Reader, ContentHandler, boolean)
|
||||
*
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public interface ContentHandler {
|
||||
/**
|
||||
* Receive notification of the beginning of JSON processing.
|
||||
* The parser will invoke this method only once.
|
||||
*
|
||||
* @throws ParseException
|
||||
* - JSONParser will stop and throw the same exception to the caller when receiving this exception.
|
||||
*/
|
||||
void startJSON() throws ParseException, IOException;
|
||||
|
||||
/**
|
||||
* Receive notification of the end of JSON processing.
|
||||
*
|
||||
* @throws ParseException
|
||||
*/
|
||||
void endJSON() throws ParseException, IOException;
|
||||
|
||||
/**
|
||||
* Receive notification of the beginning of a JSON object.
|
||||
*
|
||||
* @return false if the handler wants to stop parsing after return.
|
||||
* @throws ParseException
|
||||
* - JSONParser will stop and throw the same exception to the caller when receiving this exception.
|
||||
* @see #endJSON
|
||||
*/
|
||||
boolean startObject() throws ParseException, IOException;
|
||||
|
||||
/**
|
||||
* Receive notification of the end of a JSON object.
|
||||
*
|
||||
* @return false if the handler wants to stop parsing after return.
|
||||
* @throws ParseException
|
||||
*
|
||||
* @see #startObject
|
||||
*/
|
||||
boolean endObject() throws ParseException, IOException;
|
||||
|
||||
/**
|
||||
* Receive notification of the beginning of a JSON object entry.
|
||||
*
|
||||
* @param key - Key of a JSON object entry.
|
||||
*
|
||||
* @return false if the handler wants to stop parsing after return.
|
||||
* @throws ParseException
|
||||
*
|
||||
* @see #endObjectEntry
|
||||
*/
|
||||
boolean startObjectEntry(String key) throws ParseException, IOException;
|
||||
|
||||
/**
|
||||
* Receive notification of the end of the value of previous object entry.
|
||||
*
|
||||
* @return false if the handler wants to stop parsing after return.
|
||||
* @throws ParseException
|
||||
*
|
||||
* @see #startObjectEntry
|
||||
*/
|
||||
boolean endObjectEntry() throws ParseException, IOException;
|
||||
|
||||
/**
|
||||
* Receive notification of the beginning of a JSON array.
|
||||
*
|
||||
* @return false if the handler wants to stop parsing after return.
|
||||
* @throws ParseException
|
||||
*
|
||||
* @see #endArray
|
||||
*/
|
||||
boolean startArray() throws ParseException, IOException;
|
||||
|
||||
/**
|
||||
* Receive notification of the end of a JSON array.
|
||||
*
|
||||
* @return false if the handler wants to stop parsing after return.
|
||||
* @throws ParseException
|
||||
*
|
||||
* @see #startArray
|
||||
*/
|
||||
boolean endArray() throws ParseException, IOException;
|
||||
|
||||
/**
|
||||
* Receive notification of the JSON primitive values:
|
||||
* java.lang.String,
|
||||
* java.lang.Number,
|
||||
* java.lang.Boolean
|
||||
* null
|
||||
*
|
||||
* @param value - Instance of the following:
|
||||
* java.lang.String,
|
||||
* java.lang.Number,
|
||||
* java.lang.Boolean
|
||||
* null
|
||||
*
|
||||
* @return false if the handler wants to stop parsing after return.
|
||||
* @throws ParseException
|
||||
*/
|
||||
boolean primitive(Object value) throws ParseException, IOException;
|
||||
|
||||
}
|
|
@ -0,0 +1,533 @@
|
|||
/*
|
||||
* $Id: JSONParser.java,v 1.1 2006/04/15 14:10:48 platform Exp $
|
||||
* Created on 2006-4-15
|
||||
*/
|
||||
package org.json.simple.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
|
||||
/**
|
||||
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
|
||||
*
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public class JSONParser {
|
||||
public static final int S_INIT=0;
|
||||
public static final int S_IN_FINISHED_VALUE=1;//string,number,boolean,null,object,array
|
||||
public static final int S_IN_OBJECT=2;
|
||||
public static final int S_IN_ARRAY=3;
|
||||
public static final int S_PASSED_PAIR_KEY=4;
|
||||
public static final int S_IN_PAIR_VALUE=5;
|
||||
public static final int S_END=6;
|
||||
public static final int S_IN_ERROR=-1;
|
||||
|
||||
private LinkedList handlerStatusStack;
|
||||
private Yylex lexer = new Yylex((Reader)null);
|
||||
private Yytoken token = null;
|
||||
private int status = S_INIT;
|
||||
|
||||
private int peekStatus(LinkedList statusStack){
|
||||
if(statusStack.size()==0)
|
||||
return -1;
|
||||
Integer status=(Integer)statusStack.getFirst();
|
||||
return status.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the parser to the initial state without resetting the underlying reader.
|
||||
*
|
||||
*/
|
||||
public void reset(){
|
||||
token = null;
|
||||
status = S_INIT;
|
||||
handlerStatusStack = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the parser to the initial state with a new character reader.
|
||||
*
|
||||
* @param in - The new character reader.
|
||||
* @throws IOException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public void reset(Reader in){
|
||||
lexer.yyreset(in);
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The position of the beginning of the current token.
|
||||
*/
|
||||
public int getPosition(){
|
||||
return lexer.getPosition();
|
||||
}
|
||||
|
||||
public Object parse(String s) throws ParseException{
|
||||
return parse(s, (ContainerFactory)null);
|
||||
}
|
||||
|
||||
public Object parse(String s, ContainerFactory containerFactory) throws ParseException{
|
||||
StringReader in=new StringReader(s);
|
||||
try{
|
||||
return parse(in, containerFactory);
|
||||
}
|
||||
catch(IOException ie){
|
||||
/*
|
||||
* Actually it will never happen.
|
||||
*/
|
||||
throw new ParseException(-1, ParseException.ERROR_UNEXPECTED_EXCEPTION, ie);
|
||||
}
|
||||
}
|
||||
|
||||
public Object parse(Reader in) throws IOException, ParseException{
|
||||
return parse(in, (ContainerFactory)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse JSON text into java object from the input source.
|
||||
*
|
||||
* @param in
|
||||
* @param containerFactory - Use this factory to createyour own JSON object and JSON array containers.
|
||||
* @return Instance of the following:
|
||||
* org.json.simple.JSONObject,
|
||||
* org.json.simple.JSONArray,
|
||||
* java.lang.String,
|
||||
* java.lang.Number,
|
||||
* java.lang.Boolean,
|
||||
* null
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public Object parse(Reader in, ContainerFactory containerFactory) throws IOException, ParseException{
|
||||
reset(in);
|
||||
LinkedList statusStack = new LinkedList();
|
||||
LinkedList valueStack = new LinkedList();
|
||||
|
||||
try{
|
||||
do{
|
||||
nextToken();
|
||||
switch(status){
|
||||
case S_INIT:
|
||||
switch(token.type){
|
||||
case Yytoken.TYPE_VALUE:
|
||||
status=S_IN_FINISHED_VALUE;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
valueStack.addFirst(token.value);
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_BRACE:
|
||||
status=S_IN_OBJECT;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
valueStack.addFirst(createObjectContainer(containerFactory));
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_SQUARE:
|
||||
status=S_IN_ARRAY;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
valueStack.addFirst(createArrayContainer(containerFactory));
|
||||
break;
|
||||
default:
|
||||
status=S_IN_ERROR;
|
||||
}//inner switch
|
||||
break;
|
||||
|
||||
case S_IN_FINISHED_VALUE:
|
||||
if(token.type==Yytoken.TYPE_EOF)
|
||||
return valueStack.removeFirst();
|
||||
else
|
||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||
|
||||
case S_IN_OBJECT:
|
||||
switch(token.type){
|
||||
case Yytoken.TYPE_COMMA:
|
||||
break;
|
||||
case Yytoken.TYPE_VALUE:
|
||||
if(token.value instanceof String){
|
||||
String key=(String)token.value;
|
||||
valueStack.addFirst(key);
|
||||
status=S_PASSED_PAIR_KEY;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
}
|
||||
else{
|
||||
status=S_IN_ERROR;
|
||||
}
|
||||
break;
|
||||
case Yytoken.TYPE_RIGHT_BRACE:
|
||||
if(valueStack.size()>1){
|
||||
statusStack.removeFirst();
|
||||
valueStack.removeFirst();
|
||||
status=peekStatus(statusStack);
|
||||
}
|
||||
else{
|
||||
status=S_IN_FINISHED_VALUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
status=S_IN_ERROR;
|
||||
break;
|
||||
}//inner switch
|
||||
break;
|
||||
|
||||
case S_PASSED_PAIR_KEY:
|
||||
switch(token.type){
|
||||
case Yytoken.TYPE_COLON:
|
||||
break;
|
||||
case Yytoken.TYPE_VALUE:
|
||||
statusStack.removeFirst();
|
||||
String key=(String)valueStack.removeFirst();
|
||||
Map parent=(Map)valueStack.getFirst();
|
||||
parent.put(key,token.value);
|
||||
status=peekStatus(statusStack);
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_SQUARE:
|
||||
statusStack.removeFirst();
|
||||
key=(String)valueStack.removeFirst();
|
||||
parent=(Map)valueStack.getFirst();
|
||||
List newArray=createArrayContainer(containerFactory);
|
||||
parent.put(key,newArray);
|
||||
status=S_IN_ARRAY;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
valueStack.addFirst(newArray);
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_BRACE:
|
||||
statusStack.removeFirst();
|
||||
key=(String)valueStack.removeFirst();
|
||||
parent=(Map)valueStack.getFirst();
|
||||
Map newObject=createObjectContainer(containerFactory);
|
||||
parent.put(key,newObject);
|
||||
status=S_IN_OBJECT;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
valueStack.addFirst(newObject);
|
||||
break;
|
||||
default:
|
||||
status=S_IN_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_IN_ARRAY:
|
||||
switch(token.type){
|
||||
case Yytoken.TYPE_COMMA:
|
||||
break;
|
||||
case Yytoken.TYPE_VALUE:
|
||||
List val=(List)valueStack.getFirst();
|
||||
val.add(token.value);
|
||||
break;
|
||||
case Yytoken.TYPE_RIGHT_SQUARE:
|
||||
if(valueStack.size()>1){
|
||||
statusStack.removeFirst();
|
||||
valueStack.removeFirst();
|
||||
status=peekStatus(statusStack);
|
||||
}
|
||||
else{
|
||||
status=S_IN_FINISHED_VALUE;
|
||||
}
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_BRACE:
|
||||
val=(List)valueStack.getFirst();
|
||||
Map newObject=createObjectContainer(containerFactory);
|
||||
val.add(newObject);
|
||||
status=S_IN_OBJECT;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
valueStack.addFirst(newObject);
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_SQUARE:
|
||||
val=(List)valueStack.getFirst();
|
||||
List newArray=createArrayContainer(containerFactory);
|
||||
val.add(newArray);
|
||||
status=S_IN_ARRAY;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
valueStack.addFirst(newArray);
|
||||
break;
|
||||
default:
|
||||
status=S_IN_ERROR;
|
||||
}//inner switch
|
||||
break;
|
||||
case S_IN_ERROR:
|
||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||
}//switch
|
||||
if(status==S_IN_ERROR){
|
||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||
}
|
||||
}while(token.type!=Yytoken.TYPE_EOF);
|
||||
}
|
||||
catch(IOException ie){
|
||||
throw ie;
|
||||
}
|
||||
|
||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||
}
|
||||
|
||||
private void nextToken() throws ParseException, IOException{
|
||||
token = lexer.yylex();
|
||||
if(token == null)
|
||||
token = new Yytoken(Yytoken.TYPE_EOF, null);
|
||||
}
|
||||
|
||||
private Map createObjectContainer(ContainerFactory containerFactory){
|
||||
if(containerFactory == null)
|
||||
return new JSONObject();
|
||||
Map m = containerFactory.createObjectContainer();
|
||||
|
||||
if(m == null)
|
||||
return new JSONObject();
|
||||
return m;
|
||||
}
|
||||
|
||||
private List createArrayContainer(ContainerFactory containerFactory){
|
||||
if(containerFactory == null)
|
||||
return new JSONArray();
|
||||
List l = containerFactory.creatArrayContainer();
|
||||
|
||||
if(l == null)
|
||||
return new JSONArray();
|
||||
return l;
|
||||
}
|
||||
|
||||
public void parse(String s, ContentHandler contentHandler) throws ParseException{
|
||||
parse(s, contentHandler, false);
|
||||
}
|
||||
|
||||
public void parse(String s, ContentHandler contentHandler, boolean isResume) throws ParseException{
|
||||
StringReader in=new StringReader(s);
|
||||
try{
|
||||
parse(in, contentHandler, isResume);
|
||||
}
|
||||
catch(IOException ie){
|
||||
/*
|
||||
* Actually it will never happen.
|
||||
*/
|
||||
throw new ParseException(-1, ParseException.ERROR_UNEXPECTED_EXCEPTION, ie);
|
||||
}
|
||||
}
|
||||
|
||||
public void parse(Reader in, ContentHandler contentHandler) throws IOException, ParseException{
|
||||
parse(in, contentHandler, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream processing of JSON text.
|
||||
*
|
||||
* @see ContentHandler
|
||||
*
|
||||
* @param in
|
||||
* @param contentHandler
|
||||
* @param isResume - Indicates if it continues previous parsing operation.
|
||||
* If set to true, resume parsing the old stream, and parameter 'in' will be ignored.
|
||||
* If this method is called for the first time in this instance, isResume will be ignored.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public void parse(Reader in, ContentHandler contentHandler, boolean isResume) throws IOException, ParseException{
|
||||
if(!isResume){
|
||||
reset(in);
|
||||
handlerStatusStack = new LinkedList();
|
||||
}
|
||||
else{
|
||||
if(handlerStatusStack == null){
|
||||
isResume = false;
|
||||
reset(in);
|
||||
handlerStatusStack = new LinkedList();
|
||||
}
|
||||
}
|
||||
|
||||
LinkedList statusStack = handlerStatusStack;
|
||||
|
||||
try{
|
||||
do{
|
||||
switch(status){
|
||||
case S_INIT:
|
||||
contentHandler.startJSON();
|
||||
nextToken();
|
||||
switch(token.type){
|
||||
case Yytoken.TYPE_VALUE:
|
||||
status=S_IN_FINISHED_VALUE;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
if(!contentHandler.primitive(token.value))
|
||||
return;
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_BRACE:
|
||||
status=S_IN_OBJECT;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
if(!contentHandler.startObject())
|
||||
return;
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_SQUARE:
|
||||
status=S_IN_ARRAY;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
if(!contentHandler.startArray())
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
status=S_IN_ERROR;
|
||||
}//inner switch
|
||||
break;
|
||||
|
||||
case S_IN_FINISHED_VALUE:
|
||||
nextToken();
|
||||
if(token.type==Yytoken.TYPE_EOF){
|
||||
contentHandler.endJSON();
|
||||
status = S_END;
|
||||
return;
|
||||
}
|
||||
else{
|
||||
status = S_IN_ERROR;
|
||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||
}
|
||||
|
||||
case S_IN_OBJECT:
|
||||
nextToken();
|
||||
switch(token.type){
|
||||
case Yytoken.TYPE_COMMA:
|
||||
break;
|
||||
case Yytoken.TYPE_VALUE:
|
||||
if(token.value instanceof String){
|
||||
String key=(String)token.value;
|
||||
status=S_PASSED_PAIR_KEY;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
if(!contentHandler.startObjectEntry(key))
|
||||
return;
|
||||
}
|
||||
else{
|
||||
status=S_IN_ERROR;
|
||||
}
|
||||
break;
|
||||
case Yytoken.TYPE_RIGHT_BRACE:
|
||||
if(statusStack.size()>1){
|
||||
statusStack.removeFirst();
|
||||
status=peekStatus(statusStack);
|
||||
}
|
||||
else{
|
||||
status=S_IN_FINISHED_VALUE;
|
||||
}
|
||||
if(!contentHandler.endObject())
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
status=S_IN_ERROR;
|
||||
break;
|
||||
}//inner switch
|
||||
break;
|
||||
|
||||
case S_PASSED_PAIR_KEY:
|
||||
nextToken();
|
||||
switch(token.type){
|
||||
case Yytoken.TYPE_COLON:
|
||||
break;
|
||||
case Yytoken.TYPE_VALUE:
|
||||
statusStack.removeFirst();
|
||||
status=peekStatus(statusStack);
|
||||
if(!contentHandler.primitive(token.value))
|
||||
return;
|
||||
if(!contentHandler.endObjectEntry())
|
||||
return;
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_SQUARE:
|
||||
statusStack.removeFirst();
|
||||
statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
|
||||
status=S_IN_ARRAY;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
if(!contentHandler.startArray())
|
||||
return;
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_BRACE:
|
||||
statusStack.removeFirst();
|
||||
statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
|
||||
status=S_IN_OBJECT;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
if(!contentHandler.startObject())
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
status=S_IN_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_IN_PAIR_VALUE:
|
||||
/*
|
||||
* S_IN_PAIR_VALUE is just a marker to indicate the end of an object entry, it doesn't proccess any token,
|
||||
* therefore delay consuming token until next round.
|
||||
*/
|
||||
statusStack.removeFirst();
|
||||
status = peekStatus(statusStack);
|
||||
if(!contentHandler.endObjectEntry())
|
||||
return;
|
||||
break;
|
||||
|
||||
case S_IN_ARRAY:
|
||||
nextToken();
|
||||
switch(token.type){
|
||||
case Yytoken.TYPE_COMMA:
|
||||
break;
|
||||
case Yytoken.TYPE_VALUE:
|
||||
if(!contentHandler.primitive(token.value))
|
||||
return;
|
||||
break;
|
||||
case Yytoken.TYPE_RIGHT_SQUARE:
|
||||
if(statusStack.size()>1){
|
||||
statusStack.removeFirst();
|
||||
status=peekStatus(statusStack);
|
||||
}
|
||||
else{
|
||||
status=S_IN_FINISHED_VALUE;
|
||||
}
|
||||
if(!contentHandler.endArray())
|
||||
return;
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_BRACE:
|
||||
status=S_IN_OBJECT;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
if(!contentHandler.startObject())
|
||||
return;
|
||||
break;
|
||||
case Yytoken.TYPE_LEFT_SQUARE:
|
||||
status=S_IN_ARRAY;
|
||||
statusStack.addFirst(new Integer(status));
|
||||
if(!contentHandler.startArray())
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
status=S_IN_ERROR;
|
||||
}//inner switch
|
||||
break;
|
||||
|
||||
case S_END:
|
||||
return;
|
||||
|
||||
case S_IN_ERROR:
|
||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||
}//switch
|
||||
if(status==S_IN_ERROR){
|
||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||
}
|
||||
}while(token.type!=Yytoken.TYPE_EOF);
|
||||
}
|
||||
catch(IOException ie){
|
||||
status = S_IN_ERROR;
|
||||
throw ie;
|
||||
}
|
||||
catch(ParseException pe){
|
||||
status = S_IN_ERROR;
|
||||
throw pe;
|
||||
}
|
||||
catch(RuntimeException re){
|
||||
status = S_IN_ERROR;
|
||||
throw re;
|
||||
}
|
||||
catch(Error e){
|
||||
status = S_IN_ERROR;
|
||||
throw e;
|
||||
}
|
||||
|
||||
status = S_IN_ERROR;
|
||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package org.json.simple.parser;
|
||||
|
||||
/**
|
||||
* ParseException explains why and where the error occurs in source JSON text.
|
||||
*
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*
|
||||
*/
|
||||
public class ParseException extends Exception {
|
||||
private static final long serialVersionUID = -7880698968187728547L;
|
||||
|
||||
public static final int ERROR_UNEXPECTED_CHAR = 0;
|
||||
public static final int ERROR_UNEXPECTED_TOKEN = 1;
|
||||
public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
|
||||
|
||||
private int errorType;
|
||||
private Object unexpectedObject;
|
||||
private int position;
|
||||
|
||||
public ParseException(int errorType){
|
||||
this(-1, errorType, null);
|
||||
}
|
||||
|
||||
public ParseException(int errorType, Object unexpectedObject){
|
||||
this(-1, errorType, unexpectedObject);
|
||||
}
|
||||
|
||||
public ParseException(int position, int errorType, Object unexpectedObject){
|
||||
this.position = position;
|
||||
this.errorType = errorType;
|
||||
this.unexpectedObject = unexpectedObject;
|
||||
}
|
||||
|
||||
public int getErrorType() {
|
||||
return errorType;
|
||||
}
|
||||
|
||||
public void setErrorType(int errorType) {
|
||||
this.errorType = errorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.json.simple.parser.JSONParser#getPosition()
|
||||
*
|
||||
* @return The character position (starting with 0) of the input where the error occurs.
|
||||
*/
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.json.simple.parser.Yytoken
|
||||
*
|
||||
* @return One of the following base on the value of errorType:
|
||||
* ERROR_UNEXPECTED_CHAR java.lang.Character
|
||||
* ERROR_UNEXPECTED_TOKEN org.json.simple.parser.Yytoken
|
||||
* ERROR_UNEXPECTED_EXCEPTION java.lang.Exception
|
||||
*/
|
||||
public Object getUnexpectedObject() {
|
||||
return unexpectedObject;
|
||||
}
|
||||
|
||||
public void setUnexpectedObject(Object unexpectedObject) {
|
||||
this.unexpectedObject = unexpectedObject;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
switch(errorType){
|
||||
case ERROR_UNEXPECTED_CHAR:
|
||||
sb.append("Unexpected character (").append(unexpectedObject).append(") at position ").append(position).append(".");
|
||||
break;
|
||||
case ERROR_UNEXPECTED_TOKEN:
|
||||
sb.append("Unexpected token ").append(unexpectedObject).append(" at position ").append(position).append(".");
|
||||
break;
|
||||
case ERROR_UNEXPECTED_EXCEPTION:
|
||||
sb.append("Unexpected exception at position ").append(position).append(": ").append(unexpectedObject);
|
||||
break;
|
||||
default:
|
||||
sb.append("Unkown error at position ").append(position).append(".");
|
||||
break;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,688 @@
|
|||
/* The following code was generated by JFlex 1.4.2 */
|
||||
|
||||
package org.json.simple.parser;
|
||||
|
||||
class Yylex {
|
||||
|
||||
/** This character denotes the end of file */
|
||||
public static final int YYEOF = -1;
|
||||
|
||||
/** initial size of the lookahead buffer */
|
||||
private static final int ZZ_BUFFERSIZE = 16384;
|
||||
|
||||
/** lexical states */
|
||||
public static final int YYINITIAL = 0;
|
||||
public static final int STRING_BEGIN = 2;
|
||||
|
||||
/**
|
||||
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
|
||||
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
|
||||
* at the beginning of a line
|
||||
* l is of the form l = 2*k, k a non negative integer
|
||||
*/
|
||||
private static final int ZZ_LEXSTATE[] = {
|
||||
0, 0, 1, 1
|
||||
};
|
||||
|
||||
/**
|
||||
* Translates characters to character classes
|
||||
*/
|
||||
private static final String ZZ_CMAP_PACKED =
|
||||
"\11\0\1\7\1\7\2\0\1\7\22\0\1\7\1\0\1\11\10\0"+
|
||||
"\1\6\1\31\1\2\1\4\1\12\12\3\1\32\6\0\4\1\1\5"+
|
||||
"\1\1\24\0\1\27\1\10\1\30\3\0\1\22\1\13\2\1\1\21"+
|
||||
"\1\14\5\0\1\23\1\0\1\15\3\0\1\16\1\24\1\17\1\20"+
|
||||
"\5\0\1\25\1\0\1\26\uff82\0";
|
||||
|
||||
/**
|
||||
* Translates characters to character classes
|
||||
*/
|
||||
private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
|
||||
|
||||
/**
|
||||
* Translates DFA states to action switch labels.
|
||||
*/
|
||||
private static final int [] ZZ_ACTION = zzUnpackAction();
|
||||
|
||||
private static final String ZZ_ACTION_PACKED_0 =
|
||||
"\2\0\2\1\1\2\1\3\1\4\3\1\1\5\1\6"+
|
||||
"\1\7\1\10\1\11\1\12\1\13\1\14\1\15\5\0"+
|
||||
"\1\14\1\16\1\17\1\20\1\21\1\22\1\23\1\24"+
|
||||
"\1\0\1\25\1\0\1\25\4\0\1\26\1\27\2\0"+
|
||||
"\1\30";
|
||||
|
||||
private static int [] zzUnpackAction() {
|
||||
int [] result = new int[45];
|
||||
int offset = 0;
|
||||
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackAction(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int count = packed.charAt(i++);
|
||||
int value = packed.charAt(i++);
|
||||
do result[j++] = value; while (--count > 0);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translates a state to a row index in the transition table
|
||||
*/
|
||||
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
|
||||
|
||||
private static final String ZZ_ROWMAP_PACKED_0 =
|
||||
"\0\0\0\33\0\66\0\121\0\154\0\207\0\66\0\242"+
|
||||
"\0\275\0\330\0\66\0\66\0\66\0\66\0\66\0\66"+
|
||||
"\0\363\0\u010e\0\66\0\u0129\0\u0144\0\u015f\0\u017a\0\u0195"+
|
||||
"\0\66\0\66\0\66\0\66\0\66\0\66\0\66\0\66"+
|
||||
"\0\u01b0\0\u01cb\0\u01e6\0\u01e6\0\u0201\0\u021c\0\u0237\0\u0252"+
|
||||
"\0\66\0\66\0\u026d\0\u0288\0\66";
|
||||
|
||||
private static int [] zzUnpackRowMap() {
|
||||
int [] result = new int[45];
|
||||
int offset = 0;
|
||||
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackRowMap(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int high = packed.charAt(i++) << 16;
|
||||
result[j++] = high | packed.charAt(i++);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
/**
|
||||
* The transition table of the DFA
|
||||
*/
|
||||
private static final int ZZ_TRANS [] = {
|
||||
2, 2, 3, 4, 2, 2, 2, 5, 2, 6,
|
||||
2, 2, 7, 8, 2, 9, 2, 2, 2, 2,
|
||||
2, 10, 11, 12, 13, 14, 15, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 17, 18, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, 4, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, 4, 19, 20, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 20, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, 5, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
21, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 22, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
23, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, -1, -1, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, 24, 25,
|
||||
26, 27, 28, 29, 30, 31, 32, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
33, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, 34, 35, -1, -1,
|
||||
34, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
36, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 37, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, 38, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 39, -1, 39, -1, 39, -1, -1,
|
||||
-1, -1, -1, 39, 39, -1, -1, -1, -1, 39,
|
||||
39, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, 33, -1, 20, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, 20, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 35,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 38, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 40,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, 41, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 42, -1, 42, -1, 42,
|
||||
-1, -1, -1, -1, -1, 42, 42, -1, -1, -1,
|
||||
-1, 42, 42, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, 43, -1, 43, -1, 43, -1, -1, -1,
|
||||
-1, -1, 43, 43, -1, -1, -1, -1, 43, 43,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 44,
|
||||
-1, 44, -1, 44, -1, -1, -1, -1, -1, 44,
|
||||
44, -1, -1, -1, -1, 44, 44, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1,
|
||||
};
|
||||
|
||||
/* error codes */
|
||||
private static final int ZZ_UNKNOWN_ERROR = 0;
|
||||
private static final int ZZ_NO_MATCH = 1;
|
||||
private static final int ZZ_PUSHBACK_2BIG = 2;
|
||||
|
||||
/* error messages for the codes above */
|
||||
private static final String ZZ_ERROR_MSG[] = {
|
||||
"Unkown internal scanner error",
|
||||
"Error: could not match input",
|
||||
"Error: pushback value was too large"
|
||||
};
|
||||
|
||||
/**
|
||||
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
|
||||
*/
|
||||
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
|
||||
|
||||
private static final String ZZ_ATTRIBUTE_PACKED_0 =
|
||||
"\2\0\1\11\3\1\1\11\3\1\6\11\2\1\1\11"+
|
||||
"\5\0\10\11\1\0\1\1\1\0\1\1\4\0\2\11"+
|
||||
"\2\0\1\11";
|
||||
|
||||
private static int [] zzUnpackAttribute() {
|
||||
int [] result = new int[45];
|
||||
int offset = 0;
|
||||
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackAttribute(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int count = packed.charAt(i++);
|
||||
int value = packed.charAt(i++);
|
||||
do result[j++] = value; while (--count > 0);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
/** the input device */
|
||||
private java.io.Reader zzReader;
|
||||
|
||||
/** the current state of the DFA */
|
||||
private int zzState;
|
||||
|
||||
/** the current lexical state */
|
||||
private int zzLexicalState = YYINITIAL;
|
||||
|
||||
/** this buffer contains the current text to be matched and is
|
||||
the source of the yytext() string */
|
||||
private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
|
||||
|
||||
/** the textposition at the last accepting state */
|
||||
private int zzMarkedPos;
|
||||
|
||||
/** the current text position in the buffer */
|
||||
private int zzCurrentPos;
|
||||
|
||||
/** startRead marks the beginning of the yytext() string in the buffer */
|
||||
private int zzStartRead;
|
||||
|
||||
/** endRead marks the last character in the buffer, that has been read
|
||||
from input */
|
||||
private int zzEndRead;
|
||||
|
||||
/** number of newlines encountered up to the start of the matched text */
|
||||
private int yyline;
|
||||
|
||||
/** the number of characters up to the start of the matched text */
|
||||
private int yychar;
|
||||
|
||||
/**
|
||||
* the number of characters from the last newline up to the start of the
|
||||
* matched text
|
||||
*/
|
||||
private int yycolumn;
|
||||
|
||||
/**
|
||||
* zzAtBOL == true <=> the scanner is currently at the beginning of a line
|
||||
*/
|
||||
private boolean zzAtBOL = true;
|
||||
|
||||
/** zzAtEOF == true <=> the scanner is at the EOF */
|
||||
private boolean zzAtEOF;
|
||||
|
||||
/* user code: */
|
||||
private StringBuffer sb=new StringBuffer();
|
||||
|
||||
int getPosition(){
|
||||
return yychar;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new scanner
|
||||
* There is also a java.io.InputStream version of this constructor.
|
||||
*
|
||||
* @param in the java.io.Reader to read input from.
|
||||
*/
|
||||
Yylex(java.io.Reader in) {
|
||||
this.zzReader = in;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new scanner.
|
||||
* There is also java.io.Reader version of this constructor.
|
||||
*
|
||||
* @param in the java.io.Inputstream to read input from.
|
||||
*/
|
||||
Yylex(java.io.InputStream in) {
|
||||
this(new java.io.InputStreamReader(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks the compressed character translation table.
|
||||
*
|
||||
* @param packed the packed character translation table
|
||||
* @return the unpacked character translation table
|
||||
*/
|
||||
private static char [] zzUnpackCMap(String packed) {
|
||||
char [] map = new char[0x10000];
|
||||
int i = 0; /* index in packed string */
|
||||
int j = 0; /* index in unpacked array */
|
||||
while (i < 90) {
|
||||
int count = packed.charAt(i++);
|
||||
char value = packed.charAt(i++);
|
||||
do map[j++] = value; while (--count > 0);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Refills the input buffer.
|
||||
*
|
||||
* @return <code>false</code>, iff there was new input.
|
||||
*
|
||||
* @exception java.io.IOException if any I/O-Error occurs
|
||||
*/
|
||||
private boolean zzRefill() throws java.io.IOException {
|
||||
|
||||
/* first: make room (if you can) */
|
||||
if (zzStartRead > 0) {
|
||||
System.arraycopy(zzBuffer, zzStartRead,
|
||||
zzBuffer, 0,
|
||||
zzEndRead-zzStartRead);
|
||||
|
||||
/* translate stored positions */
|
||||
zzEndRead-= zzStartRead;
|
||||
zzCurrentPos-= zzStartRead;
|
||||
zzMarkedPos-= zzStartRead;
|
||||
zzStartRead = 0;
|
||||
}
|
||||
|
||||
/* is the buffer big enough? */
|
||||
if (zzCurrentPos >= zzBuffer.length) {
|
||||
/* if not: blow it up */
|
||||
char newBuffer[] = new char[zzCurrentPos*2];
|
||||
System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
|
||||
zzBuffer = newBuffer;
|
||||
}
|
||||
|
||||
/* finally: fill the buffer with new input */
|
||||
int numRead = zzReader.read(zzBuffer, zzEndRead,
|
||||
zzBuffer.length-zzEndRead);
|
||||
|
||||
if (numRead > 0) {
|
||||
zzEndRead+= numRead;
|
||||
return false;
|
||||
}
|
||||
// unlikely but not impossible: read 0 characters, but not at end of stream
|
||||
if (numRead == 0) {
|
||||
int c = zzReader.read();
|
||||
if (c == -1) {
|
||||
return true;
|
||||
} else {
|
||||
zzBuffer[zzEndRead++] = (char) c;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// numRead < 0
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes the input stream.
|
||||
*/
|
||||
public final void yyclose() throws java.io.IOException {
|
||||
zzAtEOF = true; /* indicate end of file */
|
||||
zzEndRead = zzStartRead; /* invalidate buffer */
|
||||
|
||||
if (zzReader != null)
|
||||
zzReader.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the scanner to read from a new input stream.
|
||||
* Does not close the old reader.
|
||||
*
|
||||
* All internal variables are reset, the old input stream
|
||||
* <b>cannot</b> be reused (internal buffer is discarded and lost).
|
||||
* Lexical state is set to <tt>ZZ_INITIAL</tt>.
|
||||
*
|
||||
* @param reader the new input stream
|
||||
*/
|
||||
public final void yyreset(java.io.Reader reader) {
|
||||
zzReader = reader;
|
||||
zzAtBOL = true;
|
||||
zzAtEOF = false;
|
||||
zzEndRead = zzStartRead = 0;
|
||||
zzCurrentPos = zzMarkedPos = 0;
|
||||
yyline = yychar = yycolumn = 0;
|
||||
zzLexicalState = YYINITIAL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current lexical state.
|
||||
*/
|
||||
public final int yystate() {
|
||||
return zzLexicalState;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enters a new lexical state
|
||||
*
|
||||
* @param newState the new lexical state
|
||||
*/
|
||||
public final void yybegin(int newState) {
|
||||
zzLexicalState = newState;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the text matched by the current regular expression.
|
||||
*/
|
||||
public final String yytext() {
|
||||
return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the character at position <tt>pos</tt> from the
|
||||
* matched text.
|
||||
*
|
||||
* It is equivalent to yytext().charAt(pos), but faster
|
||||
*
|
||||
* @param pos the position of the character to fetch.
|
||||
* A value from 0 to yylength()-1.
|
||||
*
|
||||
* @return the character at position pos
|
||||
*/
|
||||
public final char yycharat(int pos) {
|
||||
return zzBuffer[zzStartRead+pos];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the length of the matched text region.
|
||||
*/
|
||||
public final int yylength() {
|
||||
return zzMarkedPos-zzStartRead;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reports an error that occured while scanning.
|
||||
*
|
||||
* In a wellformed scanner (no or only correct usage of
|
||||
* yypushback(int) and a match-all fallback rule) this method
|
||||
* will only be called with things that "Can't Possibly Happen".
|
||||
* If this method is called, something is seriously wrong
|
||||
* (e.g. a JFlex bug producing a faulty scanner etc.).
|
||||
*
|
||||
* Usual syntax/scanner level error handling should be done
|
||||
* in error fallback rules.
|
||||
*
|
||||
* @param errorCode the code of the errormessage to display
|
||||
*/
|
||||
private void zzScanError(int errorCode) {
|
||||
String message;
|
||||
try {
|
||||
message = ZZ_ERROR_MSG[errorCode];
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
|
||||
}
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pushes the specified amount of characters back into the input stream.
|
||||
*
|
||||
* They will be read again by then next call of the scanning method
|
||||
*
|
||||
* @param number the number of characters to be read again.
|
||||
* This number must not be greater than yylength()!
|
||||
*/
|
||||
public void yypushback(int number) {
|
||||
if ( number > yylength() )
|
||||
zzScanError(ZZ_PUSHBACK_2BIG);
|
||||
|
||||
zzMarkedPos -= number;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resumes scanning until the next regular expression is matched,
|
||||
* the end of input is encountered or an I/O-Error occurs.
|
||||
*
|
||||
* @return the next token
|
||||
* @exception java.io.IOException if any I/O-Error occurs
|
||||
*/
|
||||
public Yytoken yylex() throws java.io.IOException, ParseException {
|
||||
int zzInput;
|
||||
int zzAction;
|
||||
|
||||
// cached fields:
|
||||
int zzCurrentPosL;
|
||||
int zzMarkedPosL;
|
||||
int zzEndReadL = zzEndRead;
|
||||
char [] zzBufferL = zzBuffer;
|
||||
char [] zzCMapL = ZZ_CMAP;
|
||||
|
||||
int [] zzTransL = ZZ_TRANS;
|
||||
int [] zzRowMapL = ZZ_ROWMAP;
|
||||
int [] zzAttrL = ZZ_ATTRIBUTE;
|
||||
|
||||
while (true) {
|
||||
zzMarkedPosL = zzMarkedPos;
|
||||
|
||||
yychar+= zzMarkedPosL-zzStartRead;
|
||||
|
||||
zzAction = -1;
|
||||
|
||||
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
|
||||
|
||||
zzState = ZZ_LEXSTATE[zzLexicalState];
|
||||
|
||||
|
||||
zzForAction: {
|
||||
while (true) {
|
||||
|
||||
if (zzCurrentPosL < zzEndReadL)
|
||||
zzInput = zzBufferL[zzCurrentPosL++];
|
||||
else if (zzAtEOF) {
|
||||
zzInput = YYEOF;
|
||||
break zzForAction;
|
||||
}
|
||||
else {
|
||||
// store back cached positions
|
||||
zzCurrentPos = zzCurrentPosL;
|
||||
zzMarkedPos = zzMarkedPosL;
|
||||
boolean eof = zzRefill();
|
||||
// get translated positions and possibly new buffer
|
||||
zzCurrentPosL = zzCurrentPos;
|
||||
zzMarkedPosL = zzMarkedPos;
|
||||
zzBufferL = zzBuffer;
|
||||
zzEndReadL = zzEndRead;
|
||||
if (eof) {
|
||||
zzInput = YYEOF;
|
||||
break zzForAction;
|
||||
}
|
||||
else {
|
||||
zzInput = zzBufferL[zzCurrentPosL++];
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
|
||||
if (zzNext == -1) break zzForAction;
|
||||
zzState = zzNext;
|
||||
|
||||
int zzAttributes = zzAttrL[zzState];
|
||||
if ( (zzAttributes & 1) == 1 ) {
|
||||
zzAction = zzState;
|
||||
zzMarkedPosL = zzCurrentPosL;
|
||||
if ( (zzAttributes & 8) == 8 ) break zzForAction;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// store back cached position
|
||||
zzMarkedPos = zzMarkedPosL;
|
||||
|
||||
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
|
||||
case 11:
|
||||
{ sb.append(yytext());
|
||||
}
|
||||
case 25: break;
|
||||
case 4:
|
||||
{ sb = null; sb = new StringBuffer(); yybegin(STRING_BEGIN);
|
||||
}
|
||||
case 26: break;
|
||||
case 16:
|
||||
{ sb.append('\b');
|
||||
}
|
||||
case 27: break;
|
||||
case 6:
|
||||
{ return new Yytoken(Yytoken.TYPE_RIGHT_BRACE,null);
|
||||
}
|
||||
case 28: break;
|
||||
case 23:
|
||||
{ Boolean val=Boolean.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
|
||||
}
|
||||
case 29: break;
|
||||
case 22:
|
||||
{ return new Yytoken(Yytoken.TYPE_VALUE, null);
|
||||
}
|
||||
case 30: break;
|
||||
case 13:
|
||||
{ yybegin(YYINITIAL);return new Yytoken(Yytoken.TYPE_VALUE, sb.toString());
|
||||
}
|
||||
case 31: break;
|
||||
case 12:
|
||||
{ sb.append('\\');
|
||||
}
|
||||
case 32: break;
|
||||
case 21:
|
||||
{ Double val=Double.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
|
||||
}
|
||||
case 33: break;
|
||||
case 1:
|
||||
{ throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_CHAR, new Character(yycharat(0)));
|
||||
}
|
||||
case 34: break;
|
||||
case 8:
|
||||
{ return new Yytoken(Yytoken.TYPE_RIGHT_SQUARE,null);
|
||||
}
|
||||
case 35: break;
|
||||
case 19:
|
||||
{ sb.append('\r');
|
||||
}
|
||||
case 36: break;
|
||||
case 15:
|
||||
{ sb.append('/');
|
||||
}
|
||||
case 37: break;
|
||||
case 10:
|
||||
{ return new Yytoken(Yytoken.TYPE_COLON,null);
|
||||
}
|
||||
case 38: break;
|
||||
case 14:
|
||||
{ sb.append('"');
|
||||
}
|
||||
case 39: break;
|
||||
case 5:
|
||||
{ return new Yytoken(Yytoken.TYPE_LEFT_BRACE,null);
|
||||
}
|
||||
case 40: break;
|
||||
case 17:
|
||||
{ sb.append('\f');
|
||||
}
|
||||
case 41: break;
|
||||
case 24:
|
||||
{ try{
|
||||
int ch=Integer.parseInt(yytext().substring(2),16);
|
||||
sb.append((char)ch);
|
||||
}
|
||||
catch(Exception e){
|
||||
throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_EXCEPTION, e);
|
||||
}
|
||||
}
|
||||
case 42: break;
|
||||
case 20:
|
||||
{ sb.append('\t');
|
||||
}
|
||||
case 43: break;
|
||||
case 7:
|
||||
{ return new Yytoken(Yytoken.TYPE_LEFT_SQUARE,null);
|
||||
}
|
||||
case 44: break;
|
||||
case 2:
|
||||
{ Long val=Long.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
|
||||
}
|
||||
case 45: break;
|
||||
case 18:
|
||||
{ sb.append('\n');
|
||||
}
|
||||
case 46: break;
|
||||
case 9:
|
||||
{ return new Yytoken(Yytoken.TYPE_COMMA,null);
|
||||
}
|
||||
case 47: break;
|
||||
case 3:
|
||||
{
|
||||
}
|
||||
case 48: break;
|
||||
default:
|
||||
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
|
||||
zzAtEOF = true;
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
zzScanError(ZZ_NO_MATCH);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* $Id: Yytoken.java,v 1.1 2006/04/15 14:10:48 platform Exp $
|
||||
* Created on 2006-4-15
|
||||
*/
|
||||
package org.json.simple.parser;
|
||||
|
||||
/**
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public class Yytoken {
|
||||
public static final int TYPE_VALUE=0;//JSON primitive value: string,number,boolean,null
|
||||
public static final int TYPE_LEFT_BRACE=1;
|
||||
public static final int TYPE_RIGHT_BRACE=2;
|
||||
public static final int TYPE_LEFT_SQUARE=3;
|
||||
public static final int TYPE_RIGHT_SQUARE=4;
|
||||
public static final int TYPE_COMMA=5;
|
||||
public static final int TYPE_COLON=6;
|
||||
public static final int TYPE_EOF=-1;//end of file
|
||||
|
||||
public int type=0;
|
||||
public Object value=null;
|
||||
|
||||
public Yytoken(int type,Object value){
|
||||
this.type=type;
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
StringBuffer sb = new StringBuffer();
|
||||
switch(type){
|
||||
case TYPE_VALUE:
|
||||
sb.append("VALUE(").append(value).append(")");
|
||||
break;
|
||||
case TYPE_LEFT_BRACE:
|
||||
sb.append("LEFT BRACE({)");
|
||||
break;
|
||||
case TYPE_RIGHT_BRACE:
|
||||
sb.append("RIGHT BRACE(})");
|
||||
break;
|
||||
case TYPE_LEFT_SQUARE:
|
||||
sb.append("LEFT SQUARE([)");
|
||||
break;
|
||||
case TYPE_RIGHT_SQUARE:
|
||||
sb.append("RIGHT SQUARE(])");
|
||||
break;
|
||||
case TYPE_COMMA:
|
||||
sb.append("COMMA(,)");
|
||||
break;
|
||||
case TYPE_COLON:
|
||||
sb.append("COLON(:)");
|
||||
break;
|
||||
case TYPE_EOF:
|
||||
sb.append("END OF FILE");
|
||||
break;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,288 @@
|
|||
package org.json.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JSONArrayTest extends TestCase {
|
||||
|
||||
public void testJSONArray() {
|
||||
final JSONArray jsonArray = new JSONArray();
|
||||
|
||||
assertEquals("[]", jsonArray.toJSONString());
|
||||
}
|
||||
|
||||
public void testJSONArrayCollection() {
|
||||
final ArrayList testList = new ArrayList();
|
||||
testList.add("First item");
|
||||
testList.add("Second item");
|
||||
|
||||
final JSONArray jsonArray = new JSONArray(testList);
|
||||
|
||||
assertEquals("[\"First item\",\"Second item\"]", jsonArray.toJSONString());
|
||||
}
|
||||
|
||||
public void testWriteJSONStringCollectionWriter() throws IOException, ParseException {
|
||||
final HashSet testSet = new HashSet();
|
||||
testSet.add("First item");
|
||||
testSet.add("Second item");
|
||||
|
||||
final JSONArray jsonArray = new JSONArray(testSet);
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
jsonArray.writeJSONString(writer);
|
||||
|
||||
final JSONParser parser = new JSONParser();
|
||||
final JSONArray parsedArray = (JSONArray)parser.parse(writer.toString());
|
||||
|
||||
assertTrue(parsedArray.containsAll(jsonArray));
|
||||
assertTrue(jsonArray.containsAll(parsedArray));
|
||||
assertEquals(2, jsonArray.size());
|
||||
}
|
||||
|
||||
public void testToJSONStringCollection() throws ParseException {
|
||||
final HashSet testSet = new HashSet();
|
||||
testSet.add("First item");
|
||||
testSet.add("Second item");
|
||||
|
||||
final JSONArray jsonArray = new JSONArray(testSet);
|
||||
|
||||
final JSONParser parser = new JSONParser();
|
||||
final JSONArray parsedArray = (JSONArray)parser.parse(jsonArray.toJSONString());
|
||||
|
||||
assertTrue(parsedArray.containsAll(jsonArray));
|
||||
assertTrue(jsonArray.containsAll(parsedArray));
|
||||
assertEquals(2, jsonArray.size());
|
||||
}
|
||||
|
||||
public void testByteArrayToString() throws IOException {
|
||||
assertEquals("null", JSONArray.toJSONString((byte[])null));
|
||||
assertEquals("[]", JSONArray.toJSONString(new byte[0]));
|
||||
assertEquals("[12]", JSONArray.toJSONString(new byte[] { 12 }));
|
||||
assertEquals("[-7,22,86,-99]", JSONArray.toJSONString(new byte[] { -7, 22, 86, -99 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString((byte[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new byte[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new byte[] { 12 }, writer);
|
||||
assertEquals("[12]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new byte[] { -7, 22, 86, -99 }, writer);
|
||||
assertEquals("[-7,22,86,-99]", writer.toString());
|
||||
}
|
||||
|
||||
public void testShortArrayToString() throws IOException {
|
||||
assertEquals("null", JSONArray.toJSONString((short[])null));
|
||||
assertEquals("[]", JSONArray.toJSONString(new short[0]));
|
||||
assertEquals("[12]", JSONArray.toJSONString(new short[] { 12 }));
|
||||
assertEquals("[-7,22,86,-99]", JSONArray.toJSONString(new short[] { -7, 22, 86, -99 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString((short[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new short[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new short[] { 12 }, writer);
|
||||
assertEquals("[12]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new short[] { -7, 22, 86, -99 }, writer);
|
||||
assertEquals("[-7,22,86,-99]", writer.toString());
|
||||
}
|
||||
|
||||
public void testIntArrayToString() throws IOException {
|
||||
assertEquals("null", JSONArray.toJSONString((int[])null));
|
||||
assertEquals("[]", JSONArray.toJSONString(new int[0]));
|
||||
assertEquals("[12]", JSONArray.toJSONString(new int[] { 12 }));
|
||||
assertEquals("[-7,22,86,-99]", JSONArray.toJSONString(new int[] { -7, 22, 86, -99 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString((int[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new int[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new int[] { 12 }, writer);
|
||||
assertEquals("[12]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new int[] { -7, 22, 86, -99 }, writer);
|
||||
assertEquals("[-7,22,86,-99]", writer.toString());
|
||||
}
|
||||
|
||||
public void testLongArrayToString() throws IOException {
|
||||
assertEquals("null", JSONArray.toJSONString((long[])null));
|
||||
assertEquals("[]", JSONArray.toJSONString(new long[0]));
|
||||
assertEquals("[12]", JSONArray.toJSONString(new long[] { 12 }));
|
||||
assertEquals("[-7,22,9223372036854775807,-99]", JSONArray.toJSONString(new long[] { -7, 22, 9223372036854775807L, -99 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString((long[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new long[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new long[] { 12 }, writer);
|
||||
assertEquals("[12]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new long[] { -7, 22, 86, -99 }, writer);
|
||||
assertEquals("[-7,22,86,-99]", writer.toString());
|
||||
}
|
||||
|
||||
public void testFloatArrayToString() throws IOException {
|
||||
assertEquals("null", JSONArray.toJSONString((float[])null));
|
||||
assertEquals("[]", JSONArray.toJSONString(new float[0]));
|
||||
assertEquals("[12.8]", JSONArray.toJSONString(new float[] { 12.8f }));
|
||||
assertEquals("[-7.1,22.234,86.7,-99.02]", JSONArray.toJSONString(new float[] { -7.1f, 22.234f, 86.7f, -99.02f }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString((float[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new float[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new float[] { 12.8f }, writer);
|
||||
assertEquals("[12.8]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new float[] { -7.1f, 22.234f, 86.7f, -99.02f }, writer);
|
||||
assertEquals("[-7.1,22.234,86.7,-99.02]", writer.toString());
|
||||
}
|
||||
|
||||
public void testDoubleArrayToString() throws IOException {
|
||||
assertEquals("null", JSONArray.toJSONString((double[])null));
|
||||
assertEquals("[]", JSONArray.toJSONString(new double[0]));
|
||||
assertEquals("[12.8]", JSONArray.toJSONString(new double[] { 12.8 }));
|
||||
assertEquals("[-7.1,22.234,86.7,-99.02]", JSONArray.toJSONString(new double[] { -7.1, 22.234, 86.7, -99.02 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString((double[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new double[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new double[] { 12.8 }, writer);
|
||||
assertEquals("[12.8]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new double[] { -7.1, 22.234, 86.7, -99.02 }, writer);
|
||||
assertEquals("[-7.1,22.234,86.7,-99.02]", writer.toString());
|
||||
}
|
||||
|
||||
public void testBooleanArrayToString() throws IOException {
|
||||
assertEquals("null", JSONArray.toJSONString((boolean[])null));
|
||||
assertEquals("[]", JSONArray.toJSONString(new boolean[0]));
|
||||
assertEquals("[true]", JSONArray.toJSONString(new boolean[] { true }));
|
||||
assertEquals("[true,false,true]", JSONArray.toJSONString(new boolean[] { true, false, true }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString((boolean[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new boolean[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new boolean[] { true }, writer);
|
||||
assertEquals("[true]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new boolean[] { true, false, true }, writer);
|
||||
assertEquals("[true,false,true]", writer.toString());
|
||||
}
|
||||
|
||||
public void testCharArrayToString() throws IOException {
|
||||
assertEquals("null", JSONArray.toJSONString((char[])null));
|
||||
assertEquals("[]", JSONArray.toJSONString(new char[0]));
|
||||
assertEquals("[\"a\"]", JSONArray.toJSONString(new char[] { 'a' }));
|
||||
assertEquals("[\"a\",\"b\",\"c\"]", JSONArray.toJSONString(new char[] { 'a', 'b', 'c' }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString((char[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new char[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new char[] { 'a' }, writer);
|
||||
assertEquals("[\"a\"]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new char[] { 'a', 'b', 'c' }, writer);
|
||||
assertEquals("[\"a\",\"b\",\"c\"]", writer.toString());
|
||||
}
|
||||
|
||||
public void testObjectArrayToString() throws IOException {
|
||||
assertEquals("null", JSONArray.toJSONString((Object[])null));
|
||||
assertEquals("[]", JSONArray.toJSONString(new Object[0]));
|
||||
assertEquals("[\"Hello\"]", JSONArray.toJSONString(new Object[] { "Hello" }));
|
||||
assertEquals("[\"Hello\",12,[1,2,3]]", JSONArray.toJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3 } }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString((Object[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new Object[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new Object[] { "Hello" }, writer);
|
||||
assertEquals("[\"Hello\"]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONArray.writeJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3} }, writer);
|
||||
assertEquals("[\"Hello\",12,[1,2,3]]", writer.toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,256 @@
|
|||
package org.json.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JSONValueTest extends TestCase {
|
||||
public void testByteArrayToString() throws IOException {
|
||||
assertEquals("null", JSONValue.toJSONString((byte[])null));
|
||||
assertEquals("[]", JSONValue.toJSONString(new byte[0]));
|
||||
assertEquals("[12]", JSONValue.toJSONString(new byte[] { 12 }));
|
||||
assertEquals("[-7,22,86,-99]", JSONValue.toJSONString(new byte[] { -7, 22, 86, -99 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString((byte[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new byte[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new byte[] { 12 }, writer);
|
||||
assertEquals("[12]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new byte[] { -7, 22, 86, -99 }, writer);
|
||||
assertEquals("[-7,22,86,-99]", writer.toString());
|
||||
}
|
||||
|
||||
public void testShortArrayToString() throws IOException {
|
||||
assertEquals("null", JSONValue.toJSONString((short[])null));
|
||||
assertEquals("[]", JSONValue.toJSONString(new short[0]));
|
||||
assertEquals("[12]", JSONValue.toJSONString(new short[] { 12 }));
|
||||
assertEquals("[-7,22,86,-99]", JSONValue.toJSONString(new short[] { -7, 22, 86, -99 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString((short[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new short[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new short[] { 12 }, writer);
|
||||
assertEquals("[12]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new short[] { -7, 22, 86, -99 }, writer);
|
||||
assertEquals("[-7,22,86,-99]", writer.toString());
|
||||
}
|
||||
|
||||
public void testIntArrayToString() throws IOException {
|
||||
assertEquals("null", JSONValue.toJSONString((int[])null));
|
||||
assertEquals("[]", JSONValue.toJSONString(new int[0]));
|
||||
assertEquals("[12]", JSONValue.toJSONString(new int[] { 12 }));
|
||||
assertEquals("[-7,22,86,-99]", JSONValue.toJSONString(new int[] { -7, 22, 86, -99 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString((int[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new int[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new int[] { 12 }, writer);
|
||||
assertEquals("[12]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new int[] { -7, 22, 86, -99 }, writer);
|
||||
assertEquals("[-7,22,86,-99]", writer.toString());
|
||||
}
|
||||
|
||||
public void testLongArrayToString() throws IOException {
|
||||
assertEquals("null", JSONValue.toJSONString((long[])null));
|
||||
assertEquals("[]", JSONValue.toJSONString(new long[0]));
|
||||
assertEquals("[12]", JSONValue.toJSONString(new long[] { 12 }));
|
||||
assertEquals("[-7,22,9223372036854775807,-99]", JSONValue.toJSONString(new long[] { -7, 22, 9223372036854775807L, -99 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString((long[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new long[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new long[] { 12 }, writer);
|
||||
assertEquals("[12]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new long[] { -7, 22, 86, -99 }, writer);
|
||||
assertEquals("[-7,22,86,-99]", writer.toString());
|
||||
}
|
||||
|
||||
public void testFloatArrayToString() throws IOException {
|
||||
assertEquals("null", JSONValue.toJSONString((float[])null));
|
||||
assertEquals("[]", JSONValue.toJSONString(new float[0]));
|
||||
assertEquals("[12.8]", JSONValue.toJSONString(new float[] { 12.8f }));
|
||||
assertEquals("[-7.1,22.234,86.7,-99.02]", JSONValue.toJSONString(new float[] { -7.1f, 22.234f, 86.7f, -99.02f }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString((float[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new float[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new float[] { 12.8f }, writer);
|
||||
assertEquals("[12.8]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new float[] { -7.1f, 22.234f, 86.7f, -99.02f }, writer);
|
||||
assertEquals("[-7.1,22.234,86.7,-99.02]", writer.toString());
|
||||
}
|
||||
|
||||
public void testDoubleArrayToString() throws IOException {
|
||||
assertEquals("null", JSONValue.toJSONString((double[])null));
|
||||
assertEquals("[]", JSONValue.toJSONString(new double[0]));
|
||||
assertEquals("[12.8]", JSONValue.toJSONString(new double[] { 12.8 }));
|
||||
assertEquals("[-7.1,22.234,86.7,-99.02]", JSONValue.toJSONString(new double[] { -7.1, 22.234, 86.7, -99.02 }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString((double[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new double[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new double[] { 12.8 }, writer);
|
||||
assertEquals("[12.8]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new double[] { -7.1, 22.234, 86.7, -99.02 }, writer);
|
||||
assertEquals("[-7.1,22.234,86.7,-99.02]", writer.toString());
|
||||
}
|
||||
|
||||
public void testBooleanArrayToString() throws IOException {
|
||||
assertEquals("null", JSONValue.toJSONString((boolean[])null));
|
||||
assertEquals("[]", JSONValue.toJSONString(new boolean[0]));
|
||||
assertEquals("[true]", JSONValue.toJSONString(new boolean[] { true }));
|
||||
assertEquals("[true,false,true]", JSONValue.toJSONString(new boolean[] { true, false, true }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString((boolean[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new boolean[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new boolean[] { true }, writer);
|
||||
assertEquals("[true]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new boolean[] { true, false, true }, writer);
|
||||
assertEquals("[true,false,true]", writer.toString());
|
||||
}
|
||||
|
||||
public void testCharArrayToString() throws IOException {
|
||||
assertEquals("null", JSONValue.toJSONString((char[])null));
|
||||
assertEquals("[]", JSONValue.toJSONString(new char[0]));
|
||||
assertEquals("[\"a\"]", JSONValue.toJSONString(new char[] { 'a' }));
|
||||
assertEquals("[\"a\",\"b\",\"c\"]", JSONValue.toJSONString(new char[] { 'a', 'b', 'c' }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString((char[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new char[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new char[] { 'a' }, writer);
|
||||
assertEquals("[\"a\"]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new char[] { 'a', 'b', 'c' }, writer);
|
||||
assertEquals("[\"a\",\"b\",\"c\"]", writer.toString());
|
||||
}
|
||||
|
||||
public void testObjectArrayToString() throws IOException {
|
||||
assertEquals("null", JSONValue.toJSONString((Object[])null));
|
||||
assertEquals("[]", JSONValue.toJSONString(new Object[0]));
|
||||
assertEquals("[\"Hello\"]", JSONValue.toJSONString(new Object[] { "Hello" }));
|
||||
assertEquals("[\"Hello\",12,[1,2,3]]", JSONValue.toJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3 } }));
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString((Object[])null, writer);
|
||||
assertEquals("null", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new Object[0], writer);
|
||||
assertEquals("[]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new Object[] { "Hello" }, writer);
|
||||
assertEquals("[\"Hello\"]", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3} }, writer);
|
||||
assertEquals("[\"Hello\",12,[1,2,3]]", writer.toString());
|
||||
}
|
||||
|
||||
public void testArraysOfArrays() throws IOException {
|
||||
|
||||
StringWriter writer;
|
||||
|
||||
final int[][][] nestedIntArray = new int[][][]{{{1}, {5}}, {{2}, {6}}};
|
||||
final String expectedNestedIntString = "[[[1],[5]],[[2],[6]]]";
|
||||
|
||||
assertEquals(expectedNestedIntString, JSONValue.toJSONString(nestedIntArray));
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(nestedIntArray, writer);
|
||||
assertEquals(expectedNestedIntString, writer.toString());
|
||||
|
||||
final String[][] nestedStringArray = new String[][]{{"a", "b"}, {"c", "d"}};
|
||||
final String expectedNestedStringString = "[[\"a\",\"b\"],[\"c\",\"d\"]]";
|
||||
|
||||
assertEquals(expectedNestedStringString, JSONValue.toJSONString(nestedStringArray));
|
||||
|
||||
writer = new StringWriter();
|
||||
JSONValue.writeJSONString(nestedStringArray, writer);
|
||||
assertEquals(expectedNestedStringString, writer.toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,383 @@
|
|||
/*
|
||||
* $Id: Test.java,v 1.1 2006/04/15 14:40:06 platform Exp $
|
||||
* Created on 2006-4-15
|
||||
*/
|
||||
package org.json.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.json.simple.parser.ContainerFactory;
|
||||
import org.json.simple.parser.ContentHandler;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
/**
|
||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||
*/
|
||||
public class Test extends TestCase{
|
||||
|
||||
public void testDecode() throws Exception{
|
||||
System.out.println("=======decode=======");
|
||||
|
||||
String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
|
||||
Object obj=JSONValue.parse(s);
|
||||
JSONArray array=(JSONArray)obj;
|
||||
System.out.println("======the 2nd element of array======");
|
||||
System.out.println(array.get(1));
|
||||
System.out.println();
|
||||
assertEquals("{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}",array.get(1).toString());
|
||||
|
||||
JSONObject obj2=(JSONObject)array.get(1);
|
||||
System.out.println("======field \"1\"==========");
|
||||
System.out.println(obj2.get("1"));
|
||||
assertEquals("{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}",obj2.get("1").toString());
|
||||
|
||||
s="{}";
|
||||
obj=JSONValue.parse(s);
|
||||
assertEquals("{}",obj.toString());
|
||||
|
||||
s="[5,]";
|
||||
obj=JSONValue.parse(s);
|
||||
assertEquals("[5]",obj.toString());
|
||||
|
||||
s="[5,,2]";
|
||||
obj=JSONValue.parse(s);
|
||||
assertEquals("[5,2]",obj.toString());
|
||||
|
||||
s="[\"hello\\bworld\\\"abc\\tdef\\\\ghi\\rjkl\\n123\\u4e2d\"]";
|
||||
obj=JSONValue.parse(s);
|
||||
assertEquals("hello\bworld\"abc\tdef\\ghi\rjkl\n123中",((List)obj).get(0).toString());
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
s="{\"name\":";
|
||||
try{
|
||||
obj = parser.parse(s);
|
||||
}
|
||||
catch(ParseException pe){
|
||||
assertEquals(ParseException.ERROR_UNEXPECTED_TOKEN, pe.getErrorType());
|
||||
assertEquals(8, pe.getPosition());
|
||||
}
|
||||
|
||||
s="{\"name\":}";
|
||||
try{
|
||||
obj = parser.parse(s);
|
||||
}
|
||||
catch(ParseException pe){
|
||||
assertEquals(ParseException.ERROR_UNEXPECTED_TOKEN, pe.getErrorType());
|
||||
assertEquals(8, pe.getPosition());
|
||||
}
|
||||
|
||||
|
||||
s="{\"name";
|
||||
try{
|
||||
obj = parser.parse(s);
|
||||
}
|
||||
catch(ParseException pe){
|
||||
assertEquals(ParseException.ERROR_UNEXPECTED_TOKEN, pe.getErrorType());
|
||||
assertEquals(6, pe.getPosition());
|
||||
}
|
||||
|
||||
|
||||
s = "[[null, 123.45, \"a\\\tb c\"}, true]";
|
||||
try{
|
||||
parser.parse(s);
|
||||
}
|
||||
catch(ParseException pe){
|
||||
assertEquals(24, pe.getPosition());
|
||||
System.out.println("Error at character position: " + pe.getPosition());
|
||||
switch(pe.getErrorType()){
|
||||
case ParseException.ERROR_UNEXPECTED_TOKEN:
|
||||
System.out.println("Unexpected token: " + pe.getUnexpectedObject());
|
||||
break;
|
||||
case ParseException.ERROR_UNEXPECTED_CHAR:
|
||||
System.out.println("Unexpected character: " + pe.getUnexpectedObject());
|
||||
break;
|
||||
case ParseException.ERROR_UNEXPECTED_EXCEPTION:
|
||||
((Exception)pe.getUnexpectedObject()).printStackTrace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
s = "{\"first\": 123, \"second\": [4, 5, 6], \"third\": 789}";
|
||||
ContainerFactory containerFactory = new ContainerFactory(){
|
||||
public List creatArrayContainer() {
|
||||
return new LinkedList();
|
||||
}
|
||||
|
||||
public Map createObjectContainer() {
|
||||
return new LinkedHashMap();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
try{
|
||||
Map json = (Map)parser.parse(s, containerFactory);
|
||||
Iterator iter = json.entrySet().iterator();
|
||||
System.out.println("==iterate result==");
|
||||
while(iter.hasNext()){
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
System.out.println(entry.getKey() + "=>" + entry.getValue());
|
||||
}
|
||||
|
||||
System.out.println("==toJSONString()==");
|
||||
System.out.println(JSONValue.toJSONString(json));
|
||||
assertEquals("{\"first\":123,\"second\":[4,5,6],\"third\":789}", JSONValue.toJSONString(json));
|
||||
}
|
||||
catch(ParseException pe){
|
||||
pe.printStackTrace();
|
||||
}
|
||||
|
||||
s = "{\"first\": 123, \"second\": [{\"s1\":{\"s11\":\"v11\"}}, 4, 5, 6], \"third\": 789}";
|
||||
ContentHandler myHandler = new ContentHandler() {
|
||||
|
||||
public boolean endArray() throws ParseException {
|
||||
System.out.println("endArray()");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endJSON() throws ParseException {
|
||||
System.out.println("endJSON()");
|
||||
}
|
||||
|
||||
public boolean endObject() throws ParseException {
|
||||
System.out.println("endObject()");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean endObjectEntry() throws ParseException {
|
||||
System.out.println("endObjectEntry()");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean primitive(Object value) throws ParseException {
|
||||
System.out.println("primitive(): " + value);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean startArray() throws ParseException {
|
||||
System.out.println("startArray()");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void startJSON() throws ParseException {
|
||||
System.out.println("startJSON()");
|
||||
}
|
||||
|
||||
public boolean startObject() throws ParseException {
|
||||
System.out.println("startObject()");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean startObjectEntry(String key) throws ParseException {
|
||||
System.out.println("startObjectEntry(), key:" + key);
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
try{
|
||||
parser.parse(s, myHandler);
|
||||
}
|
||||
catch(ParseException pe){
|
||||
pe.printStackTrace();
|
||||
}
|
||||
|
||||
class KeyFinder implements ContentHandler{
|
||||
private Object value;
|
||||
private boolean found = false;
|
||||
private boolean end = false;
|
||||
private String key;
|
||||
private String matchKey;
|
||||
|
||||
public void setMatchKey(String matchKey){
|
||||
this.matchKey = matchKey;
|
||||
}
|
||||
|
||||
public Object getValue(){
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean isEnd(){
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setFound(boolean found){
|
||||
this.found = found;
|
||||
}
|
||||
|
||||
public boolean isFound(){
|
||||
return found;
|
||||
}
|
||||
|
||||
public void startJSON() throws ParseException, IOException {
|
||||
found = false;
|
||||
end = false;
|
||||
}
|
||||
|
||||
public void endJSON() throws ParseException, IOException {
|
||||
end = true;
|
||||
}
|
||||
|
||||
public boolean primitive(Object value) throws ParseException, IOException {
|
||||
if(key != null){
|
||||
if(key.equals(matchKey)){
|
||||
found = true;
|
||||
this.value = value;
|
||||
key = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean startArray() throws ParseException, IOException {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean startObject() throws ParseException, IOException {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean startObjectEntry(String key) throws ParseException, IOException {
|
||||
this.key = key;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean endArray() throws ParseException, IOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean endObject() throws ParseException, IOException {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean endObjectEntry() throws ParseException, IOException {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
s = "{\"first\": 123, \"second\": [{\"k1\":{\"id\":\"id1\"}}, 4, 5, 6, {\"id\": 123}], \"third\": 789, \"id\": null}";
|
||||
parser.reset();
|
||||
KeyFinder keyFinder = new KeyFinder();
|
||||
keyFinder.setMatchKey("id");
|
||||
int i = 0;
|
||||
try{
|
||||
while(!keyFinder.isEnd()){
|
||||
parser.parse(s, keyFinder, true);
|
||||
if(keyFinder.isFound()){
|
||||
i++;
|
||||
keyFinder.setFound(false);
|
||||
System.out.println("found id:");
|
||||
System.out.println(keyFinder.getValue());
|
||||
if(i == 1)
|
||||
assertEquals("id1", keyFinder.getValue());
|
||||
if(i == 2){
|
||||
assertTrue(keyFinder.getValue() instanceof Number);
|
||||
assertEquals("123", String.valueOf(keyFinder.getValue()));
|
||||
}
|
||||
if(i == 3)
|
||||
assertTrue(null == keyFinder.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ParseException pe){
|
||||
pe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void testEncode() throws Exception{
|
||||
System.out.println("=======encode=======");
|
||||
|
||||
JSONArray array1=new JSONArray();
|
||||
array1.add("abc\u0010a/");
|
||||
array1.add(new Integer(123));
|
||||
array1.add(new Double(222.123));
|
||||
array1.add(new Boolean(true));
|
||||
System.out.println("======array1==========");
|
||||
System.out.println(array1);
|
||||
System.out.println();
|
||||
assertEquals("[\"abc\\u0010a\\/\",123,222.123,true]",array1.toString());
|
||||
|
||||
JSONObject obj1=new JSONObject();
|
||||
obj1.put("array1",array1);
|
||||
System.out.println("======obj1 with array1===========");
|
||||
System.out.println(obj1);
|
||||
System.out.println();
|
||||
assertEquals("{\"array1\":[\"abc\\u0010a\\/\",123,222.123,true]}",obj1.toString());
|
||||
|
||||
obj1.remove("array1");
|
||||
array1.add(obj1);
|
||||
System.out.println("======array1 with obj1========");
|
||||
System.out.println(array1);
|
||||
System.out.println();
|
||||
assertEquals("[\"abc\\u0010a\\/\",123,222.123,true,{}]",array1.toString());
|
||||
|
||||
List list = new ArrayList();
|
||||
list.add("abc\u0010a/");
|
||||
list.add(new Integer(123));
|
||||
list.add(new Double(222.123));
|
||||
list.add(new Boolean(true));
|
||||
list.add(null);
|
||||
System.out.println("======list==========");
|
||||
System.out.println(JSONArray.toJSONString(list));
|
||||
System.out.println();
|
||||
assertEquals("[\"abc\\u0010a\\/\",123,222.123,true,null]",JSONArray.toJSONString(list));
|
||||
|
||||
Map map = new HashMap();
|
||||
map.put("array1",list);
|
||||
System.out.println("======map with list===========");
|
||||
System.out.println(map);
|
||||
System.out.println();
|
||||
assertEquals("{\"array1\":[\"abc\\u0010a\\/\",123,222.123,true,null]}",JSONObject.toJSONString(map));
|
||||
|
||||
Map m1 = new LinkedHashMap();
|
||||
Map m2 = new LinkedHashMap();
|
||||
List l1 = new LinkedList();
|
||||
|
||||
m1.put("k11","v11");
|
||||
m1.put("k12","v12");
|
||||
m1.put("k13", "v13");
|
||||
m2.put("k21","v21");
|
||||
m2.put("k22","v22");
|
||||
m2.put("k23","v23");
|
||||
l1.add(m1);
|
||||
l1.add(m2);
|
||||
String jsonString = JSONValue.toJSONString(l1);
|
||||
System.out.println(jsonString);
|
||||
assertEquals("[{\"k11\":\"v11\",\"k12\":\"v12\",\"k13\":\"v13\"},{\"k21\":\"v21\",\"k22\":\"v22\",\"k23\":\"v23\"}]", jsonString);
|
||||
|
||||
StringWriter out = new StringWriter();
|
||||
JSONValue.writeJSONString(l1, out);
|
||||
jsonString = out.toString();
|
||||
System.out.println(jsonString);
|
||||
assertEquals("[{\"k11\":\"v11\",\"k12\":\"v12\",\"k13\":\"v13\"},{\"k21\":\"v21\",\"k22\":\"v22\",\"k23\":\"v23\"}]", jsonString);
|
||||
|
||||
List l2 = new LinkedList();
|
||||
Map m3 = new LinkedHashMap();
|
||||
m3.put("k31", "v3");
|
||||
m3.put("k32", new Double(123.45));
|
||||
m3.put("k33", new Boolean(false));
|
||||
m3.put("k34", null);
|
||||
l2.add("vvv");
|
||||
l2.add("1.23456789123456789");
|
||||
l2.add(new Boolean(true));
|
||||
l2.add(null);
|
||||
m3.put("k35", l2);
|
||||
m1.put("k14", m3);
|
||||
out = new StringWriter();
|
||||
JSONValue.writeJSONString(l1, out);
|
||||
jsonString = out.toString();
|
||||
System.out.println(jsonString);
|
||||
assertEquals("[{\"k11\":\"v11\",\"k12\":\"v12\",\"k13\":\"v13\",\"k14\":{\"k31\":\"v3\",\"k32\":123.45,\"k33\":false,\"k34\":null,\"k35\":[\"vvv\",\"1.23456789123456789\",true,null]}},{\"k21\":\"v21\",\"k22\":\"v22\",\"k23\":\"v23\"}]",jsonString);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package org.json.simple.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class YylexTest extends TestCase {
|
||||
|
||||
public void testYylex() throws Exception{
|
||||
String s="\"\\/\"";
|
||||
System.out.println(s);
|
||||
StringReader in = new StringReader(s);
|
||||
Yylex lexer=new Yylex(in);
|
||||
Yytoken token=lexer.yylex();
|
||||
assertEquals(Yytoken.TYPE_VALUE,token.type);
|
||||
assertEquals("/",token.value);
|
||||
|
||||
s="\"abc\\/\\r\\b\\n\\t\\f\\\\\"";
|
||||
System.out.println(s);
|
||||
in = new StringReader(s);
|
||||
lexer=new Yylex(in);
|
||||
token=lexer.yylex();
|
||||
assertEquals(Yytoken.TYPE_VALUE,token.type);
|
||||
assertEquals("abc/\r\b\n\t\f\\",token.value);
|
||||
|
||||
s="[\t \n\r\n{ \t \t\n\r}";
|
||||
System.out.println(s);
|
||||
in = new StringReader(s);
|
||||
lexer=new Yylex(in);
|
||||
token=lexer.yylex();
|
||||
assertEquals(Yytoken.TYPE_LEFT_SQUARE,token.type);
|
||||
token=lexer.yylex();
|
||||
assertEquals(Yytoken.TYPE_LEFT_BRACE,token.type);
|
||||
token=lexer.yylex();
|
||||
assertEquals(Yytoken.TYPE_RIGHT_BRACE,token.type);
|
||||
|
||||
s="\b\f{";
|
||||
System.out.println(s);
|
||||
in = new StringReader(s);
|
||||
lexer=new Yylex(in);
|
||||
ParseException err=null;
|
||||
try{
|
||||
token=lexer.yylex();
|
||||
}
|
||||
catch(ParseException e){
|
||||
err=e;
|
||||
System.out.println("error:"+err);
|
||||
assertEquals(ParseException.ERROR_UNEXPECTED_CHAR, e.getErrorType());
|
||||
assertEquals(0,e.getPosition());
|
||||
assertEquals(new Character('\b'),e.getUnexpectedObject());
|
||||
}
|
||||
catch(IOException ie){
|
||||
throw ie;
|
||||
}
|
||||
assertTrue(err!=null);
|
||||
|
||||
s="{a : b}";
|
||||
System.out.println(s);
|
||||
in = new StringReader(s);
|
||||
lexer=new Yylex(in);
|
||||
err=null;
|
||||
try{
|
||||
lexer.yylex();
|
||||
token=lexer.yylex();
|
||||
}
|
||||
catch(ParseException e){
|
||||
err=e;
|
||||
System.out.println("error:"+err);
|
||||
assertEquals(ParseException.ERROR_UNEXPECTED_CHAR, e.getErrorType());
|
||||
assertEquals(new Character('a'),e.getUnexpectedObject());
|
||||
assertEquals(1,e.getPosition());
|
||||
}
|
||||
catch(IOException ie){
|
||||
throw ie;
|
||||
}
|
||||
assertTrue(err!=null);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<project name="json-simple" default="main" basedir=".">
|
||||
<path id="runtime.path">
|
||||
<fileset dir="lib">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
<pathelement location="build/test"/>
|
||||
</path>
|
||||
|
||||
<path id="compile.path">
|
||||
<fileset dir="lib">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<target name="WorkoutDatesUpdater" depends="mkdir,compile,junit">
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete includeemptydirs="true">
|
||||
<fileset dir="build/test" includes="**/*"/>
|
||||
<fileset dir="." includes="TEST-*.txt"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="mkdir">
|
||||
<mkdir dir="build/test"/>
|
||||
</target>
|
||||
|
||||
<target name="compile">
|
||||
<javac srcdir="test"
|
||||
destdir="build/test"
|
||||
includes="**/*.java"
|
||||
encoding="UTF-8"
|
||||
target="1.2"
|
||||
source="1.2">
|
||||
<classpath refid="compile.path"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="junit">
|
||||
<junit>
|
||||
<classpath refid="runtime.path"/>
|
||||
<formatter type="plain"/>
|
||||
<test name="org.json.simple.Test"/>
|
||||
<test name="org.json.simple.parser.YylexTest"/>
|
||||
</junit>
|
||||
</target>
|
||||
</project>
|
|
@ -0,0 +1,166 @@
|
|||
[2022-12-11 02:00:15] Util started
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:79)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:131)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:106)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:88)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:21)
|
||||
[2022-12-11 02:01:50] Util started
|
||||
[2022-12-11 02:01:50] Error code: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Failed to parse the host:port pair 'localhost:localhost'.
|
||||
Error code: 0
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:79)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:131)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:106)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:88)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:21)
|
||||
[2022-12-11 02:02:18] Util started
|
||||
[2022-12-11 02:02:18] Error code: Communications link failure
|
||||
|
||||
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
|
||||
Error code: 0
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:106)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:88)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:21)
|
||||
[2022-12-11 02:03:11] Util started
|
||||
[2022-12-11 02:03:11] Error: Communications link failure
|
||||
|
||||
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
|
||||
[2022-12-11 02:03:11] Error: Communications link failure
|
||||
|
||||
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
|
||||
Error code: 0
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:106)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:88)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:21)
|
||||
[2022-12-11 02:03:57] Util started
|
||||
[2022-12-11 02:03:57] Error: Communications link failure
|
||||
|
||||
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
|
||||
Error trace:
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:106)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:88)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:21)
|
||||
[2022-12-11 02:06:09] Util started
|
||||
[2022-12-11 02:06:09] Trying to connect to the DB at jdbc:mysql://localhost:3306/workout
|
||||
[2022-12-11 02:06:10] Error: Communications link failure
|
||||
|
||||
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
|
||||
Error trace:
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:107)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:88)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:21)
|
||||
[2022-12-11 02:08:33] Util started
|
||||
[2022-12-11 02:08:33] Trying to connect to the DB at jdbc:mysql://localhost:3306/workout
|
||||
[2022-12-11 02:08:33] Error: Communications link failure
|
||||
|
||||
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
|
||||
Error trace:
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:107)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:88)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:21)
|
||||
[2022-12-11 02:08:55] Util started
|
||||
[2022-12-11 02:08:55] Trying to connect to the DB at jdbc:mysql://localhost:3306/workout
|
||||
[2022-12-11 02:08:55] Error: Communications link failure
|
||||
|
||||
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
|
||||
Error trace:
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:107)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:88)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:21)
|
||||
[2022-12-11 02:21:06] Util started
|
||||
[2022-12-11 02:21:06] Trying to connect to the DB at jdbc:mysql://localhost:3306/workout
|
||||
[2022-12-11 02:21:06] Error: Communications link failure
|
||||
|
||||
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
|
||||
Error trace:
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:117)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:98)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:29)
|
||||
[2022-12-11 02:21:37] Util started
|
||||
[2022-12-11 02:21:37] Trying to connect to the DB at jdbc:mysql://localhost:3306/workout
|
||||
[2022-12-11 02:21:38] Error: Communications link failure
|
||||
|
||||
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
|
||||
Error trace:
|
||||
com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
|
||||
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
|
||||
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
|
||||
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
|
||||
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)
|
||||
WorkoutDatesUpdater.Main.connectToDB(Main.java:117)
|
||||
WorkoutDatesUpdater.Main.checkDate(Main.java:98)
|
||||
WorkoutDatesUpdater.Main.main(Main.java:29)
|
|
@ -0,0 +1 @@
|
|||
[2022-12-11 01:56:50] Util started
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,4 @@
|
|||
build-date: 2022-09-03 21:54:19 +0000
|
||||
os-info: Linux i386 4.1.12-124.48.6.el6uek.x86_64
|
||||
compiler: javac 1.8.0_241
|
||||
build-tool: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
|
|
@ -0,0 +1,5 @@
|
|||
version: 8.0.31
|
||||
branch: release/8.0.31
|
||||
date: 2022-09-03 22:46:04 +0100
|
||||
commit: 0c86fc148d567b62266c2302bdad0f1e7a7e4eba
|
||||
short: 0c86fc14
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,33 @@
|
|||
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This is a release of MySQL Connector/J, a JDBC Type 4 driver for MySQL that
|
||||
also supports the new X DevAPI.
|
||||
|
||||
License information can be found in the LICENSE file.
|
||||
|
||||
This distribution may include materials developed by third parties.
|
||||
For license and attribution notices for these materials, please refer to the
|
||||
LICENSE file.
|
||||
|
||||
For more information on MySQL Connector/J, visit
|
||||
https://dev.mysql.com/doc/connector-j/8.0/en/
|
||||
|
||||
For additional downloads and the source of MySQL Connector/J, visit
|
||||
https://dev.mysql.com/downloads/
|
||||
|
||||
MySQL Connector/J is brought to you by the MySQL team at Oracle.
|
||||
|
||||
Notice:
|
||||
- In order to use the WorkoutDatesUpdater.logging capabilities provided by the default
|
||||
implementation com.mysql.cj.log.Slf4JLogger, it is required to add one or
|
||||
more jars for Simple Logging Facade for Java (SLF4J) to your CLASSPATH.
|
||||
- To use the X DevAPI features in Connector/J, you also need the external
|
||||
library protobuf-java, which you can download manually from the official
|
||||
Maven repository and add it to the CLASSPATH, or use Maven's automatic
|
||||
dependency resolution features by adding a dependency to "GroupId: com.mysql"
|
||||
and "ArtifactId: mysql-connector-j" to your project's pom.xml file.
|
||||
- To use OCI AIM authentication, you will need to add the external library
|
||||
oci-java-sdk-common, which you can download manually from the official Maven
|
||||
repository and add it to the CLASSPATH, or use Maven's automatic dependency
|
||||
resolution features by adding a dependency to "GroupId: com.oracle.oci.sdk"
|
||||
and "ArtifactId: oci-java-sdk-common" to your project's pom.xml file.
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package documentation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.mysql.cj.exceptions.MysqlErrorNumbers;
|
||||
|
||||
/**
|
||||
* Creates XML file describing mapping of MySQL error #'s to SQL92 and X/Open states.
|
||||
*/
|
||||
public class ErrorMappingsDocGenerator {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
dumpSqlStatesMappingsAsXml();
|
||||
}
|
||||
|
||||
public static void dumpSqlStatesMappingsAsXml() throws Exception {
|
||||
TreeMap<Integer, Integer> allErrorNumbers = new TreeMap<>();
|
||||
Map<Object, String> mysqlErrorNumbersToNames = new HashMap<>();
|
||||
|
||||
// Integer errorNumber = null;
|
||||
|
||||
//
|
||||
// First create a list of all 'known' error numbers that are mapped.
|
||||
//
|
||||
for (Integer errorNumber : MysqlErrorNumbers.mysqlToSql99State.keySet()) {
|
||||
allErrorNumbers.put(errorNumber, errorNumber);
|
||||
}
|
||||
|
||||
//
|
||||
// Now create a list of the actual MySQL error numbers we know about
|
||||
//
|
||||
java.lang.reflect.Field[] possibleFields = MysqlErrorNumbers.class.getDeclaredFields();
|
||||
|
||||
for (int i = 0; i < possibleFields.length; i++) {
|
||||
String fieldName = possibleFields[i].getName();
|
||||
|
||||
if (fieldName.startsWith("ER_")) {
|
||||
mysqlErrorNumbersToNames.put(possibleFields[i].get(null), fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("<ErrorMappings>");
|
||||
|
||||
for (Integer errorNumber : allErrorNumbers.keySet()) {
|
||||
String sql92State = MysqlErrorNumbers.mysqlToSql99(errorNumber.intValue());
|
||||
|
||||
System.out.println(" <ErrorMapping mysqlErrorNumber=\"" + errorNumber + "\" mysqlErrorName=\"" + mysqlErrorNumbersToNames.get(errorNumber)
|
||||
+ "\" legacySqlState=\"" + "" + "\" sql92SqlState=\"" + ((sql92State == null) ? "" : sql92State) + "\"/>");
|
||||
}
|
||||
|
||||
System.out.println("</ErrorMappings>");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package documentation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.mysql.cj.conf.PropertyDefinition;
|
||||
import com.mysql.cj.conf.PropertyDefinitions;
|
||||
|
||||
/**
|
||||
* Creates docbook table of connection properties from ConnectionProperties class.
|
||||
*/
|
||||
public class PropertiesDocGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(exposeAsXml());
|
||||
}
|
||||
|
||||
static class XmlMap {
|
||||
protected Map<Integer, Map<String, PropertyDefinition<?>>> ordered = new TreeMap<>();
|
||||
protected Map<String, PropertyDefinition<?>> alpha = new TreeMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a description of the connection properties as an XML document.
|
||||
*
|
||||
* @return the connection properties as an XML document.
|
||||
*/
|
||||
public static String exposeAsXml() {
|
||||
StringBuilder xmlBuf = new StringBuilder();
|
||||
xmlBuf.append("<ConnectionProperties>");
|
||||
|
||||
int numCategories = PropertyDefinitions.PROPERTY_CATEGORIES.length;
|
||||
|
||||
Map<String, XmlMap> propertyListByCategory = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < numCategories; i++) {
|
||||
propertyListByCategory.put(PropertyDefinitions.PROPERTY_CATEGORIES[i], new XmlMap());
|
||||
}
|
||||
|
||||
for (PropertyDefinition<?> pdef : PropertyDefinitions.PROPERTY_KEY_TO_PROPERTY_DEFINITION.values()) {
|
||||
XmlMap sortMaps = propertyListByCategory.get(pdef.getCategory());
|
||||
int orderInCategory = pdef.getOrder();
|
||||
|
||||
if (orderInCategory == Integer.MIN_VALUE) {
|
||||
sortMaps.alpha.put(pdef.getName(), pdef);
|
||||
} else {
|
||||
Integer order = Integer.valueOf(orderInCategory);
|
||||
Map<String, PropertyDefinition<?>> orderMap = sortMaps.ordered.get(order);
|
||||
|
||||
if (orderMap == null) {
|
||||
orderMap = new TreeMap<>();
|
||||
sortMaps.ordered.put(order, orderMap);
|
||||
}
|
||||
|
||||
orderMap.put(pdef.getName(), pdef);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < numCategories; j++) {
|
||||
XmlMap sortMaps = propertyListByCategory.get(PropertyDefinitions.PROPERTY_CATEGORIES[j]);
|
||||
|
||||
xmlBuf.append("\n <PropertyCategory name=\"");
|
||||
xmlBuf.append(PropertyDefinitions.PROPERTY_CATEGORIES[j]);
|
||||
xmlBuf.append("\">");
|
||||
|
||||
for (Map<String, PropertyDefinition<?>> orderedEl : sortMaps.ordered.values()) {
|
||||
for (PropertyDefinition<?> pdef : orderedEl.values()) {
|
||||
xmlBuf.append("\n <Property name=\"");
|
||||
xmlBuf.append(pdef.getName());
|
||||
|
||||
xmlBuf.append("\" default=\"");
|
||||
if (pdef.getDefaultValue() != null) {
|
||||
xmlBuf.append(pdef.getDefaultValue());
|
||||
}
|
||||
xmlBuf.append("\" sortOrder=\"");
|
||||
xmlBuf.append(pdef.getOrder());
|
||||
xmlBuf.append("\" since=\"");
|
||||
xmlBuf.append(pdef.getSinceVersion());
|
||||
xmlBuf.append("\">\n");
|
||||
xmlBuf.append(" ");
|
||||
String escapedDescription = pdef.getDescription();
|
||||
escapedDescription = escapedDescription.replace("&", "&").replace("<", "<").replace(">", ">");
|
||||
|
||||
xmlBuf.append(escapedDescription);
|
||||
xmlBuf.append("\n </Property>");
|
||||
}
|
||||
}
|
||||
|
||||
for (PropertyDefinition<?> pdef : sortMaps.alpha.values()) {
|
||||
xmlBuf.append("\n <Property name=\"");
|
||||
xmlBuf.append(pdef.getName());
|
||||
|
||||
xmlBuf.append("\" default=\"");
|
||||
if (pdef.getDefaultValue() != null) {
|
||||
xmlBuf.append(pdef.getDefaultValue());
|
||||
}
|
||||
|
||||
xmlBuf.append("\" sortOrder=\"alpha\" since=\"");
|
||||
xmlBuf.append(pdef.getSinceVersion());
|
||||
xmlBuf.append("\">\n");
|
||||
xmlBuf.append(" ");
|
||||
xmlBuf.append(pdef.getDescription());
|
||||
xmlBuf.append("\n </Property>");
|
||||
}
|
||||
|
||||
xmlBuf.append("\n </PropertyCategory>");
|
||||
}
|
||||
|
||||
xmlBuf.append("\n</ConnectionProperties>");
|
||||
|
||||
return xmlBuf.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package instrumentation;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.mysql.cj.conf.BooleanPropertyDefinition;
|
||||
import com.mysql.cj.conf.EnumPropertyDefinition;
|
||||
import com.mysql.cj.conf.IntegerPropertyDefinition;
|
||||
import com.mysql.cj.conf.LongPropertyDefinition;
|
||||
import com.mysql.cj.conf.MemorySizePropertyDefinition;
|
||||
import com.mysql.cj.conf.PropertyDefinition;
|
||||
import com.mysql.cj.conf.PropertyDefinitions;
|
||||
import com.mysql.cj.conf.StringPropertyDefinition;
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
import javassist.CtNewMethod;
|
||||
import javassist.bytecode.DuplicateMemberException;
|
||||
|
||||
public class AddMethods {
|
||||
private static boolean verbose = false;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
System.out.println("Applying AddMethods.");
|
||||
|
||||
verbose = "true".equalsIgnoreCase(args[1]);
|
||||
|
||||
ClassPool pool = ClassPool.getDefault();
|
||||
pool.insertClassPath(args[0]);
|
||||
|
||||
sysOut("---");
|
||||
CtClass clazz = pool.get(MysqlDataSource.class.getName());
|
||||
sysOut("Add properties setters/getters to " + clazz.getName());
|
||||
addPropertiesGettersSetters(clazz, PropertyDefinitions.PROPERTY_KEY_TO_PROPERTY_DEFINITION.values());
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
}
|
||||
|
||||
private static void sysOut(String s) {
|
||||
if (verbose) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addPropertiesGettersSetters(CtClass clazz, Collection<PropertyDefinition<?>> propertyDefinitions) throws Exception {
|
||||
for (PropertyDefinition<?> def : propertyDefinitions) {
|
||||
if (def.getCategory().equals(PropertyDefinitions.CATEGORY_XDEVAPI)) {
|
||||
continue;
|
||||
}
|
||||
String pname = def.hasCcAlias() ? def.getCcAlias() : def.getName();
|
||||
|
||||
if (def instanceof StringPropertyDefinition) {
|
||||
addGetter(clazz, pname, String.class.getName(), "getStringRuntimeProperty");
|
||||
addSetter(clazz, pname, String.class.getName(), "setStringRuntimeProperty");
|
||||
|
||||
} else if (def instanceof BooleanPropertyDefinition) {
|
||||
addGetter(clazz, pname, Boolean.TYPE.getName(), "getBooleanRuntimeProperty");
|
||||
addSetter(clazz, pname, Boolean.TYPE.getName(), "setBooleanRuntimeProperty");
|
||||
|
||||
} else if (def instanceof IntegerPropertyDefinition) {
|
||||
addGetter(clazz, pname, Integer.TYPE.getName(), "getIntegerRuntimeProperty");
|
||||
addSetter(clazz, pname, Integer.TYPE.getName(), "setIntegerRuntimeProperty");
|
||||
|
||||
} else if (def instanceof LongPropertyDefinition) {
|
||||
addGetter(clazz, pname, Long.TYPE.getName(), "getLongRuntimeProperty");
|
||||
addSetter(clazz, pname, Long.TYPE.getName(), "setLongRuntimeProperty");
|
||||
|
||||
} else if (def instanceof MemorySizePropertyDefinition) {
|
||||
addGetter(clazz, pname, Integer.TYPE.getName(), "getMemorySizeRuntimeProperty");
|
||||
addSetter(clazz, pname, Integer.TYPE.getName(), "setMemorySizeRuntimeProperty");
|
||||
|
||||
} else if (def instanceof EnumPropertyDefinition<?>) {
|
||||
addGetter(clazz, pname, String.class.getName(), "getEnumRuntimeProperty");
|
||||
addSetter(clazz, pname, "java.lang.String", "setEnumRuntimeProperty");
|
||||
|
||||
} else {
|
||||
throw new Exception("Unknown " + def.getName() + " property type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addGetter(CtClass clazz, String pname, String paramType, String getPropertyMethod) throws Exception {
|
||||
String mname = "get" + pname.substring(0, 1).toUpperCase() + pname.substring(1);
|
||||
String mbody = "public " + paramType + " " + mname + "() throws java.sql.SQLException { return " + getPropertyMethod + "(\"" + pname + "\");}";
|
||||
sysOut(mbody);
|
||||
try {
|
||||
CtMethod m = CtNewMethod.make(mbody, clazz);
|
||||
clazz.addMethod(m);
|
||||
sysOut(m.toString());
|
||||
} catch (DuplicateMemberException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
private static void addSetter(CtClass clazz, String pname, String paramType, String setPropertyMethod) throws Exception {
|
||||
String mname = "set" + pname.substring(0, 1).toUpperCase() + pname.substring(1);
|
||||
String mbody = "public void " + mname + "(" + paramType + " value) throws java.sql.SQLException { " + setPropertyMethod + "(\"" + pname
|
||||
+ "\", value);}";
|
||||
sysOut(mbody);
|
||||
try {
|
||||
CtMethod m = CtNewMethod.make(mbody, clazz);
|
||||
clazz.addMethod(m);
|
||||
sysOut(m.toString());
|
||||
} catch (DuplicateMemberException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package instrumentation;
|
||||
|
||||
import java.sql.Savepoint;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mysql.cj.jdbc.ConnectionImpl;
|
||||
import com.mysql.cj.jdbc.ConnectionWrapper;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
||||
public class CommonChecks {
|
||||
private static boolean verbose = false;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
System.out.println("Applying CommonChecks.");
|
||||
|
||||
verbose = "true".equalsIgnoreCase(args[1]);
|
||||
|
||||
ClassPool pool = ClassPool.getDefault();
|
||||
pool.insertClassPath(args[0]);
|
||||
|
||||
// params classes
|
||||
CtClass ctClazz = pool.get(Class.class.getName());
|
||||
//CtClass ctClob = pool.get(java.sql.Clob.class.getName());
|
||||
//CtClass ctBindValue = pool.get(BindValue.class.getName());
|
||||
CtClass ctBool = pool.get(boolean.class.getName());
|
||||
//CtClass ctBoolArray = pool.get(boolean[].class.getName());
|
||||
//CtClass ctByteArray2 = pool.get(byte[][].class.getName());
|
||||
//CtClass ctBuffer = pool.get(Buffer.class.getName());
|
||||
//CtClass ctExecutor = pool.get(Executor.class.getName());
|
||||
//CtClass ctFieldArray = pool.get(Field[].class.getName());
|
||||
CtClass ctInt = pool.get(int.class.getName());
|
||||
CtClass ctIntArray = pool.get(int[].class.getName());
|
||||
//CtClass ctInputStreamArray = pool.get(InputStream[].class.getName());
|
||||
//CtClass ctLong = pool.get(long.class.getName());
|
||||
CtClass ctMap = pool.get(Map.class.getName());
|
||||
//CtClass ctMysqlSavepoint = pool.get(MysqlSavepoint.class.getName());
|
||||
CtClass ctObjectArray = pool.get(Object[].class.getName());
|
||||
//CtClass ctProperties = pool.get(Properties.class.getName());
|
||||
//CtClass ctReader = pool.get(Reader.class.getName());
|
||||
CtClass ctSavepoint = pool.get(Savepoint.class.getName());
|
||||
//CtClass ctStatement = pool.get(Statement.class.getName());
|
||||
CtClass ctString = pool.get(String.class.getName());
|
||||
CtClass ctStringArray = pool.get(String[].class.getName());
|
||||
|
||||
CtClass clazz = pool.get(ConnectionImpl.class.getName());
|
||||
// addClosedCheck(clazz.getDeclaredMethod("changeUser", new CtClass[] { ctString, ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clientPrepareStatement", new CtClass[] { ctString, ctInt, ctInt, ctBool }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("commit", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createStatement", new CtClass[] { ctInt, ctInt }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("getMetaData", new CtClass[] { ctBool, ctBool }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("getNetworkTimeout", new CtClass[] {}));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("getSchema", new CtClass[] {}));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("isAutoCommitNonDefaultOnServer", new CtClass[] {}));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("isServerLocal", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("isWrapperFor", new CtClass[] { ctClazz }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("prepareStatement", new CtClass[] { ctString, ctInt, ctInt }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("rollback", new CtClass[] {}));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("rollback", new CtClass[] { ctSavepoint }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("setAutoCommit", new CtClass[] { ctBool }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("setCatalog", new CtClass[] { ctString }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("setNetworkTimeout", new CtClass[] { ctExecutor, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setReadOnly", new CtClass[] { ctBool }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("setSavepoint", new CtClass[] { ctMysqlSavepoint }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("setSchema", new CtClass[] { ctString }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("setTransactionIsolation", new CtClass[] { ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("versionMeetsMinimum", new CtClass[] { ctInt, ctInt, ctInt }));
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
clazz = pool.get(ConnectionWrapper.class.getName());
|
||||
addClosedCheck(clazz.getDeclaredMethod("changeUser", new CtClass[] { ctString, ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clientPrepare", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clientPrepare", new CtClass[] { ctString, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clientPrepareStatement", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clientPrepareStatement", new CtClass[] { ctString, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clientPrepareStatement", new CtClass[] { ctString, ctIntArray }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clientPrepareStatement", new CtClass[] { ctString, ctStringArray }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clientPrepareStatement", new CtClass[] { ctString, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clientPrepareStatement", new CtClass[] { ctString, ctInt, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("commit", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("clearWarnings", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createArrayOf", new CtClass[] { ctString, ctObjectArray }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createBlob", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createClob", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createNClob", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createStatement", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createStatement", new CtClass[] { ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createStatement", new CtClass[] { ctInt, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createSQLXML", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("createStruct", new CtClass[] { ctString, ctObjectArray }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getAutoCommit", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getCatalog", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getClientInfo", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getClientInfo", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getDatabase", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getHoldability", new CtClass[] {}));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("getProcessHost", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getMetaData", new CtClass[] {}));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("getNetworkTimeout", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getTransactionIsolation", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getTypeMap", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("getWarnings", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("isReadOnly", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("isReadOnly", new CtClass[] { ctBool }));
|
||||
//addClosedCheck(clazz.getDeclaredMethod("isWrapperFor", new CtClass[] { ctClazz }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("nativeSQL", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("prepareCall", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("prepareCall", new CtClass[] { ctString, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("prepareCall", new CtClass[] { ctString, ctInt, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("prepareStatement", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("prepareStatement", new CtClass[] { ctString, ctInt }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("prepareStatement", new CtClass[] { ctString, ctStringArray }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("prepareStatement", new CtClass[] { ctString, ctIntArray }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("prepareStatement", new CtClass[] { ctString, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("prepareStatement", new CtClass[] { ctString, ctInt, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("prepareStatement", new CtClass[] { ctString, ctStringArray }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("releaseSavepoint", new CtClass[] { ctSavepoint }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("resetServerState", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("rollback", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("rollback", new CtClass[] { ctSavepoint }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("serverPrepareStatement", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("serverPrepareStatement", new CtClass[] { ctString, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("serverPrepareStatement", new CtClass[] { ctString, ctIntArray }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("serverPrepareStatement", new CtClass[] { ctString, ctStringArray }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("serverPrepareStatement", new CtClass[] { ctString, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("serverPrepareStatement", new CtClass[] { ctString, ctInt, ctInt, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setAutoCommit", new CtClass[] { ctBool }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setCatalog", new CtClass[] { ctString }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("setClientInfo", new CtClass[] { ctString, ctString }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("setClientInfo", new CtClass[] { ctProperties }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setDatabase", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setHoldability", new CtClass[] { ctInt }));
|
||||
// addClosedCheck(clazz.getDeclaredMethod("setNetworkTimeout", new CtClass[] { ctExecutor, ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setReadOnly", new CtClass[] { ctBool }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setSavepoint", new CtClass[] {}));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setSavepoint", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setSchema", new CtClass[] { ctString }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setTransactionIsolation", new CtClass[] { ctInt }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("setTypeMap", new CtClass[] { ctMap }));
|
||||
addClosedCheck(clazz.getDeclaredMethod("shutdownServer", new CtClass[] {}));
|
||||
//addClosedCheck(clazz.getDeclaredMethod("versionMeetsMinimum", new CtClass[] { ctInt, ctInt, ctInt }));
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
//clazz = pool.get(MultiHostMySQLConnection.class.getName());
|
||||
//addClosedCheck(clazz.getDeclaredMethod("isWrapperFor", new CtClass[] { ctClazz }));
|
||||
//clazz.writeFile(args[0]);
|
||||
|
||||
}
|
||||
|
||||
private static void addClosedCheck(CtMethod m) throws Exception {
|
||||
sysOut(m.toString());
|
||||
m.insertBefore("checkClosed();");
|
||||
}
|
||||
|
||||
private static void sysOut(String s) {
|
||||
if (verbose) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,735 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package instrumentation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Savepoint;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.mysql.cj.QueryBindings;
|
||||
import com.mysql.cj.exceptions.CJException;
|
||||
import com.mysql.cj.jdbc.Blob;
|
||||
import com.mysql.cj.jdbc.BlobFromLocator;
|
||||
import com.mysql.cj.jdbc.CallableStatement;
|
||||
import com.mysql.cj.jdbc.CallableStatement.CallableStatementParamInfo;
|
||||
import com.mysql.cj.jdbc.ClientPreparedStatement;
|
||||
import com.mysql.cj.jdbc.Clob;
|
||||
import com.mysql.cj.jdbc.ConnectionImpl;
|
||||
import com.mysql.cj.jdbc.ConnectionWrapper;
|
||||
import com.mysql.cj.jdbc.DatabaseMetaData;
|
||||
import com.mysql.cj.jdbc.DatabaseMetaDataUsingInfoSchema;
|
||||
import com.mysql.cj.jdbc.JdbcConnection;
|
||||
import com.mysql.cj.jdbc.JdbcStatement;
|
||||
import com.mysql.cj.jdbc.MysqlConnectionPoolDataSource;
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
import com.mysql.cj.jdbc.MysqlParameterMetadata;
|
||||
import com.mysql.cj.jdbc.MysqlPooledConnection;
|
||||
import com.mysql.cj.jdbc.MysqlSQLXML;
|
||||
import com.mysql.cj.jdbc.MysqlSavepoint;
|
||||
import com.mysql.cj.jdbc.MysqlXAConnection;
|
||||
import com.mysql.cj.jdbc.MysqlXADataSource;
|
||||
import com.mysql.cj.jdbc.MysqlXid;
|
||||
import com.mysql.cj.jdbc.NClob;
|
||||
import com.mysql.cj.jdbc.NonRegisteringDriver;
|
||||
import com.mysql.cj.jdbc.ServerPreparedStatement;
|
||||
import com.mysql.cj.jdbc.StatementImpl;
|
||||
import com.mysql.cj.jdbc.SuspendableXAConnection;
|
||||
import com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping;
|
||||
import com.mysql.cj.jdbc.ha.LoadBalancedConnection;
|
||||
import com.mysql.cj.jdbc.ha.LoadBalancedMySQLConnection;
|
||||
import com.mysql.cj.jdbc.ha.MultiHostMySQLConnection;
|
||||
import com.mysql.cj.jdbc.ha.ReplicationConnection;
|
||||
import com.mysql.cj.jdbc.ha.ReplicationMySQLConnection;
|
||||
import com.mysql.cj.jdbc.result.ResultSetImpl;
|
||||
import com.mysql.cj.jdbc.result.ResultSetInternalMethods;
|
||||
import com.mysql.cj.jdbc.result.ResultSetMetaData;
|
||||
import com.mysql.cj.jdbc.result.UpdatableResultSet;
|
||||
import com.mysql.cj.protocol.ColumnDefinition;
|
||||
import com.mysql.cj.protocol.Message;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
import javassist.NotFoundException;
|
||||
|
||||
public class TranslateExceptions {
|
||||
|
||||
private static CtClass runTimeException = null;
|
||||
private static ClassPool pool = ClassPool.getDefault();
|
||||
private static Map<String, List<CtMethod>> processed = new TreeMap<>();
|
||||
|
||||
private static String EXCEPTION_INTERCEPTOR_GETTER = "getExceptionInterceptor()";
|
||||
private static String EXCEPTION_INTERCEPTOR_MEMBER = "this.exceptionInterceptor";
|
||||
private static boolean verbose = false;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
System.out.println("Applying TranslateExceptions.");
|
||||
|
||||
verbose = "true".equalsIgnoreCase(args[1]);
|
||||
|
||||
pool.insertClassPath(args[0]);
|
||||
processed.clear();
|
||||
|
||||
runTimeException = pool.get(CJException.class.getName());
|
||||
|
||||
// params classes
|
||||
//CtClass ctServerPreparedQueryBindValue = pool.get(ServerPreparedQueryBindValue.class.getName());
|
||||
CtClass ctQueryBindings = pool.get(QueryBindings.class.getName());
|
||||
//CtClass ctByteArray = pool.get(byte[].class.getName());
|
||||
CtClass ctColumnDefinition = pool.get(ColumnDefinition.class.getName());
|
||||
|
||||
CtClass ctLongArray = pool.get(long[].class.getName());
|
||||
//CtClass ctInputStream = pool.get(InputStream.class.getName());
|
||||
CtClass ctJdbcConnection = pool.get(JdbcConnection.class.getName());
|
||||
CtClass ctMysqlSavepoint = pool.get(MysqlSavepoint.class.getName());
|
||||
//CtClass ctPacketPayload = pool.get(PacketPayload.class.getName());
|
||||
CtClass ctProperties = pool.get(Properties.class.getName());
|
||||
CtClass ctResultSet = pool.get(ResultSet.class.getName());
|
||||
CtClass ctResultSetInternalMethods = pool.get(ResultSetInternalMethods.class.getName());
|
||||
CtClass ctStatement = pool.get(java.sql.Statement.class.getName());
|
||||
CtClass ctStatementImpl = pool.get(StatementImpl.class.getName());
|
||||
CtClass ctString = pool.get(String.class.getName());
|
||||
|
||||
CtClass ctMessageBody = pool.get(Message.class.getName());
|
||||
|
||||
// class we want to instrument
|
||||
CtClass clazz;
|
||||
|
||||
/*
|
||||
* java.sql.Blob
|
||||
*/
|
||||
// com.mysql.cj.jdbc.Blob implements java.sql.Blob, OutputStreamWatcher
|
||||
clazz = pool.get(Blob.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.Blob.class, false, EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
// com.mysql.cj.jdbc.BlobFromLocator implements java.sql.Blob
|
||||
clazz = pool.get(BlobFromLocator.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.Blob.class, false, EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.CallableStatement
|
||||
*/
|
||||
// com.mysql.cj.jdbc.CallableStatement extends PreparedStatement implements java.sql.CallableStatement
|
||||
clazz = pool.get(CallableStatement.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.CallableStatement.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
instrumentJdbcMethods(clazz, JdbcStatement.class, true, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
// non-JDBC
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("checkIsOutputParam", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("checkParameterIndexBounds", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("checkReadOnlyProcedure", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("convertGetProcedureColumnsToInternalDescriptors", new CtClass[] { ctResultSet }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("determineParameterTypes", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("fakeParameterTypes", new CtClass[] { CtClass.booleanType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("fixParameterName", new CtClass[] { ctString }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("generateParameterMap", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getNamedParamIndex", new CtClass[] { ctString, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getOutputParameters", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("mapOutputParameterIndexToRsIndex", new CtClass[] { CtClass.intType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("retrieveOutParams", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setInOutParamsOnServer", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setOutParams", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* com.mysql.cj.jdbc.StatementWrapper extends WrapperBase implements Statement
|
||||
*/
|
||||
// TODO: Does it's own typical exception wrapping, could be instrumented with different catch method
|
||||
|
||||
/*
|
||||
* com.mysql.cj.jdbc.PreparedStatementWrapper extends StatementWrapper implements PreparedStatement
|
||||
*/
|
||||
// TODO: Does it's own typical exception wrapping, could be instrumented with different catch method
|
||||
|
||||
/*
|
||||
* com.mysql.cj.jdbc.CallableStatementWrapper extends PreparedStatementWrapper implements CallableStatement
|
||||
*/
|
||||
// TODO: Does it's own typical exception wrapping, could be instrumented with different catch method
|
||||
|
||||
/*
|
||||
* java.sql.Clob
|
||||
*/
|
||||
// com.mysql.cj.jdbc.Clob implements java.sql.Clob, OutputStreamWatcher, WriterWatcher
|
||||
clazz = pool.get(Clob.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.Clob.class, false, EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
*
|
||||
* java.sql.Connection extends java.sql.Wrapper
|
||||
* ----> com.mysql.cj.jdbc.JdbcConnection extends java.sql.Connection, MysqlConnection
|
||||
* ----------> com.mysql.cj.jdbc.ConnectionImpl
|
||||
* ----------> com.mysql.cj.jdbc.LoadBalancedConnection extends JdbcConnection
|
||||
* -------------> com.mysql.cj.jdbc.LoadBalancedMySQLConnection extends MultiHostMySQLConnection implements LoadBalancedConnection
|
||||
* ----------> com.mysql.cj.jdbc.MultiHostMySQLConnection
|
||||
* -------> com.mysql.cj.jdbc.ReplicationConnection implements JdbcConnection, PingTarget
|
||||
* -------> com.mysql.cj.jdbc.ConnectionWrapper
|
||||
*/
|
||||
// ConnectionImpl extends AbstractJdbcConnection implements JdbcConnection
|
||||
clazz = pool.get(ConnectionImpl.class.getName());
|
||||
instrumentJdbcMethods(clazz, JdbcConnection.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
// non-JDBC
|
||||
catchRuntimeException(clazz,
|
||||
clazz.getDeclaredMethod("clientPrepareStatement", new CtClass[] { ctString, CtClass.intType, CtClass.intType, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("createNewIO", new CtClass[] { CtClass.booleanType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getMetaData", new CtClass[] { CtClass.booleanType, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("handleAutoCommitDefaults", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setSavepoint", new CtClass[] { ctMysqlSavepoint }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("versionMeetsMinimum", new CtClass[] { CtClass.intType, CtClass.intType, CtClass.intType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("rollbackNoChecks", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setupServerForTruncationChecks", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
// com.mysql.cj.jdbc.LoadBalancedMySQLConnection extends MultiHostMySQLConnection implements LoadBalancedConnection
|
||||
clazz = pool.get(LoadBalancedMySQLConnection.class.getName());
|
||||
instrumentJdbcMethods(clazz, LoadBalancedConnection.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
// MultiHostMySQLConnection implements JdbcConnection
|
||||
clazz = pool.get(MultiHostMySQLConnection.class.getName());
|
||||
instrumentJdbcMethods(clazz, JdbcConnection.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
// com.mysql.cj.jdbc.ReplicationConnection implements JdbcConnection, PingTarget
|
||||
clazz = pool.get(ReplicationMySQLConnection.class.getName());
|
||||
instrumentJdbcMethods(clazz, ReplicationConnection.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
// ConnectionWrapper extends WrapperBase implements JdbcConnection
|
||||
clazz = pool.get(ConnectionWrapper.class.getName());
|
||||
instrumentJdbcMethods(clazz, JdbcConnection.class, false, EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
// non-JDBC
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("clientPrepare", new CtClass[] { ctString }), EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("clientPrepare", new CtClass[] { ctString, CtClass.intType, CtClass.intType }),
|
||||
EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setClientInfo", new CtClass[] { ctString, ctString }), EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setClientInfo", new CtClass[] { ctProperties }), EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.DatabaseMetaData extends java.sql.Wrapper
|
||||
*/
|
||||
// com.mysql.cj.jdbc.DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
clazz = pool.get(DatabaseMetaData.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.DatabaseMetaData.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
// com.mysql.cj.jdbc.DatabaseMetaDataUsingInfoSchema extends DatabaseMetaData
|
||||
clazz = pool.get(DatabaseMetaDataUsingInfoSchema.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.DatabaseMetaData.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.Driver
|
||||
*/
|
||||
// com.mysql.cj.jdbc.Driver extends NonRegisteringDriver implements java.sql.Driver
|
||||
clazz = pool.get(NonRegisteringDriver.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.Driver.class);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.NClob
|
||||
*/
|
||||
// com.mysql.cj.jdbc.NClob extends Clob implements java.sql.NClob
|
||||
clazz = pool.get(NClob.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.NClob.class);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.ParameterMetaData extends java.sql.Wrapper
|
||||
*/
|
||||
// com.mysql.cj.jdbc.CallableStatement.CallableStatementParamInfo implements ParameterMetaData
|
||||
clazz = pool.get(CallableStatementParamInfo.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.ParameterMetaData.class);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
// com.mysql.cj.jdbc.MysqlParameterMetadata implements ParameterMetaData
|
||||
clazz = pool.get(MysqlParameterMetadata.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.ParameterMetaData.class, false, EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.PreparedStatement extends java.sql.Statement (java.sql.Statement extends java.sql.Wrapper)
|
||||
*/
|
||||
// com.mysql.cj.jdbc.ClientPreparedStatement extends com.mysql.cj.jdbc.StatementImpl implements java.sql.PreparedStatement
|
||||
clazz = pool.get(ClientPreparedStatement.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.PreparedStatement.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
instrumentJdbcMethods(clazz, JdbcStatement.class, true, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
// non-JDBC
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("toString", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("checkBounds", new CtClass[] { CtClass.intType, CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("checkReadOnlySafeStatement", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("executeBatchWithMultiValuesClause", new CtClass[] { CtClass.intType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("executeBatchSerially", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz,
|
||||
clazz.getDeclaredMethod("executeInternal",
|
||||
new CtClass[] { CtClass.intType, ctMessageBody, CtClass.booleanType, CtClass.booleanType, ctColumnDefinition, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("executePreparedBatchAsMultiStatement", new CtClass[] { CtClass.intType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("executeUpdateInternal", new CtClass[] { CtClass.booleanType, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("executeUpdateInternal", new CtClass[] { ctQueryBindings, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("generateMultiStatementForBatch", new CtClass[] { CtClass.intType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getBytesRepresentation", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getParameterBindings", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("initializeFromQueryInfo", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("isNull", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("prepareBatchedInsertSQL", new CtClass[] { ctJdbcConnection, CtClass.intType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
// catchRuntimeException(clazz,
|
||||
// clazz.getDeclaredMethod("setBytes", new CtClass[] { CtClass.intType, ctByteArray, CtClass.booleanType, CtClass.booleanType }),
|
||||
// EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setRetrieveGeneratedKeys", new CtClass[] { CtClass.booleanType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* com.mysql.cj.jdbc.ServerPreparedStatement extends ClientPreparedStatement
|
||||
*/
|
||||
clazz = pool.get(ServerPreparedStatement.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.PreparedStatement.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
instrumentJdbcMethods(clazz, JdbcStatement.class, true, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
// non-JDBC
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("toString", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getBinding", new CtClass[] { CtClass.intType, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz,
|
||||
clazz.getDeclaredMethod("executeInternal",
|
||||
new CtClass[] { CtClass.intType, ctMessageBody, CtClass.booleanType, CtClass.booleanType, ctColumnDefinition, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
//catchRuntimeException(clazz, clazz.getDeclaredMethod("isRewritableWithMultiValueClause", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("realClose", new CtClass[] { CtClass.booleanType, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("serverExecute", new CtClass[] { CtClass.intType, CtClass.booleanType, ctColumnDefinition }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
//catchRuntimeException(clazz, clazz.getDeclaredMethod("serverLongData", new CtClass[] { CtClass.intType, ctServerPreparedQueryBindValue }),
|
||||
// EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("serverPrepare", new CtClass[] { ctString }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.ResultSet extends java.sql.Wrapper
|
||||
*/
|
||||
// com.mysql.cj.jdbc.ResultSetImpl implements com.mysql.cj.jdbc.ResultSetInternalMethods (extends java.sql.ResultSet)
|
||||
clazz = pool.get(ResultSetImpl.class.getName());
|
||||
instrumentJdbcMethods(clazz, ResultSetInternalMethods.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
// com.mysql.cj.jdbc.UpdatableResultSet extends ResultSetImpl
|
||||
clazz = pool.get(UpdatableResultSet.class.getName());
|
||||
instrumentJdbcMethods(clazz, ResultSetInternalMethods.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("generateStatements", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.ResultSetMetaData extends java.sql.Wrapper
|
||||
*/
|
||||
// com.mysql.cj.jdbc.ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
clazz = pool.get(ResultSetMetaData.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.ResultSetMetaData.class, false, EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.Savepoint
|
||||
*/
|
||||
// com.mysql.cj.jdbc.MysqlSavepoint implements java.sql.Savepoint
|
||||
clazz = pool.get(MysqlSavepoint.class.getName());
|
||||
instrumentJdbcMethods(clazz, Savepoint.class, false, EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.Statement extends java.sql.Wrapper
|
||||
*/
|
||||
// com.mysql.cj.jdbc.StatementImpl implements com.mysql.cj.jdbc.Statement (extends java.sql.Statement)
|
||||
clazz = pool.get(StatementImpl.class.getName());
|
||||
instrumentJdbcMethods(clazz, JdbcStatement.class, false, EXCEPTION_INTERCEPTOR_GETTER);
|
||||
// non-JDBC
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("createResultSetUsingServerFetch", new CtClass[] { ctString }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("doPingInstead", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("executeInternal", new CtClass[] { ctString, CtClass.booleanType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz,
|
||||
clazz.getDeclaredMethod("executeBatchUsingMultiQueries", new CtClass[] { CtClass.booleanType, CtClass.intType, CtClass.intType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("executeUpdateInternal", new CtClass[] { ctString, CtClass.booleanType, CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("executeSimpleNonQuery", new CtClass[] { ctJdbcConnection, ctString }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("generatePingResultSet", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getBatchedGeneratedKeys", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getBatchedGeneratedKeys", new CtClass[] { ctStatement }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getGeneratedKeysInternal", new CtClass[] { CtClass.longType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getLastInsertID", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getLongUpdateCount", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getOpenResultSetCount", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getResultSetInternal", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("processMultiCountsAndKeys", new CtClass[] { ctStatementImpl, CtClass.intType, ctLongArray }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("removeOpenResultSet", new CtClass[] { ctResultSetInternalMethods }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("resetCancelledState", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setHoldResultsOpenOverClose", new CtClass[] { CtClass.booleanType }),
|
||||
EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setResultSetConcurrency", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("useServerFetch", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("checkCancelTimeout", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* java.sql.SQLXML
|
||||
*/
|
||||
// com.mysql.cj.jdbc.MysqlSQLXML implements SQLXML
|
||||
clazz = pool.get(MysqlSQLXML.class.getName());
|
||||
instrumentJdbcMethods(clazz, java.sql.SQLXML.class, false, EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* javax.sql.ConnectionPoolDataSource
|
||||
*/
|
||||
// MysqlConnectionPoolDataSource extends MysqlDataSource implements ConnectionPoolDataSource
|
||||
clazz = pool.get(MysqlConnectionPoolDataSource.class.getName());
|
||||
instrumentJdbcMethods(clazz, javax.sql.ConnectionPoolDataSource.class);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* javax.sql.DataSource
|
||||
*/
|
||||
// MysqlDataSource extends JdbcPropertySetImpl implements DataSource, Referenceable, Serializable, JdbcPropertySet
|
||||
clazz = pool.get(MysqlDataSource.class.getName());
|
||||
instrumentJdbcMethods(clazz, javax.sql.DataSource.class);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getStringRuntimeProperty", new CtClass[] { ctString }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setStringRuntimeProperty", new CtClass[] { ctString, ctString }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getBooleanRuntimeProperty", new CtClass[] { ctString }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setBooleanRuntimeProperty", new CtClass[] { ctString, CtClass.booleanType }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getIntegerRuntimeProperty", new CtClass[] { ctString }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setIntegerRuntimeProperty", new CtClass[] { ctString, CtClass.intType }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getLongRuntimeProperty", new CtClass[] { ctString }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setLongRuntimeProperty", new CtClass[] { ctString, CtClass.longType }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getMemorySizeRuntimeProperty", new CtClass[] { ctString }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setMemorySizeRuntimeProperty", new CtClass[] { ctString, CtClass.intType }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("getEnumRuntimeProperty", new CtClass[] { ctString }), null);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("setEnumRuntimeProperty", new CtClass[] { ctString, ctString }), null);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* javax.sql.PooledConnection
|
||||
*/
|
||||
// com.mysql.cj.jdbc.MysqlPooledConnection
|
||||
clazz = pool.get(MysqlPooledConnection.class.getName());
|
||||
instrumentJdbcMethods(clazz, javax.sql.PooledConnection.class, false, EXCEPTION_INTERCEPTOR_MEMBER);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* javax.sql.XAConnection
|
||||
* javax.transaction.xa.XAResource
|
||||
*/
|
||||
// com.mysql.cj.jdbc.MysqlXAConnection extends MysqlPooledConnection implements XAConnection, XAResource
|
||||
clazz = pool.get(MysqlXAConnection.class.getName());
|
||||
instrumentJdbcMethods(clazz, javax.sql.XAConnection.class);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
// com.mysql.cj.jdbc.SuspendableXAConnection extends MysqlPooledConnection implements XAConnection, XAResource
|
||||
clazz = pool.get(SuspendableXAConnection.class.getName());
|
||||
instrumentJdbcMethods(clazz, javax.sql.XAConnection.class);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* javax.sql.XADataSource
|
||||
*/
|
||||
// com.mysql.cj.jdbc.MysqlXADataSource extends MysqlDataSource implements javax.sql.XADataSource
|
||||
clazz = pool.get(MysqlXADataSource.class.getName());
|
||||
instrumentJdbcMethods(clazz, javax.sql.DataSource.class);
|
||||
instrumentJdbcMethods(clazz, javax.sql.XADataSource.class);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* javax.transaction.xa.Xid
|
||||
*/
|
||||
// com.mysql.cj.jdbc.MysqlXid implements Xid
|
||||
clazz = pool.get(MysqlXid.class.getName());
|
||||
instrumentJdbcMethods(clazz, javax.transaction.xa.Xid.class);
|
||||
clazz.writeFile(args[0]);
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* java.sql.DataTruncation
|
||||
*/
|
||||
// com.mysql.cj.jdbc.exceptions.MysqlDataTruncation extends DataTruncation
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* java.sql.SQLException
|
||||
*/
|
||||
// com.mysql.cj.jdbc.exceptions.NotUpdatable extends SQLException
|
||||
// com.mysql.cj.jdbc.exceptions.OperationNotSupportedException extends SQLException
|
||||
// com.mysql.cj.jdbc.exceptions.PacketTooBigException extends SQLException
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* java.sql.SQLNonTransientException
|
||||
*/
|
||||
// com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException extends SQLNonTransientException
|
||||
// com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException extends SQLNonTransientException
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* java.sql.SQLRecoverableException
|
||||
*/
|
||||
// com.mysql.cj.jdbc.exceptions.CommunicationsException extends SQLRecoverableException implements StreamingNotifiable
|
||||
// ---> com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException extends CommunicationsException
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* java.sql.SQLTransientException
|
||||
* ---> java.sql.SQLTimeoutException
|
||||
*/
|
||||
// com.mysql.cj.jdbc.exceptions.MySQLTimeoutException extends SQLTimeoutException
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* java.sql.SQLTransientException
|
||||
* ---> java.sql.SQLTransactionRollbackException
|
||||
*/
|
||||
// com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException extends SQLTransactionRollbackException implements DeadlockTimeoutRollbackMarker
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* com.mysql.cj.jdbc.MysqlXAException extends javax.transaction.xa.XAException
|
||||
*/
|
||||
|
||||
/*
|
||||
* These classes have no implementations in c/J:
|
||||
*
|
||||
* java.sql.Array
|
||||
* java.sql.BatchUpdateException
|
||||
* java.sql.ClientInfoStatus
|
||||
* java.sql.Date
|
||||
* java.sql.DriverManager
|
||||
* java.sql.DriverPropertyInfo
|
||||
* java.sql.PseudoColumnUsage
|
||||
* java.sql.Ref
|
||||
* java.sql.RowId
|
||||
* java.sql.RowIdLifetime
|
||||
* java.sql.SQLClientInfoException
|
||||
* java.sql.SQLData
|
||||
* java.sql.SQLDataException
|
||||
* java.sql.SQLFeatureNotSupportedException
|
||||
* java.sql.SQLInput
|
||||
* java.sql.SQLIntegrityConstraintViolationException
|
||||
* java.sql.SQLInvalidAuthorizationSpecException
|
||||
* java.sql.SQLNonTransientConnectionException
|
||||
* java.sql.SQLOutput
|
||||
* java.sql.SQLPermission
|
||||
* java.sql.SQLSyntaxErrorException
|
||||
* java.sql.SQLTransientConnectionException
|
||||
* java.sql.SQLWarning
|
||||
* java.sql.Struct
|
||||
* java.sql.Time
|
||||
* java.sql.Timestamp
|
||||
* java.sql.Types
|
||||
*
|
||||
* javax.sql.CommonDataSource
|
||||
* javax.sql.ConnectionEvent
|
||||
* javax.sql.ConnectionEventListener
|
||||
* javax.sql.RowSet
|
||||
* javax.sql.RowSetEvent
|
||||
* javax.sql.RowSetInternal
|
||||
* javax.sql.RowSetListener
|
||||
* javax.sql.RowSetMetaData
|
||||
* javax.sql.RowSetReader
|
||||
* javax.sql.RowSetWriter
|
||||
* javax.sql.StatementEvent
|
||||
* javax.sql.StatementEventListener
|
||||
*
|
||||
* javax.sql.rowset.BaseRowSet
|
||||
* javax.sql.rowset.CachedRowSet
|
||||
* javax.sql.rowset.FilteredRowSet
|
||||
* javax.sql.rowset.JdbcRowSet
|
||||
* javax.sql.rowset.Joinable
|
||||
* javax.sql.rowset.JoinRowSet
|
||||
* javax.sql.rowset.Predicate
|
||||
* javax.sql.rowset.RowSetFactory
|
||||
* javax.sql.rowset.RowSetMetaDataImpl
|
||||
* javax.sql.rowset.RowSetProvider
|
||||
* javax.sql.rowset.RowSetWarning
|
||||
* javax.sql.rowset.WebRowSet
|
||||
*
|
||||
* javax.sql.rowset.serial.SerialArray
|
||||
* javax.sql.rowset.serial.SerialBlob
|
||||
* javax.sql.rowset.serial.SerialClob
|
||||
* javax.sql.rowset.serial.SerialDatalink
|
||||
* javax.sql.rowset.serial.SerialException
|
||||
* javax.sql.rowset.serial.SerialJavaObject
|
||||
* javax.sql.rowset.serial.SerialRef
|
||||
* javax.sql.rowset.serial.SerialStruct
|
||||
* javax.sql.rowset.serial.SQLInputImpl
|
||||
* javax.sql.rowset.serial.SQLOutputImpl
|
||||
*
|
||||
* javax.sql.rowset.spi.SyncFactory
|
||||
* javax.sql.rowset.spi.SyncFactoryException
|
||||
* javax.sql.rowset.spi.SyncProvider
|
||||
* javax.sql.rowset.spi.SyncProviderException
|
||||
* javax.sql.rowset.spi.SyncResolver
|
||||
* javax.sql.rowset.spi.TransactionalWriter
|
||||
* javax.sql.rowset.spi.XmlReader
|
||||
* javax.sql.rowset.spi.XmlWriter
|
||||
*/
|
||||
}
|
||||
|
||||
private static void instrumentJdbcMethods(CtClass cjClazz, Class<?> jdbcClass) throws Exception {
|
||||
instrumentJdbcMethods(cjClazz, jdbcClass, false, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instruments methods of cjClazz defined in jdbcClass.
|
||||
*
|
||||
* @param cjClazz
|
||||
* CtClass to be instrumented.
|
||||
* @param jdbcClass
|
||||
* Class from JDBC specification where methods descriptors to be get.
|
||||
* @param declaredMethodsOnly
|
||||
* true - instrument methods declared in this class, false - also instrument inherited methods
|
||||
* @param exceptionInterceptorStr
|
||||
* exception interceptor reference as a string
|
||||
* @throws Exception
|
||||
* if an error occurs
|
||||
*/
|
||||
private static void instrumentJdbcMethods(CtClass cjClazz, Class<?> jdbcClass, boolean declaredMethodsOnly, String exceptionInterceptorStr)
|
||||
throws Exception {
|
||||
sysOutPrintln("---");
|
||||
sysOutPrintln(cjClazz.getName());
|
||||
|
||||
Method[] methods;
|
||||
if (declaredMethodsOnly) {
|
||||
// instrument methods declared in this class which throws SQLException
|
||||
methods = jdbcClass.getDeclaredMethods();
|
||||
} else {
|
||||
// instrument all methods, declared in this class and it's superclasses, which throws SQLException
|
||||
methods = jdbcClass.getMethods();
|
||||
}
|
||||
|
||||
for (Method method : methods) {
|
||||
CtMethod ctm = null;
|
||||
String prefix = "SKIPPED: ";
|
||||
for (Class<?> exc : method.getExceptionTypes()) {
|
||||
if (exc.equals(SQLException.class)) {
|
||||
prefix = "INSTRUMENTING... ";
|
||||
String jdbcClassName = method.getName();
|
||||
List<CtClass> params = new LinkedList<>();
|
||||
for (Class<?> param : method.getParameterTypes()) {
|
||||
params.add(pool.get(param.getName()));
|
||||
}
|
||||
try {
|
||||
ctm = cjClazz.getDeclaredMethod(jdbcClassName, params.toArray(new CtClass[0]));
|
||||
} catch (NotFoundException ex) {
|
||||
// Just ignoring because the only reason is that the method is implemented in superclass
|
||||
prefix = "NOT FOUND: ";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
sysOutPrint(prefix);
|
||||
sysOutPrint(method.toGenericString());
|
||||
if (ctm != null) {
|
||||
if (catchRuntimeException(cjClazz, ctm, exceptionInterceptorStr, false)) {
|
||||
sysOutPrint(" ... DONE.");
|
||||
} else {
|
||||
sysOutPrint(" ... ALREADY PROCESSED!!!");
|
||||
}
|
||||
}
|
||||
sysOutPrintln("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void catchRuntimeException(CtClass clazz, CtMethod m, String exceptionInterceptorStr) throws Exception {
|
||||
catchRuntimeException(clazz, m, exceptionInterceptorStr, true);
|
||||
}
|
||||
|
||||
private static boolean catchRuntimeException(CtClass clazz, CtMethod m, String exceptionInterceptorStr, boolean log) throws Exception {
|
||||
if (isProcessed(clazz.getClassFile().getName(), m)) {
|
||||
if (log) {
|
||||
sysOutPrintln("ALREADY PROCESSED!!! " + m);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (log) {
|
||||
sysOutPrintln(m + ", " + exceptionInterceptorStr);
|
||||
}
|
||||
if (exceptionInterceptorStr == null) {
|
||||
m.addCatch("{throw " + SQLExceptionsMapping.class.getName() + ".translateException(ex);}", runTimeException, "ex");
|
||||
} else {
|
||||
m.addCatch("{throw " + SQLExceptionsMapping.class.getName() + ".translateException(ex, " + exceptionInterceptorStr + ");}", runTimeException, "ex");
|
||||
}
|
||||
processed.get(clazz.getClassFile().getName()).add(m);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isProcessed(String fileName, CtMethod m) throws Exception {
|
||||
List<CtMethod> methods = processed.get(fileName);
|
||||
if (methods != null) {
|
||||
if (methods.contains(m)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
processed.put(fileName, new LinkedList<CtMethod>());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void sysOutPrint(String s) {
|
||||
if (verbose) {
|
||||
System.out.print(s);
|
||||
}
|
||||
}
|
||||
|
||||
private static void sysOutPrintln(String s) {
|
||||
if (verbose) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (c) 2019, 2020, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License, version 2.0, as published by the
|
||||
Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including but not
|
||||
limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
particular file or component or in included license documentation. The
|
||||
authors of MySQL hereby grant you an additional permission to link the
|
||||
program and your derivative works with the separately licensed software that
|
||||
they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file, which is
|
||||
part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
This program 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 General Public License, version 2.0,
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
-->
|
||||
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
|
||||
<Product Id="*" Name="MySQL Connector J" Language="1033" Version="$(var.ProductVersion)" Manufacturer="Oracle Corporation" UpgradeCode="a887f346-5f02-4cf1-bb85-bf34b4c5f248">
|
||||
<Package InstallerVersion="200" Compressed="yes" />
|
||||
<Upgrade Id="574f7b74-d753-4965-995d-2de6a79afd01">
|
||||
<UpgradeVersion OnlyDetect="no"
|
||||
Minimum="6.0.0"
|
||||
IncludeMinimum="yes"
|
||||
Maximum="8.0.12"
|
||||
IncludeMaximum="yes"
|
||||
Property="OLDERVERSIONBEINGUPGRADED_OLD"/>
|
||||
</Upgrade>
|
||||
<Upgrade Id="a887f346-5f02-4cf1-bb85-bf34b4c5f248">
|
||||
<UpgradeVersion OnlyDetect="no"
|
||||
Minimum="8.0.13"
|
||||
IncludeMinimum="yes"
|
||||
Maximum="$(var.ProductVersion)"
|
||||
Property="OLDERVERSIONBEINGUPGRADED"
|
||||
IncludeMaximum="yes" />
|
||||
</Upgrade>
|
||||
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
|
||||
<Directory Id="TARGETDIR" Name="SourceDir">
|
||||
<Directory Id="ProgramFilesFolder">
|
||||
<Directory Id="MySQL" Name="MySQL">
|
||||
<Directory Id="INSTALLLOCATION" Name="MySQL Connector J 8.0">
|
||||
<!-- Components Autogenerated using the WiX tool named Heat. See the Project properties for cmd line. -->
|
||||
</Directory>
|
||||
</Directory>
|
||||
</Directory>
|
||||
</Directory>
|
||||
<Feature Id="ProductFeature" Title="wix_solution" Level="1">
|
||||
<ComponentGroupRef Id="ConnJZipContents"/>
|
||||
</Feature>
|
||||
<InstallExecuteSequence>
|
||||
<RemoveExistingProducts After="InstallInitialize" />
|
||||
</InstallExecuteSequence>
|
||||
</Product>
|
||||
</Wix>
|
|
@ -0,0 +1,5 @@
|
|||
@PRODUCT_NAME@@PACKAGE_SUFFIX@ (@MYSQL_CJ_VERSION@@MYSQL_CJ_VERSION_SNAPSHOT@@DEB_VERSION_SUFFIX@@ID_RELEASE@) @CODENAME@; urgency=low
|
||||
|
||||
* For release notes, please refer to https://dev.mysql.com/doc/relnotes/connector-j/8.0/en/
|
||||
|
||||
-- @MAINTAINER_EMAIL@ @PACKAGE_TIMESTAMP@
|
|
@ -0,0 +1 @@
|
|||
11
|
|
@ -0,0 +1,17 @@
|
|||
Source: @PRODUCT_NAME@@PACKAGE_SUFFIX@
|
||||
Section: database
|
||||
Priority: optional
|
||||
Maintainer: Oracle MySQL Product Engineering Team <mysql-build@oss.oracle.com>
|
||||
Standards-Version: 3.9.2
|
||||
Build-Depends: debhelper (>= 8.9.4)
|
||||
Homepage: http://dev.mysql.com/downloads/connector/j/
|
||||
|
||||
Package: @PRODUCT_NAME@@PACKAGE_SUFFIX@
|
||||
Section: database
|
||||
Architecture: all
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
Replaces: mysql-connector-java@PACKAGE_SUFFIX@ (<< 8.0.31)
|
||||
Breaks: mysql-connector-java@PACKAGE_SUFFIX@ (<< 8.0.31)
|
||||
Provides: mysql-connector-java@PACKAGE_SUFFIX@
|
||||
Description: MySQL Connector/J
|
||||
Standardized MySQL database driver for Java
|
|
@ -0,0 +1,9 @@
|
|||
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: @PRODUCT@
|
||||
Upstream-Contact: MySQL Release Engineering <mysql-build@oss.oracle.com>
|
||||
Source: http://dev.mysql.com/
|
||||
|
||||
Files: *
|
||||
Copyright: 2002, 2021, Oracle and/or its affiliates.
|
||||
License:
|
||||
For licensing information see the LICENSE file in this distribution.
|
|
@ -0,0 +1,8 @@
|
|||
@DIR_PACKAGE@/@PRODUCT_NAME@-@VERSION_FULL@.jar usr/share/java
|
||||
|
||||
#legal
|
||||
@DIR_PACKAGE@/@LIC_FILE@ usr/share/doc/@PRODUCT_NAME@@PACKAGE_SUFFIX@
|
||||
@DIR_PACKAGE@/README usr/share/doc/@PRODUCT_NAME@@PACKAGE_SUFFIX@
|
||||
@DIR_PACKAGE@/CHANGES usr/share/doc/@PRODUCT_NAME@@PACKAGE_SUFFIX@
|
||||
@DIR_PACKAGE@/INFO_SRC usr/share/doc/@PRODUCT_NAME@@PACKAGE_SUFFIX@
|
||||
@DIR_PACKAGE@/INFO_BIN usr/share/doc/@PRODUCT_NAME@@PACKAGE_SUFFIX@
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/make -f
|
||||
# Copyright (c) 2016, 2022, Oracle and/or its affiliates.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License, version 2.0, as published by the
|
||||
# Free Software Foundation.
|
||||
#
|
||||
# This program is also distributed with certain software (including but not
|
||||
# limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
# particular file or component or in included license documentation. The
|
||||
# authors of MySQL hereby grant you an additional permission to link the
|
||||
# program and your derivative works with the separately licensed software that
|
||||
# they have included with MySQL.
|
||||
#
|
||||
# Without limiting anything contained in the foregoing, this file, which is
|
||||
# part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
# version 1.0, a copy of which can be found at
|
||||
# http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
#
|
||||
# This program 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 General Public License, version 2.0,
|
||||
# for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
upstream_version := $(shell dpkg-parsechangelog | sed -n -e'/^Version: / { s/Version: //; s/-[^-]\+$$//; p }')
|
||||
base_version = $(shell echo $(upstream_version) | sed -e's/r[0-9]\+$$//')
|
||||
|
||||
ANT_COMMON_OPTIONS=\
|
||||
-Dcom.mysql.cj.build.dir.driver=build/driver \
|
||||
-Dcom.mysql.cj.extra.libs=@WITH_JARDEPS@ \
|
||||
-Dcom.mysql.cj.build.driver.version.status=@MYSQL_CJ_VERSION_STATUS@ \
|
||||
-Dcom.mysql.cj.build.driver.version.extra=@MYSQL_CJ_VERSION_EXTRA@ \
|
||||
-Dcom.mysql.cj.build.driver.version.snapshot=@MYSQL_CJ_VERSION_SNAPSHOT@ \
|
||||
-Dcom.mysql.cj.build.driver.extraName=@MYSQL_CJ_EXTRA_NAME@ \
|
||||
-Dcom.mysql.cj.dist.licenseUrl=@MYSQL_CJ_LICENSEURL@ \
|
||||
-Djava.awt.headless=true
|
||||
|
||||
ifeq ($(ANT_HOME),)
|
||||
ANT_CMD=ant
|
||||
else
|
||||
ANT_CMD=$(ANT_HOME)/bin/ant
|
||||
endif
|
||||
|
||||
ANT_OPTS=-Xmx512M
|
||||
|
||||
ifneq ($(JAVA_HOME),)
|
||||
ANT_JAVA_OPT=-Dcom.mysql.cj.build.jdk=$(JAVA_HOME)
|
||||
endif
|
||||
|
||||
ifneq ($(COMMERCIAL),)
|
||||
ANT_COM_OPT=-Dcom.mysql.cj.build.commercial=true
|
||||
endif
|
||||
|
||||
%:
|
||||
#dh $@ --with autoreconf
|
||||
dh $@
|
||||
|
||||
override_dh_auto_configure:
|
||||
|
||||
override_dh_auto_build:
|
||||
echo $(PATH)
|
||||
echo $(JAVA_HOME)
|
||||
$(ANT_CMD) \
|
||||
$(ANT_COMMON_OPTIONS) \
|
||||
$(ANT_JAVA_OPT) \
|
||||
$(ANT_COM_OPT) \
|
||||
package-no-sources
|
||||
|
||||
override_dh_auto_clean:
|
||||
$(ANT_CMD) $(ANT_COMMON_OPTIONS) clean
|
||||
|
||||
override_dh_installchangelogs:
|
||||
dh_installchangelogs -XCHANGES
|
|
@ -0,0 +1 @@
|
|||
3.0 (quilt)
|
|
@ -0,0 +1,2 @@
|
|||
version=3
|
||||
http://mysql.osuosl.org/Downloads/@PRODUCT_NAME@-(.+)\.tar\.gz
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
Copyright (c) 2006, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License, version 2.0, as published by the
|
||||
Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including but not
|
||||
limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
particular file or component or in included license documentation. The
|
||||
authors of MySQL hereby grant you an additional permission to link the
|
||||
program and your derivative works with the separately licensed software that
|
||||
they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file, which is
|
||||
part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
This program 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 General Public License, version 2.0,
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>@MYSQL_CJ_EXTENDED_PROD_NAME_RELOCATION@</artifactId>
|
||||
<version>@MYSQL_CJ_VERSION@</version>
|
||||
|
||||
<distributionManagement>
|
||||
<relocation>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>@MYSQL_CJ_EXTENDED_PROD_NAME@</artifactId>
|
||||
<message>MySQL Connector/J artifacts moved to reverse-DNS compliant Maven 2+ coordinates.</message>
|
||||
</relocation>
|
||||
</distributionManagement>
|
||||
</project>
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
Copyright (c) 2006, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License, version 2.0, as published by the
|
||||
Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including but not
|
||||
limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
particular file or component or in included license documentation. The
|
||||
authors of MySQL hereby grant you an additional permission to link the
|
||||
program and your derivative works with the separately licensed software that
|
||||
they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file, which is
|
||||
part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
This program 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 General Public License, version 2.0,
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>@MYSQL_CJ_EXTENDED_PROD_NAME@</artifactId>
|
||||
<version>@MYSQL_CJ_VERSION@</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MySQL Connector/J</name>
|
||||
<description>JDBC Type 4 driver for MySQL.</description>
|
||||
<url>http://dev.mysql.com/doc/connector-j/en/</url>
|
||||
|
||||
<organization>
|
||||
<name>Oracle Corporation</name>
|
||||
<url>http://www.oracle.com</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>@MYSQL_CJ_LICENSE_NAME@</name>
|
||||
<distribution>repo</distribution>
|
||||
<comments>For detailed license information see the LICENSE file in this distribution.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:mysql/mysql-connector-j.git</connection>
|
||||
<url>https://github.com/mysql/mysql-connector-j</url>
|
||||
</scm>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>3.19.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.oracle.oci.sdk</groupId>
|
||||
<artifactId>oci-java-sdk-common</artifactId>
|
||||
<version>2.14.1</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,202 @@
|
|||
# Copyright (c) 2017, 2022, Oracle and/or its affiliates.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License, version 2.0, as published by the
|
||||
# Free Software Foundation.
|
||||
#
|
||||
# This program is also distributed with certain software (including but not
|
||||
# limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
# particular file or component or in included license documentation. The
|
||||
# authors of MySQL hereby grant you an additional permission to link the
|
||||
# program and your derivative works with the separately licensed software that
|
||||
# they have included with MySQL.
|
||||
#
|
||||
# Without limiting anything contained in the foregoing, this file, which is
|
||||
# part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
# version 1.0, a copy of which can be found at
|
||||
# http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
#
|
||||
# This program 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 General Public License, version 2.0,
|
||||
# for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
# You can pass these options to "rpmbuild"
|
||||
#
|
||||
# --define="commercial <nonempty>"
|
||||
# --define="with_ant <path>"
|
||||
# --define="with_java <path>"
|
||||
# --define="with_jardeps <path>"
|
||||
# --define="with_docs <path>"
|
||||
#
|
||||
# The 'with_docs' option should have a path that points out
|
||||
#
|
||||
# <docs-base>/en/html/connector-j.html
|
||||
# <docs-base>/en/html/mvl.css (not really used)
|
||||
# <docs-base>/en/pdf/connector-j.pdf
|
||||
# <docs-base>/en/txt/connector-j.txt
|
||||
|
||||
# Some linux distributions doesn't set the "dist" macro. There is a
|
||||
# list how to identify dists here
|
||||
# https://en.opensuse.org/openSUSE:Build_Service_cross_distribution_howto
|
||||
|
||||
# SuSE will not set "dist", others do
|
||||
%if 0%{?suse_version} == 1315
|
||||
%global dist .sles12
|
||||
%global sles12 1
|
||||
%endif
|
||||
|
||||
%if 0%{?suse_version} == 1500
|
||||
%global dist .sl15
|
||||
%global sles15 1
|
||||
%endif
|
||||
|
||||
%if 0%{?commercial:1}
|
||||
%global lic_tag Commercial
|
||||
%else
|
||||
%global lic_tag GPLv2
|
||||
%endif
|
||||
|
||||
Summary: Standardized MySQL database driver for Java
|
||||
Name: @MYSQL_CJ_EXTENDED_PROD_NAME@@MYSQL_CJ_RPM_PACKAGE_SUFFIX@
|
||||
Version: @MYSQL_CJ_VERSION_NUMERIC@
|
||||
Release: @MYSQL_CJ_RPM_RELEASE_FULL@%{?dist}
|
||||
Epoch: 1
|
||||
License: %{lic_tag}
|
||||
Group: Development/Libraries
|
||||
URL: http://dev.mysql.com/downloads/connector/j/
|
||||
Source0: https://cdn.mysql.com/Downloads/Connector-J/@MYSQL_CJ_FULL_PROD_NAME@.tar.gz
|
||||
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||
BuildArch: noarch
|
||||
|
||||
Obsoletes: mysql-connector-java@MYSQL_CJ_RPM_PACKAGE_SUFFIX@ < %{version}-%{release}
|
||||
Provides: mysql-connector-java@MYSQL_CJ_RPM_PACKAGE_SUFFIX@ = %{version}-%{release}
|
||||
|
||||
%if 0%{?commercial:1}
|
||||
Obsoletes: mysql-connector-java < %{version}-%{release}
|
||||
Provides: mysql-connector-java = %{version}-%{release}
|
||||
Obsoletes: @MYSQL_CJ_EXTENDED_PROD_NAME@ < %{version}-%{release}
|
||||
Provides: @MYSQL_CJ_EXTENDED_PROD_NAME@ = %{version}-%{release}
|
||||
%endif
|
||||
|
||||
%if 0%{!?with_ant:1}
|
||||
BuildRequires: ant
|
||||
%endif
|
||||
|
||||
%if 0%{!?with_java:1}
|
||||
BuildRequires: java-devel >= 1:1.8.0
|
||||
%endif
|
||||
|
||||
%if 0%{?sles12:1} || 0%{?sles15:1}
|
||||
Requires: java-headless >= 1.8.0
|
||||
%else
|
||||
Requires: java-headless >= 1:1.8.0
|
||||
%endif
|
||||
|
||||
%description
|
||||
MySQL provides connectivity for client applications developed in the
|
||||
Java programming language with @MYSQL_CJ_DISPLAY_PROD_NAME@, a driver that
|
||||
implements the [Java Database Connectivity (JDBC) API]
|
||||
(http://www.oracle.com/technetwork/java/javase/jdbc/).
|
||||
|
||||
@MYSQL_CJ_DISPLAY_PROD_NAME@ @MYSQL_CJ_VERSION_SERIES@ is a JDBC Type 4 driver that is compatible with
|
||||
the [JDBC 4.2](http://docs.oracle.com/javase/8/docs/technotes/guides/jdbc/)
|
||||
specification. The Type 4 designation means that the driver is a pure
|
||||
Java implementation of the MySQL protocol and does not rely on the
|
||||
MySQL client libraries.
|
||||
|
||||
For detailed information please visit the official
|
||||
[@MYSQL_CJ_DISPLAY_PROD_NAME@ documentation]
|
||||
(http://dev.mysql.com/doc/connector-j/en/).
|
||||
|
||||
%prep
|
||||
%setup -q -n @MYSQL_CJ_FULL_PROD_NAME@
|
||||
|
||||
%build
|
||||
COMMON_OPTIONS="\
|
||||
-Dcom.mysql.cj.build.dir.driver=build/driver
|
||||
-Dcom.mysql.cj.extra.libs=%{with_jardeps} \
|
||||
-Dcom.mysql.cj.build.driver.version.status=@MYSQL_CJ_VERSION_STATUS@ \
|
||||
-Dcom.mysql.cj.build.driver.version.extra=@MYSQL_CJ_VERSION_EXTRA@ \
|
||||
-Dcom.mysql.cj.build.driver.version.snapshot=@MYSQL_CJ_VERSION_SNAPSHOT@ \
|
||||
-Dcom.mysql.cj.build.driver.extraName=@MYSQL_CJ_EXTRA_NAME@ \
|
||||
-Dcom.mysql.cj.dist.licenseUrl=@MYSQL_CJ_LICENSEURL@ \
|
||||
-Djava.awt.headless=true"
|
||||
|
||||
%if 0%{?with_ant:1}
|
||||
export ANT_HOME=%{with_ant}
|
||||
export ANT_CMD="${ANT_HOME}/bin/ant"
|
||||
%else
|
||||
export ANT_CMD="ant"
|
||||
%endif
|
||||
|
||||
export ANT_OPTS=-Xmx512M
|
||||
|
||||
%if 0%{?with_java:1}
|
||||
export JAVA_HOME=%{with_java}
|
||||
export PATH=${JAVA_HOME}/bin:$PATH
|
||||
COMMON_OPTIONS="${COMMON_OPTIONS} -Dcom.mysql.cj.build.jdk=${JAVA_HOME}"
|
||||
%endif
|
||||
|
||||
%if 0%{?commercial:1}
|
||||
COMMON_OPTIONS="${COMMON_OPTIONS} -Dcom.mysql.cj.build.commercial=true"
|
||||
%endif
|
||||
|
||||
# Get the file revision-info.properties again because it was excluded
|
||||
# from SOURCES
|
||||
cp %{_tmppath}/@MYSQL_CJ_FULL_PROD_NAME@/revision-info.properties .
|
||||
|
||||
${ANT_CMD} \
|
||||
${COMMON_OPTIONS} \
|
||||
package-no-sources
|
||||
|
||||
# We use the 'package-no-sources' as there are changes done only
|
||||
# when creating a package, 'build' is not enough. To make it a bit easier
|
||||
# in the install step, we rename the directory with the content
|
||||
mv @DIR_PACKAGE@ package-content
|
||||
|
||||
# The 'package' target doesn't copy the HTML or PDF doc like 'dist',
|
||||
# we copy it here
|
||||
%if 0%{?with_docs:1}
|
||||
mkdir -p package-content/docs
|
||||
cp %{with_docs}/en/html/connector-j.html package-content/docs/
|
||||
cp %{with_docs}/en/html/mvl.css package-content/docs/
|
||||
cp %{with_docs}/en/pdf/connector-j.pdf package-content/docs/
|
||||
cp %{with_docs}/en/txt/connector-j.txt package-content/docs/
|
||||
%endif
|
||||
|
||||
%install
|
||||
install -d -m 0755 %{buildroot}%{_javadir}
|
||||
install -p -m 0644 package-content/@MYSQL_CJ_FULL_PROD_NAME@.jar %{buildroot}%{_javadir}/%{name}.jar
|
||||
|
||||
%clean
|
||||
rm -rf %{buildroot}
|
||||
|
||||
%files
|
||||
%doc package-content/CHANGES
|
||||
# EL6 doesn't like 'license' macro here, so we use 'doc'
|
||||
%doc package-content/LICENSE
|
||||
%doc package-content/README
|
||||
%doc package-content/INFO_BIN
|
||||
%doc package-content/INFO_SRC
|
||||
|
||||
%if 0%{?with_docs:1}
|
||||
# README.txt is a rename of "connector-j.txt"
|
||||
%doc package-content/docs/connector-j.txt
|
||||
%doc package-content/docs/connector-j.pdf
|
||||
%doc package-content/docs/connector-j.html
|
||||
%doc package-content/docs/mvl.css
|
||||
%endif
|
||||
|
||||
%{_javadir}/%{name}.jar
|
||||
|
||||
%changelog
|
||||
* Mon Nov 27 2017 MySQL Release Engineering <mysql-build@oss.oracle.com> - 8.0.9-1
|
||||
- Set more in "build.xml"
|
||||
* Tue Mar 14 2017 MySQL Release Engineering <mysql-build@oss.oracle.com> - 6.0.7-1
|
||||
- initial package
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package demo.x.devapi;
|
||||
|
||||
import com.mysql.cj.xdevapi.Collection;
|
||||
import com.mysql.cj.xdevapi.DbDoc;
|
||||
import com.mysql.cj.xdevapi.DbDocImpl;
|
||||
import com.mysql.cj.xdevapi.DocResult;
|
||||
import com.mysql.cj.xdevapi.JsonNumber;
|
||||
import com.mysql.cj.xdevapi.JsonString;
|
||||
import com.mysql.cj.xdevapi.Schema;
|
||||
import com.mysql.cj.xdevapi.Session;
|
||||
import com.mysql.cj.xdevapi.SessionFactory;
|
||||
|
||||
/*
|
||||
* Sample program showing how to use Connector/J's Dev API support.
|
||||
*/
|
||||
public class DevApiSample {
|
||||
public static void main(String[] args) {
|
||||
Session session = new SessionFactory().getSession("mysqlx://localhost:33060/test?user=user&password=password1234");
|
||||
System.err.println("Connected!");
|
||||
Schema schema = session.getDefaultSchema();
|
||||
System.err.println("Default schema is: " + schema);
|
||||
|
||||
documentWalkthrough(schema);
|
||||
}
|
||||
|
||||
public static void documentWalkthrough(Schema schema) {
|
||||
// document walthrough
|
||||
Collection coll = schema.createCollection("myBooks", /* reuseExisting? */ true);
|
||||
DbDoc newDoc = new DbDocImpl().add("isbn", new JsonString().setValue("12345"));
|
||||
newDoc.add("title", new JsonString().setValue("Effi Briest"));
|
||||
newDoc.add("author", new JsonString().setValue("Theodor Fontane"));
|
||||
newDoc.add("currentlyReadingPage", new JsonNumber().setValue(String.valueOf(42)));
|
||||
coll.add(newDoc).execute();
|
||||
|
||||
// note: "$" prefix for document paths is optional. "$.title.somethingElse[0]" is the same as "title.somethingElse[0]" in document expressions
|
||||
DocResult docs = coll.find("$.title = 'Effi Briest' and $.currentlyReadingPage > 10").execute();
|
||||
DbDoc book = docs.next();
|
||||
System.err.println("Currently reading " + ((JsonString) book.get("title")).getString() + " on page "
|
||||
+ ((JsonNumber) book.get("currentlyReadingPage")).getInteger());
|
||||
|
||||
// increment the page number and fetch it again
|
||||
coll.modify("$.isbn = 12345").set("$.currentlyReadingPage", ((JsonNumber) book.get("currentlyReadingPage")).getInteger() + 1).execute();
|
||||
|
||||
docs = coll.find("$.title = 'Effi Briest' and $.currentlyReadingPage > 10").execute();
|
||||
book = docs.next();
|
||||
System.err.println("Currently reading " + ((JsonString) book.get("title")).getString() + " on page "
|
||||
+ ((JsonNumber) book.get("currentlyReadingPage")).getInteger());
|
||||
|
||||
// remove the doc
|
||||
coll.remove("true").execute();
|
||||
System.err.println("Number of books in collection: " + coll.count());
|
||||
|
||||
schema.dropCollection(coll.getName());
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Message classes used for serialization with Google Protocol Buffers to support the X Protocol. Classes are generated using <i>protoc</i> like so:
|
||||
*
|
||||
* <pre>
|
||||
* protoc --java_out=PATH/src/generated/java --proto_path=PATH_TO_IMPORTS -I=PATH_TO_MYSQL_REPO/rapid/plugin/x/protocol PATH_TO_MYSQL_REPO/rapid/plugin/x/protocol/*.proto
|
||||
* </pre>
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
|
||||
package com.mysql.cj.x.protobuf;
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.jdbc;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Backwards compatibility to support apps that call <code>Class.forName("com.mysql.jdbc.Driver");</code>.
|
||||
*/
|
||||
public class Driver extends com.mysql.cj.jdbc.Driver {
|
||||
public Driver() throws SQLException {
|
||||
super();
|
||||
}
|
||||
|
||||
static {
|
||||
System.err.println("Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. "
|
||||
+ "The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.jdbc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Interface to allow pluggable socket creation in the driver
|
||||
*
|
||||
* @deprecated Use {@link com.mysql.cj.protocol.SocketFactory} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface SocketFactory {
|
||||
|
||||
/**
|
||||
* Called by the driver after issuing the MySQL protocol handshake and
|
||||
* reading the results of the handshake.
|
||||
*
|
||||
* @throws SocketException
|
||||
* if a socket error occurs
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*
|
||||
* @return the socket to use after the handshake
|
||||
*/
|
||||
Socket afterHandshake() throws SocketException, IOException;
|
||||
|
||||
/**
|
||||
* Called by the driver before issuing the MySQL protocol handshake. Should
|
||||
* return the socket instance that should be used during the handshake.
|
||||
*
|
||||
* @throws SocketException
|
||||
* if a socket error occurs
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*
|
||||
* @return the socket to use before the handshake
|
||||
*/
|
||||
Socket beforeHandshake() throws SocketException, IOException;
|
||||
|
||||
/**
|
||||
* Creates a new socket using the given properties. Properties are parsed by
|
||||
* the driver from the URL. All properties other than sensitive ones (user
|
||||
* and password) are passed to this method. The driver will instantiate the
|
||||
* socket factory with the class name given in the property
|
||||
* "socketFactory", where the standard is <code>com.mysql.jdbc.StandardSocketFactory</code> Implementing classes
|
||||
* are responsible for handling synchronization of this method (if needed).
|
||||
*
|
||||
* @param host
|
||||
* the hostname passed in the JDBC URL. It will be a single
|
||||
* hostname, as the driver parses multi-hosts (for failover) and
|
||||
* calls this method for each host connection attempt.
|
||||
*
|
||||
* @param portNumber
|
||||
* the port number to connect to (if required).
|
||||
*
|
||||
* @param props
|
||||
* properties passed to the driver via the URL and/or properties
|
||||
* instance.
|
||||
*
|
||||
* @return a socket connected to the given host
|
||||
* @throws SocketException
|
||||
* if a socket error occurs
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
Socket connect(String host, int portNumber, Properties props) throws SocketException, IOException;
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.jdbc;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.mysql.cj.conf.PropertySet;
|
||||
import com.mysql.cj.log.Log;
|
||||
import com.mysql.cj.protocol.ServerSession;
|
||||
import com.mysql.cj.protocol.SocketConnection;
|
||||
import com.mysql.cj.protocol.SocketFactory;
|
||||
import com.mysql.cj.protocol.StandardSocketFactory;
|
||||
|
||||
/**
|
||||
* Wraps the legacy com.mysql.jdbc.SocketFactory implementations so they can be used as {@link SocketFactory}
|
||||
*/
|
||||
public class SocketFactoryWrapper extends StandardSocketFactory implements SocketFactory {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
com.mysql.jdbc.SocketFactory socketFactory;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public SocketFactoryWrapper(Object legacyFactory) {
|
||||
this.socketFactory = (com.mysql.jdbc.SocketFactory) legacyFactory;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@Override
|
||||
public <T extends Closeable> T connect(String hostname, int portNumber, PropertySet pset, int loginTimeout) throws IOException {
|
||||
this.rawSocket = this.socketFactory.connect(hostname, portNumber, pset.exposeAsProperties());
|
||||
return (T) this.rawSocket;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T extends Closeable> T performTlsHandshake(SocketConnection socketConnection, ServerSession serverSession, Log log) throws IOException {
|
||||
return (T) super.performTlsHandshake(socketConnection, serverSession, log);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void beforeHandshake() throws IOException {
|
||||
this.socketFactory.beforeHandshake();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void afterHandshake() throws IOException {
|
||||
this.socketFactory.afterHandshake();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.mysql.cj.protocol.Message;
|
||||
import com.mysql.cj.result.Field;
|
||||
|
||||
public interface BindValue {
|
||||
|
||||
BindValue clone();
|
||||
|
||||
void reset();
|
||||
|
||||
boolean isNull();
|
||||
|
||||
void setNull(boolean isNull);
|
||||
|
||||
boolean isStream();
|
||||
|
||||
MysqlType getMysqlType();
|
||||
|
||||
void setMysqlType(MysqlType type);
|
||||
|
||||
byte[] getByteValue();
|
||||
|
||||
boolean isSet();
|
||||
|
||||
void setBinding(Object obj, MysqlType type, int numberOfExecutions, AtomicBoolean sendTypesToServer);
|
||||
|
||||
Calendar getCalendar();
|
||||
|
||||
void setCalendar(Calendar cal);
|
||||
|
||||
boolean escapeBytesIfNeeded();
|
||||
|
||||
void setEscapeBytesIfNeeded(boolean val);
|
||||
|
||||
Object getValue();
|
||||
|
||||
boolean isNational();
|
||||
|
||||
void setIsNational(boolean isNational);
|
||||
|
||||
int getFieldType();
|
||||
|
||||
/**
|
||||
* Gets the length of this bind value in the text protocol representation.
|
||||
*
|
||||
* @return
|
||||
* the expected length, in bytes, of this bind value after being encoded.
|
||||
*/
|
||||
long getTextLength();
|
||||
|
||||
/**
|
||||
* Gets the length of this bind value in the binary protocol representation.
|
||||
*
|
||||
* @return
|
||||
* the expected length, in bytes, of this bind value after being encoded.
|
||||
*/
|
||||
long getBinaryLength();
|
||||
|
||||
long getBoundBeforeExecutionNum();
|
||||
|
||||
/**
|
||||
* Get a String representation of the value.
|
||||
*
|
||||
* @return value as a String
|
||||
*/
|
||||
String getString();
|
||||
|
||||
Field getField();
|
||||
|
||||
void setField(Field field);
|
||||
|
||||
boolean keepOrigNanos();
|
||||
|
||||
/**
|
||||
* Should the value keep original fractional seconds ignoring sendFractionalSeconds and sendFractionalSecondsForTime?
|
||||
* <p>
|
||||
* <i>If the value is a part of key for UpdatableResultSet updater, it should keep original milliseconds.</i>
|
||||
* </p>
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
void setKeepOrigNanos(boolean value);
|
||||
|
||||
void setScaleOrLength(long scaleOrLength);
|
||||
|
||||
long getScaleOrLength();
|
||||
|
||||
/**
|
||||
* Gets the name of this query attribute.
|
||||
*
|
||||
* @return
|
||||
* the name of this query attribute.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
void writeAsText(Message intoMessage);
|
||||
|
||||
void writeAsBinary(Message intoMessage);
|
||||
|
||||
void writeAsQueryAttribute(Message intoMessage);
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface CacheAdapter<K, V> {
|
||||
V get(K key);
|
||||
|
||||
void put(K key, V value);
|
||||
|
||||
void invalidate(K key);
|
||||
|
||||
void invalidateAll(Set<K> keys);
|
||||
|
||||
void invalidateAll();
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
public interface CacheAdapterFactory<K, V> {
|
||||
|
||||
CacheAdapter<K, V> getInstance(Object syncMutex, String url, int cacheMaxSize, int maxKeySize);
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
public interface CancelQueryTask {
|
||||
|
||||
boolean cancel();
|
||||
|
||||
Throwable getCaughtWhileCancelling();
|
||||
|
||||
void setCaughtWhileCancelling(Throwable caughtWhileCancelling);
|
||||
|
||||
Query getQueryToCancel();
|
||||
|
||||
void setQueryToCancel(Query queryToCancel);
|
||||
|
||||
}
|
|
@ -0,0 +1,820 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Mapping between MySQL charset names and Java charset names. I've investigated placing these in a .properties file, but unfortunately under most appservers
|
||||
* this complicates configuration because the security policy needs to be changed by the user to allow the driver to read them :(
|
||||
*/
|
||||
public class CharsetMapping {
|
||||
|
||||
public static final int MAP_SIZE = 1024; // Size of static maps
|
||||
private static final String[] COLLATION_INDEX_TO_COLLATION_NAME;
|
||||
private static final Map<Integer, MysqlCharset> COLLATION_INDEX_TO_CHARSET;
|
||||
|
||||
private static final Map<String, MysqlCharset> CHARSET_NAME_TO_CHARSET;
|
||||
private static final Map<String, Integer> CHARSET_NAME_TO_COLLATION_INDEX;
|
||||
private static final Map<String, Integer> COLLATION_NAME_TO_COLLATION_INDEX;
|
||||
|
||||
private static final Map<String, List<MysqlCharset>> JAVA_ENCODING_UC_TO_MYSQL_CHARSET;
|
||||
|
||||
private static final Set<String> MULTIBYTE_ENCODINGS;
|
||||
|
||||
/**
|
||||
* Indexes of collations using ucs2, utf16, utf16le or utf32 character sets and that cannot be set to character_set_client system variable.
|
||||
*/
|
||||
private static final Set<Integer> IMPERMISSIBLE_INDEXES;
|
||||
|
||||
public static final String MYSQL_CHARSET_NAME_armscii8 = "armscii8";
|
||||
public static final String MYSQL_CHARSET_NAME_ascii = "ascii";
|
||||
public static final String MYSQL_CHARSET_NAME_big5 = "big5";
|
||||
public static final String MYSQL_CHARSET_NAME_binary = "binary";
|
||||
public static final String MYSQL_CHARSET_NAME_cp1250 = "cp1250";
|
||||
public static final String MYSQL_CHARSET_NAME_cp1251 = "cp1251";
|
||||
public static final String MYSQL_CHARSET_NAME_cp1256 = "cp1256";
|
||||
public static final String MYSQL_CHARSET_NAME_cp1257 = "cp1257";
|
||||
public static final String MYSQL_CHARSET_NAME_cp850 = "cp850";
|
||||
public static final String MYSQL_CHARSET_NAME_cp852 = "cp852";
|
||||
public static final String MYSQL_CHARSET_NAME_cp866 = "cp866";
|
||||
public static final String MYSQL_CHARSET_NAME_cp932 = "cp932";
|
||||
public static final String MYSQL_CHARSET_NAME_dec8 = "dec8";
|
||||
public static final String MYSQL_CHARSET_NAME_eucjpms = "eucjpms";
|
||||
public static final String MYSQL_CHARSET_NAME_euckr = "euckr";
|
||||
public static final String MYSQL_CHARSET_NAME_gb18030 = "gb18030";
|
||||
public static final String MYSQL_CHARSET_NAME_gb2312 = "gb2312";
|
||||
public static final String MYSQL_CHARSET_NAME_gbk = "gbk";
|
||||
public static final String MYSQL_CHARSET_NAME_geostd8 = "geostd8";
|
||||
public static final String MYSQL_CHARSET_NAME_greek = "greek";
|
||||
public static final String MYSQL_CHARSET_NAME_hebrew = "hebrew";
|
||||
public static final String MYSQL_CHARSET_NAME_hp8 = "hp8";
|
||||
public static final String MYSQL_CHARSET_NAME_keybcs2 = "keybcs2";
|
||||
public static final String MYSQL_CHARSET_NAME_koi8r = "koi8r";
|
||||
public static final String MYSQL_CHARSET_NAME_koi8u = "koi8u";
|
||||
public static final String MYSQL_CHARSET_NAME_latin1 = "latin1";
|
||||
public static final String MYSQL_CHARSET_NAME_latin2 = "latin2";
|
||||
public static final String MYSQL_CHARSET_NAME_latin5 = "latin5";
|
||||
public static final String MYSQL_CHARSET_NAME_latin7 = "latin7";
|
||||
public static final String MYSQL_CHARSET_NAME_macce = "macce";
|
||||
public static final String MYSQL_CHARSET_NAME_macroman = "macroman";
|
||||
public static final String MYSQL_CHARSET_NAME_sjis = "sjis";
|
||||
public static final String MYSQL_CHARSET_NAME_swe7 = "swe7";
|
||||
public static final String MYSQL_CHARSET_NAME_tis620 = "tis620";
|
||||
public static final String MYSQL_CHARSET_NAME_ucs2 = "ucs2";
|
||||
public static final String MYSQL_CHARSET_NAME_ujis = "ujis";
|
||||
public static final String MYSQL_CHARSET_NAME_utf16 = "utf16";
|
||||
public static final String MYSQL_CHARSET_NAME_utf16le = "utf16le";
|
||||
public static final String MYSQL_CHARSET_NAME_utf32 = "utf32";
|
||||
public static final String MYSQL_CHARSET_NAME_utf8 = "utf8";
|
||||
public static final String MYSQL_CHARSET_NAME_utf8mb3 = "utf8mb3";
|
||||
public static final String MYSQL_CHARSET_NAME_utf8mb4 = "utf8mb4";
|
||||
|
||||
public static final int MYSQL_COLLATION_INDEX_utf8mb4_general_ci = 45;
|
||||
public static final int MYSQL_COLLATION_INDEX_utf8mb4_0900_ai_ci = 255;
|
||||
public static final int MYSQL_COLLATION_INDEX_binary = 63;
|
||||
|
||||
static {
|
||||
// complete list of mysql character sets and their corresponding java encoding names
|
||||
MysqlCharset[] charset = new MysqlCharset[] { new MysqlCharset(MYSQL_CHARSET_NAME_ascii, 1, 0, new String[] { "US-ASCII", "ASCII" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_big5, 2, 0, new String[] { "Big5" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_gbk, 2, 0, new String[] { "GBK" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_sjis, 2, 0, new String[] { "SHIFT_JIS", "Cp943", "WINDOWS-31J" }), // SJIS is alias for SHIFT_JIS, Cp943 is rather a cp932 but we map it to sjis for years
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_cp932, 2, 1, new String[] { "WINDOWS-31J" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_gb2312, 2, 0, new String[] { "GB2312" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_ujis, 3, 0, new String[] { "EUC_JP" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_eucjpms, 3, 0, new String[] { "EUC_JP_Solaris" }, new ServerVersion(5, 0, 3)),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_gb18030, 4, 0, new String[] { "GB18030" }, new ServerVersion(5, 7, 4)),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_euckr, 2, 0, new String[] { "EUC-KR" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_latin1, 1, 1, new String[] { "Cp1252", "ISO8859_1" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_swe7, 1, 0, new String[] { "Cp1252" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_hp8, 1, 0, new String[] { "Cp1252" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_dec8, 1, 0, new String[] { "Cp1252" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_armscii8, 1, 0, new String[] { "Cp1252" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_geostd8, 1, 0, new String[] { "Cp1252" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_latin2, 1, 0, new String[] { "ISO8859_2" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_greek, 1, 0, new String[] { "ISO8859_7", "greek" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_latin7, 1, 0, new String[] { "ISO-8859-13" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_hebrew, 1, 0, new String[] { "ISO8859_8" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_latin5, 1, 0, new String[] { "ISO8859_9" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_cp850, 1, 0, new String[] { "Cp850", "Cp437" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_cp852, 1, 0, new String[] { "Cp852" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_keybcs2, 1, 0, new String[] { "Cp852" }), // Kamenicky encoding usually known as Cp895 but there is no official cp895 specification; close to Cp852, see http://ftp.muni.cz/pub/localization/charsets/cs-encodings-faq
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_cp866, 1, 0, new String[] { "Cp866" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_koi8r, 1, 1, new String[] { "KOI8_R" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_koi8u, 1, 0, new String[] { "KOI8_R" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_tis620, 1, 0, new String[] { "TIS620" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_cp1250, 1, 0, new String[] { "Cp1250" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_cp1251, 1, 1, new String[] { "Cp1251" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_cp1256, 1, 0, new String[] { "Cp1256" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_cp1257, 1, 0, new String[] { "Cp1257" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_macroman, 1, 0, new String[] { "MacRoman" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_macce, 1, 0, new String[] { "MacCentralEurope" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_utf8mb3, 3, 0, new String[] { "UTF-8" }, new String[] { MYSQL_CHARSET_NAME_utf8 }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_utf8mb4, 4, 1, new String[] { "UTF-8" }), // "UTF-8 = *> 5.5.2 utf8mb4"
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_binary, 1, 1, new String[] { "ISO8859_1" }),
|
||||
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_ucs2, 2, 0, new String[] { "UnicodeBig" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_utf16, 4, 0, new String[] { "UTF-16" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_utf16le, 4, 0, new String[] { "UTF-16LE" }),
|
||||
new MysqlCharset(MYSQL_CHARSET_NAME_utf32, 4, 0, new String[] { "UTF-32" })
|
||||
|
||||
};
|
||||
HashMap<String, MysqlCharset> charsetNameToMysqlCharsetMap = new HashMap<>();
|
||||
HashMap<String, List<MysqlCharset>> javaUcToMysqlCharsetMap = new HashMap<>();
|
||||
Set<String> tempMultibyteEncodings = new HashSet<>();
|
||||
|
||||
for (int i = 0; i < charset.length; i++) {
|
||||
String charsetName = charset[i].charsetName;
|
||||
charsetNameToMysqlCharsetMap.put(charsetName, charset[i]);
|
||||
for (String alias : charset[i].aliases) {
|
||||
charsetNameToMysqlCharsetMap.put(alias, charset[i]);
|
||||
}
|
||||
|
||||
for (String encUC : charset[i].javaEncodingsUc) {
|
||||
List<MysqlCharset> charsets = javaUcToMysqlCharsetMap.get(encUC);
|
||||
if (charsets == null) {
|
||||
charsets = new ArrayList<>();
|
||||
javaUcToMysqlCharsetMap.put(encUC, charsets);
|
||||
}
|
||||
charsets.add(charset[i]);
|
||||
|
||||
if (charset[i].mblen > 1) {
|
||||
tempMultibyteEncodings.add(encUC);
|
||||
}
|
||||
}
|
||||
}
|
||||
CHARSET_NAME_TO_CHARSET = Collections.unmodifiableMap(charsetNameToMysqlCharsetMap);
|
||||
JAVA_ENCODING_UC_TO_MYSQL_CHARSET = Collections.unmodifiableMap(javaUcToMysqlCharsetMap);
|
||||
MULTIBYTE_ENCODINGS = Collections.unmodifiableSet(tempMultibyteEncodings);
|
||||
|
||||
// Complete list of MySQL collations and their corresponding character set.
|
||||
// Collations may have different default names in different MySQL versions, while the remaining are accepted as aliases.
|
||||
Collation[] collation = new Collation[MAP_SIZE];
|
||||
collation[1] = new Collation(1, "big5_chinese_ci", 1, MYSQL_CHARSET_NAME_big5);
|
||||
collation[2] = new Collation(2, "latin2_czech_cs", 0, MYSQL_CHARSET_NAME_latin2);
|
||||
collation[3] = new Collation(3, "dec8_swedish_ci", 0, MYSQL_CHARSET_NAME_dec8);
|
||||
collation[4] = new Collation(4, "cp850_general_ci", 1, MYSQL_CHARSET_NAME_cp850);
|
||||
collation[5] = new Collation(5, "latin1_german1_ci", 0, MYSQL_CHARSET_NAME_latin1);
|
||||
collation[6] = new Collation(6, "hp8_english_ci", 0, MYSQL_CHARSET_NAME_hp8);
|
||||
collation[7] = new Collation(7, "koi8r_general_ci", 0, MYSQL_CHARSET_NAME_koi8r);
|
||||
collation[8] = new Collation(8, "latin1_swedish_ci", 1, MYSQL_CHARSET_NAME_latin1);
|
||||
collation[9] = new Collation(9, "latin2_general_ci", 1, MYSQL_CHARSET_NAME_latin2);
|
||||
collation[10] = new Collation(10, "swe7_swedish_ci", 0, MYSQL_CHARSET_NAME_swe7);
|
||||
collation[11] = new Collation(11, "ascii_general_ci", 0, MYSQL_CHARSET_NAME_ascii);
|
||||
collation[12] = new Collation(12, "ujis_japanese_ci", 0, MYSQL_CHARSET_NAME_ujis);
|
||||
collation[13] = new Collation(13, "sjis_japanese_ci", 0, MYSQL_CHARSET_NAME_sjis);
|
||||
collation[14] = new Collation(14, "cp1251_bulgarian_ci", 0, MYSQL_CHARSET_NAME_cp1251);
|
||||
collation[15] = new Collation(15, "latin1_danish_ci", 0, MYSQL_CHARSET_NAME_latin1);
|
||||
collation[16] = new Collation(16, "hebrew_general_ci", 0, MYSQL_CHARSET_NAME_hebrew);
|
||||
// 17
|
||||
collation[18] = new Collation(18, "tis620_thai_ci", 0, MYSQL_CHARSET_NAME_tis620);
|
||||
collation[19] = new Collation(19, "euckr_korean_ci", 0, MYSQL_CHARSET_NAME_euckr);
|
||||
collation[20] = new Collation(20, "latin7_estonian_cs", 0, MYSQL_CHARSET_NAME_latin7);
|
||||
collation[21] = new Collation(21, "latin2_hungarian_ci", 0, MYSQL_CHARSET_NAME_latin2);
|
||||
collation[22] = new Collation(22, "koi8u_general_ci", 0, MYSQL_CHARSET_NAME_koi8u);
|
||||
collation[23] = new Collation(23, "cp1251_ukrainian_ci", 0, MYSQL_CHARSET_NAME_cp1251);
|
||||
collation[24] = new Collation(24, "gb2312_chinese_ci", 0, MYSQL_CHARSET_NAME_gb2312);
|
||||
collation[25] = new Collation(25, "greek_general_ci", 0, MYSQL_CHARSET_NAME_greek);
|
||||
collation[26] = new Collation(26, "cp1250_general_ci", 1, MYSQL_CHARSET_NAME_cp1250);
|
||||
collation[27] = new Collation(27, "latin2_croatian_ci", 0, MYSQL_CHARSET_NAME_latin2);
|
||||
collation[28] = new Collation(28, "gbk_chinese_ci", 1, MYSQL_CHARSET_NAME_gbk);
|
||||
collation[29] = new Collation(29, "cp1257_lithuanian_ci", 0, MYSQL_CHARSET_NAME_cp1257);
|
||||
collation[30] = new Collation(30, "latin5_turkish_ci", 1, MYSQL_CHARSET_NAME_latin5);
|
||||
collation[31] = new Collation(31, "latin1_german2_ci", 0, MYSQL_CHARSET_NAME_latin1);
|
||||
collation[32] = new Collation(32, "armscii8_general_ci", 0, MYSQL_CHARSET_NAME_armscii8);
|
||||
collation[33] = new Collation(33, new String[] { "utf8mb3_general_ci", "utf8_general_ci" }, 1, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[34] = new Collation(34, "cp1250_czech_cs", 0, MYSQL_CHARSET_NAME_cp1250);
|
||||
collation[35] = new Collation(35, "ucs2_general_ci", 1, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[36] = new Collation(36, "cp866_general_ci", 1, MYSQL_CHARSET_NAME_cp866);
|
||||
collation[37] = new Collation(37, "keybcs2_general_ci", 1, MYSQL_CHARSET_NAME_keybcs2);
|
||||
collation[38] = new Collation(38, "macce_general_ci", 1, MYSQL_CHARSET_NAME_macce);
|
||||
collation[39] = new Collation(39, "macroman_general_ci", 1, MYSQL_CHARSET_NAME_macroman);
|
||||
collation[40] = new Collation(40, "cp852_general_ci", 1, MYSQL_CHARSET_NAME_cp852);
|
||||
collation[41] = new Collation(41, "latin7_general_ci", 1, MYSQL_CHARSET_NAME_latin7);
|
||||
collation[42] = new Collation(42, "latin7_general_cs", 0, MYSQL_CHARSET_NAME_latin7);
|
||||
collation[43] = new Collation(43, "macce_bin", 0, MYSQL_CHARSET_NAME_macce);
|
||||
collation[44] = new Collation(44, "cp1250_croatian_ci", 0, MYSQL_CHARSET_NAME_cp1250);
|
||||
collation[45] = new Collation(45, "utf8mb4_general_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[46] = new Collation(46, "utf8mb4_bin", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[47] = new Collation(47, "latin1_bin", 0, MYSQL_CHARSET_NAME_latin1);
|
||||
collation[48] = new Collation(48, "latin1_general_ci", 0, MYSQL_CHARSET_NAME_latin1);
|
||||
collation[49] = new Collation(49, "latin1_general_cs", 0, MYSQL_CHARSET_NAME_latin1);
|
||||
collation[50] = new Collation(50, "cp1251_bin", 0, MYSQL_CHARSET_NAME_cp1251);
|
||||
collation[51] = new Collation(51, "cp1251_general_ci", 1, MYSQL_CHARSET_NAME_cp1251);
|
||||
collation[52] = new Collation(52, "cp1251_general_cs", 0, MYSQL_CHARSET_NAME_cp1251);
|
||||
collation[53] = new Collation(53, "macroman_bin", 0, MYSQL_CHARSET_NAME_macroman);
|
||||
collation[54] = new Collation(54, "utf16_general_ci", 1, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[55] = new Collation(55, "utf16_bin", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[56] = new Collation(56, "utf16le_general_ci", 1, MYSQL_CHARSET_NAME_utf16le);
|
||||
collation[57] = new Collation(57, "cp1256_general_ci", 1, MYSQL_CHARSET_NAME_cp1256);
|
||||
collation[58] = new Collation(58, "cp1257_bin", 0, MYSQL_CHARSET_NAME_cp1257);
|
||||
collation[59] = new Collation(59, "cp1257_general_ci", 1, MYSQL_CHARSET_NAME_cp1257);
|
||||
collation[60] = new Collation(60, "utf32_general_ci", 1, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[61] = new Collation(61, "utf32_bin", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[62] = new Collation(62, "utf16le_bin", 0, MYSQL_CHARSET_NAME_utf16le);
|
||||
collation[63] = new Collation(63, "binary", 1, MYSQL_CHARSET_NAME_binary);
|
||||
collation[64] = new Collation(64, "armscii8_bin", 0, MYSQL_CHARSET_NAME_armscii8);
|
||||
collation[65] = new Collation(65, "ascii_bin", 0, MYSQL_CHARSET_NAME_ascii);
|
||||
collation[66] = new Collation(66, "cp1250_bin", 0, MYSQL_CHARSET_NAME_cp1250);
|
||||
collation[67] = new Collation(67, "cp1256_bin", 0, MYSQL_CHARSET_NAME_cp1256);
|
||||
collation[68] = new Collation(68, "cp866_bin", 0, MYSQL_CHARSET_NAME_cp866);
|
||||
collation[69] = new Collation(69, "dec8_bin", 0, MYSQL_CHARSET_NAME_dec8);
|
||||
collation[70] = new Collation(70, "greek_bin", 0, MYSQL_CHARSET_NAME_greek);
|
||||
collation[71] = new Collation(71, "hebrew_bin", 0, MYSQL_CHARSET_NAME_hebrew);
|
||||
collation[72] = new Collation(72, "hp8_bin", 0, MYSQL_CHARSET_NAME_hp8);
|
||||
collation[73] = new Collation(73, "keybcs2_bin", 0, MYSQL_CHARSET_NAME_keybcs2);
|
||||
collation[74] = new Collation(74, "koi8r_bin", 0, MYSQL_CHARSET_NAME_koi8r);
|
||||
collation[75] = new Collation(75, "koi8u_bin", 0, MYSQL_CHARSET_NAME_koi8u);
|
||||
collation[76] = new Collation(76, new String[] { "utf8mb3_tolower_ci", "utf8_tolower_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[77] = new Collation(77, "latin2_bin", 0, MYSQL_CHARSET_NAME_latin2);
|
||||
collation[78] = new Collation(78, "latin5_bin", 0, MYSQL_CHARSET_NAME_latin5);
|
||||
collation[79] = new Collation(79, "latin7_bin", 0, MYSQL_CHARSET_NAME_latin7);
|
||||
collation[80] = new Collation(80, "cp850_bin", 0, MYSQL_CHARSET_NAME_cp850);
|
||||
collation[81] = new Collation(81, "cp852_bin", 0, MYSQL_CHARSET_NAME_cp852);
|
||||
collation[82] = new Collation(82, "swe7_bin", 0, MYSQL_CHARSET_NAME_swe7);
|
||||
collation[83] = new Collation(83, new String[] { "utf8mb3_bin", "utf8_bin" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[84] = new Collation(84, "big5_bin", 0, MYSQL_CHARSET_NAME_big5);
|
||||
collation[85] = new Collation(85, "euckr_bin", 0, MYSQL_CHARSET_NAME_euckr);
|
||||
collation[86] = new Collation(86, "gb2312_bin", 0, MYSQL_CHARSET_NAME_gb2312);
|
||||
collation[87] = new Collation(87, "gbk_bin", 0, MYSQL_CHARSET_NAME_gbk);
|
||||
collation[88] = new Collation(88, "sjis_bin", 0, MYSQL_CHARSET_NAME_sjis);
|
||||
collation[89] = new Collation(89, "tis620_bin", 0, MYSQL_CHARSET_NAME_tis620);
|
||||
collation[90] = new Collation(90, "ucs2_bin", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[91] = new Collation(91, "ujis_bin", 0, MYSQL_CHARSET_NAME_ujis);
|
||||
collation[92] = new Collation(92, "geostd8_general_ci", 0, MYSQL_CHARSET_NAME_geostd8);
|
||||
collation[93] = new Collation(93, "geostd8_bin", 0, MYSQL_CHARSET_NAME_geostd8);
|
||||
collation[94] = new Collation(94, "latin1_spanish_ci", 0, MYSQL_CHARSET_NAME_latin1);
|
||||
collation[95] = new Collation(95, "cp932_japanese_ci", 1, MYSQL_CHARSET_NAME_cp932);
|
||||
collation[96] = new Collation(96, "cp932_bin", 0, MYSQL_CHARSET_NAME_cp932);
|
||||
collation[97] = new Collation(97, "eucjpms_japanese_ci", 1, MYSQL_CHARSET_NAME_eucjpms);
|
||||
collation[98] = new Collation(98, "eucjpms_bin", 0, MYSQL_CHARSET_NAME_eucjpms);
|
||||
collation[99] = new Collation(99, "cp1250_polish_ci", 0, MYSQL_CHARSET_NAME_cp1250);
|
||||
// 100
|
||||
collation[101] = new Collation(101, "utf16_unicode_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[102] = new Collation(102, "utf16_icelandic_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[103] = new Collation(103, "utf16_latvian_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[104] = new Collation(104, "utf16_romanian_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[105] = new Collation(105, "utf16_slovenian_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[106] = new Collation(106, "utf16_polish_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[107] = new Collation(107, "utf16_estonian_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[108] = new Collation(108, "utf16_spanish_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[109] = new Collation(109, "utf16_swedish_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[110] = new Collation(110, "utf16_turkish_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[111] = new Collation(111, "utf16_czech_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[112] = new Collation(112, "utf16_danish_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[113] = new Collation(113, "utf16_lithuanian_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[114] = new Collation(114, "utf16_slovak_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[115] = new Collation(115, "utf16_spanish2_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[116] = new Collation(116, "utf16_roman_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[117] = new Collation(117, "utf16_persian_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[118] = new Collation(118, "utf16_esperanto_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[119] = new Collation(119, "utf16_hungarian_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[120] = new Collation(120, "utf16_sinhala_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[121] = new Collation(121, "utf16_german2_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[122] = new Collation(122, "utf16_croatian_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[123] = new Collation(123, "utf16_unicode_520_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
collation[124] = new Collation(124, "utf16_vietnamese_ci", 0, MYSQL_CHARSET_NAME_utf16);
|
||||
// 125..127
|
||||
collation[128] = new Collation(128, "ucs2_unicode_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[129] = new Collation(129, "ucs2_icelandic_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[130] = new Collation(130, "ucs2_latvian_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[131] = new Collation(131, "ucs2_romanian_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[132] = new Collation(132, "ucs2_slovenian_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[133] = new Collation(133, "ucs2_polish_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[134] = new Collation(134, "ucs2_estonian_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[135] = new Collation(135, "ucs2_spanish_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[136] = new Collation(136, "ucs2_swedish_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[137] = new Collation(137, "ucs2_turkish_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[138] = new Collation(138, "ucs2_czech_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[139] = new Collation(139, "ucs2_danish_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[140] = new Collation(140, "ucs2_lithuanian_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[141] = new Collation(141, "ucs2_slovak_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[142] = new Collation(142, "ucs2_spanish2_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[143] = new Collation(143, "ucs2_roman_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[144] = new Collation(144, "ucs2_persian_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[145] = new Collation(145, "ucs2_esperanto_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[146] = new Collation(146, "ucs2_hungarian_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[147] = new Collation(147, "ucs2_sinhala_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[148] = new Collation(148, "ucs2_german2_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[149] = new Collation(149, "ucs2_croatian_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[150] = new Collation(150, "ucs2_unicode_520_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[151] = new Collation(151, "ucs2_vietnamese_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
// 152..158
|
||||
collation[159] = new Collation(159, "ucs2_general_mysql500_ci", 0, MYSQL_CHARSET_NAME_ucs2);
|
||||
collation[160] = new Collation(160, "utf32_unicode_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[161] = new Collation(161, "utf32_icelandic_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[162] = new Collation(162, "utf32_latvian_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[163] = new Collation(163, "utf32_romanian_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[164] = new Collation(164, "utf32_slovenian_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[165] = new Collation(165, "utf32_polish_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[166] = new Collation(166, "utf32_estonian_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[167] = new Collation(167, "utf32_spanish_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[168] = new Collation(168, "utf32_swedish_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[169] = new Collation(169, "utf32_turkish_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[170] = new Collation(170, "utf32_czech_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[171] = new Collation(171, "utf32_danish_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[172] = new Collation(172, "utf32_lithuanian_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[173] = new Collation(173, "utf32_slovak_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[174] = new Collation(174, "utf32_spanish2_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[175] = new Collation(175, "utf32_roman_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[176] = new Collation(176, "utf32_persian_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[177] = new Collation(177, "utf32_esperanto_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[178] = new Collation(178, "utf32_hungarian_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[179] = new Collation(179, "utf32_sinhala_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[180] = new Collation(180, "utf32_german2_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[181] = new Collation(181, "utf32_croatian_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[182] = new Collation(182, "utf32_unicode_520_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
collation[183] = new Collation(183, "utf32_vietnamese_ci", 0, MYSQL_CHARSET_NAME_utf32);
|
||||
// 184..191
|
||||
collation[192] = new Collation(192, new String[] { "utf8mb3_unicode_ci", "utf8_unicode_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[193] = new Collation(193, new String[] { "utf8mb3_icelandic_ci", "utf8_icelandic_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[194] = new Collation(194, new String[] { "utf8mb3_latvian_ci", "utf8_latvian_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[195] = new Collation(195, new String[] { "utf8mb3_romanian_ci", "utf8_romanian_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[196] = new Collation(196, new String[] { "utf8mb3_slovenian_ci", "utf8_slovenian_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[197] = new Collation(197, new String[] { "utf8mb3_polish_ci", "utf8_polish_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[198] = new Collation(198, new String[] { "utf8mb3_estonian_ci", "utf8_estonian_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[199] = new Collation(199, new String[] { "utf8mb3_spanish_ci", "utf8_spanish_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[200] = new Collation(200, new String[] { "utf8mb3_swedish_ci", "utf8_swedish_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[201] = new Collation(201, new String[] { "utf8mb3_turkish_ci", "utf8_turkish_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[202] = new Collation(202, new String[] { "utf8mb3_czech_ci", "utf8_czech_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[203] = new Collation(203, new String[] { "utf8mb3_danish_ci", "utf8_danish_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[204] = new Collation(204, new String[] { "utf8mb3_lithuanian_ci", "utf8_lithuanian_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[205] = new Collation(205, new String[] { "utf8mb3_slovak_ci", "utf8_slovak_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[206] = new Collation(206, new String[] { "utf8mb3_spanish2_ci", "utf8_spanish2_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[207] = new Collation(207, new String[] { "utf8mb3_roman_ci", "utf8_roman_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[208] = new Collation(208, new String[] { "utf8mb3_persian_ci", "utf8_persian_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[209] = new Collation(209, new String[] { "utf8mb3_esperanto_ci", "utf8_esperanto_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[210] = new Collation(210, new String[] { "utf8mb3_hungarian_ci", "utf8_hungarian_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[211] = new Collation(211, new String[] { "utf8mb3_sinhala_ci", "utf8_sinhala_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[212] = new Collation(212, new String[] { "utf8mb3_german2_ci", "utf8_german2_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[213] = new Collation(213, new String[] { "utf8mb3_croatian_ci", "utf8_croatian_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[214] = new Collation(214, new String[] { "utf8mb3_unicode_520_ci", "utf8_unicode_520_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[215] = new Collation(215, new String[] { "utf8mb3_vietnamese_ci", "utf8_vietnamese_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
// 216..222
|
||||
collation[223] = new Collation(223, new String[] { "utf8mb3_general_mysql500_ci", "utf8_general_mysql500_ci" }, 0, MYSQL_CHARSET_NAME_utf8mb3);
|
||||
collation[224] = new Collation(224, "utf8mb4_unicode_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[225] = new Collation(225, "utf8mb4_icelandic_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[226] = new Collation(226, "utf8mb4_latvian_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[227] = new Collation(227, "utf8mb4_romanian_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[228] = new Collation(228, "utf8mb4_slovenian_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[229] = new Collation(229, "utf8mb4_polish_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[230] = new Collation(230, "utf8mb4_estonian_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[231] = new Collation(231, "utf8mb4_spanish_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[232] = new Collation(232, "utf8mb4_swedish_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[233] = new Collation(233, "utf8mb4_turkish_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[234] = new Collation(234, "utf8mb4_czech_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[235] = new Collation(235, "utf8mb4_danish_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[236] = new Collation(236, "utf8mb4_lithuanian_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[237] = new Collation(237, "utf8mb4_slovak_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[238] = new Collation(238, "utf8mb4_spanish2_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[239] = new Collation(239, "utf8mb4_roman_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[240] = new Collation(240, "utf8mb4_persian_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[241] = new Collation(241, "utf8mb4_esperanto_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[242] = new Collation(242, "utf8mb4_hungarian_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[243] = new Collation(243, "utf8mb4_sinhala_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[244] = new Collation(244, "utf8mb4_german2_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[245] = new Collation(245, "utf8mb4_croatian_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[246] = new Collation(246, "utf8mb4_unicode_520_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[247] = new Collation(247, "utf8mb4_vietnamese_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[248] = new Collation(248, "gb18030_chinese_ci", 1, MYSQL_CHARSET_NAME_gb18030);
|
||||
collation[249] = new Collation(249, "gb18030_bin", 0, MYSQL_CHARSET_NAME_gb18030);
|
||||
collation[250] = new Collation(250, "gb18030_unicode_520_ci", 0, MYSQL_CHARSET_NAME_gb18030);
|
||||
// 251..254
|
||||
collation[255] = new Collation(255, "utf8mb4_0900_ai_ci", 1, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[256] = new Collation(256, "utf8mb4_de_pb_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[257] = new Collation(257, "utf8mb4_is_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[258] = new Collation(258, "utf8mb4_lv_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[259] = new Collation(259, "utf8mb4_ro_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[260] = new Collation(260, "utf8mb4_sl_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[261] = new Collation(261, "utf8mb4_pl_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[262] = new Collation(262, "utf8mb4_et_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[263] = new Collation(263, "utf8mb4_es_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[264] = new Collation(264, "utf8mb4_sv_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[265] = new Collation(265, "utf8mb4_tr_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[266] = new Collation(266, "utf8mb4_cs_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[267] = new Collation(267, "utf8mb4_da_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[268] = new Collation(268, "utf8mb4_lt_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[269] = new Collation(269, "utf8mb4_sk_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[270] = new Collation(270, "utf8mb4_es_trad_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[271] = new Collation(271, "utf8mb4_la_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
// 272
|
||||
collation[273] = new Collation(273, "utf8mb4_eo_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[274] = new Collation(274, "utf8mb4_hu_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[275] = new Collation(275, "utf8mb4_hr_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
// 276
|
||||
collation[277] = new Collation(277, "utf8mb4_vi_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[278] = new Collation(278, "utf8mb4_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[279] = new Collation(279, "utf8mb4_de_pb_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[280] = new Collation(280, "utf8mb4_is_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[281] = new Collation(281, "utf8mb4_lv_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[282] = new Collation(282, "utf8mb4_ro_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[283] = new Collation(283, "utf8mb4_sl_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[284] = new Collation(284, "utf8mb4_pl_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[285] = new Collation(285, "utf8mb4_et_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[286] = new Collation(286, "utf8mb4_es_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[287] = new Collation(287, "utf8mb4_sv_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[288] = new Collation(288, "utf8mb4_tr_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[289] = new Collation(289, "utf8mb4_cs_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[290] = new Collation(290, "utf8mb4_da_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[291] = new Collation(291, "utf8mb4_lt_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[292] = new Collation(292, "utf8mb4_sk_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[293] = new Collation(293, "utf8mb4_es_trad_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[294] = new Collation(294, "utf8mb4_la_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
// 295
|
||||
collation[296] = new Collation(296, "utf8mb4_eo_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[297] = new Collation(297, "utf8mb4_hu_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[298] = new Collation(298, "utf8mb4_hr_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
// 299
|
||||
collation[300] = new Collation(300, "utf8mb4_vi_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
// 301,302
|
||||
collation[303] = new Collation(303, "utf8mb4_ja_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[304] = new Collation(304, "utf8mb4_ja_0900_as_cs_ks", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[305] = new Collation(305, "utf8mb4_0900_as_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[306] = new Collation(306, "utf8mb4_ru_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[307] = new Collation(307, "utf8mb4_ru_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[308] = new Collation(308, "utf8mb4_zh_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[309] = new Collation(309, "utf8mb4_0900_bin", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[310] = new Collation(310, "utf8mb4_nb_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[311] = new Collation(311, "utf8mb4_nb_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[312] = new Collation(312, "utf8mb4_nn_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[313] = new Collation(313, "utf8mb4_nn_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[314] = new Collation(314, "utf8mb4_sr_latn_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[315] = new Collation(315, "utf8mb4_sr_latn_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[316] = new Collation(316, "utf8mb4_bs_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[317] = new Collation(317, "utf8mb4_bs_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[318] = new Collation(318, "utf8mb4_bg_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[319] = new Collation(319, "utf8mb4_bg_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[320] = new Collation(320, "utf8mb4_gl_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[321] = new Collation(321, "utf8mb4_gl_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[322] = new Collation(322, "utf8mb4_mn_cyrl_0900_ai_ci", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
collation[323] = new Collation(323, "utf8mb4_mn_cyrl_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
|
||||
COLLATION_INDEX_TO_COLLATION_NAME = new String[MAP_SIZE];
|
||||
Map<Integer, MysqlCharset> collationIndexToCharset = new TreeMap<>();
|
||||
Map<String, Integer> charsetNameToCollationIndexMap = new TreeMap<>();
|
||||
Map<String, Integer> charsetNameToCollationPriorityMap = new TreeMap<>();
|
||||
Map<String, Integer> collationNameToCollationIndexMap = new TreeMap<>();
|
||||
Set<Integer> impermissibleIndexes = new HashSet<>();
|
||||
|
||||
for (int i = 1; i < MAP_SIZE; i++) {
|
||||
Collation coll = collation[i];
|
||||
if (coll != null) {
|
||||
COLLATION_INDEX_TO_COLLATION_NAME[i] = coll.collationNames[0];
|
||||
collationIndexToCharset.put(i, coll.mysqlCharset);
|
||||
for (String collationName : coll.collationNames) {
|
||||
collationNameToCollationIndexMap.put(collationName, i);
|
||||
}
|
||||
String charsetName = coll.mysqlCharset.charsetName;
|
||||
|
||||
if (!charsetNameToCollationIndexMap.containsKey(charsetName) || charsetNameToCollationPriorityMap.get(charsetName) < coll.priority) {
|
||||
charsetNameToCollationIndexMap.put(charsetName, i);
|
||||
charsetNameToCollationPriorityMap.put(charsetName, coll.priority);
|
||||
}
|
||||
|
||||
// Filling indexes of impermissible client character sets ucs2, utf16, utf16le, utf32
|
||||
if (charsetName.equals(MYSQL_CHARSET_NAME_ucs2) || charsetName.equals(MYSQL_CHARSET_NAME_utf16)
|
||||
|| charsetName.equals(MYSQL_CHARSET_NAME_utf16le) || charsetName.equals(MYSQL_CHARSET_NAME_utf32)) {
|
||||
impermissibleIndexes.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Integer idx;
|
||||
for (MysqlCharset cs : charset) {
|
||||
if (!cs.aliases.isEmpty() && (idx = charsetNameToCollationIndexMap.get(cs.charsetName)) != null) {
|
||||
for (String alias : cs.aliases) {
|
||||
charsetNameToCollationIndexMap.put(alias, idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
COLLATION_INDEX_TO_CHARSET = Collections.unmodifiableMap(collationIndexToCharset);
|
||||
CHARSET_NAME_TO_COLLATION_INDEX = Collections.unmodifiableMap(charsetNameToCollationIndexMap);
|
||||
COLLATION_NAME_TO_COLLATION_INDEX = Collections.unmodifiableMap(collationNameToCollationIndexMap);
|
||||
IMPERMISSIBLE_INDEXES = Collections.unmodifiableSet(impermissibleIndexes);
|
||||
|
||||
collation = null;
|
||||
}
|
||||
|
||||
protected static String getStaticMysqlCharsetForJavaEncoding(String javaEncoding, ServerVersion version) {
|
||||
List<MysqlCharset> mysqlCharsets = CharsetMapping.JAVA_ENCODING_UC_TO_MYSQL_CHARSET.get(javaEncoding.toUpperCase(Locale.ENGLISH));
|
||||
if (mysqlCharsets != null) {
|
||||
if (version == null) {
|
||||
return mysqlCharsets.get(0).charsetName; // Take the first one we get
|
||||
}
|
||||
MysqlCharset currentChoice = null;
|
||||
for (MysqlCharset charset : mysqlCharsets) {
|
||||
if (charset.isOkayForVersion(version) && (currentChoice == null || currentChoice.minimumVersion.compareTo(charset.minimumVersion) < 0
|
||||
|| currentChoice.priority < charset.priority && currentChoice.minimumVersion.compareTo(charset.minimumVersion) == 0)) {
|
||||
currentChoice = charset;
|
||||
}
|
||||
}
|
||||
if (currentChoice != null) {
|
||||
return currentChoice.charsetName;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static int getStaticCollationIndexForJavaEncoding(String javaEncoding, ServerVersion version) {
|
||||
String charsetName = getStaticMysqlCharsetForJavaEncoding(javaEncoding, version);
|
||||
return getStaticCollationIndexForMysqlCharsetName(charsetName);
|
||||
}
|
||||
|
||||
protected static int getStaticCollationIndexForMysqlCharsetName(String charsetName) {
|
||||
if (charsetName != null) {
|
||||
Integer ci = CHARSET_NAME_TO_COLLATION_INDEX.get(charsetName);
|
||||
if (ci != null) {
|
||||
return ci.intValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO turn it to protected when com.mysql.cj.xdevapi.ColumnImpl can use dynamic maps
|
||||
public static String getStaticMysqlCharsetNameForCollationIndex(Integer collationIndex) {
|
||||
MysqlCharset charset = null;
|
||||
if (collationIndex != null) {
|
||||
charset = COLLATION_INDEX_TO_CHARSET.get(collationIndex);
|
||||
}
|
||||
return charset != null ? charset.charsetName : null;
|
||||
}
|
||||
|
||||
// TODO turn it to protected when com.mysql.cj.xdevapi.ColumnImpl can use dynamic maps
|
||||
public static String getStaticCollationNameForCollationIndex(Integer collationIndex) {
|
||||
if (collationIndex != null && collationIndex > 0 && collationIndex < MAP_SIZE) {
|
||||
return COLLATION_INDEX_TO_COLLATION_NAME[collationIndex];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static Integer getStaticCollationIndexForCollationName(String collationName) {
|
||||
return CharsetMapping.COLLATION_NAME_TO_COLLATION_INDEX.get(collationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL charset could map to several Java encodings.
|
||||
* So here we choose the one according to next rules:
|
||||
* <ul>
|
||||
* <li>if there is no static mapping for this charset then return javaEncoding value as is because this
|
||||
* could be a custom charset for example
|
||||
* <li>if static mapping exists and javaEncoding equals to one of Java encoding canonical names or aliases available
|
||||
* for this mapping then javaEncoding value as is; this is required when result should match to connection encoding, for example if connection encoding is
|
||||
* Cp943 we must avoid getting SHIFT_JIS for sjis mysql charset
|
||||
* <li>if static mapping exists and javaEncoding doesn't match any Java encoding canonical
|
||||
* names or aliases available for this mapping then return default Java encoding (the first in mapping list)
|
||||
* </ul>
|
||||
*
|
||||
* @param mysqlCharsetName
|
||||
* MySQL charset name
|
||||
* @param fallbackJavaEncoding
|
||||
* fall-back java encoding name
|
||||
* @return java encoding name
|
||||
*/
|
||||
protected static String getStaticJavaEncodingForMysqlCharset(String mysqlCharsetName, String fallbackJavaEncoding) {
|
||||
MysqlCharset cs = getStaticMysqlCharsetByName(mysqlCharsetName);
|
||||
return cs != null ? cs.getMatchingJavaEncoding(fallbackJavaEncoding) : fallbackJavaEncoding;
|
||||
}
|
||||
|
||||
protected static MysqlCharset getStaticMysqlCharsetByName(String mysqlCharsetName) {
|
||||
return CHARSET_NAME_TO_CHARSET.get(mysqlCharsetName);
|
||||
}
|
||||
|
||||
protected static List<String> getStaticMysqlCharsetAliasesByName(String mysqlCharsetName) {
|
||||
MysqlCharset cs;
|
||||
if ((cs = CHARSET_NAME_TO_CHARSET.get(mysqlCharsetName)) != null) {
|
||||
return cs.aliases;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String getStaticJavaEncodingForMysqlCharset(String mysqlCharsetName) {
|
||||
return getStaticJavaEncodingForMysqlCharset(mysqlCharsetName, null);
|
||||
}
|
||||
|
||||
protected static String getStaticJavaEncodingForCollationIndex(Integer collationIndex, String fallbackJavaEncoding) {
|
||||
MysqlCharset charset = null;
|
||||
if (collationIndex != null) {
|
||||
charset = COLLATION_INDEX_TO_CHARSET.get(collationIndex);
|
||||
}
|
||||
return charset != null ? charset.getMatchingJavaEncoding(fallbackJavaEncoding) : fallbackJavaEncoding;
|
||||
}
|
||||
|
||||
// TODO turn it to protected when com.mysql.cj.protocol.x.FieldFactory can use dynamic maps
|
||||
public static String getStaticJavaEncodingForCollationIndex(Integer collationIndex) {
|
||||
return getStaticJavaEncodingForCollationIndex(collationIndex, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the character set contain multi-byte encoded characters.
|
||||
*
|
||||
* @param javaEncodingName
|
||||
* java encoding name
|
||||
* @return true if the character set contains multi-byte encoded characters.
|
||||
*/
|
||||
protected static boolean isStaticMultibyteCharset(String javaEncodingName) {
|
||||
return MULTIBYTE_ENCODINGS.contains(javaEncodingName.toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
protected static int getStaticMblen(String charsetName) {
|
||||
if (charsetName != null) {
|
||||
MysqlCharset cs = getStaticMysqlCharsetByName(charsetName);
|
||||
if (cs != null) {
|
||||
return cs.mblen;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected static boolean isStaticImpermissibleCollation(int collationIndex) {
|
||||
return CharsetMapping.IMPERMISSIBLE_INDEXES.contains(collationIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MysqlCharset {
|
||||
public final String charsetName;
|
||||
public final int mblen;
|
||||
public final int priority;
|
||||
public final List<String> javaEncodingsUc = new ArrayList<>();
|
||||
public final List<String> aliases = new ArrayList<>();
|
||||
|
||||
public final ServerVersion minimumVersion;
|
||||
|
||||
/**
|
||||
* Constructs MysqlCharset object
|
||||
*
|
||||
* @param charsetName
|
||||
* MySQL charset name
|
||||
* @param mblen
|
||||
* Max number of bytes per character
|
||||
* @param priority
|
||||
* MysqlCharset with highest value of this param will be used for Java encoding --> Mysql charsets conversion.
|
||||
* @param javaEncodings
|
||||
* List of Java encodings corresponding to this MySQL charset; the first name in list is the default for mysql --> java data conversion
|
||||
*/
|
||||
public MysqlCharset(String charsetName, int mblen, int priority, String[] javaEncodings) {
|
||||
this(charsetName, mblen, priority, javaEncodings, new ServerVersion(0, 0, 0));
|
||||
}
|
||||
|
||||
public MysqlCharset(String charsetName, int mblen, int priority, String[] javaEncodings, String[] charsetAliases) {
|
||||
this(charsetName, mblen, priority, javaEncodings, new ServerVersion(0, 0, 0));
|
||||
if (charsetAliases != null) {
|
||||
for (String alias : charsetAliases) {
|
||||
this.aliases.add(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addEncodingMapping(String encoding) {
|
||||
String encodingUc = encoding.toUpperCase(Locale.ENGLISH);
|
||||
|
||||
if (!this.javaEncodingsUc.contains(encodingUc)) {
|
||||
this.javaEncodingsUc.add(encodingUc);
|
||||
}
|
||||
}
|
||||
|
||||
public MysqlCharset(String charsetName, int mblen, int priority, String[] javaEncodings, ServerVersion minimumVersion) {
|
||||
this.charsetName = charsetName;
|
||||
this.mblen = mblen;
|
||||
this.priority = priority;
|
||||
|
||||
for (int i = 0; i < javaEncodings.length; i++) {
|
||||
String encoding = javaEncodings[i];
|
||||
try {
|
||||
Charset cs = Charset.forName(encoding);
|
||||
addEncodingMapping(cs.name());
|
||||
cs.aliases().forEach(this::addEncodingMapping);
|
||||
} catch (Exception e) {
|
||||
// if there is no support of this charset in JVM it's still possible to use our converter for 1-byte charsets
|
||||
if (mblen == 1) {
|
||||
addEncodingMapping(encoding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.javaEncodingsUc.size() == 0) {
|
||||
addEncodingMapping(mblen > 1 ? "UTF-8" : "Cp1252");
|
||||
}
|
||||
|
||||
this.minimumVersion = minimumVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder asString = new StringBuilder();
|
||||
asString.append("[");
|
||||
asString.append("charsetName=");
|
||||
asString.append(this.charsetName);
|
||||
asString.append(",mblen=");
|
||||
asString.append(this.mblen);
|
||||
// asString.append(",javaEncoding=");
|
||||
// asString.append(this.javaEncodings.toString());
|
||||
asString.append("]");
|
||||
return asString.toString();
|
||||
}
|
||||
|
||||
boolean isOkayForVersion(ServerVersion version) {
|
||||
return version.meetsMinimum(this.minimumVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* If javaEncoding parameter value is one of available java encodings for this charset
|
||||
* then returns javaEncoding value as is. Otherwise returns first available java encoding name.
|
||||
*
|
||||
* @param javaEncoding
|
||||
* java encoding name
|
||||
* @return java encoding name
|
||||
*/
|
||||
String getMatchingJavaEncoding(String javaEncoding) {
|
||||
if (javaEncoding != null && this.javaEncodingsUc.contains(javaEncoding.toUpperCase(Locale.ENGLISH))) {
|
||||
return javaEncoding;
|
||||
}
|
||||
return this.javaEncodingsUc.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
class Collation {
|
||||
public final int index;
|
||||
public final String[] collationNames;
|
||||
public final int priority;
|
||||
public final MysqlCharset mysqlCharset;
|
||||
|
||||
public Collation(int index, String collationName, int priority, String charsetName) {
|
||||
this(index, new String[] { collationName }, priority, charsetName);
|
||||
}
|
||||
|
||||
public Collation(int index, String[] collationNames, int priority, String charsetName) {
|
||||
this.index = index;
|
||||
this.collationNames = collationNames;
|
||||
this.priority = priority;
|
||||
this.mysqlCharset = CharsetMapping.getStaticMysqlCharsetByName(charsetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder asString = new StringBuilder();
|
||||
asString.append("[");
|
||||
asString.append("index=");
|
||||
asString.append(this.index);
|
||||
asString.append(",collationNames=");
|
||||
asString.append(Arrays.toString(this.collationNames));
|
||||
asString.append(",charsetName=");
|
||||
asString.append(this.mysqlCharset.charsetName);
|
||||
asString.append(",javaCharsetName=");
|
||||
asString.append(this.mysqlCharset.getMatchingJavaEncoding(null));
|
||||
asString.append("]");
|
||||
return asString.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
public interface CharsetSettings {
|
||||
|
||||
public static final String CHARACTER_SET_CLIENT = "character_set_client";
|
||||
public static final String CHARACTER_SET_CONNECTION = "character_set_connection";
|
||||
public static final String CHARACTER_SET_RESULTS = "character_set_results";
|
||||
public static final String COLLATION_CONNECTION = "collation_connection";
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Choose the MySQL collation index for the handshake packet and the corresponding Java encodings for the password and error messages.
|
||||
* </p>
|
||||
* <p>
|
||||
* This index will be sent with HandshakeResponse setting server variables 'character_set_connection', 'collation_connection', 'character_set_client'
|
||||
* and 'character_set_results' which will be used by the server for decoding passwords during the authentication phase and later on, if
|
||||
* no SET NAMES are issued by {@link #configurePostHandshake(boolean)}.
|
||||
* </p>
|
||||
* <p>
|
||||
* It also means that collation index should be set according to:
|
||||
* <ol>
|
||||
* <li>'passwordCharacterEncoding' if it's present, or
|
||||
* <li>'connectionCollation' if it's present, or
|
||||
* <li>'characterEncoding' if it's present
|
||||
* </ol>
|
||||
* otherwise it will be set to utf8mb4_general_ci or utf8mb4_0900_ai_ci depending on server version.
|
||||
* <p>
|
||||
* Since Protocol::HandshakeV10 and Protocol::HandshakeResponse41 has only one byte for the collation it's not possible to use indexes > 255 during the
|
||||
* handshake.
|
||||
* Also, ucs2, utf16, utf16le and utf32 character sets are impermissible here. Connector/J will try to use utf8mb4 instead.
|
||||
* </p>
|
||||
*
|
||||
* @param reset
|
||||
* reset the charsets configuration; needed for changeUser call.
|
||||
*
|
||||
* @return MySQL collation index to be used during the handshake.
|
||||
*/
|
||||
int configurePreHandshake(boolean reset);
|
||||
|
||||
/**
|
||||
* Sets up client character set. This must be done before any further communication with the server!
|
||||
*
|
||||
* The 'collation_connection', 'character_set_client', 'character_set_connection' and 'character_set_results' server variables are set
|
||||
* according to the collation index selected by {@link #configurePreHandshake(boolean)} and sent in the Protocol::HandshakeV10 packet.
|
||||
* Here Connector/J alters these server variables if needed.
|
||||
*
|
||||
* @param dontCheckServerMatch
|
||||
* if true then send the SET NAMES query even if server charset already matches the new value; needed for changeUser call.
|
||||
*/
|
||||
void configurePostHandshake(boolean dontCheckServerMatch);
|
||||
|
||||
public boolean doesPlatformDbCharsetMatches();
|
||||
|
||||
String getPasswordCharacterEncoding();
|
||||
|
||||
String getErrorMessageEncoding();
|
||||
|
||||
String getMetadataEncoding();
|
||||
|
||||
int getMetadataCollationIndex();
|
||||
|
||||
boolean getRequiresEscapingEncoder();
|
||||
|
||||
String getJavaEncodingForCollationIndex(int collationIndex);
|
||||
|
||||
int getMaxBytesPerChar(String javaCharsetName);
|
||||
|
||||
int getMaxBytesPerChar(Integer charsetIndex, String javaCharsetName);
|
||||
|
||||
Integer getCollationIndexForCollationName(String collationName);
|
||||
|
||||
String getCollationNameForCollationIndex(Integer collationIndex);
|
||||
|
||||
String getMysqlCharsetNameForCollationIndex(Integer collationIndex);
|
||||
|
||||
int getCollationIndexForJavaEncoding(String javaEncoding, ServerVersion version);
|
||||
|
||||
int getCollationIndexForMysqlCharsetName(String charsetName);
|
||||
|
||||
String getJavaEncodingForMysqlCharset(String mysqlCharsetName);
|
||||
|
||||
String getMysqlCharsetForJavaEncoding(String javaEncoding, ServerVersion version);
|
||||
|
||||
boolean isMultibyteCharset(String javaEncodingName);
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import com.mysql.cj.conf.PropertyDefinitions;
|
||||
|
||||
/**
|
||||
* Represents various constants used in the driver.
|
||||
*/
|
||||
public class Constants {
|
||||
/**
|
||||
* Avoids allocation of empty byte[] when representing 0-length strings.
|
||||
*/
|
||||
public final static byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
|
||||
/**
|
||||
* I18N'd representation of the abbreviation for "ms"
|
||||
*/
|
||||
public final static String MILLIS_I18N = Messages.getString("Milliseconds");
|
||||
|
||||
public final static byte[] SLASH_STAR_SPACE_AS_BYTES = new byte[] { (byte) '/', (byte) '*', (byte) ' ' };
|
||||
|
||||
public final static byte[] SPACE_STAR_SLASH_SPACE_AS_BYTES = new byte[] { (byte) ' ', (byte) '*', (byte) '/', (byte) ' ' };
|
||||
|
||||
public static final String JVM_VENDOR = System.getProperty(PropertyDefinitions.SYSP_java_vendor);
|
||||
public static final String JVM_VERSION = System.getProperty(PropertyDefinitions.SYSP_java_version);
|
||||
|
||||
public static final String OS_NAME = System.getProperty(PropertyDefinitions.SYSP_os_name);
|
||||
public static final String OS_ARCH = System.getProperty(PropertyDefinitions.SYSP_os_arch);
|
||||
public static final String OS_VERSION = System.getProperty(PropertyDefinitions.SYSP_os_version);
|
||||
|
||||
public static final String CJ_NAME = "@MYSQL_CJ_DISPLAY_PROD_NAME@";
|
||||
public static final String CJ_FULL_NAME = "@MYSQL_CJ_FULL_PROD_NAME@";
|
||||
public static final String CJ_REVISION = "@MYSQL_CJ_REVISION@";
|
||||
public static final String CJ_VERSION = "@MYSQL_CJ_VERSION@";
|
||||
public static final String CJ_MAJOR_VERSION = "@MYSQL_CJ_MAJOR_VERSION@";
|
||||
public static final String CJ_MINOR_VERSION = "@MYSQL_CJ_MINOR_VERSION@";
|
||||
public static final String CJ_LICENSE = "@MYSQL_CJ_LICENSE_TYPE@";
|
||||
|
||||
public static final BigInteger BIG_INTEGER_ZERO = BigInteger.valueOf(0);
|
||||
public static final BigInteger BIG_INTEGER_ONE = BigInteger.valueOf(1);
|
||||
public static final BigInteger BIG_INTEGER_NEGATIVE_ONE = BigInteger.valueOf(-1);
|
||||
public static final BigInteger BIG_INTEGER_MIN_BYTE_VALUE = BigInteger.valueOf(Byte.MIN_VALUE);
|
||||
public static final BigInteger BIG_INTEGER_MAX_BYTE_VALUE = BigInteger.valueOf(Byte.MAX_VALUE);
|
||||
public static final BigInteger BIG_INTEGER_MIN_SHORT_VALUE = BigInteger.valueOf(Short.MIN_VALUE);
|
||||
public static final BigInteger BIG_INTEGER_MAX_SHORT_VALUE = BigInteger.valueOf(Short.MAX_VALUE);
|
||||
public static final BigInteger BIG_INTEGER_MIN_INTEGER_VALUE = BigInteger.valueOf(Integer.MIN_VALUE);
|
||||
public static final BigInteger BIG_INTEGER_MAX_INTEGER_VALUE = BigInteger.valueOf(Integer.MAX_VALUE);
|
||||
public static final BigInteger BIG_INTEGER_MIN_LONG_VALUE = BigInteger.valueOf(Long.MIN_VALUE);
|
||||
public static final BigInteger BIG_INTEGER_MAX_LONG_VALUE = BigInteger.valueOf(Long.MAX_VALUE);
|
||||
|
||||
public static final BigDecimal BIG_DECIMAL_ZERO = BigDecimal.valueOf(0);
|
||||
public static final BigDecimal BIG_DECIMAL_ONE = BigDecimal.valueOf(1);
|
||||
public static final BigDecimal BIG_DECIMAL_NEGATIVE_ONE = BigDecimal.valueOf(-1);
|
||||
public static final BigDecimal BIG_DECIMAL_MIN_BYTE_VALUE = BigDecimal.valueOf(Byte.MIN_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MAX_BYTE_VALUE = BigDecimal.valueOf(Byte.MAX_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MIN_SHORT_VALUE = BigDecimal.valueOf(Short.MIN_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MAX_SHORT_VALUE = BigDecimal.valueOf(Short.MAX_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MIN_INTEGER_VALUE = BigDecimal.valueOf(Integer.MIN_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MAX_INTEGER_VALUE = BigDecimal.valueOf(Integer.MAX_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MIN_LONG_VALUE = BigDecimal.valueOf(Long.MIN_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MAX_LONG_VALUE = BigDecimal.valueOf(Long.MAX_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MAX_DOUBLE_VALUE = BigDecimal.valueOf(Double.MAX_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MAX_NEGATIVE_DOUBLE_VALUE = BigDecimal.valueOf(-Double.MAX_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MAX_FLOAT_VALUE = BigDecimal.valueOf(Float.MAX_VALUE);
|
||||
public static final BigDecimal BIG_DECIMAL_MAX_NEGATIVE_FLOAT_VALUE = BigDecimal.valueOf(-Float.MAX_VALUE);
|
||||
|
||||
public static final int UNSIGNED_BYTE_MAX_VALUE = 255;
|
||||
|
||||
/**
|
||||
* Prevents instantiation
|
||||
*/
|
||||
private Constants() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
public interface DataStoreMetadata {
|
||||
|
||||
boolean schemaExists(String schemaName);
|
||||
|
||||
boolean tableExists(String schemaName, String tableName);
|
||||
|
||||
long getTableRowCount(String schemaName, String tableName);
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mysql.cj.protocol.Message;
|
||||
|
||||
public interface MessageBuilder<M extends Message> {
|
||||
|
||||
M buildSqlStatement(String statement);
|
||||
|
||||
M buildSqlStatement(String statement, List<Object> args);
|
||||
|
||||
M buildClose();
|
||||
|
||||
M buildComQuery(M sharedPacket, Session sess, PreparedQuery preparedQuery, QueryBindings bindings, String characterEncoding);
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Support for localized messages.
|
||||
*/
|
||||
public class Messages {
|
||||
private static final String BUNDLE_NAME = "com.mysql.cj.LocalizedErrorMessages";
|
||||
|
||||
private static final ResourceBundle RESOURCE_BUNDLE;
|
||||
private static final Object[] emptyObjectArray = {};
|
||||
|
||||
static {
|
||||
ResourceBundle temp = null;
|
||||
|
||||
//
|
||||
// Overly-pedantic here, some appserver and JVM combos don't deal well with the no-args version, others don't deal well with the three-arg version, so
|
||||
// we need to try both :(
|
||||
//
|
||||
|
||||
try {
|
||||
temp = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault(), Messages.class.getClassLoader());
|
||||
} catch (Throwable t) {
|
||||
try {
|
||||
temp = ResourceBundle.getBundle(BUNDLE_NAME);
|
||||
} catch (Throwable t2) {
|
||||
RuntimeException rt = new RuntimeException("Can't load resource bundle due to underlying exception " + t.toString());
|
||||
rt.initCause(t2);
|
||||
|
||||
throw rt;
|
||||
}
|
||||
} finally {
|
||||
RESOURCE_BUNDLE = temp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the localized message for the given message key
|
||||
*
|
||||
* @param key
|
||||
* the message key
|
||||
* @return The localized message for the key
|
||||
*/
|
||||
public static String getString(String key) {
|
||||
return getString(key, emptyObjectArray);
|
||||
}
|
||||
|
||||
public static String getString(String key, Object[] args) {
|
||||
if (RESOURCE_BUNDLE == null) {
|
||||
throw new RuntimeException("Localized messages from resource bundle '" + BUNDLE_NAME + "' not loaded during initialization of driver.");
|
||||
}
|
||||
|
||||
try {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("Message key can not be null");
|
||||
}
|
||||
|
||||
String message = RESOURCE_BUNDLE.getString(key);
|
||||
|
||||
if (message == null) {
|
||||
message = "Missing error message for key '" + key + "'";
|
||||
}
|
||||
|
||||
return MessageFormat.format(message, args);
|
||||
} catch (MissingResourceException e) {
|
||||
return '!' + key + '!';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dis-allow construction ...
|
||||
*/
|
||||
private Messages() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.mysql.cj.conf.PropertySet;
|
||||
import com.mysql.cj.exceptions.ExceptionInterceptor;
|
||||
import com.mysql.cj.protocol.ServerSessionStateController;
|
||||
|
||||
public interface MysqlConnection {
|
||||
|
||||
PropertySet getPropertySet();
|
||||
|
||||
/**
|
||||
* Creates an IO channel to the server.
|
||||
*
|
||||
* @param isForReconnect
|
||||
* is this request for a re-connect
|
||||
*/
|
||||
void createNewIO(boolean isForReconnect);
|
||||
|
||||
long getId();
|
||||
|
||||
/**
|
||||
* Returns the parsed and passed in properties for this connection.
|
||||
*
|
||||
* @return {@link Properties}
|
||||
*/
|
||||
Properties getProperties();
|
||||
|
||||
Object getConnectionMutex();
|
||||
|
||||
Session getSession();
|
||||
|
||||
String getURL();
|
||||
|
||||
String getUser();
|
||||
|
||||
ExceptionInterceptor getExceptionInterceptor();
|
||||
|
||||
void checkClosed();
|
||||
|
||||
void normalClose();
|
||||
|
||||
/**
|
||||
* Destroys this connection and any underlying resources.
|
||||
*
|
||||
* @param whyCleanedUp
|
||||
* exception caused the connection clean up
|
||||
*/
|
||||
void cleanup(Throwable whyCleanedUp);
|
||||
|
||||
ServerSessionStateController getServerSessionStateController();
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.mysql.cj.util.LRUCache;
|
||||
|
||||
public class PerConnectionLRUFactory implements CacheAdapterFactory<String, QueryInfo> {
|
||||
|
||||
public CacheAdapter<String, QueryInfo> getInstance(Object syncMutex, String url, int cacheMaxSize, int maxKeySize) {
|
||||
|
||||
return new PerConnectionLRU(syncMutex, cacheMaxSize, maxKeySize);
|
||||
}
|
||||
|
||||
class PerConnectionLRU implements CacheAdapter<String, QueryInfo> {
|
||||
private final int cacheSqlLimit;
|
||||
private final LRUCache<String, QueryInfo> cache;
|
||||
private final Object syncMutex;
|
||||
|
||||
protected PerConnectionLRU(Object syncMutex, int cacheMaxSize, int maxKeySize) {
|
||||
final int cacheSize = cacheMaxSize;
|
||||
this.cacheSqlLimit = maxKeySize;
|
||||
this.cache = new LRUCache<>(cacheSize);
|
||||
this.syncMutex = syncMutex;
|
||||
}
|
||||
|
||||
public QueryInfo get(String key) {
|
||||
if (key == null || key.length() > this.cacheSqlLimit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized (this.syncMutex) {
|
||||
return this.cache.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void put(String key, QueryInfo value) {
|
||||
if (key == null || key.length() > this.cacheSqlLimit) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (this.syncMutex) {
|
||||
this.cache.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void invalidate(String key) {
|
||||
synchronized (this.syncMutex) {
|
||||
this.cache.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void invalidateAll(Set<String> keys) {
|
||||
synchronized (this.syncMutex) {
|
||||
for (String key : keys) {
|
||||
this.cache.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void invalidateAll() {
|
||||
synchronized (this.syncMutex) {
|
||||
this.cache.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
public interface PingTarget {
|
||||
|
||||
void doPing() throws Exception;
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import com.mysql.cj.protocol.Message;
|
||||
|
||||
public interface PreparedQuery extends Query {
|
||||
|
||||
QueryInfo getQueryInfo();
|
||||
|
||||
void setQueryInfo(QueryInfo queryInfo);
|
||||
|
||||
void checkNullOrEmptyQuery(String sql);
|
||||
|
||||
String getOriginalSql();
|
||||
|
||||
void setOriginalSql(String originalSql);
|
||||
|
||||
int getParameterCount();
|
||||
|
||||
void setParameterCount(int parameterCount);
|
||||
|
||||
public QueryBindings getQueryBindings();
|
||||
|
||||
public void setQueryBindings(QueryBindings queryBindings);
|
||||
|
||||
int computeBatchSize(int numBatchedArgs);
|
||||
|
||||
int getBatchCommandIndex();
|
||||
|
||||
void setBatchCommandIndex(int batchCommandIndex);
|
||||
|
||||
String asSql();
|
||||
|
||||
<M extends Message> M fillSendPacket(QueryBindings bindings);
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.mysql.cj.protocol.Message;
|
||||
import com.mysql.cj.protocol.ProtocolEntityFactory;
|
||||
import com.mysql.cj.protocol.Resultset;
|
||||
|
||||
public interface Query {
|
||||
|
||||
public enum CancelStatus {
|
||||
NOT_CANCELED, CANCELED_BY_USER, CANCELED_BY_TIMEOUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query id used when profiling
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
int getId();
|
||||
|
||||
void setCancelStatus(CancelStatus cs);
|
||||
|
||||
void checkCancelTimeout();
|
||||
|
||||
<T extends Resultset, M extends Message> ProtocolEntityFactory<T, M> getResultSetFactory();
|
||||
|
||||
Session getSession();
|
||||
|
||||
Object getCancelTimeoutMutex();
|
||||
|
||||
void resetCancelledState();
|
||||
|
||||
void closeQuery();
|
||||
|
||||
void addBatch(Object batch);
|
||||
|
||||
/**
|
||||
* Get the batched args as added by the addBatch method(s).
|
||||
* The list is unmodifiable and might contain any combination of String,
|
||||
* ClientPreparedQueryBindings, or ServerPreparedQueryBindings depending on how the parameters were
|
||||
* batched.
|
||||
*
|
||||
* @return an unmodifiable List of batched args
|
||||
*/
|
||||
List<Object> getBatchedArgs();
|
||||
|
||||
void clearBatchedArgs();
|
||||
|
||||
QueryAttributesBindings getQueryAttributesBindings();
|
||||
|
||||
int getResultFetchSize();
|
||||
|
||||
void setResultFetchSize(int fetchSize);
|
||||
|
||||
Resultset.Type getResultType();
|
||||
|
||||
void setResultType(Resultset.Type resultSetType);
|
||||
|
||||
int getTimeoutInMillis();
|
||||
|
||||
void setTimeoutInMillis(int timeoutInMillis);
|
||||
|
||||
void setExecuteTime(long executeTime);
|
||||
|
||||
/**
|
||||
* Returns the elapsed time for the server to execute the query.
|
||||
*
|
||||
* @return the time it took for the server to execute the query.
|
||||
*/
|
||||
long getExecuteTime();
|
||||
|
||||
CancelQueryTask startQueryTimer(Query stmtToCancel, int timeout);
|
||||
|
||||
AtomicBoolean getStatementExecuting();
|
||||
|
||||
String getCurrentDatabase();
|
||||
|
||||
void setCurrentDatabase(String currentDb);
|
||||
|
||||
boolean isClearWarningsCalled();
|
||||
|
||||
void setClearWarningsCalled(boolean clearWarningsCalled);
|
||||
|
||||
void statementBegins();
|
||||
|
||||
void stopQueryTimer(CancelQueryTask timeoutTask, boolean rethrowCancelReason, boolean checkCancelTimeout);
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.sql.Statement;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Instances of this interface keep the list of query attributes assigned to a {@link Statement} object.
|
||||
*/
|
||||
public interface QueryAttributesBindings {
|
||||
/**
|
||||
* Adds a new query attribute to the list of query attributes. Implementations must validate the type of the given the object and reject it or replace it by
|
||||
* another representation if not supported, by its String version, for example. Query attribute names are not checked for duplication.
|
||||
*
|
||||
* @param name
|
||||
* the query attribute name.
|
||||
*
|
||||
* @param value
|
||||
* the query attribute value.
|
||||
*/
|
||||
void setAttribute(String name, Object value);
|
||||
|
||||
/**
|
||||
* Get the count of query attributes in the list.
|
||||
*
|
||||
* @return
|
||||
* the number of query attributes existing in the list.
|
||||
*/
|
||||
int getCount();
|
||||
|
||||
/**
|
||||
* Returns an internal representation of the query attribute in the given position of the query attributes list. It's implementation dependent what to do
|
||||
* when the index value is invalid.
|
||||
*
|
||||
* @param index
|
||||
* the position of the query attribute value to return.
|
||||
*
|
||||
* @return
|
||||
* the {@link BindValue} in the given position of the query attributes list.
|
||||
*/
|
||||
BindValue getAttributeValue(int index);
|
||||
|
||||
/**
|
||||
* Runs through all query attributes while feeding the given {@link Consumer} with each one of them.
|
||||
*
|
||||
* @param bindAttribute
|
||||
* A {@link Consumer} for each one of the single query attributes.
|
||||
*/
|
||||
void runThroughAll(Consumer<BindValue> bindAttribute);
|
||||
|
||||
/**
|
||||
* Removes all query attributes from the query attributes list.
|
||||
*/
|
||||
void clearAttributes();
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Clob;
|
||||
import java.sql.Date;
|
||||
import java.sql.NClob;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.mysql.cj.protocol.ColumnDefinition;
|
||||
import com.mysql.cj.result.Field;
|
||||
|
||||
public interface QueryBindings {
|
||||
|
||||
QueryBindings clone();
|
||||
|
||||
void setColumnDefinition(ColumnDefinition colDef);
|
||||
|
||||
BindValue[] getBindValues();
|
||||
|
||||
void setBindValues(BindValue[] bindValues);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if bind values had long data
|
||||
*/
|
||||
boolean clearBindValues();
|
||||
|
||||
void checkParameterSet(int columnIndex);
|
||||
|
||||
void checkAllParametersSet();
|
||||
|
||||
int getNumberOfExecutions();
|
||||
|
||||
void setNumberOfExecutions(int numberOfExecutions);
|
||||
|
||||
boolean isLongParameterSwitchDetected();
|
||||
|
||||
void setLongParameterSwitchDetected(boolean longParameterSwitchDetected);
|
||||
|
||||
AtomicBoolean getSendTypesToServer();
|
||||
|
||||
BindValue getBinding(int parameterIndex, boolean forLongData);
|
||||
|
||||
void setFromBindValue(int parameterIndex, BindValue bv);
|
||||
|
||||
void setAsciiStream(int parameterIndex, InputStream x, int length);
|
||||
|
||||
void setBigDecimal(int parameterIndex, BigDecimal x);
|
||||
|
||||
void setBigInteger(int parameterIndex, BigInteger x);
|
||||
|
||||
void setBinaryStream(int parameterIndex, InputStream x, int length);
|
||||
|
||||
void setBlob(int parameterIndex, java.sql.Blob x);
|
||||
|
||||
void setBoolean(int parameterIndex, boolean x);
|
||||
|
||||
void setByte(int parameterIndex, byte x);
|
||||
|
||||
void setBytes(int parameterIndex, byte[] x, boolean escapeIfNeeded);
|
||||
|
||||
void setCharacterStream(int parameterIndex, Reader reader, int length);
|
||||
|
||||
void setClob(int i, Clob x);
|
||||
|
||||
void setDate(int parameterIndex, Date x, Calendar cal);
|
||||
|
||||
void setDouble(int parameterIndex, double x);
|
||||
|
||||
void setFloat(int parameterIndex, float x);
|
||||
|
||||
void setInt(int parameterIndex, int x);
|
||||
|
||||
void setLong(int parameterIndex, long x);
|
||||
|
||||
void setNCharacterStream(int parameterIndex, Reader reader, long length);
|
||||
|
||||
void setNClob(int parameterIndex, NClob value);
|
||||
|
||||
void setNString(int parameterIndex, String x);
|
||||
|
||||
void setNull(int parameterIndex);
|
||||
|
||||
boolean isNull(int parameterIndex);
|
||||
|
||||
void setObject(int parameterIndex, Object parameterObj);
|
||||
|
||||
void setObject(int parameterIndex, Object parameterObj, MysqlType targetMysqlType, int scaleOrLength);
|
||||
|
||||
void setShort(int parameterIndex, short x);
|
||||
|
||||
void setString(int parameterIndex, String x);
|
||||
|
||||
void setTime(int parameterIndex, Time x, Calendar cal);
|
||||
|
||||
void setTimestamp(int parameterIndex, Timestamp x, Calendar targetCalendar, Field field, MysqlType targetMysqlType);
|
||||
|
||||
byte[] getBytesRepresentation(int parameterIndex);
|
||||
}
|
|
@ -0,0 +1,712 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.mysql.cj.conf.PropertyKey;
|
||||
import com.mysql.cj.exceptions.ExceptionFactory;
|
||||
import com.mysql.cj.exceptions.WrongArgumentException;
|
||||
import com.mysql.cj.util.SearchMode;
|
||||
import com.mysql.cj.util.StringInspector;
|
||||
import com.mysql.cj.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Represents the "parsed" state of a prepared query, with the statement broken up into its static and dynamic (where parameters are bound) parts.
|
||||
*/
|
||||
public class QueryInfo {
|
||||
private static final String OPENING_MARKERS = "`'\"";
|
||||
private static final String CLOSING_MARKERS = "`'\"";
|
||||
private static final String OVERRIDING_MARKERS = "";
|
||||
|
||||
private static final String INSERT_STATEMENT = "INSERT";
|
||||
private static final String REPLACE_STATEMENT = "REPLACE";
|
||||
|
||||
private static final String VALUE_CLAUSE = "VALUE";
|
||||
private static final String AS_CLAUSE = "AS";
|
||||
private static final String[] ODKU_CLAUSE = new String[] { "ON", "DUPLICATE", "KEY", "UPDATE" };
|
||||
private static final String LAST_INSERT_ID_FUNC = "LAST_INSERT_ID";
|
||||
|
||||
private QueryInfo baseQueryInfo = null;
|
||||
|
||||
private String sql;
|
||||
private String encoding;
|
||||
private QueryReturnType queryReturnType = null;
|
||||
private int queryLength = 0;
|
||||
private int queryStartPos = 0;
|
||||
private char statementFirstChar = Character.MIN_VALUE;
|
||||
private int batchCount = 1;
|
||||
private int numberOfPlaceholders = 0;
|
||||
private int numberOfQueries = 0;
|
||||
private boolean containsOnDuplicateKeyUpdate = false;
|
||||
private boolean isRewritableWithMultiValuesClause = false;
|
||||
private int valuesClauseLength = -1;
|
||||
private ArrayList<Integer> valuesEndpoints = new ArrayList<>();
|
||||
private byte[][] staticSqlParts = null;
|
||||
|
||||
/**
|
||||
* Constructs a {@link QueryInfo} object for the given query or multi-query. The parsed result of this query allows to determine the location of the
|
||||
* placeholders, the query static parts and whether this query can be rewritten as a multi-values clause query.
|
||||
*
|
||||
* @param sql
|
||||
* the query SQL string to parse and analyze
|
||||
* @param session
|
||||
* the {@link Session} under which the query analysis must be done.
|
||||
* @param encoding
|
||||
* the characters encoding to use when extracting the query static parts as byte arrays.
|
||||
*/
|
||||
public QueryInfo(String sql, Session session, String encoding) {
|
||||
if (sql == null) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("QueryInfo.NullSql"), session.getExceptionInterceptor());
|
||||
}
|
||||
|
||||
this.baseQueryInfo = this;
|
||||
|
||||
this.sql = sql;
|
||||
this.encoding = encoding;
|
||||
|
||||
boolean noBackslashEscapes = session.getServerSession().isNoBackslashEscapesSet();
|
||||
boolean rewriteBatchedStatements = session.getPropertySet().getBooleanProperty(PropertyKey.rewriteBatchedStatements).getValue();
|
||||
boolean dontCheckOnDuplicateKeyUpdateInSQL = session.getPropertySet().getBooleanProperty(PropertyKey.dontCheckOnDuplicateKeyUpdateInSQL).getValue();
|
||||
|
||||
this.queryReturnType = getQueryReturnType(this.sql, noBackslashEscapes);
|
||||
this.queryLength = this.sql.length();
|
||||
|
||||
StringInspector strInspector = new StringInspector(this.sql, OPENING_MARKERS, CLOSING_MARKERS, OVERRIDING_MARKERS,
|
||||
noBackslashEscapes ? SearchMode.__MRK_COM_MYM_HNT_WS : SearchMode.__BSE_MRK_COM_MYM_HNT_WS);
|
||||
|
||||
// Skip comments at the beginning of queries.
|
||||
this.queryStartPos = strInspector.indexOfNextAlphanumericChar();
|
||||
if (this.queryStartPos == -1) {
|
||||
this.queryStartPos = this.queryLength;
|
||||
} else {
|
||||
this.numberOfQueries = 1;
|
||||
this.statementFirstChar = Character.toUpperCase(strInspector.getChar());
|
||||
}
|
||||
|
||||
// Only INSERT and REPLACE statements support multi-values clause rewriting.
|
||||
boolean isInsert = strInspector.matchesIgnoreCase(INSERT_STATEMENT) != -1;
|
||||
if (isInsert) {
|
||||
strInspector.incrementPosition(INSERT_STATEMENT.length()); // Advance to the end of "INSERT".
|
||||
}
|
||||
boolean isReplace = !isInsert && strInspector.matchesIgnoreCase(REPLACE_STATEMENT) != -1;
|
||||
if (isReplace) {
|
||||
strInspector.incrementPosition(REPLACE_STATEMENT.length()); // Advance to the end of "REPLACE".
|
||||
}
|
||||
|
||||
// Check if the statement has potential to be rewritten as a multi-values clause statement, i.e., if it is an INSERT or REPLACE statement and
|
||||
// 'rewriteBatchedStatements' is enabled.
|
||||
boolean rewritableAsMultiValues = (isInsert || isReplace) && rewriteBatchedStatements;
|
||||
|
||||
// Check if should look for ON DUPLICATE KEY UPDATE CLAUSE, i.e., if it is an INSERT statement and `dontCheckOnDuplicateKeyUpdateInSQL` is disabled.
|
||||
boolean lookForInDuplicateKeyUpdate = isInsert && !dontCheckOnDuplicateKeyUpdateInSQL;
|
||||
|
||||
// Scan placeholders.
|
||||
int generalEndpointStart = 0;
|
||||
int valuesEndpointStart = 0;
|
||||
int valuesClauseBegin = -1;
|
||||
int valuesClauseEnd = -1;
|
||||
boolean withinValuesClause = false;
|
||||
int parensLevel = 0;
|
||||
int matchEnd = -1;
|
||||
|
||||
// Endpoints for the satement's static sections (parts around placeholders).
|
||||
ArrayList<Integer> staticEndpoints = new ArrayList<>();
|
||||
|
||||
while (strInspector.indexOfNextChar() != -1) {
|
||||
if (strInspector.getChar() == '?') {
|
||||
this.numberOfPlaceholders++;
|
||||
int endpointEnd = strInspector.getPosition();
|
||||
staticEndpoints.add(generalEndpointStart);
|
||||
staticEndpoints.add(endpointEnd);
|
||||
strInspector.incrementPosition();
|
||||
generalEndpointStart = strInspector.getPosition(); // Next section starts after the placeholder.
|
||||
|
||||
if (rewritableAsMultiValues) {
|
||||
if (valuesClauseBegin == -1) { // There's a placeholder before the VALUES clause.
|
||||
rewritableAsMultiValues = false;
|
||||
} else if (valuesClauseEnd != -1) { // There's a placeholder after the end of the VALUES clause.
|
||||
rewritableAsMultiValues = false;
|
||||
} else if (withinValuesClause) {
|
||||
this.valuesEndpoints.add(valuesEndpointStart);
|
||||
this.valuesEndpoints.add(endpointEnd);
|
||||
valuesEndpointStart = generalEndpointStart;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (strInspector.getChar() == ';') {
|
||||
strInspector.incrementPosition();
|
||||
if (strInspector.indexOfNextNonWsChar() != -1) {
|
||||
this.numberOfQueries++;
|
||||
|
||||
if (rewritableAsMultiValues) {
|
||||
rewritableAsMultiValues = false;
|
||||
valuesClauseBegin = -1;
|
||||
valuesClauseEnd = -1;
|
||||
withinValuesClause = false;
|
||||
parensLevel = 0;
|
||||
}
|
||||
|
||||
// Check if continue looking for ON DUPLICATE KEY UPDATE.
|
||||
if (dontCheckOnDuplicateKeyUpdateInSQL || this.containsOnDuplicateKeyUpdate) {
|
||||
lookForInDuplicateKeyUpdate = false;
|
||||
} else {
|
||||
isInsert = strInspector.matchesIgnoreCase(INSERT_STATEMENT) != -1;
|
||||
if (isInsert) {
|
||||
strInspector.incrementPosition(INSERT_STATEMENT.length()); // Advance to the end of "INSERT".
|
||||
}
|
||||
lookForInDuplicateKeyUpdate = isInsert;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (rewritableAsMultiValues || lookForInDuplicateKeyUpdate) {
|
||||
if (valuesClauseBegin == -1 && strInspector.matchesIgnoreCase(VALUE_CLAUSE) != -1) { // VALUE(S) clause found.
|
||||
strInspector.incrementPosition(VALUE_CLAUSE.length()); // Advance to the end of "VALUE".
|
||||
if (strInspector.matchesIgnoreCase("S") != -1) { // Check for the "S" in "VALUE(S)" and advance 1 more character if needed.
|
||||
strInspector.incrementPosition();
|
||||
}
|
||||
withinValuesClause = true;
|
||||
strInspector.indexOfNextChar(); // Position on the first values list character.
|
||||
valuesClauseBegin = strInspector.getPosition();
|
||||
|
||||
if (rewritableAsMultiValues) {
|
||||
valuesEndpointStart = valuesClauseBegin;
|
||||
}
|
||||
|
||||
} else if (withinValuesClause && strInspector.getChar() == '(') {
|
||||
parensLevel++;
|
||||
strInspector.incrementPosition();
|
||||
|
||||
} else if (withinValuesClause && strInspector.getChar() == ')') {
|
||||
parensLevel--;
|
||||
if (parensLevel < 0) {
|
||||
parensLevel = 0; // Keep going, not checking for syntax validity.
|
||||
}
|
||||
strInspector.incrementPosition();
|
||||
valuesClauseEnd = strInspector.getPosition(); // It may not be the end of the VALUES clause yet but save it for later.
|
||||
|
||||
} else if (withinValuesClause && parensLevel == 0 && isInsert && strInspector.matchesIgnoreCase(AS_CLAUSE) != -1) { // End of VALUES clause.
|
||||
if (valuesClauseEnd == -1) {
|
||||
valuesClauseEnd = strInspector.getPosition();
|
||||
}
|
||||
withinValuesClause = false;
|
||||
strInspector.incrementPosition(AS_CLAUSE.length()); // Advance to the end of "AS".
|
||||
|
||||
if (rewritableAsMultiValues) {
|
||||
this.valuesEndpoints.add(valuesEndpointStart);
|
||||
this.valuesEndpoints.add(valuesClauseEnd);
|
||||
}
|
||||
|
||||
} else if (withinValuesClause && parensLevel == 0 && isInsert && (matchEnd = strInspector.matchesIgnoreCase(ODKU_CLAUSE)) != -1) { // End of VALUES clause.
|
||||
if (valuesClauseEnd == -1) {
|
||||
valuesClauseEnd = strInspector.getPosition();
|
||||
}
|
||||
withinValuesClause = false;
|
||||
lookForInDuplicateKeyUpdate = false;
|
||||
this.containsOnDuplicateKeyUpdate = true;
|
||||
strInspector.incrementPosition(matchEnd - strInspector.getPosition()); // Advance to the end of "ON DUPLICATE KEY UPDATE".
|
||||
|
||||
if (rewritableAsMultiValues) {
|
||||
this.valuesEndpoints.add(valuesEndpointStart);
|
||||
this.valuesEndpoints.add(valuesClauseEnd);
|
||||
}
|
||||
|
||||
} else if (rewritableAsMultiValues && valuesClauseBegin != -1 && strInspector.matchesIgnoreCase(LAST_INSERT_ID_FUNC) != -1) {
|
||||
rewritableAsMultiValues = false;
|
||||
strInspector.incrementPosition(LAST_INSERT_ID_FUNC.length()); // Advance to the end of "LAST_INSERT_ID".
|
||||
|
||||
} else {
|
||||
strInspector.incrementPosition();
|
||||
}
|
||||
|
||||
} else {
|
||||
strInspector.incrementPosition();
|
||||
}
|
||||
}
|
||||
staticEndpoints.add(generalEndpointStart);
|
||||
staticEndpoints.add(this.queryLength);
|
||||
if (rewritableAsMultiValues) {
|
||||
if (withinValuesClause) {
|
||||
withinValuesClause = false;
|
||||
this.valuesEndpoints.add(valuesEndpointStart);
|
||||
this.valuesEndpoints.add(valuesClauseEnd != -1 ? valuesClauseEnd : this.queryLength);
|
||||
}
|
||||
|
||||
if (valuesClauseBegin != -1) {
|
||||
this.valuesClauseLength = (valuesClauseEnd != -1 ? valuesClauseEnd : this.queryLength) - valuesClauseBegin;
|
||||
} else {
|
||||
rewritableAsMultiValues = false;
|
||||
}
|
||||
} else {
|
||||
this.valuesEndpoints.clear();
|
||||
}
|
||||
this.isRewritableWithMultiValuesClause = rewritableAsMultiValues;
|
||||
|
||||
this.staticSqlParts = new byte[this.numberOfPlaceholders + 1][];
|
||||
for (int i = 0, j = 0; i <= this.numberOfPlaceholders; i++) {
|
||||
int begin = staticEndpoints.get(j++);
|
||||
int end = staticEndpoints.get(j++);
|
||||
int length = end - begin;
|
||||
this.staticSqlParts[i] = StringUtils.getBytes(this.sql, begin, length, this.encoding);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link QueryInfo} object with a multi-value clause for the specified batch count, that stems from the specified baseQueryInfo.
|
||||
*
|
||||
* @param baseQueryInfo
|
||||
* the {@link QueryInfo} instance that provides the query static parts used to create the new instance now augmented to accommodate the extra
|
||||
* number of parameters
|
||||
* @param batchCount
|
||||
* the number of batches, i.e., the number of times the VALUES clause needs to be repeated inside the new query
|
||||
*/
|
||||
private QueryInfo(QueryInfo baseQueryInfo, int batchCount) {
|
||||
this.baseQueryInfo = baseQueryInfo;
|
||||
|
||||
this.sql = null;
|
||||
this.encoding = this.baseQueryInfo.encoding;
|
||||
this.queryReturnType = this.baseQueryInfo.queryReturnType;
|
||||
this.queryLength = 0;
|
||||
this.queryStartPos = this.baseQueryInfo.queryStartPos;
|
||||
this.statementFirstChar = this.baseQueryInfo.statementFirstChar;
|
||||
this.batchCount = batchCount;
|
||||
this.numberOfPlaceholders = this.baseQueryInfo.numberOfPlaceholders * this.batchCount;
|
||||
this.numberOfQueries = 1;
|
||||
this.containsOnDuplicateKeyUpdate = this.baseQueryInfo.containsOnDuplicateKeyUpdate;
|
||||
this.isRewritableWithMultiValuesClause = true;
|
||||
this.valuesClauseLength = -1;
|
||||
|
||||
if (this.numberOfPlaceholders == 0) {
|
||||
this.staticSqlParts = new byte[1][];
|
||||
|
||||
int begin = this.baseQueryInfo.valuesEndpoints.get(0);
|
||||
int end = this.baseQueryInfo.valuesEndpoints.get(1);
|
||||
int length = end - begin;
|
||||
byte[] valuesSegment = StringUtils.getBytes(this.baseQueryInfo.sql, begin, length, this.encoding);
|
||||
byte[] bindingSegment = StringUtils.getBytes(",", this.encoding);
|
||||
|
||||
// First batch is in the query.
|
||||
ByteBuffer queryByteBuffer = ByteBuffer.allocate(this.baseQueryInfo.queryLength + (length + bindingSegment.length) * (batchCount - 1));
|
||||
|
||||
// Head section: from the start to the end of the values - includes first values batch.
|
||||
queryByteBuffer.put(StringUtils.getBytes(this.baseQueryInfo.sql, 0, this.baseQueryInfo.valuesEndpoints.get(1), this.encoding));
|
||||
|
||||
// Values section: repeat as many times as needed to complete the requested batch count.
|
||||
for (int i = 0; i < this.batchCount - 1; i++) {
|
||||
// Add the segment that binds two batches followed by the next batch.
|
||||
queryByteBuffer.put(bindingSegment);
|
||||
queryByteBuffer.put(valuesSegment);
|
||||
}
|
||||
|
||||
// Tail section: from the end of values until the end.
|
||||
begin = this.baseQueryInfo.valuesEndpoints.get(1);
|
||||
end = this.baseQueryInfo.queryLength;
|
||||
length = end - begin;
|
||||
queryByteBuffer.put(StringUtils.getBytes(this.baseQueryInfo.sql, begin, length, this.encoding));
|
||||
|
||||
this.staticSqlParts[0] = queryByteBuffer.array();
|
||||
|
||||
} else {
|
||||
this.staticSqlParts = new byte[this.numberOfPlaceholders + 1][];
|
||||
|
||||
// Build the values binding segment: [values_end][comma][values_begin], e.g., "),(".
|
||||
int begin = this.baseQueryInfo.valuesEndpoints.get(this.baseQueryInfo.valuesEndpoints.size() - 2);
|
||||
int end = this.baseQueryInfo.valuesEndpoints.get(this.baseQueryInfo.valuesEndpoints.size() - 1);
|
||||
int length = end - begin;
|
||||
byte[] valuesEndSegment = StringUtils.getBytes(this.baseQueryInfo.sql, begin, length, this.encoding);
|
||||
byte[] delimiter = StringUtils.getBytes(",", this.encoding);
|
||||
begin = this.baseQueryInfo.valuesEndpoints.get(0);
|
||||
end = this.baseQueryInfo.valuesEndpoints.get(1);
|
||||
length = end - begin;
|
||||
byte[] valuesBeginSegment = StringUtils.getBytes(this.baseQueryInfo.sql, begin, length, this.encoding);
|
||||
ByteBuffer bindingSegmentByteBuffer = ByteBuffer.allocate(valuesEndSegment.length + delimiter.length + valuesBeginSegment.length);
|
||||
bindingSegmentByteBuffer.put(valuesEndSegment).put(delimiter).put(valuesBeginSegment);
|
||||
byte[] bindingSegment = bindingSegmentByteBuffer.array();
|
||||
|
||||
// Head section: same as in the original query.
|
||||
this.staticSqlParts[0] = this.baseQueryInfo.staticSqlParts[0];
|
||||
|
||||
// Values section: repeat as many times as the requested batch count.
|
||||
for (int i = 0, p = 1; i < this.batchCount; i++, p++) {
|
||||
for (int j = 1; j < this.baseQueryInfo.staticSqlParts.length - 1; j++, p++) {
|
||||
this.staticSqlParts[p] = this.baseQueryInfo.staticSqlParts[j];
|
||||
}
|
||||
// Add the segment that binds two batches.
|
||||
this.staticSqlParts[p] = bindingSegment;
|
||||
}
|
||||
|
||||
// Tail section: same as in the original query.
|
||||
this.staticSqlParts[this.staticSqlParts.length - 1] = this.baseQueryInfo.staticSqlParts[this.baseQueryInfo.staticSqlParts.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of queries identified in the original SQL string. Different queries are identified by the presence of the query delimiter character,
|
||||
* i.e., a semicolon.
|
||||
*
|
||||
* @return the number of queries identified in the original SQL string
|
||||
*/
|
||||
public int getNumberOfQueries() {
|
||||
return this.numberOfQueries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the return type of the parsed query. This operation does not take into consideration the multiplicity of queries in the specified SQL.
|
||||
*
|
||||
* @return the return type of the parsed query
|
||||
*/
|
||||
public QueryReturnType getQueryReturnType() {
|
||||
return this.queryReturnType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first character of the statement from the query used to build this {@link QueryInfo}.
|
||||
*
|
||||
* @return the first character of the statement
|
||||
*/
|
||||
public char getFirstStmtChar() {
|
||||
/* TODO: First char based logic is questionable. Consider replacing by statement check. */
|
||||
return this.baseQueryInfo.statementFirstChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this object represents a query that is re-writable as a multi-values statement and if rewriting batched statements is enabled, then returns the
|
||||
* length of the parsed VALUES clause section, including the placeholder characters themselves, otherwise returns -1.
|
||||
*
|
||||
* @return the length of the parsed VALUES clause section, including the placeholder characters themselves, otherwise returns -1
|
||||
*/
|
||||
public int getValuesClauseLength() {
|
||||
return this.baseQueryInfo.valuesClauseLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this query info represent a query that contains an ON DUPLICATE KEY UPDATE clause? This operation does not take into consideration the multiplicity
|
||||
* of queries in the original SQL.
|
||||
*
|
||||
* Checking whether the original query contains an ON DUPLICATE KEY UPDATE clause is conditional to how the connection properties
|
||||
* `dontCheckOnDuplicateKeyUpdateInSQL` and `rewriteBatchedStatements` are set, with `rewriteBatchedStatements=true` implicitly disabling
|
||||
* `dontCheckOnDuplicateKeyUpdateInSQL`.
|
||||
*
|
||||
* @return <code>true</code> if the query or any of the original queries contain an ON DUPLICATE KEY UPDATE clause.
|
||||
*/
|
||||
public boolean containsOnDuplicateKeyUpdate() {
|
||||
return this.containsOnDuplicateKeyUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located.
|
||||
*
|
||||
* @return the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located
|
||||
*/
|
||||
public byte[][] getStaticSqlParts() {
|
||||
return this.staticSqlParts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can this query be rewritten as a multi-values clause?
|
||||
*
|
||||
* @return <code>true</code> if the query can be rewritten as a multi-values query.
|
||||
*/
|
||||
public boolean isRewritableWithMultiValuesClause() {
|
||||
return this.isRewritableWithMultiValuesClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link QueryInfo} for a multi-values INSERT/REPLACE assembled for the specified batch count, without re-parsing.
|
||||
*
|
||||
* @param count
|
||||
* the number of parameter batches
|
||||
* @return {@link QueryInfo}
|
||||
*/
|
||||
public QueryInfo getQueryInfoForBatch(int count) {
|
||||
if (count == 1) {
|
||||
return this.baseQueryInfo;
|
||||
}
|
||||
if (count == this.batchCount) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (!this.isRewritableWithMultiValuesClause) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new QueryInfo(this.baseQueryInfo, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a preparable query for the batch count of this {@link QueryInfo}.
|
||||
*
|
||||
* @return
|
||||
* a preparable query string with the appropriate number of placeholders
|
||||
*/
|
||||
public String getSqlForBatch() {
|
||||
if (this.batchCount == 1) {
|
||||
return this.baseQueryInfo.sql;
|
||||
}
|
||||
|
||||
int size = this.baseQueryInfo.queryLength + (this.batchCount - 1) * this.baseQueryInfo.valuesClauseLength + this.batchCount - 1;
|
||||
StringBuilder buf = new StringBuilder(size);
|
||||
buf.append(StringUtils.toString(this.staticSqlParts[0], this.encoding));
|
||||
for (int i = 1; i < this.staticSqlParts.length; i++) {
|
||||
buf.append("?").append(StringUtils.toString(this.staticSqlParts[i], this.encoding));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a preparable query for the specified batch count.
|
||||
*
|
||||
* @param count
|
||||
* number of parameter batches
|
||||
* @return a preparable query string with the appropriate number of placeholders
|
||||
*/
|
||||
public String getSqlForBatch(int count) {
|
||||
QueryInfo batchInfo = getQueryInfoForBatch(count);
|
||||
return batchInfo.getSqlForBatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and returns the position of the first non-whitespace character from the specified SQL, skipping comments and quoted text.
|
||||
*
|
||||
* @param sql
|
||||
* the query to search
|
||||
* @param noBackslashEscapes
|
||||
* whether backslash escapes are disabled or not
|
||||
* @return the position of the first character of the query
|
||||
*/
|
||||
public static int indexOfStatementKeyword(String sql, boolean noBackslashEscapes) {
|
||||
return StringUtils.indexOfNextAlphanumericChar(0, sql, OPENING_MARKERS, CLOSING_MARKERS, OVERRIDING_MARKERS,
|
||||
noBackslashEscapes ? SearchMode.__MRK_COM_MYM_HNT_WS : SearchMode.__BSE_MRK_COM_MYM_HNT_WS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and returns the first non-whitespace character from the specified SQL, skipping comments and quoted text.
|
||||
*
|
||||
* @param sql
|
||||
* the query to search
|
||||
* @param noBackslashEscapes
|
||||
* whether backslash escapes are disabled or not
|
||||
* @return the first character of the query, in upper case
|
||||
*/
|
||||
public static char firstCharOfStatementUc(String sql, boolean noBackslashEscapes) {
|
||||
int statementKeywordPos = indexOfStatementKeyword(sql, noBackslashEscapes);
|
||||
if (statementKeywordPos == -1) {
|
||||
return Character.MIN_VALUE;
|
||||
}
|
||||
return Character.toUpperCase(sql.charAt(statementKeywordPos));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given query is safe to run in a read-only session. In case of doubt it is assumed to be safe. This operation does not take into
|
||||
* consideration the multiplicity of queries in the specified SQL.
|
||||
*
|
||||
* @param sql
|
||||
* the query to check
|
||||
* @param noBackslashEscapes
|
||||
* whether backslash escapes are disabled or not
|
||||
* @return <code>true</code> if the query is read-only safe, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isReadOnlySafeQuery(String sql, boolean noBackslashEscapes) {
|
||||
/*
|
||||
* Read-only unsafe statements:
|
||||
* - ALTER; CHANGE; CREATE; DELETE; DROP; GRANT; IMPORT; INSERT; INSTALL; LOAD; OPTIMIZE; RENAME; REPAIR; REPLACE; RESET; REVOKE; TRUNCATE; UNINSTALL;
|
||||
* - UPDATE; WITH ... DELETE|UPDATE
|
||||
*
|
||||
* Read-only safe statements:
|
||||
* - ANALYZE; BEGIN; BINLOG; CACHE; CALL; CHECK; CHECKSUM; CLONE; COMMIT; DEALLOCATE; DESC; DESCRIBE; EXECUTE; EXPLAIN; FLUSH; GET; HANDLER; HELP; KILL;
|
||||
* - LOCK; PREPARE; PURGE; RELEASE; RESIGNAL; ROLLBACK; SAVEPOINT; SELECT; SET; SHOW; SIGNAL; START; STOP; TABLE; UNLOCK; USE; VALUES;
|
||||
* - WITH ... [SELECT|TABLE|VALUES]; XA
|
||||
*/
|
||||
int statementKeywordPos = indexOfStatementKeyword(sql, noBackslashEscapes);
|
||||
if (statementKeywordPos == -1) {
|
||||
return true; // Assume it's safe.
|
||||
}
|
||||
char firstStatementChar = Character.toUpperCase(sql.charAt(statementKeywordPos));
|
||||
if (firstStatementChar == 'A' && StringUtils.startsWithIgnoreCaseAndWs(sql, "ALTER", statementKeywordPos)) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'C' && (StringUtils.startsWithIgnoreCaseAndWs(sql, "CHANGE", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "CREATE", statementKeywordPos))) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'D' && (StringUtils.startsWithIgnoreCaseAndWs(sql, "DELETE", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "DROP", statementKeywordPos))) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'G' && StringUtils.startsWithIgnoreCaseAndWs(sql, "GRANT", statementKeywordPos)) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'I' && (StringUtils.startsWithIgnoreCaseAndWs(sql, "IMPORT", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "INSERT", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "INSTALL", statementKeywordPos))) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'L' && StringUtils.startsWithIgnoreCaseAndWs(sql, "LOAD", statementKeywordPos)) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'O' && StringUtils.startsWithIgnoreCaseAndWs(sql, "OPTIMIZE", statementKeywordPos)) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'R' && (StringUtils.startsWithIgnoreCaseAndWs(sql, "RENAME", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "REPAIR", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "REPLACE", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "RESET", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "REVOKE", statementKeywordPos))) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'T' && StringUtils.startsWithIgnoreCaseAndWs(sql, "TRUNCATE", statementKeywordPos)) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'U' && (StringUtils.startsWithIgnoreCaseAndWs(sql, "UNINSTALL", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "UPDATE", statementKeywordPos))) {
|
||||
return false;
|
||||
} else if (firstStatementChar == 'W' && StringUtils.startsWithIgnoreCaseAndWs(sql, "WITH", statementKeywordPos)) {
|
||||
String context = getContextForWithStatement(sql, noBackslashEscapes);
|
||||
return context == null || !context.equalsIgnoreCase("DELETE") && !context.equalsIgnoreCase("UPDATE");
|
||||
}
|
||||
return true; // Assume it's safe by default.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of return that can be expected from executing the given query. This operation does not take into consideration the multiplicity
|
||||
* of queries in the specified SQL.
|
||||
*
|
||||
* @param sql
|
||||
* the query to check
|
||||
* @param noBackslashEscapes
|
||||
* whether backslash escapes are disabled or not
|
||||
* @return the return type that can be expected from the given query, one of the elements of {@link QueryReturnType}.
|
||||
*/
|
||||
public static QueryReturnType getQueryReturnType(String sql, boolean noBackslashEscapes) {
|
||||
/*
|
||||
* Statements that return results:
|
||||
* - ANALYZE; CHECK/CHECKSUM; DESC/DESCRIBE; EXPLAIN; HELP; OPTIMIZE; REPAIR; SELECT; SHOW; TABLE; VALUES; WITH ... SELECT|TABLE|VALUES ...; XA RECOVER;
|
||||
*
|
||||
* Statements that may return results:
|
||||
* - CALL; EXECUTE;
|
||||
*
|
||||
* Statements that do not return results:
|
||||
* - ALTER; BINLOG; CACHE; CHANGE; CLONE; COMMIT; CREATE; DEALLOCATE; DELETE; DO; DROP; FLUSH; GET; GRANT; HANDLER; IMPORT; INSERT; INSTALL; KILL; LOAD;
|
||||
* - LOCK; PREPARE; PURGE; RELEASE; RENAME; REPLACE; RESET; RESIGNAL; RESTART; REVOKE; ROLLBACK; SAVEPOINT; SET; SHUTDOWN; SIGNAL; START; STOP;
|
||||
* - TRUNCATE; UNINSTALL; UNLOCK; UPDATE; USE; WITH ... DELETE|UPDATE ...; XA [!RECOVER];
|
||||
*/
|
||||
int statementKeywordPos = indexOfStatementKeyword(sql, noBackslashEscapes);
|
||||
if (statementKeywordPos == -1) {
|
||||
return QueryReturnType.NONE;
|
||||
}
|
||||
char firstStatementChar = Character.toUpperCase(sql.charAt(statementKeywordPos));
|
||||
if (firstStatementChar == 'A' && StringUtils.startsWithIgnoreCaseAndWs(sql, "ANALYZE", statementKeywordPos)) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'C' && StringUtils.startsWithIgnoreCaseAndWs(sql, "CALL", statementKeywordPos)) {
|
||||
return QueryReturnType.MAY_PRODUCE_RESULT_SET;
|
||||
} else if (firstStatementChar == 'C' && StringUtils.startsWithIgnoreCaseAndWs(sql, "CHECK", statementKeywordPos)) { // Also matches "CHECKSUM".
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'D' && StringUtils.startsWithIgnoreCaseAndWs(sql, "DESC", statementKeywordPos)) { // Also matches "DESCRIBE".
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'E' && StringUtils.startsWithIgnoreCaseAndWs(sql, "EXPLAIN", statementKeywordPos)) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'E' && StringUtils.startsWithIgnoreCaseAndWs(sql, "EXECUTE", statementKeywordPos)) {
|
||||
return QueryReturnType.MAY_PRODUCE_RESULT_SET;
|
||||
} else if (firstStatementChar == 'H' && StringUtils.startsWithIgnoreCaseAndWs(sql, "HELP", statementKeywordPos)) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'O' && StringUtils.startsWithIgnoreCaseAndWs(sql, "OPTIMIZE", statementKeywordPos)) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'R' && StringUtils.startsWithIgnoreCaseAndWs(sql, "REPAIR", statementKeywordPos)) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'S' && (StringUtils.startsWithIgnoreCaseAndWs(sql, "SELECT", statementKeywordPos)
|
||||
|| StringUtils.startsWithIgnoreCaseAndWs(sql, "SHOW", statementKeywordPos))) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'T' && StringUtils.startsWithIgnoreCaseAndWs(sql, "TABLE", statementKeywordPos)) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'V' && StringUtils.startsWithIgnoreCaseAndWs(sql, "VALUES", statementKeywordPos)) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else if (firstStatementChar == 'W' && StringUtils.startsWithIgnoreCaseAndWs(sql, "WITH", statementKeywordPos)) {
|
||||
String context = getContextForWithStatement(sql, noBackslashEscapes);
|
||||
if (context == null) {
|
||||
return QueryReturnType.MAY_PRODUCE_RESULT_SET;
|
||||
} else if (context.equalsIgnoreCase("SELECT") || context.equalsIgnoreCase("TABLE") || context.equalsIgnoreCase("VALUES")) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
} else {
|
||||
return QueryReturnType.DOES_NOT_PRODUCE_RESULT_SET;
|
||||
}
|
||||
} else if (firstStatementChar == 'X' && StringUtils.indexOfIgnoreCase(statementKeywordPos, sql, new String[] { "XA", "RECOVER" }, OPENING_MARKERS,
|
||||
CLOSING_MARKERS, noBackslashEscapes ? SearchMode.__MRK_COM_MYM_HNT_WS : SearchMode.__FULL) == statementKeywordPos) {
|
||||
return QueryReturnType.PRODUCES_RESULT_SET;
|
||||
}
|
||||
return QueryReturnType.DOES_NOT_PRODUCE_RESULT_SET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context of the WITH statement. The context can be: SELECT, TABLE, VALUES, UPDATE or DELETE. This operation does not take into consideration
|
||||
* the multiplicity of queries in the specified SQL.
|
||||
*
|
||||
* @param sql
|
||||
* the query to search
|
||||
* @param noBackslashEscapes
|
||||
* whether backslash escapes are disabled or not
|
||||
* @return the context of the WITH statement or null if failed to find it
|
||||
*/
|
||||
private static String getContextForWithStatement(String sql, boolean noBackslashEscapes) {
|
||||
// Must remove all comments first.
|
||||
String commentsFreeSql = StringUtils.stripCommentsAndHints(sql, OPENING_MARKERS, CLOSING_MARKERS, !noBackslashEscapes);
|
||||
|
||||
// Iterate through statement words, skipping all sub-queries sections enclosed by parens.
|
||||
StringInspector strInspector = new StringInspector(commentsFreeSql, OPENING_MARKERS + "(", CLOSING_MARKERS + ")", OPENING_MARKERS,
|
||||
noBackslashEscapes ? SearchMode.__MRK_COM_MYM_HNT_WS : SearchMode.__BSE_MRK_COM_MYM_HNT_WS);
|
||||
boolean asFound = false;
|
||||
while (true) {
|
||||
int nws = strInspector.indexOfNextNonWsChar();
|
||||
if (nws == -1) { // No more parts to analyze.
|
||||
return null;
|
||||
}
|
||||
int ws = strInspector.indexOfNextWsChar();
|
||||
if (ws == -1) { // End of query.
|
||||
ws = commentsFreeSql.length();
|
||||
}
|
||||
String section = commentsFreeSql.substring(nws, ws);
|
||||
if (!asFound && section.equalsIgnoreCase(AS_CLAUSE)) {
|
||||
asFound = true; // Since the subquery part is skipped, this must be followed by a "," or the context statement.
|
||||
} else if (asFound) {
|
||||
if (section.equalsIgnoreCase(",")) {
|
||||
asFound = false; // Another CTE is expected.
|
||||
} else {
|
||||
return section;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the specified SQL contains or not an ON DUPLICATE KEY UPDATE clause. This operation does not take into consideration the multiplicity of
|
||||
* queries in the specified SQL.
|
||||
*
|
||||
* @param sql
|
||||
* the query to search
|
||||
* @param noBackslashEscapes
|
||||
* whether backslash escapes are disabled or not.
|
||||
* @return <code>true</code> if the query contains an ON DUPLICATE KEY UPDATE clause, <code>false</code> otherwise
|
||||
*/
|
||||
public static boolean containsOnDuplicateKeyUpdateClause(String sql, boolean noBackslashEscapes) {
|
||||
return StringUtils.indexOfIgnoreCase(0, sql, ODKU_CLAUSE, OPENING_MARKERS, CLOSING_MARKERS,
|
||||
noBackslashEscapes ? SearchMode.__MRK_COM_MYM_HNT_WS : SearchMode.__BSE_MRK_COM_MYM_HNT_WS) != -1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 2.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including but not
|
||||
* limited to OpenSSL) that is licensed under separate terms, as designated in a
|
||||
* particular file or component or in included license documentation. The
|
||||
* authors of MySQL hereby grant you an additional permission to link the
|
||||
* program and your derivative works with the separately licensed software that
|
||||
* they have included with MySQL.
|
||||
*
|
||||
* Without limiting anything contained in the foregoing, this file, which is
|
||||
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
|
||||
* version 1.0, a copy of which can be found at
|
||||
* http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
*
|
||||
* This program 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 General Public License, version 2.0,
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.mysql.cj;
|
||||
|
||||
public interface QueryResult {
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue