MAJ V2
This commit is contained in:
55
src/controleur/Cheval.java
Normal file
55
src/controleur/Cheval.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package controleur;
|
||||
|
||||
public class Cheval {
|
||||
private int id, age;
|
||||
private String nom, sexe, robe, type, race, proprietaire, image;
|
||||
public Cheval()
|
||||
{//ADD
|
||||
this.id=this.age=0;
|
||||
this.nom=this.sexe=this.proprietaire=this.robe=this.type=this.image="";
|
||||
}
|
||||
public Cheval (int id, String nom, String sexe, String robe, String type, String race, String proprietaire, int age, String image)
|
||||
{//ALL
|
||||
this.id= id;
|
||||
this.nom = nom;
|
||||
this.sexe = sexe;
|
||||
this.robe = robe;
|
||||
this.type = type;
|
||||
this.race = race;
|
||||
this.proprietaire = proprietaire;
|
||||
this.age = age;
|
||||
this.image = image;
|
||||
}
|
||||
public Cheval (String nom, String sexe, String robe, String type, String race, String proprietaire, int age)
|
||||
{//ADD
|
||||
this.nom = nom;
|
||||
this.sexe = sexe;
|
||||
this.robe = robe;
|
||||
this.type = type;
|
||||
this.race = race;
|
||||
this.proprietaire = proprietaire;
|
||||
this.age = age;
|
||||
}
|
||||
public Cheval (String nom)
|
||||
{//DELETE
|
||||
this.nom = nom;
|
||||
}
|
||||
public int getId() { return id; }
|
||||
public String getNom() { return nom; }
|
||||
public String getSexe() { return sexe; }
|
||||
public String getRobe() { return robe; }
|
||||
public String getType() { return type; }
|
||||
public String getRace() { return race; }
|
||||
public String getProprietaire() { return proprietaire; }
|
||||
public int getAge() { return age; }
|
||||
public String getImage() { return image; }
|
||||
public void setId(int id) { this.id = id; }
|
||||
public void setNom(String nom) { this.nom = nom; }
|
||||
public void setSexe(String sexe) { this.sexe = sexe; }
|
||||
public void setRobe(String robe) { this.robe = robe; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
public void setRace(String race) { this.race = race; }
|
||||
public void setProprietaire(String proprietaire) { this.proprietaire = proprietaire; }
|
||||
public void setAge(int age) { this.age = age; }
|
||||
public void setImage(String image) { this.image = image; }
|
||||
}
|
||||
50
src/controleur/Cours.java
Normal file
50
src/controleur/Cours.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package controleur;
|
||||
|
||||
public class Cours
|
||||
{
|
||||
private int idcours;
|
||||
private String datecours, heuredebut, heurefin;
|
||||
public Cours()
|
||||
{
|
||||
this.idcours=0;
|
||||
this.datecours = this.heuredebut=this.heurefin="";
|
||||
}
|
||||
public Cours (int idcours, String datecours, String heuredebut, String heurefin)
|
||||
{
|
||||
this.idcours= idcours;
|
||||
this.datecours = datecours;
|
||||
this.heuredebut = heuredebut;
|
||||
this.heurefin = heurefin;
|
||||
}
|
||||
public Cours ( String datecours, String heuredebut, String heurefin)
|
||||
{
|
||||
this.idcours= 0;
|
||||
this.datecours = datecours;
|
||||
this.heuredebut = heuredebut;
|
||||
this.heurefin = heurefin;
|
||||
}
|
||||
public int getIdCours() {
|
||||
return idcours;
|
||||
}
|
||||
public void setIdCours(int idcours) {
|
||||
this.idcours = idcours;
|
||||
}
|
||||
public String getDateCours() {
|
||||
return datecours;
|
||||
}
|
||||
public void setDateCours(String datecours) {
|
||||
this.datecours = datecours;
|
||||
}
|
||||
public String getHeureDebut() {
|
||||
return heuredebut;
|
||||
}
|
||||
public void setHeureDebut(String heuredebut) {
|
||||
this.heuredebut = heuredebut;
|
||||
}
|
||||
public String getHeureFin() {
|
||||
return heurefin;
|
||||
}
|
||||
public void setHeureFin(String heurefin) {
|
||||
this.heurefin = heurefin;
|
||||
}
|
||||
}
|
||||
66
src/controleur/Eleve.java
Normal file
66
src/controleur/Eleve.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package controleur;
|
||||
|
||||
public class Eleve
|
||||
{
|
||||
private int id, privilege, age, galop;
|
||||
private String record, pseudo, prenom, nom, sexe, adresse, mdp, mail, imageeleve;
|
||||
public Eleve() {//ALL
|
||||
this.id=this.privilege=this.age=this.galop=0;
|
||||
this.record=this.pseudo=this.prenom=this.nom=this.sexe=this.adresse=this.mail="";
|
||||
}
|
||||
public Eleve (int id, int privilege, String record, String pseudo, String prenom, String nom, String sexe, int age, String adresse, String mdp, String mail, int galop, String imageeleve)
|
||||
{//ALL
|
||||
this.id= id;
|
||||
this.privilege = privilege;
|
||||
this.record = record;
|
||||
this.pseudo = pseudo;
|
||||
this.prenom = prenom;
|
||||
this.nom = nom;
|
||||
this.sexe = sexe;
|
||||
this.age = age;
|
||||
this.adresse = adresse;
|
||||
this.mdp = mdp;
|
||||
this.mail = mail;
|
||||
this.galop = galop;
|
||||
this.imageeleve = imageeleve;
|
||||
}
|
||||
public Eleve (String prenom, String nom, String sexe, int age, String adresse, String mail, int galop)
|
||||
{//ADD & Modify
|
||||
this.prenom = prenom;
|
||||
this.nom = nom;
|
||||
this.sexe = sexe;
|
||||
this.age = age;
|
||||
this.adresse = adresse;
|
||||
this.mail = mail;
|
||||
this.galop = galop;
|
||||
}
|
||||
public Eleve (String mail) {//DELETE
|
||||
this.mail = mail;
|
||||
}
|
||||
public int getId() { return id; }
|
||||
public int getPrivilege() { return privilege; }
|
||||
public String getRecord() { return record; }
|
||||
public String getPseudo() { return pseudo; }
|
||||
public String getPrenom() { return prenom; }
|
||||
public String getNom() { return nom; }
|
||||
public String getSexe() { return sexe; }
|
||||
public int getAge() { return age; }
|
||||
public String getAdresse() { return adresse; }
|
||||
public String getMdp() { return mdp; }
|
||||
public String getMail() { return mail; }
|
||||
public int getGalop() { return galop; }
|
||||
public String getImageEleve() { return imageeleve; }
|
||||
public void setid(int id) { this.id = id; }
|
||||
public void setPrivilege(int privilege) { this.privilege = privilege; }
|
||||
public void setrecord(String record) { this.record = record; }
|
||||
public void setPseudo(String pseudo) { this.pseudo = pseudo; }
|
||||
public void setPrenom(String prenom) { this.prenom = prenom; }
|
||||
public void setNom(String nom) { this.nom = nom; }
|
||||
public void setSexe(String sexe) { this.sexe = sexe; }
|
||||
public void setAge(int age) { this.age = age; }
|
||||
public void setAdresse(String adresse) { this.adresse = adresse; }
|
||||
public void setMdp(String mdp) { this.mdp = mdp; }
|
||||
public void setMail(String mail) { this.mail = mail; }
|
||||
public void setGalop(int galop) { this.galop = galop; }
|
||||
public void setImageEleve(String imageeleve) { this.imageeleve = imageeleve; }
|
||||
}
|
||||
59
src/controleur/Formateur.java
Normal file
59
src/controleur/Formateur.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package controleur;
|
||||
|
||||
public class Formateur
|
||||
{
|
||||
private int idformateur, privilege, age, galop;
|
||||
private String login, prenom, nom, sexe, mail, mdp ;
|
||||
public Formateur()
|
||||
{//ALL
|
||||
this.idformateur=this.privilege=this.age=this.galop=0;
|
||||
this.login=this.prenom=this.nom=this.sexe=this.mail=this.mdp="";
|
||||
}
|
||||
public Formateur (int idformateur, String login, int privilege, String prenom, String nom, int age, int galop, String sexe, String mail, String mdp)
|
||||
{//ALL
|
||||
this.idformateur= idformateur;
|
||||
this.login = login;
|
||||
this.privilege = privilege;
|
||||
this.prenom = prenom;
|
||||
this.nom = nom;
|
||||
this.age = age;
|
||||
this.galop = galop;
|
||||
this.sexe = sexe;
|
||||
this.mail = mail;
|
||||
this.mdp = mdp;
|
||||
}
|
||||
public Formateur(String prenom,String nom, int age, int galop, String sexe, String mail, String mdp)
|
||||
{//ADD
|
||||
this.prenom = prenom;
|
||||
this.nom = nom;
|
||||
this.age = age;
|
||||
this.galop = galop;
|
||||
this.sexe = sexe;
|
||||
this.mail = mail;
|
||||
this.mdp = mdp;
|
||||
}
|
||||
public Formateur(String mail)
|
||||
{//DELETE
|
||||
this.mail = mail;
|
||||
}
|
||||
public int getId() { return idformateur; }
|
||||
public String getLogin() { return login; }
|
||||
public int getPrivilege() { return privilege; }
|
||||
public String getPrenom() { return prenom; }
|
||||
public String getNom() { return nom; }
|
||||
public int getAge() { return age; }
|
||||
public int getGalop() { return galop;}
|
||||
public String getSexe() {return sexe;}
|
||||
public String getMail() { return mail; }
|
||||
public String getMdp() { return mdp; }
|
||||
public void setId(int idformateur) { this.idformateur = idformateur; }
|
||||
public void setLogin(String login) { this.login = login; }
|
||||
public void setPrivilege(int privilege) { this.privilege = privilege; }
|
||||
public void setPrenom(String prenom) { this.prenom = prenom; }
|
||||
public void setNom(String nom) { this.nom = nom; }
|
||||
public void setAge(int age) { this.age = age; }
|
||||
public void setGalop(int galop) {this.galop = galop; }
|
||||
public void setSexe(String sexe) {this.sexe = sexe; }
|
||||
public void setMail(String mail) { this.mail = mail; }
|
||||
public void setMdp(String mdp) { this.mdp = mdp; }
|
||||
}
|
||||
23
src/controleur/Gestion.java
Normal file
23
src/controleur/Gestion.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package controleur;
|
||||
|
||||
import vue.Connexion;
|
||||
|
||||
public class Gestion
|
||||
{
|
||||
private static Connexion uneConnexion;
|
||||
public Gestion()
|
||||
{
|
||||
uneConnexion = new Connexion();
|
||||
uneConnexion.rendreVisible(true);
|
||||
}
|
||||
|
||||
public static void rendreVisible(boolean val)
|
||||
{
|
||||
uneConnexion.rendreVisible(val);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
new Gestion();
|
||||
}
|
||||
}
|
||||
BIN
src/images/choix1.png
Normal file
BIN
src/images/choix1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
BIN
src/images/choix2.png
Normal file
BIN
src/images/choix2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
src/images/choosemyday_logo.png
Normal file
BIN
src/images/choosemyday_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
src/images/ec_launcher-web.png
Normal file
BIN
src/images/ec_launcher-web.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
BIN
src/images/favicon.png
Normal file
BIN
src/images/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.2 KiB |
BIN
src/images/logo.png
Normal file
BIN
src/images/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
53
src/modele/BDD.java
Normal file
53
src/modele/BDD.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package modele;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class BDD {
|
||||
private String serveur, nombdd, user, mdp;
|
||||
private Connection maConnexion;
|
||||
|
||||
public BDD() {
|
||||
this.serveur = "localhost";
|
||||
this.nombdd = "Ecurie";
|
||||
this.user = "USER";
|
||||
this.mdp = "MDP";
|
||||
this.maConnexion = null;
|
||||
}
|
||||
public void chargerPilote() {
|
||||
// v<>rifie la pr<70>sence du pilote JDBC MySQL
|
||||
try {
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
}
|
||||
catch(ClassNotFoundException exp) {
|
||||
System.out.println("Abscence du pilote JDBC !");
|
||||
System.out.println("V<EFBFBD>rifier Project -> Build Path -> Configure -> Libraries -> Add External JARs");
|
||||
}
|
||||
}
|
||||
public void seConnecter() {
|
||||
// connexion au serveur de la BDD
|
||||
this.chargerPilote();
|
||||
String url = "jdbc:mariadb://" + this.serveur + "/" + this.nombdd;
|
||||
try {
|
||||
this.maConnexion = DriverManager.getConnection(url, this.user, this.mdp);
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Impossible de se connecter <20><> " + url);
|
||||
}
|
||||
}
|
||||
public void seDeconnecter() {
|
||||
// d<>connexion au serveur de la BDD
|
||||
try {
|
||||
if(this.maConnexion != null) this.maConnexion.close();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("La d<>connexion a <20>chou<6F> !");
|
||||
}
|
||||
}
|
||||
public Connection getMaConnexion()
|
||||
{
|
||||
return this.maConnexion;
|
||||
}
|
||||
}
|
||||
107
src/modele/ModeleCheval.java
Normal file
107
src/modele/ModeleCheval.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package modele;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import controleur.Cheval;
|
||||
|
||||
public class ModeleCheval {
|
||||
public static ArrayList<Cheval> selectAll() {
|
||||
ArrayList<Cheval> lesChevaux = new ArrayList<Cheval>();
|
||||
String requete = "select * from Cheval;";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
while(unRes.next()) {
|
||||
int id = unRes.getInt("idcheval");
|
||||
String nom = unRes.getString("nom");
|
||||
String sexe = unRes.getString("sexe");
|
||||
String robe = unRes.getString("robe");
|
||||
String type = unRes.getString("type");
|
||||
String race = unRes.getString("race");
|
||||
String proprietaire = unRes.getString("proprietaire");
|
||||
int age = unRes.getInt("age");
|
||||
String image = unRes.getString("imagecheval");
|
||||
Cheval unCheval = new Cheval(id, nom, sexe, robe, type, race, proprietaire, age, image);
|
||||
lesChevaux.add(unCheval);
|
||||
}
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
return lesChevaux;
|
||||
}
|
||||
public static Cheval selectWhere(String nom) {
|
||||
String requete = "select * from Cheval where nom='" + nom + "';";
|
||||
Cheval unCheval = null;
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
if(unRes.next()) {
|
||||
int id = unRes.getInt("idcheval");
|
||||
//Nom
|
||||
String sexe = unRes.getString("sexe");
|
||||
String robe = unRes.getString("robe");
|
||||
String type = unRes.getString("type");
|
||||
String race = unRes.getString("race");
|
||||
String proprietaire = unRes.getString("proprietaire");
|
||||
int age = unRes.getInt("age");
|
||||
String image = unRes.getString("imagecheval");
|
||||
unCheval = new Cheval(id, nom, sexe, robe, type, race, proprietaire, age, image);
|
||||
}
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
return unCheval;
|
||||
}
|
||||
public static void insert(Cheval unCheval) {
|
||||
String requete = "insert into Cheval (nom, sexe, robe, type, race, proprietaire, age) values ('"
|
||||
+ unCheval.getNom() + "', '"
|
||||
+ unCheval.getSexe() + "', '"
|
||||
+ unCheval.getRobe() + "', '"
|
||||
+ unCheval.getType() + "', '"
|
||||
+ unCheval.getRace() + "', '"
|
||||
+ unCheval.getProprietaire() + "', '"
|
||||
+ unCheval.getAge() + "');";
|
||||
/*+ unCheval.getImage()+ "');";*/
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
public static void delete(String nom) {
|
||||
String requete = "delete from Cheval where nom='" + nom + "';";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
}
|
||||
95
src/modele/ModeleCours.java
Normal file
95
src/modele/ModeleCours.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package modele;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import controleur.Cours;
|
||||
|
||||
public class ModeleCours
|
||||
{
|
||||
public static ArrayList<Cours> selectAll()
|
||||
{
|
||||
ArrayList<Cours> lesCours = new ArrayList<Cours>();
|
||||
String requete = "select * from Cours;";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
while(unRes.next()) {
|
||||
int idcours = unRes.getInt("idcours");
|
||||
String datecours = unRes.getString("datecours");
|
||||
String heuredebut = unRes.getString("heuredebut");
|
||||
String heurefin = unRes.getString("heurefin");
|
||||
Cours unCours = new Cours(idcours, datecours, heuredebut, heurefin);
|
||||
lesCours.add(unCours);
|
||||
}
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
return lesCours;
|
||||
}
|
||||
public static void insert(Cours unCours)
|
||||
{
|
||||
String requete = "insert into Cours (datecours, heuredebut, heurefin ) values ('"
|
||||
+ unCours.getDateCours() + "', '"
|
||||
+ unCours.getHeureDebut() + "', '"
|
||||
+ unCours.getHeureFin() + "');";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp)
|
||||
{
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
public static void delete(String datecours, String heuredebut) {
|
||||
String requete = "delete from Cours where datecours='" + datecours + "AND heuredebut='" + heuredebut + "';";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
public static Cours selectWhere(String datecours, String heuredebut)
|
||||
{
|
||||
String requete = "select * from Cours where datecours='" + datecours + "' and heuredebut='" + heuredebut + "';";
|
||||
Cours unCours = null;
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
if(unRes.next())
|
||||
{
|
||||
String heurefin = unRes.getString("heurefin");
|
||||
unCours = new Cours(datecours, heuredebut, heurefin);
|
||||
}
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
return unCours;
|
||||
}
|
||||
}
|
||||
151
src/modele/ModeleEleve.java
Normal file
151
src/modele/ModeleEleve.java
Normal file
@@ -0,0 +1,151 @@
|
||||
package modele;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import controleur.Eleve;
|
||||
|
||||
public class ModeleEleve
|
||||
{
|
||||
public static ArrayList<Eleve> selectAll() {
|
||||
ArrayList<Eleve> lesEleves = new ArrayList<Eleve>();
|
||||
String requete = "select * from Eleve;";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
while(unRes.next()) {
|
||||
int id = unRes.getInt("ideleve");
|
||||
int privilege = unRes.getInt("privilege");
|
||||
String record = unRes.getString("dateenregistre");
|
||||
String pseudo = unRes.getString("pseudo");
|
||||
String prenom = unRes.getString("prenom");
|
||||
String nom = unRes.getString("nom");
|
||||
String sexe = unRes.getString("sexe");
|
||||
int age = unRes.getInt("age");
|
||||
String adresse = unRes.getString("adresse");
|
||||
String mdp = unRes.getString("mdp");
|
||||
String mail = unRes.getString("adressemail");
|
||||
int galop = unRes.getInt("galop");
|
||||
String image = unRes.getString("imageeleve");
|
||||
Eleve unEleve = new Eleve(id, privilege, record, pseudo, prenom, nom, sexe, age, adresse, mdp, mail, galop, image);
|
||||
lesEleves.add(unEleve);
|
||||
}
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
return lesEleves;
|
||||
}
|
||||
public static Eleve selectWhere(String mail) {
|
||||
String requete = "select * from Eleve where adressemail='" + mail + "';";
|
||||
Eleve unEleve = null;
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
if(unRes.next()) {
|
||||
int id = unRes.getInt("ideleve");
|
||||
int privilege = unRes.getInt("privilege");
|
||||
String record = unRes.getString("dateenregistre");
|
||||
String pseudo = unRes.getString("pseudo");
|
||||
String prenom = unRes.getString("prenom");
|
||||
String nom = unRes.getString("nom");
|
||||
String sexe = unRes.getString("sexe");
|
||||
int age = unRes.getInt("age");
|
||||
String adresse = unRes.getString("adresse");
|
||||
String mdp = unRes.getString("mdp");
|
||||
//adressemail
|
||||
int galop = unRes.getInt("galop");
|
||||
String image = unRes.getString("imageeleve");
|
||||
unEleve = new Eleve(id, privilege, record, pseudo, prenom, nom, sexe, age, adresse, mdp, mail, galop, image);
|
||||
}
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
return unEleve;
|
||||
}
|
||||
public static void insert(Eleve unEleve) {
|
||||
String requete = "insert into Eleve (privilege, dateenregistre, pseudo, prenom, nom, sexe, age, adresse, mdp, adressemail, galop, imageeleve) values ('"
|
||||
+ "2', NOW(), 'NEW', '"
|
||||
+ unEleve.getPrenom() + "', '"
|
||||
+ unEleve.getNom() + "', '"
|
||||
+ unEleve.getSexe() + "', "
|
||||
+ unEleve.getAge() + ", '"
|
||||
+ unEleve.getAdresse() + "', '"
|
||||
+ "CCB', '"
|
||||
+ unEleve.getMail() + "', "
|
||||
+ unEleve.getGalop() + ", '"
|
||||
+ "./images/avatars/img_user.jpg');";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
public static void update(Eleve unEleve, String mail) {
|
||||
String valuePrenom = unEleve.getPrenom();
|
||||
String valueNom = unEleve.getNom();
|
||||
String valueSexe = unEleve.getSexe();
|
||||
String valueAge = String.valueOf(unEleve.getAge());
|
||||
String valueGalop = String.valueOf(unEleve.getGalop());
|
||||
String valueAdresse = unEleve.getAdresse();
|
||||
//adressemail
|
||||
if (unEleve.getPrenom().equals("")) { valuePrenom = ""; }
|
||||
else { valuePrenom = ", prenom = '"+ unEleve.getPrenom() +"'"; }
|
||||
if (unEleve.getNom().equals("")) { valueNom = ""; }
|
||||
else { valueNom = ", nom = '"+ unEleve.getNom() +"'"; }
|
||||
if (unEleve.getSexe().equals("")) { valueSexe = ""; }
|
||||
else { valueSexe = ", sexe = '"+ unEleve.getSexe() +"'"; }
|
||||
if (String.valueOf(unEleve.getAge()).equals("")) { valueAge = ""; }
|
||||
else { valueAge = ", age = "+ unEleve.getAge(); }
|
||||
if (unEleve.getAdresse().equals("")) { valueAdresse = ""; }
|
||||
else { valueAdresse = ", adresse = '"+ unEleve.getAdresse() +"'"; }
|
||||
if (String.valueOf(unEleve.getGalop()).equals("")) { valueGalop = ""; }
|
||||
else { valueGalop = ", galop = "+ unEleve.getGalop(); }
|
||||
String requete = "update Eleve set adressemail ='"+ unEleve.getMail() +"'" + valuePrenom + valueNom + valueSexe + valueAge + valueAdresse + valueGalop + " where adressemail='"+ mail +"';";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
public static void delete(String mail) {
|
||||
String requete = "delete from Eleve where adressemail='" + mail + "';";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
}
|
||||
109
src/modele/ModeleFormateur.java
Normal file
109
src/modele/ModeleFormateur.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package modele;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import controleur.Formateur;
|
||||
|
||||
public class ModeleFormateur
|
||||
{
|
||||
public static ArrayList<Formateur> selectAll() {
|
||||
ArrayList<Formateur> lesFormateurs = new ArrayList<Formateur>();
|
||||
String requete = "select * from Formateur;";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
while(unRes.next()) {
|
||||
int idformateur = unRes.getInt("idformateur");
|
||||
String login = unRes.getString("login");
|
||||
int privilege = unRes.getInt("privilege");
|
||||
String prenom = unRes.getString("prenom");
|
||||
String nom = unRes.getString("nom");
|
||||
int age = unRes.getInt("age");
|
||||
int galop = unRes.getInt("galop");
|
||||
String sexe = unRes.getString("sexe");
|
||||
String mail = unRes.getString("adressemail");
|
||||
String mdp = unRes.getString("mdp");
|
||||
Formateur unFormateur = new Formateur(idformateur, login, privilege, prenom, nom, age, galop, sexe, mail, mdp);
|
||||
lesFormateurs.add(unFormateur);
|
||||
}
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
return lesFormateurs;
|
||||
}
|
||||
public static Formateur selectWhere(String mail, String mdp) {
|
||||
String requete = "select * from Formateur where adressemail='" + mail + "' and mdp='" + mdp + "';";
|
||||
Formateur unFormateur = null;
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
if(unRes.next())
|
||||
{
|
||||
int idformateur = unRes.getInt("idformateur");
|
||||
String login = unRes.getString("login");
|
||||
int privilege = unRes.getInt("privilege");
|
||||
String prenom = unRes.getString("prenom");
|
||||
String nom = unRes.getString("nom");
|
||||
int age = unRes.getInt("age");
|
||||
int galop = unRes.getInt("galop");
|
||||
String sexe = unRes.getString("sexe");
|
||||
// adressemail & mdp
|
||||
unFormateur = new Formateur(idformateur, login, privilege, prenom, nom, age, galop, sexe, mail, mdp);
|
||||
}
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
return unFormateur;
|
||||
}
|
||||
public static void insert(Formateur unFormateur) {
|
||||
String requete = "insert into Formateur (login, privilege, prenom, nom, age, galop, sexe, adressemail, mdp) values ('"
|
||||
+ unFormateur.getLogin() + "', '"
|
||||
+ unFormateur.getPrivilege() + "', '"
|
||||
+ unFormateur.getPrenom() + "', '"
|
||||
+ unFormateur.getNom() + "', '"
|
||||
+ unFormateur.getAge() + "', '"
|
||||
+ unFormateur.getGalop() + "', '"
|
||||
+ unFormateur.getSexe() + "', '"
|
||||
+ unFormateur.getMail() + "', '"
|
||||
+ unFormateur.getMdp() + "');";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
public static void delete(String mail) {
|
||||
String requete = "delete from Formateur where adressemail='" + mail + "';";
|
||||
try {
|
||||
BDD uneBDD = new BDD();
|
||||
uneBDD.seConnecter();
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
}
|
||||
6089
src/mysql-connector-java-8.0.26/CHANGES
Normal file
6089
src/mysql-connector-java-8.0.26/CHANGES
Normal file
File diff suppressed because it is too large
Load Diff
4
src/mysql-connector-java-8.0.26/INFO_BIN
Normal file
4
src/mysql-connector-java-8.0.26/INFO_BIN
Normal file
@@ -0,0 +1,4 @@
|
||||
build-date: 2021-06-08 16:39:29 +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
|
||||
5
src/mysql-connector-java-8.0.26/INFO_SRC
Normal file
5
src/mysql-connector-java-8.0.26/INFO_SRC
Normal file
@@ -0,0 +1,5 @@
|
||||
version: 8.0.26
|
||||
branch: release/8.0.26
|
||||
date: 2021-06-08 14:49:03 +0100
|
||||
commit: 9aae1e450989d62c06616c1dcda3e404ef84df70
|
||||
short: 9aae1e45
|
||||
1976
src/mysql-connector-java-8.0.26/LICENSE
Normal file
1976
src/mysql-connector-java-8.0.26/LICENSE
Normal file
File diff suppressed because it is too large
Load Diff
28
src/mysql-connector-java-8.0.26/README
Normal file
28
src/mysql-connector-java-8.0.26/README
Normal file
@@ -0,0 +1,28 @@
|
||||
Copyright (c) 2000, 2021, 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 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: mysql"
|
||||
and "ArtifactId: mysql-connector-java" to your project's pom.xml file.
|
||||
1591
src/mysql-connector-java-8.0.26/build.xml
Normal file
1591
src/mysql-connector-java-8.0.26/build.xml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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,734 @@
|
||||
/*
|
||||
* 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.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.PreparedStatement 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("asSql", new CtClass[] { CtClass.booleanType }), 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("executeBatchedInserts", 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("initializeFromParseInfo", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("isNull", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
|
||||
catchRuntimeException(clazz, clazz.getDeclaredMethod("isSelectQuery", new CtClass[] {}), 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 PreparedStatement
|
||||
*/
|
||||
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("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("canRewriteAsMultiValueInsertAtSqlLevel", 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
17
src/mysql-connector-java-8.0.26/src/build/misc/.project
Normal file
17
src/mysql-connector-java-8.0.26/src/build/misc/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>misc</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
66
src/mysql-connector-java-8.0.26/src/build/misc/Product.wxs
Normal file
66
src/mysql-connector-java-8.0.26/src/build/misc/Product.wxs
Normal file
@@ -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@@PRODUCT_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 @@
|
||||
9
|
||||
@@ -0,0 +1,14 @@
|
||||
Source: @PRODUCT_NAME@@PRODUCT_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@@PRODUCT_SUFFIX@
|
||||
Section: database
|
||||
Architecture: all
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
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 @@
|
||||
dist/toArchive/@PACKAGE_NAME@/@PRODUCT_NAME@@PRODUCT_SUFFIX@-@VERSION_FULL@.jar usr/share/java
|
||||
|
||||
#legal
|
||||
dist/toArchive/@PACKAGE_NAME@/@LIC_FILE@ usr/share/doc/@PRODUCT_NAME@@PRODUCT_SUFFIX@
|
||||
dist/toArchive/@PACKAGE_NAME@/README usr/share/doc/@PRODUCT_NAME@@PRODUCT_SUFFIX@
|
||||
dist/toArchive/@PACKAGE_NAME@/CHANGES usr/share/doc/@PRODUCT_NAME@@PRODUCT_SUFFIX@
|
||||
dist/toArchive/@PACKAGE_NAME@/INFO_SRC usr/share/doc/@PRODUCT_NAME@@PRODUCT_SUFFIX@
|
||||
dist/toArchive/@PACKAGE_NAME@/INFO_BIN usr/share/doc/@PRODUCT_NAME@@PRODUCT_SUFFIX@
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/make -f
|
||||
# Copyright (c) 2016, 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
|
||||
|
||||
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=@PRODUCT_SUFFIX@ \
|
||||
-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) \
|
||||
full-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
|
||||
67
src/mysql-connector-java-8.0.26/src/build/misc/pom.xml
Normal file
67
src/mysql-connector-java-8.0.26/src/build/misc/pom.xml
Normal file
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
Copyright (c) 2006, 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
|
||||
-->
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>@MYSQL_CJ_VERSION@</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MySQL Connector/J</name>
|
||||
<description>JDBC Type 4 driver for MySQL</description>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The GNU General Public License, v2 with FOSS exception</name>
|
||||
<distribution>repo</distribution>
|
||||
<comments>For detailed license information see the LICENSE file in this distribution.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<url>http://dev.mysql.com/doc/connector-j/en/</url>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:mysql/mysql-connector-j.git</connection>
|
||||
<url>https://github.com/mysql/mysql-connector-j</url>
|
||||
</scm>
|
||||
|
||||
<organization>
|
||||
<name>Oracle Corporation</name>
|
||||
<url>http://www.oracle.com</url>
|
||||
</organization>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>3.11.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
197
src/mysql-connector-java-8.0.26/src/build/misc/rpm.spec.in
Normal file
197
src/mysql-connector-java-8.0.26/src/build/misc/rpm.spec.in
Normal file
@@ -0,0 +1,197 @@
|
||||
# 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
|
||||
|
||||
# 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@
|
||||
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
|
||||
|
||||
%if 0%{?commercial:1}
|
||||
Obsoletes: mysql-connector-java < %{version}-%{release}
|
||||
Provides: mysql-connector-java = %{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} \
|
||||
full-package-no-sources
|
||||
|
||||
# We use the 'full-package-no-sources' as there are changes done only
|
||||
# when creating a package, 'dist' is not enough. To make it a bit easier
|
||||
# in the install step, we rename the directory with the content
|
||||
mv dist/toArchive/@PACKAGE_NAME@ 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,88 @@
|
||||
/*
|
||||
* 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 com.mysql.cj;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import com.mysql.cj.util.StringUtils;
|
||||
|
||||
public class AppendingBatchVisitor implements BatchVisitor {
|
||||
LinkedList<byte[]> statementComponents = new LinkedList<>();
|
||||
|
||||
public BatchVisitor append(byte[] values) {
|
||||
this.statementComponents.addLast(values);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BatchVisitor increment() {
|
||||
// no-op
|
||||
return this;
|
||||
}
|
||||
|
||||
public BatchVisitor decrement() {
|
||||
this.statementComponents.removeLast();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BatchVisitor merge(byte[] front, byte[] back) {
|
||||
int mergedLength = front.length + back.length;
|
||||
byte[] merged = new byte[mergedLength];
|
||||
System.arraycopy(front, 0, merged, 0, front.length);
|
||||
System.arraycopy(back, 0, merged, front.length, back.length);
|
||||
this.statementComponents.addLast(merged);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatchVisitor mergeWithLast(byte[] values) {
|
||||
if (this.statementComponents.isEmpty()) {
|
||||
return append(values);
|
||||
}
|
||||
return merge(this.statementComponents.removeLast(), values);
|
||||
}
|
||||
|
||||
public byte[][] getStaticSqlStrings() {
|
||||
byte[][] asBytes = new byte[this.statementComponents.size()][];
|
||||
this.statementComponents.toArray(asBytes);
|
||||
|
||||
return asBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte[] comp : this.statementComponents) {
|
||||
sb.append(StringUtils.toString(comp));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 com.mysql.cj;
|
||||
|
||||
public interface BatchVisitor {
|
||||
|
||||
BatchVisitor increment();
|
||||
|
||||
BatchVisitor decrement();
|
||||
|
||||
BatchVisitor append(byte[] values);
|
||||
|
||||
BatchVisitor merge(byte[] begin, byte[] end);
|
||||
|
||||
BatchVisitor mergeWithLast(byte[] values);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 com.mysql.cj;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface BindValue {
|
||||
|
||||
BindValue clone();
|
||||
|
||||
void reset();
|
||||
|
||||
boolean isNull();
|
||||
|
||||
void setNull(boolean isNull);
|
||||
|
||||
boolean isStream();
|
||||
|
||||
void setIsStream(boolean isStream);
|
||||
|
||||
MysqlType getMysqlType();
|
||||
|
||||
void setMysqlType(MysqlType type);
|
||||
|
||||
byte[] getByteValue();
|
||||
|
||||
void setByteValue(byte[] parameterValue);
|
||||
|
||||
void setOrigByteValue(byte[] origParamValue);
|
||||
|
||||
byte[] getOrigByteValue();
|
||||
|
||||
InputStream getStreamValue();
|
||||
|
||||
void setStreamValue(InputStream parameterStream, long streamLength);
|
||||
|
||||
long getStreamLength();
|
||||
|
||||
boolean isSet();
|
||||
}
|
||||
@@ -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,767 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 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.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
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_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_utf8, 3, 0, new String[] { "UTF-8" }),
|
||||
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 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 sets each element of collation[1]..collation[MAP_SIZE-1] must not be null
|
||||
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);
|
||||
|
||||
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, "utf8_general_ci", 1, MYSQL_CHARSET_NAME_utf8);
|
||||
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, "utf8_tolower_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
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, "utf8_bin", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
collation[192] = new Collation(192, "utf8_unicode_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[193] = new Collation(193, "utf8_icelandic_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[194] = new Collation(194, "utf8_latvian_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[195] = new Collation(195, "utf8_romanian_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[196] = new Collation(196, "utf8_slovenian_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[197] = new Collation(197, "utf8_polish_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[198] = new Collation(198, "utf8_estonian_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[199] = new Collation(199, "utf8_spanish_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[200] = new Collation(200, "utf8_swedish_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[201] = new Collation(201, "utf8_turkish_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[202] = new Collation(202, "utf8_czech_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[203] = new Collation(203, "utf8_danish_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[204] = new Collation(204, "utf8_lithuanian_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[205] = new Collation(205, "utf8_slovak_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[206] = new Collation(206, "utf8_spanish2_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[207] = new Collation(207, "utf8_roman_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[208] = new Collation(208, "utf8_persian_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[209] = new Collation(209, "utf8_esperanto_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[210] = new Collation(210, "utf8_hungarian_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[211] = new Collation(211, "utf8_sinhala_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[212] = new Collation(212, "utf8_german2_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[213] = new Collation(213, "utf8_croatian_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[214] = new Collation(214, "utf8_unicode_520_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
collation[215] = new Collation(215, "utf8_vietnamese_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
|
||||
collation[223] = new Collation(223, "utf8_general_mysql500_ci", 0, MYSQL_CHARSET_NAME_utf8);
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
collation[300] = new Collation(300, "utf8mb4_vi_0900_as_cs", 0, MYSQL_CHARSET_NAME_utf8mb4);
|
||||
|
||||
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_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.collationName;
|
||||
collationIndexToCharset.put(i, coll.mysqlCharset);
|
||||
collationNameToCollationIndexMap.put(coll.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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 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));
|
||||
}
|
||||
|
||||
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 collationName;
|
||||
public final int priority;
|
||||
public final MysqlCharset mysqlCharset;
|
||||
|
||||
public Collation(int index, String collationName, int priority, String charsetName) {
|
||||
this.index = index;
|
||||
this.collationName = collationName;
|
||||
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(",collationName=");
|
||||
asString.append(this.collationName);
|
||||
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,106 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 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.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 PLATFORM_ENCODING = System.getProperty(PropertyDefinitions.SYSP_file_encoding);
|
||||
|
||||
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,43 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -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,596 @@
|
||||
/*
|
||||
* 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 com.mysql.cj;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
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.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 ParseInfo {
|
||||
|
||||
protected static final String[] ON_DUPLICATE_KEY_UPDATE_CLAUSE = new String[] { "ON", "DUPLICATE", "KEY", "UPDATE" };
|
||||
|
||||
private char firstStmtChar = 0;
|
||||
|
||||
private boolean foundLoadData = false;
|
||||
|
||||
long lastUsed = 0;
|
||||
|
||||
int statementLength = 0;
|
||||
|
||||
int statementStartPos = 0;
|
||||
|
||||
boolean canRewriteAsMultiValueInsert = false;
|
||||
|
||||
byte[][] staticSql = null;
|
||||
|
||||
boolean hasPlaceholders = false;
|
||||
|
||||
public int numberOfQueries = 1;
|
||||
|
||||
boolean isOnDuplicateKeyUpdate = false;
|
||||
|
||||
int locationOfOnDuplicateKeyUpdate = -1;
|
||||
|
||||
String valuesClause;
|
||||
|
||||
boolean parametersInDuplicateKeyClause = false;
|
||||
|
||||
String charEncoding;
|
||||
|
||||
private ParseInfo batchHead;
|
||||
|
||||
private ParseInfo batchValues;
|
||||
|
||||
private ParseInfo batchODKUClause;
|
||||
|
||||
private ParseInfo(byte[][] staticSql, char firstStmtChar, boolean foundLoadData, boolean isOnDuplicateKeyUpdate, int locationOfOnDuplicateKeyUpdate,
|
||||
int statementLength, int statementStartPos) {
|
||||
this.firstStmtChar = firstStmtChar;
|
||||
this.foundLoadData = foundLoadData;
|
||||
this.isOnDuplicateKeyUpdate = isOnDuplicateKeyUpdate;
|
||||
this.locationOfOnDuplicateKeyUpdate = locationOfOnDuplicateKeyUpdate;
|
||||
this.statementLength = statementLength;
|
||||
this.statementStartPos = statementStartPos;
|
||||
this.staticSql = staticSql;
|
||||
}
|
||||
|
||||
public ParseInfo(String sql, Session session, String encoding) {
|
||||
this(sql, session, encoding, true);
|
||||
}
|
||||
|
||||
public ParseInfo(String sql, Session session, String encoding, boolean buildRewriteInfo) {
|
||||
|
||||
try {
|
||||
if (sql == null) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("PreparedStatement.61"),
|
||||
session.getExceptionInterceptor());
|
||||
}
|
||||
|
||||
this.charEncoding = encoding;
|
||||
this.lastUsed = System.currentTimeMillis();
|
||||
|
||||
String quotedIdentifierString = session.getIdentifierQuoteString();
|
||||
|
||||
char quotedIdentifierChar = 0;
|
||||
|
||||
if ((quotedIdentifierString != null) && !quotedIdentifierString.equals(" ") && (quotedIdentifierString.length() > 0)) {
|
||||
quotedIdentifierChar = quotedIdentifierString.charAt(0);
|
||||
}
|
||||
|
||||
this.statementLength = sql.length();
|
||||
|
||||
ArrayList<int[]> endpointList = new ArrayList<>();
|
||||
boolean inQuotes = false;
|
||||
char quoteChar = 0;
|
||||
boolean inQuotedId = false;
|
||||
int lastParmEnd = 0;
|
||||
int i;
|
||||
|
||||
boolean noBackslashEscapes = session.getServerSession().isNoBackslashEscapesSet();
|
||||
|
||||
// we're not trying to be real pedantic here, but we'd like to skip comments at the beginning of statements, as frameworks such as Hibernate
|
||||
// use them to aid in debugging
|
||||
|
||||
this.statementStartPos = findStartOfStatement(sql);
|
||||
|
||||
for (i = this.statementStartPos; i < this.statementLength; ++i) {
|
||||
char c = sql.charAt(i);
|
||||
|
||||
if ((this.firstStmtChar == 0) && Character.isLetter(c)) {
|
||||
// Determine what kind of statement we're doing (_S_elect, _I_nsert, etc.)
|
||||
this.firstStmtChar = Character.toUpperCase(c);
|
||||
|
||||
// no need to search for "ON DUPLICATE KEY UPDATE" if not an INSERT statement
|
||||
if (this.firstStmtChar == 'I') {
|
||||
this.locationOfOnDuplicateKeyUpdate = getOnDuplicateKeyLocation(sql,
|
||||
session.getPropertySet().getBooleanProperty(PropertyKey.dontCheckOnDuplicateKeyUpdateInSQL).getValue(),
|
||||
session.getPropertySet().getBooleanProperty(PropertyKey.rewriteBatchedStatements).getValue(),
|
||||
session.getServerSession().isNoBackslashEscapesSet());
|
||||
this.isOnDuplicateKeyUpdate = this.locationOfOnDuplicateKeyUpdate != -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!noBackslashEscapes && c == '\\' && i < (this.statementLength - 1)) {
|
||||
i++;
|
||||
continue; // next character is escaped
|
||||
}
|
||||
|
||||
// are we in a quoted identifier? (only valid when the id is not inside a 'string')
|
||||
if (!inQuotes && (quotedIdentifierChar != 0) && (c == quotedIdentifierChar)) {
|
||||
inQuotedId = !inQuotedId;
|
||||
} else if (!inQuotedId) {
|
||||
// only respect quotes when not in a quoted identifier
|
||||
|
||||
if (inQuotes) {
|
||||
if (((c == '\'') || (c == '"')) && c == quoteChar) {
|
||||
if (i < (this.statementLength - 1) && sql.charAt(i + 1) == quoteChar) {
|
||||
i++;
|
||||
continue; // inline quote escape
|
||||
}
|
||||
|
||||
inQuotes = !inQuotes;
|
||||
quoteChar = 0;
|
||||
} else if (((c == '\'') || (c == '"')) && c == quoteChar) {
|
||||
inQuotes = !inQuotes;
|
||||
quoteChar = 0;
|
||||
}
|
||||
} else {
|
||||
if (c == '#' || (c == '-' && (i + 1) < this.statementLength && sql.charAt(i + 1) == '-')) {
|
||||
// run out to end of statement, or newline, whichever comes first
|
||||
int endOfStmt = this.statementLength - 1;
|
||||
|
||||
for (; i < endOfStmt; i++) {
|
||||
c = sql.charAt(i);
|
||||
|
||||
if (c == '\r' || c == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
} else if (c == '/' && (i + 1) < this.statementLength) {
|
||||
// Comment?
|
||||
char cNext = sql.charAt(i + 1);
|
||||
|
||||
if (cNext == '*') {
|
||||
i += 2;
|
||||
|
||||
for (int j = i; j < this.statementLength; j++) {
|
||||
i++;
|
||||
cNext = sql.charAt(j);
|
||||
|
||||
if (cNext == '*' && (j + 1) < this.statementLength) {
|
||||
if (sql.charAt(j + 1) == '/') {
|
||||
i++;
|
||||
|
||||
if (i < this.statementLength) {
|
||||
c = sql.charAt(i);
|
||||
}
|
||||
|
||||
break; // comment done
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ((c == '\'') || (c == '"')) {
|
||||
inQuotes = true;
|
||||
quoteChar = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!inQuotes && !inQuotedId) {
|
||||
if ((c == '?')) {
|
||||
endpointList.add(new int[] { lastParmEnd, i });
|
||||
lastParmEnd = i + 1;
|
||||
|
||||
if (this.isOnDuplicateKeyUpdate && i > this.locationOfOnDuplicateKeyUpdate) {
|
||||
this.parametersInDuplicateKeyClause = true;
|
||||
}
|
||||
} else if (c == ';') {
|
||||
int j = i + 1;
|
||||
if (j < this.statementLength) {
|
||||
for (; j < this.statementLength; j++) {
|
||||
if (!Character.isWhitespace(sql.charAt(j))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j < this.statementLength) {
|
||||
this.numberOfQueries++;
|
||||
}
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.firstStmtChar == 'L') {
|
||||
if (StringUtils.startsWithIgnoreCaseAndWs(sql, "LOAD DATA")) {
|
||||
this.foundLoadData = true;
|
||||
} else {
|
||||
this.foundLoadData = false;
|
||||
}
|
||||
} else {
|
||||
this.foundLoadData = false;
|
||||
}
|
||||
|
||||
endpointList.add(new int[] { lastParmEnd, this.statementLength });
|
||||
this.staticSql = new byte[endpointList.size()][];
|
||||
this.hasPlaceholders = this.staticSql.length > 1;
|
||||
|
||||
for (i = 0; i < this.staticSql.length; i++) {
|
||||
int[] ep = endpointList.get(i);
|
||||
int end = ep[1];
|
||||
int begin = ep[0];
|
||||
int len = end - begin;
|
||||
|
||||
if (this.foundLoadData) {
|
||||
this.staticSql[i] = StringUtils.getBytes(sql, begin, len);
|
||||
} else if (encoding == null) {
|
||||
byte[] buf = new byte[len];
|
||||
|
||||
for (int j = 0; j < len; j++) {
|
||||
buf[j] = (byte) sql.charAt(begin + j);
|
||||
}
|
||||
|
||||
this.staticSql[i] = buf;
|
||||
} else {
|
||||
this.staticSql[i] = StringUtils.getBytes(sql, begin, len, encoding);
|
||||
}
|
||||
}
|
||||
} catch (StringIndexOutOfBoundsException oobEx) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("PreparedStatement.62", new Object[] { sql }), oobEx,
|
||||
session.getExceptionInterceptor());
|
||||
}
|
||||
|
||||
if (buildRewriteInfo) {
|
||||
this.canRewriteAsMultiValueInsert = this.numberOfQueries == 1 && !this.parametersInDuplicateKeyClause
|
||||
&& canRewrite(sql, this.isOnDuplicateKeyUpdate, this.locationOfOnDuplicateKeyUpdate, this.statementStartPos);
|
||||
if (this.canRewriteAsMultiValueInsert && session.getPropertySet().getBooleanProperty(PropertyKey.rewriteBatchedStatements).getValue()) {
|
||||
buildRewriteBatchedParams(sql, session, encoding);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public byte[][] getStaticSql() {
|
||||
return this.staticSql;
|
||||
}
|
||||
|
||||
public String getValuesClause() {
|
||||
return this.valuesClause;
|
||||
}
|
||||
|
||||
public int getLocationOfOnDuplicateKeyUpdate() {
|
||||
return this.locationOfOnDuplicateKeyUpdate;
|
||||
}
|
||||
|
||||
public boolean canRewriteAsMultiValueInsertAtSqlLevel() {
|
||||
return this.canRewriteAsMultiValueInsert;
|
||||
}
|
||||
|
||||
public boolean containsOnDuplicateKeyUpdateInSQL() {
|
||||
return this.isOnDuplicateKeyUpdate;
|
||||
}
|
||||
|
||||
private void buildRewriteBatchedParams(String sql, Session session, String encoding) {
|
||||
this.valuesClause = extractValuesClause(sql, session.getIdentifierQuoteString());
|
||||
String odkuClause = this.isOnDuplicateKeyUpdate ? sql.substring(this.locationOfOnDuplicateKeyUpdate) : null;
|
||||
|
||||
String headSql = null;
|
||||
|
||||
if (this.isOnDuplicateKeyUpdate) {
|
||||
headSql = sql.substring(0, this.locationOfOnDuplicateKeyUpdate);
|
||||
} else {
|
||||
headSql = sql;
|
||||
}
|
||||
|
||||
this.batchHead = new ParseInfo(headSql, session, encoding, false);
|
||||
this.batchValues = new ParseInfo("," + this.valuesClause, session, encoding, false);
|
||||
this.batchODKUClause = null;
|
||||
|
||||
if (odkuClause != null && odkuClause.length() > 0) {
|
||||
this.batchODKUClause = new ParseInfo("," + this.valuesClause + " " + odkuClause, session, encoding, false);
|
||||
}
|
||||
}
|
||||
|
||||
private String extractValuesClause(String sql, String quoteCharStr) {
|
||||
int indexOfValues = -1;
|
||||
int valuesSearchStart = this.statementStartPos;
|
||||
|
||||
while (indexOfValues == -1) {
|
||||
if (quoteCharStr.length() > 0) {
|
||||
indexOfValues = StringUtils.indexOfIgnoreCase(valuesSearchStart, sql, "VALUES", quoteCharStr, quoteCharStr,
|
||||
StringUtils.SEARCH_MODE__MRK_COM_WS);
|
||||
} else {
|
||||
indexOfValues = StringUtils.indexOfIgnoreCase(valuesSearchStart, sql, "VALUES");
|
||||
}
|
||||
|
||||
if (indexOfValues > 0) {
|
||||
/* check if the char immediately preceding VALUES may be part of the table name */
|
||||
char c = sql.charAt(indexOfValues - 1);
|
||||
if (!(Character.isWhitespace(c) || c == ')' || c == '`')) {
|
||||
valuesSearchStart = indexOfValues + 6;
|
||||
indexOfValues = -1;
|
||||
} else {
|
||||
/* check if the char immediately following VALUES may be whitespace or open parenthesis */
|
||||
c = sql.charAt(indexOfValues + 6);
|
||||
if (!(Character.isWhitespace(c) || c == '(')) {
|
||||
valuesSearchStart = indexOfValues + 6;
|
||||
indexOfValues = -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (indexOfValues == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int indexOfFirstParen = sql.indexOf('(', indexOfValues + 6);
|
||||
|
||||
if (indexOfFirstParen == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int endOfValuesClause = this.isOnDuplicateKeyUpdate ? this.locationOfOnDuplicateKeyUpdate : sql.length();
|
||||
|
||||
return sql.substring(indexOfFirstParen, endOfValuesClause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ParseInfo for a multi-value INSERT for a batch of size numBatch (without parsing!).
|
||||
*
|
||||
* @param numBatch
|
||||
* number of batched parameters
|
||||
* @return {@link ParseInfo}
|
||||
*/
|
||||
public synchronized ParseInfo getParseInfoForBatch(int numBatch) {
|
||||
AppendingBatchVisitor apv = new AppendingBatchVisitor();
|
||||
buildInfoForBatch(numBatch, apv);
|
||||
|
||||
ParseInfo batchParseInfo = new ParseInfo(apv.getStaticSqlStrings(), this.firstStmtChar, this.foundLoadData, this.isOnDuplicateKeyUpdate,
|
||||
this.locationOfOnDuplicateKeyUpdate, this.statementLength, this.statementStartPos);
|
||||
|
||||
return batchParseInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a preparable SQL string for the number of batched parameters; used by server-side prepared statements
|
||||
* when re-writing batch INSERTs.
|
||||
*
|
||||
* @param numBatch
|
||||
* number of batched parameters
|
||||
* @return SQL string
|
||||
* @throws UnsupportedEncodingException
|
||||
* if an error occurs
|
||||
*/
|
||||
public String getSqlForBatch(int numBatch) throws UnsupportedEncodingException {
|
||||
ParseInfo batchInfo = getParseInfoForBatch(numBatch);
|
||||
|
||||
return batchInfo.getSqlForBatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for filling in the SQL for getPreparedSql() - for debugging
|
||||
*
|
||||
* @return sql string
|
||||
* @throws UnsupportedEncodingException
|
||||
* if an error occurs
|
||||
*/
|
||||
public String getSqlForBatch() throws UnsupportedEncodingException {
|
||||
int size = 0;
|
||||
final byte[][] sqlStrings = this.staticSql;
|
||||
final int sqlStringsLength = sqlStrings.length;
|
||||
|
||||
for (int i = 0; i < sqlStringsLength; i++) {
|
||||
size += sqlStrings[i].length;
|
||||
size++; // for the '?'
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder(size);
|
||||
|
||||
for (int i = 0; i < sqlStringsLength - 1; i++) {
|
||||
buf.append(StringUtils.toString(sqlStrings[i], this.charEncoding));
|
||||
buf.append("?");
|
||||
}
|
||||
|
||||
buf.append(StringUtils.toString(sqlStrings[sqlStringsLength - 1]));
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a ParseInfo for the given batch size, without parsing. We use
|
||||
* a visitor pattern here, because the if {}s make computing a size for the
|
||||
* resultant byte[][] make this too complex, and we don't necessarily want to
|
||||
* use a List for this, because the size can be dynamic, and thus we'll not be
|
||||
* able to guess a good initial size for an array-based list, and it's not
|
||||
* efficient to convert a LinkedList to an array.
|
||||
*
|
||||
* @param numBatch
|
||||
* number of batched parameters
|
||||
* @param visitor
|
||||
* visitor
|
||||
*/
|
||||
private void buildInfoForBatch(int numBatch, BatchVisitor visitor) {
|
||||
if (!this.hasPlaceholders) {
|
||||
if (numBatch == 1) {
|
||||
// ParseInfo for a multi-value INSERT that doesn't have any placeholder may require two or more batches (depends on if ODKU is present or not).
|
||||
// The original sql should be able to handle it.
|
||||
visitor.append(this.staticSql[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Without placeholders, only the values segment of the query needs repeating.
|
||||
|
||||
final byte[] headStaticSql = this.batchHead.staticSql[0];
|
||||
visitor.append(headStaticSql).increment();
|
||||
|
||||
int numValueRepeats = numBatch - 1; // First one is in the "head".
|
||||
if (this.batchODKUClause != null) {
|
||||
numValueRepeats--; // Last one is in the ODKU clause.
|
||||
}
|
||||
|
||||
final byte[] valuesStaticSql = this.batchValues.staticSql[0];
|
||||
for (int i = 0; i < numValueRepeats; i++) {
|
||||
visitor.mergeWithLast(valuesStaticSql).increment();
|
||||
}
|
||||
|
||||
if (this.batchODKUClause != null) {
|
||||
final byte[] batchOdkuStaticSql = this.batchODKUClause.staticSql[0];
|
||||
visitor.mergeWithLast(batchOdkuStaticSql).increment();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Placeholders require assembling all the parts in each segment of the query and repeat them as needed.
|
||||
|
||||
// Add the head section except the last part.
|
||||
final byte[][] headStaticSql = this.batchHead.staticSql;
|
||||
final int headStaticSqlLength = headStaticSql.length;
|
||||
byte[] endOfHead = headStaticSql[headStaticSqlLength - 1];
|
||||
|
||||
for (int i = 0; i < headStaticSqlLength - 1; i++) {
|
||||
visitor.append(headStaticSql[i]).increment();
|
||||
}
|
||||
|
||||
// Repeat the values section as many times as needed.
|
||||
int numValueRepeats = numBatch - 1; // First one is in the "head".
|
||||
if (this.batchODKUClause != null) {
|
||||
numValueRepeats--; // Last one is in the ODKU clause.
|
||||
}
|
||||
|
||||
final byte[][] valuesStaticSql = this.batchValues.staticSql;
|
||||
final int valuesStaticSqlLength = valuesStaticSql.length;
|
||||
byte[] beginOfValues = valuesStaticSql[0];
|
||||
byte[] endOfValues = valuesStaticSql[valuesStaticSqlLength - 1];
|
||||
|
||||
for (int i = 0; i < numValueRepeats; i++) {
|
||||
visitor.merge(endOfValues, beginOfValues).increment();
|
||||
for (int j = 1; j < valuesStaticSqlLength - 1; j++) {
|
||||
visitor.append(valuesStaticSql[j]).increment();
|
||||
}
|
||||
}
|
||||
|
||||
// Append the last value and/or ending.
|
||||
if (this.batchODKUClause != null) {
|
||||
final byte[][] batchOdkuStaticSql = this.batchODKUClause.staticSql;
|
||||
final int batchOdkuStaticSqlLength = batchOdkuStaticSql.length;
|
||||
byte[] beginOfOdku = batchOdkuStaticSql[0];
|
||||
byte[] endOfOdku = batchOdkuStaticSql[batchOdkuStaticSqlLength - 1];
|
||||
|
||||
if (numBatch > 1) {
|
||||
visitor.merge(numValueRepeats > 0 ? endOfValues : endOfHead, beginOfOdku).increment();
|
||||
for (int i = 1; i < batchOdkuStaticSqlLength; i++) {
|
||||
visitor.append(batchOdkuStaticSql[i]).increment();
|
||||
}
|
||||
} else {
|
||||
visitor.append(endOfOdku).increment();
|
||||
}
|
||||
} else {
|
||||
visitor.append(endOfHead);
|
||||
}
|
||||
}
|
||||
|
||||
protected static int findStartOfStatement(String sql) {
|
||||
int statementStartPos = 0;
|
||||
|
||||
if (StringUtils.startsWithIgnoreCaseAndWs(sql, "/*")) {
|
||||
statementStartPos = sql.indexOf("*/");
|
||||
|
||||
if (statementStartPos == -1) {
|
||||
statementStartPos = 0;
|
||||
} else {
|
||||
statementStartPos += 2;
|
||||
}
|
||||
} else if (StringUtils.startsWithIgnoreCaseAndWs(sql, "--") || StringUtils.startsWithIgnoreCaseAndWs(sql, "#")) {
|
||||
statementStartPos = sql.indexOf('\n');
|
||||
|
||||
if (statementStartPos == -1) {
|
||||
statementStartPos = sql.indexOf('\r');
|
||||
|
||||
if (statementStartPos == -1) {
|
||||
statementStartPos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return statementStartPos;
|
||||
}
|
||||
|
||||
public static int getOnDuplicateKeyLocation(String sql, boolean dontCheckOnDuplicateKeyUpdateInSQL, boolean rewriteBatchedStatements,
|
||||
boolean noBackslashEscapes) {
|
||||
return dontCheckOnDuplicateKeyUpdateInSQL && !rewriteBatchedStatements ? -1 : StringUtils.indexOfIgnoreCase(0, sql, ON_DUPLICATE_KEY_UPDATE_CLAUSE,
|
||||
"\"'`", "\"'`", noBackslashEscapes ? StringUtils.SEARCH_MODE__MRK_COM_WS : StringUtils.SEARCH_MODE__ALL);
|
||||
}
|
||||
|
||||
protected static boolean canRewrite(String sql, boolean isOnDuplicateKeyUpdate, int locationOfOnDuplicateKeyUpdate, int statementStartPos) {
|
||||
// Needs to be INSERT or REPLACE.
|
||||
// Can't have INSERT ... SELECT or INSERT ... ON DUPLICATE KEY UPDATE with an id=LAST_INSERT_ID(...).
|
||||
|
||||
if (StringUtils.startsWithIgnoreCaseAndWs(sql, "INSERT", statementStartPos)) {
|
||||
if (StringUtils.indexOfIgnoreCase(statementStartPos, sql, "SELECT", "\"'`", "\"'`", StringUtils.SEARCH_MODE__MRK_COM_WS) != -1) {
|
||||
return false;
|
||||
}
|
||||
if (isOnDuplicateKeyUpdate) {
|
||||
int updateClausePos = StringUtils.indexOfIgnoreCase(locationOfOnDuplicateKeyUpdate, sql, " UPDATE ");
|
||||
if (updateClausePos != -1) {
|
||||
return StringUtils.indexOfIgnoreCase(updateClausePos, sql, "LAST_INSERT_ID", "\"'`", "\"'`", StringUtils.SEARCH_MODE__MRK_COM_WS) == -1;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return StringUtils.startsWithIgnoreCaseAndWs(sql, "REPLACE", statementStartPos)
|
||||
&& StringUtils.indexOfIgnoreCase(statementStartPos, sql, "SELECT", "\"'`", "\"'`", StringUtils.SEARCH_MODE__MRK_COM_WS) == -1;
|
||||
}
|
||||
|
||||
public boolean isFoundLoadData() {
|
||||
return this.foundLoadData;
|
||||
}
|
||||
|
||||
public char getFirstStmtChar() {
|
||||
return this.firstStmtChar;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.mysql.cj.util.LRUCache;
|
||||
|
||||
public class PerConnectionLRUFactory implements CacheAdapterFactory<String, ParseInfo> {
|
||||
|
||||
public CacheAdapter<String, ParseInfo> getInstance(Object syncMutex, String url, int cacheMaxSize, int maxKeySize) {
|
||||
|
||||
return new PerConnectionLRU(syncMutex, cacheMaxSize, maxKeySize);
|
||||
}
|
||||
|
||||
class PerConnectionLRU implements CacheAdapter<String, ParseInfo> {
|
||||
private final int cacheSqlLimit;
|
||||
private final LRUCache<String, ParseInfo> 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 ParseInfo 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, ParseInfo 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,67 @@
|
||||
/*
|
||||
* 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 com.mysql.cj;
|
||||
|
||||
import com.mysql.cj.protocol.Message;
|
||||
|
||||
public interface PreparedQuery<T extends QueryBindings<?>> extends Query {
|
||||
|
||||
ParseInfo getParseInfo();
|
||||
|
||||
void setParseInfo(ParseInfo parseInfo);
|
||||
|
||||
void checkNullOrEmptyQuery(String sql);
|
||||
|
||||
String getOriginalSql();
|
||||
|
||||
void setOriginalSql(String originalSql);
|
||||
|
||||
int getParameterCount();
|
||||
|
||||
void setParameterCount(int parameterCount);
|
||||
|
||||
public T getQueryBindings();
|
||||
|
||||
public void setQueryBindings(T queryBindings);
|
||||
|
||||
int computeBatchSize(int numBatchedArgs);
|
||||
|
||||
int getBatchCommandIndex();
|
||||
|
||||
void setBatchCommandIndex(int batchCommandIndex);
|
||||
|
||||
String asSql();
|
||||
|
||||
String asSql(boolean quoteStreamsAndUnknowns);
|
||||
|
||||
<M extends Message> M fillSendPacket();
|
||||
|
||||
<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,76 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* An internal representation of a query attribute bind value.
|
||||
*
|
||||
*/
|
||||
public interface QueryAttributesBindValue {
|
||||
/**
|
||||
* Checks whether this query attribute is the <code>null</code> value.
|
||||
*
|
||||
* @return
|
||||
* <code>true</code> if this query attribute value is <code>null</code>.
|
||||
*/
|
||||
boolean isNull();
|
||||
|
||||
/**
|
||||
* Gets the name of this query attribute.
|
||||
*
|
||||
* @return
|
||||
* the name of this query attribute.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the type of this query attribute. Query attributes types are one of the {@link MysqlType}.FIELD_TYPE_*.
|
||||
*
|
||||
* @return
|
||||
* the type of this query attribute.
|
||||
*/
|
||||
int getType();
|
||||
|
||||
/**
|
||||
* Gets the value of this query attribute.
|
||||
*
|
||||
* @return
|
||||
* the value of this query attribute.
|
||||
*/
|
||||
Object getValue();
|
||||
|
||||
/**
|
||||
* Gets the length of this query attribute.
|
||||
*
|
||||
* @return
|
||||
* the expected length, in Bytes, of this query attribute value after being encoded.
|
||||
*/
|
||||
long getBoundLength();
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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 QueryAttributesBindValue} in the given position of the query attributes list.
|
||||
*/
|
||||
QueryAttributesBindValue 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<QueryAttributesBindValue> bindAttribute);
|
||||
|
||||
/**
|
||||
* Removes all query attributes from the query attributes list.
|
||||
*/
|
||||
void clearAttributes();
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* 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.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.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.mysql.cj.protocol.ColumnDefinition;
|
||||
|
||||
public interface QueryBindings<T extends BindValue> {
|
||||
|
||||
QueryBindings<T> clone();
|
||||
|
||||
void setColumnDefinition(ColumnDefinition colDef);
|
||||
|
||||
boolean isLoadDataQuery();
|
||||
|
||||
void setLoadDataQuery(boolean isLoadDataQuery);
|
||||
|
||||
T[] getBindValues();
|
||||
|
||||
void setBindValues(T[] bindValues);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if bind values had long data
|
||||
*/
|
||||
boolean clearBindValues();
|
||||
|
||||
void checkParameterSet(int columnIndex);
|
||||
|
||||
void checkAllParametersSet();
|
||||
|
||||
int getNumberOfExecutions();
|
||||
|
||||
void setNumberOfExecutions(int numberOfExecutions);
|
||||
|
||||
void setValue(int paramIndex, byte[] val, MysqlType type);
|
||||
|
||||
void setValue(int paramIndex, String val, MysqlType type);
|
||||
|
||||
// Array getArray(int parameterIndex);
|
||||
|
||||
void setAsciiStream(int parameterIndex, InputStream x);
|
||||
|
||||
void setAsciiStream(int parameterIndex, InputStream x, int length);
|
||||
|
||||
void setAsciiStream(int parameterIndex, InputStream x, long length);
|
||||
|
||||
// InputStream getAsciiStream(int parameterIndex);
|
||||
|
||||
void setBigDecimal(int parameterIndex, BigDecimal x);
|
||||
|
||||
// BigDecimal getBigDecimal(int parameterIndex);
|
||||
|
||||
void setBigInteger(int parameterIndex, BigInteger x);
|
||||
|
||||
// BigInteger getBigInteger(int parameterIndex);
|
||||
|
||||
void setBinaryStream(int parameterIndex, InputStream x);
|
||||
|
||||
void setBinaryStream(int parameterIndex, InputStream x, int length);
|
||||
|
||||
void setBinaryStream(int parameterIndex, InputStream x, long length);
|
||||
|
||||
// InputStream getBinaryStream(int parameterIndex);
|
||||
|
||||
void setBlob(int parameterIndex, java.sql.Blob x);
|
||||
|
||||
void setBlob(int parameterIndex, InputStream inputStream);
|
||||
|
||||
void setBlob(int parameterIndex, InputStream inputStream, long length);
|
||||
|
||||
// java.sql.Blob getBlob(int parameterIndex);
|
||||
|
||||
void setBoolean(int parameterIndex, boolean x);
|
||||
|
||||
// boolean getBoolean(int parameterIndex);
|
||||
|
||||
void setByte(int parameterIndex, byte x);
|
||||
|
||||
// byte getByte(int parameterIndex);
|
||||
|
||||
void setBytes(int parameterIndex, byte[] x);
|
||||
|
||||
void setBytes(int parameterIndex, byte[] x, boolean checkForIntroducer, boolean escapeForMBChars);
|
||||
|
||||
void setBytesNoEscape(int parameterIndex, byte[] parameterAsBytes);
|
||||
|
||||
void setBytesNoEscapeNoQuotes(int parameterIndex, byte[] parameterAsBytes);
|
||||
|
||||
// byte[] getBytes(int parameterIndex);
|
||||
|
||||
void setCharacterStream(int parameterIndex, Reader reader);
|
||||
|
||||
void setCharacterStream(int parameterIndex, Reader reader, int length);
|
||||
|
||||
void setCharacterStream(int parameterIndex, Reader reader, long length);
|
||||
|
||||
// Reader getCharacterStream(int parameterIndex);
|
||||
|
||||
void setClob(int i, Clob x);
|
||||
|
||||
void setClob(int parameterIndex, Reader reader);
|
||||
|
||||
void setClob(int parameterIndex, Reader reader, long length);
|
||||
|
||||
// Clob getClob(int parameterIndex);
|
||||
|
||||
void setDate(int parameterIndex, Date x);
|
||||
|
||||
void setDate(int parameterIndex, Date x, Calendar cal);
|
||||
|
||||
// Date getDate(int parameterIndex);
|
||||
|
||||
void setDouble(int parameterIndex, double x);
|
||||
|
||||
// double getDouble(int parameterIndex)
|
||||
|
||||
void setFloat(int parameterIndex, float x);
|
||||
|
||||
// float getFloat(int parameterIndex);
|
||||
|
||||
void setInt(int parameterIndex, int x);
|
||||
|
||||
// int getInt(int parameterIndex);
|
||||
|
||||
void setLong(int parameterIndex, long x);
|
||||
|
||||
// long getLong(int parameterIndex);
|
||||
|
||||
void setNCharacterStream(int parameterIndex, Reader value);
|
||||
|
||||
void setNCharacterStream(int parameterIndex, Reader reader, long length);
|
||||
|
||||
// Reader getNCharacterStream(int parameterIndex);
|
||||
|
||||
void setNClob(int parameterIndex, Reader reader);
|
||||
|
||||
void setNClob(int parameterIndex, Reader reader, long length);
|
||||
|
||||
void setNClob(int parameterIndex, NClob value);
|
||||
|
||||
// Reader getNClob(int parameterIndex);
|
||||
|
||||
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);
|
||||
|
||||
void setObject(int parameterIndex, Object parameterObj, MysqlType targetMysqlType, int scaleOrLength);
|
||||
|
||||
// Object getObject(int parameterIndex);
|
||||
|
||||
// Ref getRef(int parameterIndex);
|
||||
|
||||
void setShort(int parameterIndex, short x);
|
||||
|
||||
// short getShort(int parameterIndex);
|
||||
|
||||
void setString(int parameterIndex, String x);
|
||||
|
||||
// String getString(int parameterIndex);
|
||||
|
||||
void setTime(int parameterIndex, Time x);
|
||||
|
||||
void setTime(int parameterIndex, Time x, Calendar cal);
|
||||
|
||||
// Time getTime(int parameterIndex);
|
||||
|
||||
void setTimestamp(int parameterIndex, Timestamp x, Calendar cal, MysqlType targetMysqlType);
|
||||
|
||||
void setTimestamp(int parameterIndex, Timestamp x, MysqlType targetMysqlType);
|
||||
|
||||
void setTimestamp(int parameterIndex, Timestamp x, Calendar targetCalendar, int fractionalLength, MysqlType targetMysqlType);
|
||||
|
||||
void bindTimestamp(int parameterIndex, Timestamp x, Calendar targetCalendar, int fractionalLength, MysqlType targetMysqlType);
|
||||
|
||||
// Timestamp getTimestamp(int parameterIndex);
|
||||
|
||||
// URL getURL(int parameterIndex);
|
||||
|
||||
byte[] getBytesRepresentation(int parameterIndex);
|
||||
|
||||
byte[] getOrigBytes(int parameterIndex);
|
||||
|
||||
void setLocalDate(int parameterIndex, LocalDate x, MysqlType targetMysqlType);
|
||||
|
||||
void setLocalTime(int parameterIndex, LocalTime x, MysqlType targetMysqlType);
|
||||
|
||||
void setLocalDateTime(int parameterIndex, LocalDateTime x, MysqlType targetMysqlType);
|
||||
|
||||
void setDuration(int parameterIndex, Duration x, MysqlType targetMysqlType);
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.cj;
|
||||
|
||||
/**
|
||||
* A server version.
|
||||
*/
|
||||
public class ServerVersion implements Comparable<ServerVersion> {
|
||||
private String completeVersion;
|
||||
private Integer major;
|
||||
private Integer minor;
|
||||
private Integer subminor;
|
||||
|
||||
public ServerVersion(String completeVersion, int major, int minor, int subminor) {
|
||||
this.completeVersion = completeVersion;
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.subminor = subminor;
|
||||
}
|
||||
|
||||
public ServerVersion(int major, int minor, int subminor) {
|
||||
this(null, major, minor, subminor);
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return this.major;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return this.minor;
|
||||
}
|
||||
|
||||
public int getSubminor() {
|
||||
return this.subminor;
|
||||
}
|
||||
|
||||
/**
|
||||
* A string representation of this version. If this version was parsed from, or provided with, a "complete" string which may contain more than just the
|
||||
* version number, this string is returned verbatim. Otherwise, a string representation of the version numbers is given.
|
||||
*
|
||||
* @return string version representation
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.completeVersion != null) {
|
||||
return this.completeVersion;
|
||||
}
|
||||
return String.format("%d.%d.%d", this.major, this.minor, this.subminor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || !ServerVersion.class.isAssignableFrom(obj.getClass())) {
|
||||
return false;
|
||||
}
|
||||
ServerVersion another = (ServerVersion) obj;
|
||||
if (this.getMajor() != another.getMajor() || this.getMinor() != another.getMinor() || this.getSubminor() != another.getSubminor()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 23;
|
||||
hash += 19 * hash + this.major;
|
||||
hash += 19 * hash + this.minor;
|
||||
hash += 19 * hash + this.subminor;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public int compareTo(ServerVersion other) {
|
||||
int c;
|
||||
if ((c = this.major.compareTo(other.getMajor())) != 0) {
|
||||
return c;
|
||||
} else if ((c = this.minor.compareTo(other.getMinor())) != 0) {
|
||||
return c;
|
||||
}
|
||||
return this.subminor.compareTo(other.getSubminor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this version meet the minimum specified by `min'?
|
||||
*
|
||||
* @param min
|
||||
* The minimum version to compare against.
|
||||
* @return true if version meets the minimum specified by `min'
|
||||
*/
|
||||
public boolean meetsMinimum(ServerVersion min) {
|
||||
return compareTo(min) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the server version into major/minor/subminor.
|
||||
*
|
||||
* @param versionString
|
||||
* string version representation
|
||||
* @return {@link ServerVersion}
|
||||
*/
|
||||
public static ServerVersion parseVersion(final String versionString) {
|
||||
int point = versionString.indexOf('.');
|
||||
|
||||
if (point != -1) {
|
||||
try {
|
||||
int serverMajorVersion = Integer.parseInt(versionString.substring(0, point));
|
||||
|
||||
String remaining = versionString.substring(point + 1, versionString.length());
|
||||
point = remaining.indexOf('.');
|
||||
|
||||
if (point != -1) {
|
||||
int serverMinorVersion = Integer.parseInt(remaining.substring(0, point));
|
||||
|
||||
remaining = remaining.substring(point + 1, remaining.length());
|
||||
|
||||
int pos = 0;
|
||||
|
||||
while (pos < remaining.length()) {
|
||||
if ((remaining.charAt(pos) < '0') || (remaining.charAt(pos) > '9')) {
|
||||
break;
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
int serverSubminorVersion = Integer.parseInt(remaining.substring(0, pos));
|
||||
|
||||
return new ServerVersion(versionString, serverMajorVersion, serverMinorVersion, serverSubminorVersion);
|
||||
}
|
||||
} catch (NumberFormatException NFE1) {
|
||||
}
|
||||
}
|
||||
|
||||
// can't parse the server version
|
||||
return new ServerVersion(0, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* 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.cj;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collector;
|
||||
|
||||
import com.mysql.cj.conf.HostInfo;
|
||||
import com.mysql.cj.conf.PropertySet;
|
||||
import com.mysql.cj.exceptions.CJOperationNotSupportedException;
|
||||
import com.mysql.cj.exceptions.ExceptionFactory;
|
||||
import com.mysql.cj.exceptions.ExceptionInterceptor;
|
||||
import com.mysql.cj.log.Log;
|
||||
import com.mysql.cj.log.ProfilerEventHandler;
|
||||
import com.mysql.cj.protocol.Message;
|
||||
import com.mysql.cj.protocol.Protocol;
|
||||
import com.mysql.cj.protocol.ResultBuilder;
|
||||
import com.mysql.cj.protocol.ServerSession;
|
||||
import com.mysql.cj.result.Row;
|
||||
|
||||
/**
|
||||
* {@link Session} exposes logical level which user API uses internally to call {@link Protocol} methods.
|
||||
* It's a higher-level abstraction than MySQL server session ({@link ServerSession}). {@link Protocol} and {@link ServerSession} methods
|
||||
* should never be used directly from user API.
|
||||
*
|
||||
*/
|
||||
public interface Session {
|
||||
|
||||
PropertySet getPropertySet();
|
||||
|
||||
<M extends Message> MessageBuilder<M> getMessageBuilder();
|
||||
|
||||
/**
|
||||
* Re-authenticates as the given user and password
|
||||
*
|
||||
* @param userName
|
||||
* DB user name
|
||||
* @param password
|
||||
* DB user password
|
||||
* @param database
|
||||
* database name
|
||||
*
|
||||
*/
|
||||
void changeUser(String userName, String password, String database);
|
||||
|
||||
ExceptionInterceptor getExceptionInterceptor();
|
||||
|
||||
void setExceptionInterceptor(ExceptionInterceptor exceptionInterceptor);
|
||||
|
||||
/**
|
||||
* Log-off of the MySQL server and close the socket.
|
||||
*
|
||||
*/
|
||||
void quit();
|
||||
|
||||
/**
|
||||
* Clobbers the physical network connection and marks this session as closed.
|
||||
*/
|
||||
void forceClose();
|
||||
|
||||
/**
|
||||
* Does the version of the MySQL server we are connected to meet the given
|
||||
* minimums?
|
||||
*
|
||||
* @param major
|
||||
* major version number
|
||||
* @param minor
|
||||
* minor version number
|
||||
* @param subminor
|
||||
* sub-minor version number
|
||||
* @return true if current server version equal or higher than provided one
|
||||
*/
|
||||
boolean versionMeetsMinimum(int major, int minor, int subminor);
|
||||
|
||||
long getThreadId();
|
||||
|
||||
boolean isSetNeededForAutoCommitMode(boolean autoCommitFlag);
|
||||
|
||||
/**
|
||||
* Returns the log mechanism that should be used to log information from/for this Session.
|
||||
*
|
||||
* @return the Log instance to use for logging messages.
|
||||
*/
|
||||
Log getLog();
|
||||
|
||||
/**
|
||||
* Returns the current ProfilerEventHandler or initializes a new one if none exists.
|
||||
*
|
||||
* @return the {@link ProfilerEventHandler} object.
|
||||
*/
|
||||
ProfilerEventHandler getProfilerEventHandler();
|
||||
|
||||
HostInfo getHostInfo();
|
||||
|
||||
String getQueryTimingUnits();
|
||||
|
||||
ServerSession getServerSession();
|
||||
|
||||
boolean isSSLEstablished();
|
||||
|
||||
SocketAddress getRemoteSocketAddress();
|
||||
|
||||
String getProcessHost();
|
||||
|
||||
/**
|
||||
* Add listener for this session status changes.
|
||||
*
|
||||
* @param l
|
||||
* {@link SessionEventListener} instance.
|
||||
*/
|
||||
void addListener(SessionEventListener l);
|
||||
|
||||
/**
|
||||
* Remove session listener.
|
||||
*
|
||||
* @param l
|
||||
* {@link SessionEventListener} instance.
|
||||
*/
|
||||
void removeListener(SessionEventListener l);
|
||||
|
||||
public static interface SessionEventListener {
|
||||
void handleNormalClose();
|
||||
|
||||
void handleReconnect();
|
||||
|
||||
void handleCleanup(Throwable whyCleanedUp);
|
||||
}
|
||||
|
||||
boolean isClosed();
|
||||
|
||||
String getIdentifierQuoteString();
|
||||
|
||||
DataStoreMetadata getDataStoreMetadata();
|
||||
|
||||
/**
|
||||
* Synchronously query database with applying rows filtering and mapping.
|
||||
*
|
||||
* @param message
|
||||
* query message
|
||||
* @param rowFilter
|
||||
* row filter function
|
||||
* @param rowMapper
|
||||
* row map function
|
||||
* @param collector
|
||||
* result collector
|
||||
* @param <M>
|
||||
* Message type
|
||||
* @param <R>
|
||||
* Row type
|
||||
* @param <RES>
|
||||
* Result type
|
||||
* @return List of rows
|
||||
*/
|
||||
default <M extends Message, R, RES> RES query(M message, Predicate<Row> rowFilter, Function<Row, R> rowMapper, Collector<R, ?, RES> collector) {
|
||||
throw ExceptionFactory.createException(CJOperationNotSupportedException.class, "Not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously query database.
|
||||
*
|
||||
* @param message
|
||||
* query message
|
||||
* @param resultBuilder
|
||||
* ResultBuilder instance
|
||||
* @param <M>
|
||||
* Message type
|
||||
* @param <R>
|
||||
* Result type
|
||||
* @return {@link QueryResult} object
|
||||
*/
|
||||
default <M extends Message, R extends QueryResult> R query(M message, ResultBuilder<R> resultBuilder) {
|
||||
throw ExceptionFactory.createException(CJOperationNotSupportedException.class, "Not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously query database.
|
||||
*
|
||||
* @param message
|
||||
* query message
|
||||
* @param resultBuilder
|
||||
* ResultBuilder instance
|
||||
* @param <M>
|
||||
* Message type
|
||||
* @param <R>
|
||||
* Result type
|
||||
* @return CompletableFuture providing a {@link QueryResult} object
|
||||
*/
|
||||
default <M extends Message, R extends QueryResult> CompletableFuture<R> queryAsync(M message, ResultBuilder<R> resultBuilder) {
|
||||
throw ExceptionFactory.createException(CJOperationNotSupportedException.class, "Not supported");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 com.mysql.cj;
|
||||
|
||||
public interface TransactionEventHandler {
|
||||
|
||||
void transactionBegun();
|
||||
|
||||
void transactionCompleted();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.cj;
|
||||
|
||||
/**
|
||||
* A warning listener is notified of warnings as they happen throughout the driver. They can be queued for consumption by JDBC clients, thrown as exceptions, or
|
||||
* ignored.
|
||||
*/
|
||||
public interface WarningListener {
|
||||
void warningEncountered(String warning);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 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.callback;
|
||||
|
||||
/**
|
||||
* Implementations of this interface can be passed to a {@link MysqlCallbackHandler} so that the owner of the callback handler and its caller can share data in
|
||||
* a way that would otherwise require tight coupling.
|
||||
*/
|
||||
public interface MysqlCallback {
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 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.callback;
|
||||
|
||||
/**
|
||||
* A functional interface for implementing callback handlers.
|
||||
*
|
||||
* The single method {@link MysqlCallbackHandler#handle(MysqlCallback)} is called by the classes where the callback handler is passed when they need to share
|
||||
* data with the caller. The kind of data to exchange depends on the implementations of {@link MysqlCallback} they choose to use.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MysqlCallbackHandler {
|
||||
/**
|
||||
* Exchanges information between the caller of this method and the owner of the {@link MysqlCallbackHandler} instance. The method can be called multiple
|
||||
* times with different callback implementations to exchange different types of information. A typical {@link MysqlCallbackHandler} implementation looks
|
||||
* like:
|
||||
*
|
||||
* <pre>
|
||||
* private MysqlCallbackHandler callbackHandler = (cb) -> {
|
||||
* if (cb instanceof UsernameCallback) {
|
||||
* this.username = ((UsernameCallback) cb).getUsername();
|
||||
* }
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
* @param cb
|
||||
*
|
||||
*/
|
||||
void handle(MysqlCallback cb);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 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.callback;
|
||||
|
||||
/**
|
||||
* A callback that can be used to exchange username information to a callback handler owner.
|
||||
*/
|
||||
public class UsernameCallback implements MysqlCallback {
|
||||
private String username;
|
||||
|
||||
public UsernameCallback(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the username provided by the caller of {@link MysqlCallbackHandler#handle(MysqlCallback)}.
|
||||
*
|
||||
* @return
|
||||
* the username to pass over to the callback handler.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.conf;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Implement this interface, and pass the class name as the 'propertiesTransform' property in your URL, and the driver will pass the properties it has
|
||||
* parsed to your transform implementation so that you can modify/substitute/add any that you desire.
|
||||
*/
|
||||
public interface ConnectionPropertiesTransform {
|
||||
/**
|
||||
* The driver will call this method if the user has loaded your
|
||||
* implementation of this interface by specifying the 'propertiesTransform'
|
||||
* property in their URL.
|
||||
*
|
||||
* @param props
|
||||
* the properties as passed by the driver (never null)
|
||||
*
|
||||
* @return the same properties with any transformations that your
|
||||
* implementation has made
|
||||
*
|
||||
*/
|
||||
Properties transformProperties(Properties props);
|
||||
}
|
||||
@@ -0,0 +1,830 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.conf;
|
||||
|
||||
import static com.mysql.cj.util.StringUtils.isNullOrEmpty;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import com.mysql.cj.Messages;
|
||||
import com.mysql.cj.exceptions.CJException;
|
||||
import com.mysql.cj.exceptions.ExceptionFactory;
|
||||
import com.mysql.cj.exceptions.InvalidConnectionAttributeException;
|
||||
import com.mysql.cj.exceptions.UnsupportedConnectionStringException;
|
||||
import com.mysql.cj.exceptions.WrongArgumentException;
|
||||
import com.mysql.cj.util.DnsSrv;
|
||||
import com.mysql.cj.util.DnsSrv.SrvRecord;
|
||||
import com.mysql.cj.util.LRUCache;
|
||||
import com.mysql.cj.util.Util;
|
||||
|
||||
/**
|
||||
* A container for a database URL and a collection of given connection arguments.
|
||||
* The connection string is parsed and split by its components, each of which is then processed and fixed according to the needs of the connection type.
|
||||
* This abstract class holds all common behavior to all connection string types. Its subclasses must implement their own specifics such as classifying hosts by
|
||||
* type or apply validation rules.
|
||||
*/
|
||||
public abstract class ConnectionUrl implements DatabaseUrlContainer {
|
||||
public static final String DEFAULT_HOST = "localhost";
|
||||
public static final int DEFAULT_PORT = 3306;
|
||||
|
||||
private static final LRUCache<String, ConnectionUrl> connectionUrlCache = new LRUCache<>(100);
|
||||
private static final ReadWriteLock rwLock = new ReentrantReadWriteLock();
|
||||
|
||||
/**
|
||||
* The rules describing the number of hosts a database URL may contain.
|
||||
*/
|
||||
public enum HostsCardinality {
|
||||
SINGLE {
|
||||
@Override
|
||||
public boolean assertSize(int n) {
|
||||
return n == 1;
|
||||
}
|
||||
},
|
||||
MULTIPLE {
|
||||
@Override
|
||||
public boolean assertSize(int n) {
|
||||
return n > 1;
|
||||
}
|
||||
},
|
||||
ONE_OR_MORE {
|
||||
@Override
|
||||
public boolean assertSize(int n) {
|
||||
return n >= 1;
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean assertSize(int n);
|
||||
}
|
||||
|
||||
/**
|
||||
* The database URL type which is determined by the scheme section of the connection string.
|
||||
*/
|
||||
public enum Type {
|
||||
// DNS SRV schemes (cardinality is validated by implementing classes):
|
||||
FAILOVER_DNS_SRV_CONNECTION("jdbc:mysql+srv:", HostsCardinality.ONE_OR_MORE, "com.mysql.cj.conf.url.FailoverDnsSrvConnectionUrl"), //
|
||||
LOADBALANCE_DNS_SRV_CONNECTION("jdbc:mysql+srv:loadbalance:", HostsCardinality.ONE_OR_MORE, "com.mysql.cj.conf.url.LoadBalanceDnsSrvConnectionUrl"), //
|
||||
REPLICATION_DNS_SRV_CONNECTION("jdbc:mysql+srv:replication:", HostsCardinality.ONE_OR_MORE, "com.mysql.cj.conf.url.ReplicationDnsSrvConnectionUrl"), //
|
||||
XDEVAPI_DNS_SRV_SESSION("mysqlx+srv:", HostsCardinality.ONE_OR_MORE, "com.mysql.cj.conf.url.XDevApiDnsSrvConnectionUrl"), //
|
||||
// Standard schemes:
|
||||
SINGLE_CONNECTION("jdbc:mysql:", HostsCardinality.SINGLE, "com.mysql.cj.conf.url.SingleConnectionUrl", PropertyKey.dnsSrv, FAILOVER_DNS_SRV_CONNECTION), //
|
||||
FAILOVER_CONNECTION("jdbc:mysql:", HostsCardinality.MULTIPLE, "com.mysql.cj.conf.url.FailoverConnectionUrl", PropertyKey.dnsSrv,
|
||||
FAILOVER_DNS_SRV_CONNECTION), //
|
||||
LOADBALANCE_CONNECTION("jdbc:mysql:loadbalance:", HostsCardinality.ONE_OR_MORE, "com.mysql.cj.conf.url.LoadBalanceConnectionUrl", PropertyKey.dnsSrv,
|
||||
LOADBALANCE_DNS_SRV_CONNECTION), //
|
||||
REPLICATION_CONNECTION("jdbc:mysql:replication:", HostsCardinality.ONE_OR_MORE, "com.mysql.cj.conf.url.ReplicationConnectionUrl", PropertyKey.dnsSrv,
|
||||
REPLICATION_DNS_SRV_CONNECTION), //
|
||||
XDEVAPI_SESSION("mysqlx:", HostsCardinality.ONE_OR_MORE, "com.mysql.cj.conf.url.XDevApiConnectionUrl", PropertyKey.xdevapiDnsSrv,
|
||||
XDEVAPI_DNS_SRV_SESSION);
|
||||
|
||||
private String scheme;
|
||||
private HostsCardinality cardinality;
|
||||
private String implementingClass;
|
||||
private PropertyKey dnsSrvPropertyKey;
|
||||
private Type alternateDnsSrvType;
|
||||
|
||||
private Type(String scheme, HostsCardinality cardinality, String implementingClass) {
|
||||
this(scheme, cardinality, implementingClass, null, null);
|
||||
}
|
||||
|
||||
private Type(String scheme, HostsCardinality cardinality, String implementingClass, PropertyKey dnsSrvPropertyKey, Type alternateDnsSrvType) {
|
||||
this.scheme = scheme;
|
||||
this.cardinality = cardinality;
|
||||
this.implementingClass = implementingClass;
|
||||
this.dnsSrvPropertyKey = dnsSrvPropertyKey;
|
||||
this.alternateDnsSrvType = alternateDnsSrvType;
|
||||
}
|
||||
|
||||
public String getScheme() {
|
||||
return this.scheme;
|
||||
}
|
||||
|
||||
public HostsCardinality getCardinality() {
|
||||
return this.cardinality;
|
||||
}
|
||||
|
||||
public String getImplementingClass() {
|
||||
return this.implementingClass;
|
||||
}
|
||||
|
||||
public PropertyKey getDnsSrvPropertyKey() {
|
||||
return this.dnsSrvPropertyKey;
|
||||
}
|
||||
|
||||
public Type getAlternateDnsSrvType() {
|
||||
return this.alternateDnsSrvType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Type} corresponding to the given scheme and number of hosts, if any.
|
||||
* Otherwise throws an {@link UnsupportedConnectionStringException}.
|
||||
* Calling this method with the argument n lower than 0 skips the hosts cardinality validation.
|
||||
*
|
||||
* @param scheme
|
||||
* one of supported schemes
|
||||
* @param n
|
||||
* the number of hosts in the database URL
|
||||
* @return the {@link Type} corresponding to the given protocol and number of hosts
|
||||
*/
|
||||
public static Type fromValue(String scheme, int n) {
|
||||
for (Type t : values()) {
|
||||
if (t.getScheme().equalsIgnoreCase(scheme) && (n < 0 || t.getCardinality().assertSize(n))) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
if (n < 0) {
|
||||
throw ExceptionFactory.createException(UnsupportedConnectionStringException.class,
|
||||
Messages.getString("ConnectionString.5", new Object[] { scheme }));
|
||||
}
|
||||
throw ExceptionFactory.createException(UnsupportedConnectionStringException.class,
|
||||
Messages.getString("ConnectionString.6", new Object[] { scheme, n }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a class that implements the right type of connection URLs for the given {@link ConnectionUrlParser}.
|
||||
*
|
||||
* @param parser
|
||||
* the {@link ConnectionUrlParser} containing the URL components.
|
||||
* @param info
|
||||
* a connection properties map to add to the {@link ConnectionUrl} structure.
|
||||
* @return
|
||||
* an instance of {@link ConnectionUrl}.
|
||||
*/
|
||||
public static ConnectionUrl getConnectionUrlInstance(ConnectionUrlParser parser, Properties info) {
|
||||
int hostsCount = parser.getHosts().size();
|
||||
Type type = fromValue(parser.getScheme(), hostsCount);
|
||||
PropertyKey dnsSrvPropKey = type.getDnsSrvPropertyKey();
|
||||
Map<String, String> parsedProperties;
|
||||
|
||||
// Check if the Type must be replaced by a DNS SRV one.
|
||||
if (dnsSrvPropKey != null && type.getAlternateDnsSrvType() != null) {
|
||||
if (info != null && info.containsKey(dnsSrvPropKey.getKeyName())) { // Properties map prevails over connection string options.
|
||||
if ((Boolean) PropertyDefinitions.getPropertyDefinition(dnsSrvPropKey).parseObject(info.getProperty(dnsSrvPropKey.getKeyName()), null)) {
|
||||
type = fromValue(type.getAlternateDnsSrvType().getScheme(), hostsCount);
|
||||
}
|
||||
} else if ((parsedProperties = parser.getProperties()).containsKey(dnsSrvPropKey.getKeyName()) && (Boolean) PropertyDefinitions
|
||||
.getPropertyDefinition(dnsSrvPropKey).parseObject(parsedProperties.get(dnsSrvPropKey.getKeyName()), null)) {
|
||||
type = fromValue(type.getAlternateDnsSrvType().getScheme(), hostsCount);
|
||||
}
|
||||
}
|
||||
|
||||
return type.getImplementingInstance(parser, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given scheme corresponds to one of the connection types the driver supports.
|
||||
*
|
||||
* @param scheme
|
||||
* scheme part from connection string, like "jdbc:mysql:"
|
||||
* @return true if the given scheme is supported by driver
|
||||
*/
|
||||
public static boolean isSupported(String scheme) {
|
||||
for (Type t : values()) {
|
||||
if (t.getScheme().equalsIgnoreCase(scheme)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a class that implements this type of connection URLs with the given arguments.
|
||||
*
|
||||
* @param parser
|
||||
* the {@link ConnectionUrlParser} containing the URL components.
|
||||
* @param info
|
||||
* a connection properties map to add to the {@link ConnectionUrl} structure.
|
||||
* @return
|
||||
* an instance of {@link ConnectionUrl}.
|
||||
*/
|
||||
private ConnectionUrl getImplementingInstance(ConnectionUrlParser parser, Properties info) {
|
||||
return (ConnectionUrl) Util.getInstance(getImplementingClass(), new Class<?>[] { ConnectionUrlParser.class, Properties.class },
|
||||
new Object[] { parser, info }, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected Type type;
|
||||
protected String originalConnStr;
|
||||
protected String originalDatabase;
|
||||
protected List<HostInfo> hosts = new ArrayList<>();
|
||||
protected Map<String, String> properties = new HashMap<>();
|
||||
ConnectionPropertiesTransform propertiesTransformer;
|
||||
|
||||
/**
|
||||
* Static factory method that returns either a new instance of a {@link ConnectionUrl} or a cached one.
|
||||
* Returns "null" it can't handle the connection string.
|
||||
*
|
||||
* @param connString
|
||||
* the connection string
|
||||
* @param info
|
||||
* the connection arguments map
|
||||
* @return an instance of a {@link ConnectionUrl} or "null" if isn't able to handle the connection string
|
||||
*/
|
||||
public static ConnectionUrl getConnectionUrlInstance(String connString, Properties info) {
|
||||
if (connString == null) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.0"));
|
||||
}
|
||||
String connStringCacheKey = buildConnectionStringCacheKey(connString, info);
|
||||
ConnectionUrl connectionUrl;
|
||||
|
||||
rwLock.readLock().lock();
|
||||
connectionUrl = connectionUrlCache.get(connStringCacheKey);
|
||||
if (connectionUrl == null) {
|
||||
rwLock.readLock().unlock();
|
||||
rwLock.writeLock().lock();
|
||||
try {
|
||||
// Check again, in the meantime it could have been cached by another thread.
|
||||
connectionUrl = connectionUrlCache.get(connStringCacheKey);
|
||||
if (connectionUrl == null) {
|
||||
ConnectionUrlParser connStrParser = ConnectionUrlParser.parseConnectionString(connString);
|
||||
connectionUrl = Type.getConnectionUrlInstance(connStrParser, info);
|
||||
connectionUrlCache.put(connStringCacheKey, connectionUrl);
|
||||
}
|
||||
rwLock.readLock().lock();
|
||||
} finally {
|
||||
rwLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
rwLock.readLock().unlock();
|
||||
return connectionUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a connection URL cache map key based on the connection string itself plus the string representation of the given connection properties.
|
||||
*
|
||||
* @param connString
|
||||
* the connection string
|
||||
* @param info
|
||||
* the connection arguments map
|
||||
* @return a connection string cache map key
|
||||
*/
|
||||
private static String buildConnectionStringCacheKey(String connString, Properties info) {
|
||||
StringBuilder sbKey = new StringBuilder(connString);
|
||||
sbKey.append("\u00A7"); // Section sign.
|
||||
sbKey.append(
|
||||
info == null ? null : info.stringPropertyNames().stream().map(k -> k + "=" + info.getProperty(k)).collect(Collectors.joining(", ", "{", "}")));
|
||||
return sbKey.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this {@link ConnectionUrl} is able to process the given database URL.
|
||||
*
|
||||
* @param connString
|
||||
* the connection string
|
||||
* @return true if this class is able to process the given URL, false otherwise
|
||||
*/
|
||||
public static boolean acceptsUrl(String connString) {
|
||||
return ConnectionUrlParser.isConnectionStringSupported(connString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty constructor. Required for subclasses initialization.
|
||||
*/
|
||||
protected ConnectionUrl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for unsupported URLs
|
||||
*
|
||||
* @param origUrl
|
||||
* URLs
|
||||
*/
|
||||
public ConnectionUrl(String origUrl) {
|
||||
this.originalConnStr = origUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of {@link ConnectionUrl}, performing all the required initializations.
|
||||
*
|
||||
* @param connStrParser
|
||||
* a {@link ConnectionUrlParser} instance containing the parsed version of the original connection string
|
||||
* @param info
|
||||
* the connection arguments map
|
||||
*/
|
||||
protected ConnectionUrl(ConnectionUrlParser connStrParser, Properties info) {
|
||||
this.originalConnStr = connStrParser.getDatabaseUrl();
|
||||
this.originalDatabase = connStrParser.getPath() == null ? "" : connStrParser.getPath();
|
||||
collectProperties(connStrParser, info); // Fill properties before filling hosts info.
|
||||
collectHostsInfo(connStrParser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins the connection arguments from the connection string with the ones from the given connection arguments map collecting them in a single map.
|
||||
* Additionally may also collect other connection arguments from configuration files.
|
||||
*
|
||||
* @param connStrParser
|
||||
* the {@link ConnectionUrlParser} from where to collect the properties
|
||||
* @param info
|
||||
* the connection arguments map
|
||||
*/
|
||||
protected void collectProperties(ConnectionUrlParser connStrParser, Properties info) {
|
||||
// Fill in the properties from the connection string.
|
||||
connStrParser.getProperties().entrySet().stream().forEach(e -> this.properties.put(PropertyKey.normalizeCase(e.getKey()), e.getValue()));
|
||||
|
||||
// Properties passed in override the ones from the connection string.
|
||||
if (info != null) {
|
||||
info.stringPropertyNames().stream().forEach(k -> this.properties.put(PropertyKey.normalizeCase(k), info.getProperty(k)));
|
||||
}
|
||||
|
||||
// Collect properties from additional sources.
|
||||
setupPropertiesTransformer();
|
||||
expandPropertiesFromConfigFiles(this.properties);
|
||||
injectPerTypeProperties(this.properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the {@link ConnectionPropertiesTransform} if one was provided.
|
||||
*/
|
||||
protected void setupPropertiesTransformer() {
|
||||
String propertiesTransformClassName = this.properties.get(PropertyKey.propertiesTransform.getKeyName());
|
||||
if (!isNullOrEmpty(propertiesTransformClassName)) {
|
||||
try {
|
||||
this.propertiesTransformer = (ConnectionPropertiesTransform) Class.forName(propertiesTransformClassName).newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | CJException e) {
|
||||
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class,
|
||||
Messages.getString("ConnectionString.9", new Object[] { propertiesTransformClassName, e.toString() }), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands the connection argument "useConfig" by reading the mentioned configuration files.
|
||||
*
|
||||
* @param props
|
||||
* a connection arguments map from where to read the "useConfig" property and where to save the loaded properties.
|
||||
*/
|
||||
protected void expandPropertiesFromConfigFiles(Map<String, String> props) {
|
||||
// Properties from config files should not override the existing ones.
|
||||
String configFiles = props.get(PropertyKey.useConfigs.getKeyName());
|
||||
if (!isNullOrEmpty(configFiles)) {
|
||||
Properties configProps = getPropertiesFromConfigFiles(configFiles);
|
||||
configProps.stringPropertyNames().stream().map(PropertyKey::normalizeCase).filter(k -> !props.containsKey(k))
|
||||
.forEach(k -> props.put(k, configProps.getProperty(k)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map containing the properties read from the given configuration files. Multiple files can be referenced using a comma as separator.
|
||||
*
|
||||
* @param configFiles
|
||||
* the list of the configuration files to read
|
||||
* @return the map containing all the properties read
|
||||
*/
|
||||
public static Properties getPropertiesFromConfigFiles(String configFiles) {
|
||||
Properties configProps = new Properties();
|
||||
for (String configFile : configFiles.split(",")) {
|
||||
try (InputStream configAsStream = ConnectionUrl.class.getResourceAsStream("/com/mysql/cj/configurations/" + configFile + ".properties")) {
|
||||
if (configAsStream == null) {
|
||||
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class,
|
||||
Messages.getString("ConnectionString.10", new Object[] { configFile }));
|
||||
}
|
||||
configProps.load(configAsStream);
|
||||
} catch (IOException e) {
|
||||
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class,
|
||||
Messages.getString("ConnectionString.11", new Object[] { configFile }), e);
|
||||
}
|
||||
}
|
||||
return configProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses must override this method if they need to inject additional properties in the connection arguments map while it's being constructed.
|
||||
*
|
||||
* @param props
|
||||
* the properties already containing all known connection arguments
|
||||
*/
|
||||
protected void injectPerTypeProperties(Map<String, String> props) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some acceptable property values have changed in c/J 8.0 but old values remain hard-coded in widely used software.
|
||||
* So, old values must be accepted and translated to new ones.
|
||||
*
|
||||
* @param props
|
||||
* the host properties map to fix
|
||||
*/
|
||||
protected void replaceLegacyPropertyValues(Map<String, String> props) {
|
||||
// Workaround for zeroDateTimeBehavior=convertToNull hard-coded in NetBeans
|
||||
String zeroDateTimeBehavior = props.get(PropertyKey.zeroDateTimeBehavior.getKeyName());
|
||||
if (zeroDateTimeBehavior != null && zeroDateTimeBehavior.equalsIgnoreCase("convertToNull")) {
|
||||
props.put(PropertyKey.zeroDateTimeBehavior.getKeyName(), "CONVERT_TO_NULL");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the hosts information from the {@link ConnectionUrlParser}.
|
||||
*
|
||||
* @param connStrParser
|
||||
* the {@link ConnectionUrlParser} from where to collect the hosts information
|
||||
*/
|
||||
protected void collectHostsInfo(ConnectionUrlParser connStrParser) {
|
||||
connStrParser.getHosts().stream().map(this::fixHostInfo).forEach(this.hosts::add);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes the host information by moving data around and filling in missing data.
|
||||
* Applies properties transformations to the collected properties if {@link ConnectionPropertiesTransform} was declared in the connection arguments.
|
||||
*
|
||||
* @param hi
|
||||
* the host information data to fix
|
||||
* @return a new {@link HostInfo} with all required data
|
||||
*/
|
||||
protected HostInfo fixHostInfo(HostInfo hi) {
|
||||
Map<String, String> hostProps = new HashMap<>();
|
||||
|
||||
// Add global connection arguments.
|
||||
hostProps.putAll(this.properties);
|
||||
// Add/override host specific connection arguments.
|
||||
hi.getHostProperties().entrySet().stream().forEach(e -> hostProps.put(PropertyKey.normalizeCase(e.getKey()), e.getValue()));
|
||||
// Add the database name
|
||||
if (!hostProps.containsKey(PropertyKey.DBNAME.getKeyName())) {
|
||||
hostProps.put(PropertyKey.DBNAME.getKeyName(), getDatabase());
|
||||
}
|
||||
|
||||
preprocessPerTypeHostProperties(hostProps);
|
||||
|
||||
String host = hostProps.remove(PropertyKey.HOST.getKeyName());
|
||||
if (!isNullOrEmpty(hi.getHost())) {
|
||||
host = hi.getHost();
|
||||
} else if (isNullOrEmpty(host)) {
|
||||
host = getDefaultHost();
|
||||
}
|
||||
|
||||
String portAsString = hostProps.remove(PropertyKey.PORT.getKeyName());
|
||||
int port = hi.getPort();
|
||||
if (port == HostInfo.NO_PORT && !isNullOrEmpty(portAsString)) {
|
||||
try {
|
||||
port = Integer.valueOf(portAsString);
|
||||
} catch (NumberFormatException e) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class,
|
||||
Messages.getString("ConnectionString.7", new Object[] { hostProps.get(PropertyKey.PORT.getKeyName()) }), e);
|
||||
}
|
||||
}
|
||||
if (port == HostInfo.NO_PORT) {
|
||||
port = getDefaultPort();
|
||||
}
|
||||
|
||||
String user = hostProps.remove(PropertyKey.USER.getKeyName());
|
||||
if (!isNullOrEmpty(hi.getUser())) {
|
||||
user = hi.getUser();
|
||||
} else if (isNullOrEmpty(user)) {
|
||||
user = getDefaultUser();
|
||||
}
|
||||
|
||||
String password = hostProps.remove(PropertyKey.PASSWORD.getKeyName());
|
||||
if (!isNullOrEmpty(hi.getPassword())) {
|
||||
password = hi.getPassword();
|
||||
} else if (isNullOrEmpty(password)) {
|
||||
password = getDefaultPassword();
|
||||
}
|
||||
|
||||
expandPropertiesFromConfigFiles(hostProps);
|
||||
fixProtocolDependencies(hostProps);
|
||||
replaceLegacyPropertyValues(hostProps);
|
||||
|
||||
return buildHostInfo(host, port, user, password, hostProps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should override this to perform any required pre-processing on the host information properties.
|
||||
*
|
||||
* @param hostProps
|
||||
* the host properties map to process
|
||||
*/
|
||||
protected void preprocessPerTypeHostProperties(Map<String, String> hostProps) {
|
||||
// To be overridden in subclasses if needed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default host. Subclasses must override this method if they have different default host value.
|
||||
*
|
||||
* @return the default host
|
||||
*/
|
||||
public String getDefaultHost() {
|
||||
return DEFAULT_HOST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default port. Subclasses must override this method if they have different default port value.
|
||||
*
|
||||
* @return the default port
|
||||
*/
|
||||
public int getDefaultPort() {
|
||||
return DEFAULT_PORT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default user. Usually the one provided in the method {@link DriverManager#getConnection(String, String, String)} or as connection argument.
|
||||
*
|
||||
* @return the default user
|
||||
*/
|
||||
public String getDefaultUser() {
|
||||
return this.properties.get(PropertyKey.USER.getKeyName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default password. Usually the one provided in the method {@link DriverManager#getConnection(String, String, String)} or as connection
|
||||
* argument.
|
||||
*
|
||||
* @return the default password
|
||||
*/
|
||||
public String getDefaultPassword() {
|
||||
return this.properties.get(PropertyKey.PASSWORD.getKeyName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes the protocol (TCP vs PIPE) dependencies for the given host properties map.
|
||||
*
|
||||
* @param hostProps
|
||||
* the host properties map to fix
|
||||
*/
|
||||
protected void fixProtocolDependencies(Map<String, String> hostProps) {
|
||||
String protocol = hostProps.get(PropertyKey.PROTOCOL.getKeyName());
|
||||
if (!isNullOrEmpty(protocol) && protocol.equalsIgnoreCase("PIPE")) {
|
||||
if (!hostProps.containsKey(PropertyKey.socketFactory.getKeyName())) {
|
||||
hostProps.put(PropertyKey.socketFactory.getKeyName(), "com.mysql.cj.protocol.NamedPipeSocketFactory");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this connection URL type.
|
||||
*
|
||||
* @return the connection URL type
|
||||
*/
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the original database URL that produced this connection string.
|
||||
*
|
||||
* @return the original database URL
|
||||
*/
|
||||
@Override
|
||||
public String getDatabaseUrl() {
|
||||
return this.originalConnStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database from this connection URL. Note that a "DBNAME" property overrides the database identified in the connection string.
|
||||
*
|
||||
* @return the database name
|
||||
*/
|
||||
public String getDatabase() {
|
||||
return this.properties.containsKey(PropertyKey.DBNAME.getKeyName()) ? this.properties.get(PropertyKey.DBNAME.getKeyName()) : this.originalDatabase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hosts in this connection URL.
|
||||
*
|
||||
* @return the number of hosts
|
||||
*/
|
||||
public int hostsCount() {
|
||||
return this.hosts.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the single or first host info structure.
|
||||
*
|
||||
* @return the first host info structure
|
||||
*/
|
||||
public HostInfo getMainHost() {
|
||||
return this.hosts.isEmpty() ? null : this.hosts.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the hosts in this connection URL.
|
||||
*
|
||||
* @return the hosts list from this connection URL
|
||||
*/
|
||||
public List<HostInfo> getHostsList() {
|
||||
return getHostsList(HostsListView.ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the hosts in this connection URL, filtered for the given view.
|
||||
*
|
||||
* By default returns all hosts. Subclasses should override this method in order to implement support for different views, usually by splitting the global
|
||||
* hosts into smaller sub-lists.
|
||||
*
|
||||
* @param view
|
||||
* the type of the view to use in the returned list of hosts. This argument is ignored in this implementation.
|
||||
* @return
|
||||
* the hosts list from this connection URL, filtered for the given view.
|
||||
*/
|
||||
public List<HostInfo> getHostsList(HostsListView view) {
|
||||
return Collections.unmodifiableList(this.hosts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an existing host info with the same host:port part or spawns a new isolated host info based on this connection URL if none was found.
|
||||
*
|
||||
* @param hostPortPair
|
||||
* the host:port part to search for
|
||||
* @return the existing host info or a new independent one
|
||||
*/
|
||||
public HostInfo getHostOrSpawnIsolated(String hostPortPair) {
|
||||
return getHostOrSpawnIsolated(hostPortPair, this.hosts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an existing host info with the same host:port part or spawns a new isolated host info based on this connection URL if none was found.
|
||||
*
|
||||
* @param hostPortPair
|
||||
* the host:port part to search for
|
||||
* @param hostsList
|
||||
* the hosts list from where to search the host list
|
||||
* @return the existing host info or a new independent one
|
||||
*/
|
||||
public HostInfo getHostOrSpawnIsolated(String hostPortPair, List<HostInfo> hostsList) {
|
||||
for (HostInfo hi : hostsList) {
|
||||
if (hostPortPair.equals(hi.getHostPortPair())) {
|
||||
return hi;
|
||||
}
|
||||
}
|
||||
|
||||
ConnectionUrlParser.Pair<String, Integer> hostAndPort = ConnectionUrlParser.parseHostPortPair(hostPortPair);
|
||||
String host = hostAndPort.left;
|
||||
Integer port = hostAndPort.right;
|
||||
String user = getDefaultUser();
|
||||
String password = getDefaultPassword();
|
||||
|
||||
return buildHostInfo(host, port, user, password, this.properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link HostInfo} structure with the given components, passing through the properties transformer if there is one defined in this connection
|
||||
* string;
|
||||
*
|
||||
* @param host
|
||||
* the host
|
||||
* @param port
|
||||
* the port
|
||||
* @param user
|
||||
* the user name
|
||||
* @param password
|
||||
* the password
|
||||
* @param hostProps
|
||||
* the host properties map
|
||||
* @return a new instance of {@link HostInfo}
|
||||
*/
|
||||
protected HostInfo buildHostInfo(String host, int port, String user, String password, Map<String, String> hostProps) {
|
||||
// Apply properties transformations if needed.
|
||||
if (this.propertiesTransformer != null) {
|
||||
Properties props = new Properties();
|
||||
props.putAll(hostProps);
|
||||
|
||||
props.setProperty(PropertyKey.HOST.getKeyName(), host);
|
||||
props.setProperty(PropertyKey.PORT.getKeyName(), String.valueOf(port));
|
||||
if (user != null) {
|
||||
props.setProperty(PropertyKey.USER.getKeyName(), user);
|
||||
}
|
||||
if (password != null) {
|
||||
props.setProperty(PropertyKey.PASSWORD.getKeyName(), password);
|
||||
}
|
||||
|
||||
Properties transformedProps = this.propertiesTransformer.transformProperties(props);
|
||||
|
||||
host = transformedProps.getProperty(PropertyKey.HOST.getKeyName());
|
||||
try {
|
||||
port = Integer.parseInt(transformedProps.getProperty(PropertyKey.PORT.getKeyName()));
|
||||
} catch (NumberFormatException e) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.8",
|
||||
new Object[] { PropertyKey.PORT.getKeyName(), transformedProps.getProperty(PropertyKey.PORT.getKeyName()) }), e);
|
||||
}
|
||||
user = transformedProps.getProperty(PropertyKey.USER.getKeyName());
|
||||
password = transformedProps.getProperty(PropertyKey.PASSWORD.getKeyName());
|
||||
|
||||
Map<String, String> transformedHostProps = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
transformedProps.stringPropertyNames().stream().forEach(k -> transformedHostProps.put(k, transformedProps.getProperty(k)));
|
||||
// Remove surplus keys.
|
||||
transformedHostProps.remove(PropertyKey.HOST.getKeyName());
|
||||
transformedHostProps.remove(PropertyKey.PORT.getKeyName());
|
||||
transformedHostProps.remove(PropertyKey.USER.getKeyName());
|
||||
transformedHostProps.remove(PropertyKey.PASSWORD.getKeyName());
|
||||
|
||||
hostProps = transformedHostProps;
|
||||
}
|
||||
|
||||
return new HostInfo(this, host, port, user, password, hostProps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the original (common to all hosts) connection arguments as provided in the connection string query section.
|
||||
*
|
||||
* @return the original (common to all hosts) connection arguments
|
||||
*/
|
||||
public Map<String, String> getOriginalProperties() {
|
||||
return Collections.unmodifiableMap(this.properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Properties} instance containing the connection arguments extracted from the URL query section, i.e., per host attributes are excluded.
|
||||
* Applies properties transformations to the collected properties if {@link ConnectionPropertiesTransform} was declared in the connection arguments.
|
||||
*
|
||||
* @return a {@link Properties} instance containing the common connection arguments.
|
||||
*/
|
||||
public Properties getConnectionArgumentsAsProperties() {
|
||||
Properties props = new Properties();
|
||||
if (this.properties != null) {
|
||||
props.putAll(this.properties);
|
||||
}
|
||||
|
||||
return this.propertiesTransformer != null ? this.propertiesTransformer.transformProperties(props) : props;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hosts list built from the result of the DNS SRV lookup for the original host name.
|
||||
*
|
||||
* @param srvHost
|
||||
* the {@link HostInfo} from where to get the DNS SRV service name to lookup.
|
||||
* @return
|
||||
* the hosts list from the result of the DNS SRV lookup, filtered for the given view.
|
||||
*/
|
||||
public List<HostInfo> getHostsListFromDnsSrv(HostInfo srvHost) {
|
||||
String srvServiceName = srvHost.getHost();
|
||||
List<SrvRecord> srvRecords = null;
|
||||
|
||||
try {
|
||||
srvRecords = DnsSrv.lookupSrvRecords(srvServiceName);
|
||||
} catch (NamingException e) {
|
||||
throw ExceptionFactory.createException(Messages.getString("ConnectionString.26", new Object[] { srvServiceName }), e);
|
||||
}
|
||||
if (srvRecords == null || srvRecords.size() == 0) {
|
||||
throw ExceptionFactory.createException(Messages.getString("ConnectionString.26", new Object[] { srvServiceName }));
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(srvRecordsToHostsList(srvRecords, srvHost));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of DNS SRV records into a hosts list.
|
||||
*
|
||||
* @param srvRecords
|
||||
* the list of DNS SRV records.
|
||||
* @param baseHostInfo
|
||||
* the {@link HostInfo} to use as source of all common host specific options.
|
||||
* @return
|
||||
* a list of hosts.
|
||||
*/
|
||||
private List<HostInfo> srvRecordsToHostsList(List<SrvRecord> srvRecords, HostInfo baseHostInfo) {
|
||||
return srvRecords.stream()
|
||||
.map(s -> buildHostInfo(s.getTarget(), s.getPort(), baseHostInfo.getUser(), baseHostInfo.getPassword(), baseHostInfo.getHostProperties()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*
|
||||
* @return a string representation of this object
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder asStr = new StringBuilder(super.toString());
|
||||
asStr.append(String.format(" :: {type: \"%s\", hosts: %s, database: \"%s\", properties: %s, propertiesTransformer: %s}", this.type, this.hosts,
|
||||
this.originalDatabase, this.properties, this.propertiesTransformer));
|
||||
return asStr.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,707 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.conf;
|
||||
|
||||
import static com.mysql.cj.util.StringUtils.isNullOrEmpty;
|
||||
import static com.mysql.cj.util.StringUtils.safeTrim;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.mysql.cj.Messages;
|
||||
import com.mysql.cj.conf.ConnectionUrl.Type;
|
||||
import com.mysql.cj.exceptions.ExceptionFactory;
|
||||
import com.mysql.cj.exceptions.UnsupportedConnectionStringException;
|
||||
import com.mysql.cj.exceptions.WrongArgumentException;
|
||||
import com.mysql.cj.util.StringUtils;
|
||||
|
||||
/**
|
||||
* This class parses a connection string using the general URI structure defined in RFC 3986. Instead of using a URI instance to ensure the correct syntax of
|
||||
* the connection string, this implementation uses regular expressions which is faster but also less strict in terms of validations. This actually works better
|
||||
* because database URLs don't exactly stick to the RFC 3986 rules.
|
||||
* <p>
|
||||
* <i>scheme://authority/path?query#fragment</i>
|
||||
* <p>
|
||||
* This results in splitting the connection string URL and processing its internal parts:
|
||||
* <dl>
|
||||
* <dt>scheme</dt>
|
||||
* <dd>The protocol and subprotocol identification. Usually "jdbc:mysql:" or "mysqlx:".</dd>
|
||||
* <dt>authority</dt>
|
||||
* <dd>Contains information about the user credentials and/or the host and port information. Unlike its definition in the RFC 3986 specification, there can be
|
||||
* multiple authority sections separated by a single comma (,) in a connection string. It is also possible to use an alternative syntax for the user and/or host
|
||||
* identification, that also allows setting per host connection properties, in the form of
|
||||
* "[user[:password]@]address=(key1=value)[(key2=value)]...[,address=(key3=value)[(key4=value)]...]...".</dd>
|
||||
* <dt>path</dt>
|
||||
* <dd>Corresponds to the database identification.</dd>
|
||||
* <dt>query</dt>
|
||||
* <dd>The connection properties, written as "propertyName1[=[propertyValue1]][&propertyName2[=[propertyValue2]]]..."</dd>
|
||||
* <dt>fragment</dt>
|
||||
* <dd>The fragment section is ignored in Connector/J connection strings.</dd>
|
||||
* </dl>
|
||||
*/
|
||||
public class ConnectionUrlParser implements DatabaseUrlContainer {
|
||||
private static final String DUMMY_SCHEMA = "cj://";
|
||||
private static final String USER_PASS_SEPARATOR = ":";
|
||||
private static final String USER_HOST_SEPARATOR = "@";
|
||||
private static final String HOSTS_SEPARATOR = ",";
|
||||
private static final String KEY_VALUE_HOST_INFO_OPENING_MARKER = "(";
|
||||
private static final String KEY_VALUE_HOST_INFO_CLOSING_MARKER = ")";
|
||||
private static final String HOSTS_LIST_OPENING_MARKERS = "[(";
|
||||
private static final String HOSTS_LIST_CLOSING_MARKERS = "])";
|
||||
private static final String ADDRESS_EQUALS_HOST_INFO_PREFIX = "ADDRESS=";
|
||||
|
||||
private static final Pattern CONNECTION_STRING_PTRN = Pattern.compile("(?<scheme>[\\w\\+:%]+)\\s*" // scheme: required; alphanumeric, plus, colon or percent
|
||||
+ "(?://(?<authority>[^/?#]*))?\\s*" // authority: optional; starts with "//" followed by any char except "/", "?" and "#"
|
||||
+ "(?:/(?!\\s*/)(?<path>[^?#]*))?" // path: optional; starts with "/" but not followed by "/", and then followed by by any char except "?" and "#"
|
||||
+ "(?:\\?(?!\\s*\\?)(?<query>[^#]*))?" // query: optional; starts with "?" but not followed by "?", and then followed by by any char except "#"
|
||||
+ "(?:\\s*#(?<fragment>.*))?"); // fragment: optional; starts with "#", and then followed by anything
|
||||
private static final Pattern SCHEME_PTRN = Pattern.compile("(?<scheme>[\\w\\+:%]+).*");
|
||||
private static final Pattern HOST_LIST_PTRN = Pattern.compile("^\\[(?<hosts>.*)\\]$");
|
||||
private static final Pattern GENERIC_HOST_PTRN = Pattern.compile("^(?<host>.*?)(?::(?<port>[^:]*))?$");
|
||||
private static final Pattern KEY_VALUE_HOST_PTRN = Pattern.compile("[,\\s]*(?<key>[\\w\\.\\-\\s%]*)(?:=(?<value>[^,]*))?");
|
||||
private static final Pattern ADDRESS_EQUALS_HOST_PTRN = Pattern.compile("\\s*\\(\\s*(?<key>[\\w\\.\\-%]+)?\\s*(?:=(?<value>[^)]*))?\\)\\s*");
|
||||
private static final Pattern PROPERTIES_PTRN = Pattern.compile("[&\\s]*(?<key>[\\w\\.\\-\\s%]*)(?:=(?<value>[^&]*))?");
|
||||
|
||||
private final String baseConnectionString;
|
||||
private String scheme;
|
||||
private String authority;
|
||||
private String path;
|
||||
private String query;
|
||||
|
||||
private List<HostInfo> parsedHosts = null;
|
||||
private Map<String, String> parsedProperties = null;
|
||||
|
||||
/**
|
||||
* Static factory method for constructing instances of this class.
|
||||
*
|
||||
* @param connString
|
||||
* The connection string to parse.
|
||||
* @return an instance of {@link ConnectionUrlParser}
|
||||
*/
|
||||
public static ConnectionUrlParser parseConnectionString(String connString) {
|
||||
return new ConnectionUrlParser(connString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a connection string parser for the given connection string.
|
||||
*
|
||||
* @param connString
|
||||
* the connection string to parse
|
||||
*/
|
||||
private ConnectionUrlParser(String connString) {
|
||||
if (connString == null) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.0"));
|
||||
}
|
||||
if (!isConnectionStringSupported(connString)) {
|
||||
throw ExceptionFactory.createException(UnsupportedConnectionStringException.class,
|
||||
Messages.getString("ConnectionString.17", new String[] { connString }));
|
||||
}
|
||||
this.baseConnectionString = connString;
|
||||
parseConnectionString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the scheme part of given connection string matches one of the {@link Type}s supported by Connector/J.
|
||||
* Throws {@link WrongArgumentException} if connString is null.
|
||||
*
|
||||
* @param connString
|
||||
* connection string
|
||||
* @return true if supported
|
||||
*/
|
||||
public static boolean isConnectionStringSupported(String connString) {
|
||||
if (connString == null) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.0"));
|
||||
}
|
||||
Matcher matcher = SCHEME_PTRN.matcher(connString);
|
||||
return matcher.matches() && Type.isSupported(decodeSkippingPlusSign(matcher.group("scheme")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the connection string in its main sections.
|
||||
*/
|
||||
private void parseConnectionString() {
|
||||
String connString = this.baseConnectionString;
|
||||
Matcher matcher = CONNECTION_STRING_PTRN.matcher(connString);
|
||||
if (!matcher.matches()) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.1"));
|
||||
}
|
||||
this.scheme = decodeSkippingPlusSign(matcher.group("scheme"));
|
||||
this.authority = matcher.group("authority"); // Don't decode just yet.
|
||||
this.path = matcher.group("path") == null ? null : decode(matcher.group("path")).trim();
|
||||
this.query = matcher.group("query"); // Don't decode just yet.
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the authority section (user and/or host identification) of the connection string URI.
|
||||
*/
|
||||
private void parseAuthoritySection() {
|
||||
if (isNullOrEmpty(this.authority)) {
|
||||
// Add an empty, default, host.
|
||||
this.parsedHosts.add(new HostInfo());
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> authoritySegments = StringUtils.split(this.authority, HOSTS_SEPARATOR, HOSTS_LIST_OPENING_MARKERS, HOSTS_LIST_CLOSING_MARKERS, true,
|
||||
StringUtils.SEARCH_MODE__MRK_WS);
|
||||
for (String hi : authoritySegments) {
|
||||
parseAuthoritySegment(hi);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given sub authority segment, which can take one of the following syntaxes:
|
||||
* <ul>
|
||||
* <li>_user_:_password_@_host_:_port_
|
||||
* <li>_user_:_password_@(key1=value1,key2=value2,...)
|
||||
* <li>_user_:_password_@address=(key1=value1)(key2=value2)...
|
||||
* <li>_user_:_password_@[_any_of_the_above_1_,_any_of_the_above_2_,...]
|
||||
* </ul>
|
||||
* Most of the above placeholders can be omitted, representing a null, empty, or default value.
|
||||
* The placeholder _host_, can be a host name, IPv4 or IPv6. This parser doesn't check IP syntax. IPv6 addresses are enclosed by square brackets ([::1]).
|
||||
* The placeholder _any_of_the_above_?_ can be any of the above except for the user information part (_user_:_password_@).
|
||||
* When the symbol ":" is not used, it means an null/empty password or a default (HostInfo.NO_PORT) port, respectively.
|
||||
* When the symbol "@" is not used, it means that the authority part doesn't contain user information (depending on the scheme type can still be provided
|
||||
* via key=value pairs).
|
||||
*
|
||||
* @param authSegment
|
||||
* the string containing the authority segment
|
||||
*/
|
||||
private void parseAuthoritySegment(String authSegment) {
|
||||
/*
|
||||
* Start by splitting the user and host information parts from the authority segment and process the user information, if any.
|
||||
*/
|
||||
Pair<String, String> userHostInfoSplit = splitByUserInfoAndHostInfo(authSegment);
|
||||
String userInfo = safeTrim(userHostInfoSplit.left);
|
||||
String user = null;
|
||||
String password = null;
|
||||
if (!isNullOrEmpty(userInfo)) {
|
||||
Pair<String, String> userInfoPair = parseUserInfo(userInfo);
|
||||
user = decode(safeTrim(userInfoPair.left));
|
||||
password = decode(safeTrim(userInfoPair.right));
|
||||
}
|
||||
String hostInfo = safeTrim(userHostInfoSplit.right);
|
||||
|
||||
/*
|
||||
* Handle an authority part without host information.
|
||||
*/
|
||||
HostInfo hi = buildHostInfoForEmptyHost(user, password, hostInfo);
|
||||
if (hi != null) {
|
||||
this.parsedHosts.add(hi);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try using a java.net.URI instance to parse the host information. This helps dealing with the IPv6 syntax.
|
||||
*/
|
||||
hi = buildHostInfoResortingToUriParser(user, password, authSegment);
|
||||
if (hi != null) {
|
||||
this.parsedHosts.add(hi);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Using a URI didn't work, now check if the host part is composed by a sub list of hosts and process them, one by one if so.
|
||||
*/
|
||||
List<HostInfo> hiList = buildHostInfoResortingToSubHostsListParser(user, password, hostInfo);
|
||||
if (hiList != null) {
|
||||
this.parsedHosts.addAll(hiList);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* The hosts list syntax didn't work, now check if the host information is written in the alternate syntax "(Key1=value1,key2=value2)".
|
||||
*/
|
||||
hi = buildHostInfoResortingToKeyValueSyntaxParser(user, password, hostInfo);
|
||||
if (hi != null) {
|
||||
this.parsedHosts.add(hi);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Key/value syntax didn't work either, now check if the host information is written in the alternate syntax "address=(...)".
|
||||
* This parser needs to run after the key/value one because a key named "address" could invalidate it.
|
||||
*/
|
||||
hi = buildHostInfoResortingToAddressEqualsSyntaxParser(user, password, hostInfo);
|
||||
if (hi != null) {
|
||||
this.parsedHosts.add(hi);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Alternate syntax also failed, let's wind up the corner cases the URI couldn't handle.
|
||||
*/
|
||||
hi = buildHostInfoResortingToGenericSyntaxParser(user, password, hostInfo);
|
||||
if (hi != null) {
|
||||
this.parsedHosts.add(hi);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Failed parsing the authority segment.
|
||||
*/
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.2", new Object[] { authSegment }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an {@link HostInfo} instance for empty host authority segments.
|
||||
*
|
||||
* @param user
|
||||
* the user to include in the final {@link HostInfo}
|
||||
* @param password
|
||||
* the password to include in the final {@link HostInfo}
|
||||
* @param hostInfo
|
||||
* the string containing the host information part
|
||||
* @return the {@link HostInfo} instance containing the parsed information or <code>null</code> if the host part is not empty
|
||||
*/
|
||||
private HostInfo buildHostInfoForEmptyHost(String user, String password, String hostInfo) {
|
||||
if (isNullOrEmpty(hostInfo)) {
|
||||
if (isNullOrEmpty(user) && isNullOrEmpty(password)) {
|
||||
return new HostInfo();
|
||||
}
|
||||
return new HostInfo(this, null, HostInfo.NO_PORT, user, password);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the host information resorting to a URI object. This process handles most single-host well formed addresses.
|
||||
*
|
||||
* @param user
|
||||
* the user to include in the final {@link HostInfo}
|
||||
* @param password
|
||||
* the password to include in the final {@link HostInfo}
|
||||
* @param hostInfo
|
||||
* the string containing the host information part
|
||||
*
|
||||
* @return the {@link HostInfo} instance containing the parsed information or <code>null</code> if unable to parse the host information
|
||||
*/
|
||||
private HostInfo buildHostInfoResortingToUriParser(String user, String password, String hostInfo) {
|
||||
String host = null;
|
||||
int port = HostInfo.NO_PORT;
|
||||
|
||||
try {
|
||||
URI uri = URI.create(DUMMY_SCHEMA + hostInfo);
|
||||
if (uri.getHost() != null) {
|
||||
host = decode(uri.getHost());
|
||||
}
|
||||
if (uri.getPort() != -1) { // getPort() returns -1 if the port is undefined.
|
||||
port = uri.getPort();
|
||||
}
|
||||
if (uri.getUserInfo() != null) {
|
||||
// Can't have another one. The user information should have been handled already.
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// The URI failed to parse the host information.
|
||||
return null;
|
||||
}
|
||||
if (host != null || port != HostInfo.NO_PORT) {
|
||||
// The host info parsing succeeded.
|
||||
return new HostInfo(this, host, port, user, password);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the host information using the alternate sub hosts lists syntax "[host1, host2, ...]".
|
||||
*
|
||||
* @param user
|
||||
* the user to include in all the resulting {@link HostInfo}
|
||||
* @param password
|
||||
* the password to include in all the resulting {@link HostInfo}
|
||||
* @param hostInfo
|
||||
* the string containing the host information part
|
||||
* @return a list with all {@link HostInfo} instances containing the parsed information or <code>null</code> if unable to parse the host information
|
||||
*/
|
||||
private List<HostInfo> buildHostInfoResortingToSubHostsListParser(String user, String password, String hostInfo) {
|
||||
Matcher matcher = HOST_LIST_PTRN.matcher(hostInfo);
|
||||
if (matcher.matches()) {
|
||||
String hosts = matcher.group("hosts");
|
||||
List<String> hostsList = StringUtils.split(hosts, HOSTS_SEPARATOR, HOSTS_LIST_OPENING_MARKERS, HOSTS_LIST_CLOSING_MARKERS, true,
|
||||
StringUtils.SEARCH_MODE__MRK_WS);
|
||||
// One single element could, in fact, be an IPv6 stripped from its delimiters.
|
||||
boolean maybeIPv6 = hostsList.size() == 1 && hostsList.get(0).matches("(?i)^[\\dabcdef:]+$");
|
||||
List<HostInfo> hostInfoList = new ArrayList<>();
|
||||
for (String h : hostsList) {
|
||||
HostInfo hi;
|
||||
if ((hi = buildHostInfoForEmptyHost(user, password, h)) != null) {
|
||||
hostInfoList.add(hi);
|
||||
} else if ((hi = buildHostInfoResortingToUriParser(user, password, h)) != null
|
||||
|| (maybeIPv6 && (hi = buildHostInfoResortingToUriParser(user, password, "[" + h + "]")) != null)) {
|
||||
hostInfoList.add(hi);
|
||||
} else if ((hi = buildHostInfoResortingToKeyValueSyntaxParser(user, password, h)) != null) {
|
||||
hostInfoList.add(hi);
|
||||
} else if ((hi = buildHostInfoResortingToAddressEqualsSyntaxParser(user, password, h)) != null) {
|
||||
hostInfoList.add(hi);
|
||||
} else if ((hi = buildHostInfoResortingToGenericSyntaxParser(user, password, h)) != null) {
|
||||
hostInfoList.add(hi);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return hostInfoList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the host information using the alternate syntax "(key1=value1, key2=value2, ...)".
|
||||
*
|
||||
* @param user
|
||||
* the user to include in the resulting {@link HostInfo}
|
||||
* @param password
|
||||
* the password to include in the resulting {@link HostInfo}
|
||||
* @param hostInfo
|
||||
* the string containing the host information part
|
||||
* @return the {@link HostInfo} instance containing the parsed information or <code>null</code> if unable to parse the host information
|
||||
*/
|
||||
private HostInfo buildHostInfoResortingToKeyValueSyntaxParser(String user, String password, String hostInfo) {
|
||||
if (!hostInfo.startsWith(KEY_VALUE_HOST_INFO_OPENING_MARKER) || !hostInfo.endsWith(KEY_VALUE_HOST_INFO_CLOSING_MARKER)) {
|
||||
// This pattern won't work.
|
||||
return null;
|
||||
}
|
||||
hostInfo = hostInfo.substring(KEY_VALUE_HOST_INFO_OPENING_MARKER.length(), hostInfo.length() - KEY_VALUE_HOST_INFO_CLOSING_MARKER.length());
|
||||
return new HostInfo(this, null, HostInfo.NO_PORT, user, password, processKeyValuePattern(KEY_VALUE_HOST_PTRN, hostInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the host information using the alternate syntax "address=(key1=value1)(key2=value2)...".
|
||||
*
|
||||
* @param user
|
||||
* the user to include in the resulting {@link HostInfo}
|
||||
* @param password
|
||||
* the password to include in the resulting {@link HostInfo}
|
||||
* @param hostInfo
|
||||
* the string containing the host information part
|
||||
* @return the {@link HostInfo} instance containing the parsed information or <code>null</code> if unable to parse the host information
|
||||
*/
|
||||
private HostInfo buildHostInfoResortingToAddressEqualsSyntaxParser(String user, String password, String hostInfo) {
|
||||
int p = StringUtils.indexOfIgnoreCase(hostInfo, ADDRESS_EQUALS_HOST_INFO_PREFIX);
|
||||
if (p != 0) {
|
||||
// This pattern won't work.
|
||||
return null;
|
||||
}
|
||||
hostInfo = hostInfo.substring(p + ADDRESS_EQUALS_HOST_INFO_PREFIX.length()).trim();
|
||||
return new HostInfo(this, null, HostInfo.NO_PORT, user, password, processKeyValuePattern(ADDRESS_EQUALS_HOST_PTRN, hostInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the host information using the generic syntax "host:port".
|
||||
*
|
||||
* @param user
|
||||
* the user to include in the resulting {@link HostInfo}
|
||||
* @param password
|
||||
* the password to include in the resulting {@link HostInfo}
|
||||
* @param hostInfo
|
||||
* the string containing the host information part
|
||||
* @return the {@link HostInfo} instance containing the parsed information or <code>null</code> if unable to parse the host information
|
||||
*/
|
||||
private HostInfo buildHostInfoResortingToGenericSyntaxParser(String user, String password, String hostInfo) {
|
||||
if (splitByUserInfoAndHostInfo(hostInfo).left != null) {
|
||||
// This host information is invalid if contains another user information part.
|
||||
return null;
|
||||
}
|
||||
Pair<String, Integer> hostPortPair = parseHostPortPair(hostInfo);
|
||||
String host = decode(safeTrim(hostPortPair.left));
|
||||
Integer port = hostPortPair.right;
|
||||
return new HostInfo(this, isNullOrEmpty(host) ? null : host, port, user, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the given authority segment in the user information part and the host part.
|
||||
*
|
||||
* @param authSegment
|
||||
* the string containing the authority segment, i.e., the user and host information parts
|
||||
* @return
|
||||
* a {@link Pair} containing the user information in the left side and the host information in the right
|
||||
*/
|
||||
private Pair<String, String> splitByUserInfoAndHostInfo(String authSegment) {
|
||||
String userInfoPart = null;
|
||||
String hostInfoPart = authSegment;
|
||||
int p = authSegment.indexOf(USER_HOST_SEPARATOR);
|
||||
if (p >= 0) {
|
||||
userInfoPart = authSegment.substring(0, p);
|
||||
hostInfoPart = authSegment.substring(p + USER_HOST_SEPARATOR.length());
|
||||
}
|
||||
return new Pair<>(userInfoPart, hostInfoPart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given user information which is formed by the parts [user][:password].
|
||||
*
|
||||
* @param userInfo
|
||||
* the string containing the user information
|
||||
* @return a {@link Pair} containing the user and password information or null if the user information can't be parsed
|
||||
*/
|
||||
public static Pair<String, String> parseUserInfo(String userInfo) {
|
||||
if (isNullOrEmpty(userInfo)) {
|
||||
return null;
|
||||
}
|
||||
String[] userInfoParts = userInfo.split(USER_PASS_SEPARATOR, 2);
|
||||
String userName = userInfoParts[0];
|
||||
String password = userInfoParts.length > 1 ? userInfoParts[1] : null;
|
||||
return new Pair<>(userName, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a host:port pair and returns the two elements in a {@link Pair}
|
||||
*
|
||||
* @param hostInfo
|
||||
* the host:pair to parse
|
||||
* @return a {@link Pair} containing the host and port information or null if the host information can't be parsed
|
||||
*/
|
||||
public static Pair<String, Integer> parseHostPortPair(String hostInfo) {
|
||||
if (isNullOrEmpty(hostInfo)) {
|
||||
return null;
|
||||
}
|
||||
Matcher matcher = GENERIC_HOST_PTRN.matcher(hostInfo);
|
||||
if (matcher.matches()) {
|
||||
String host = matcher.group("host");
|
||||
String portAsString = decode(safeTrim(matcher.group("port")));
|
||||
Integer portAsInteger = HostInfo.NO_PORT;
|
||||
if (!isNullOrEmpty(portAsString)) {
|
||||
try {
|
||||
portAsInteger = Integer.parseInt(portAsString);
|
||||
} catch (NumberFormatException e) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.3", new Object[] { hostInfo }),
|
||||
e);
|
||||
}
|
||||
}
|
||||
return new Pair<>(host, portAsInteger);
|
||||
}
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.3", new Object[] { hostInfo }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the connection properties section and stores the extracted key/value pairs into a local map.
|
||||
*/
|
||||
private void parseQuerySection() {
|
||||
if (isNullOrEmpty(this.query)) {
|
||||
this.parsedProperties = new HashMap<>();
|
||||
return;
|
||||
}
|
||||
this.parsedProperties = processKeyValuePattern(PROPERTIES_PTRN, this.query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a two-matching-groups (respectively named "key" and "value") pattern which is successively tested against the given string and produces a key/value
|
||||
* map with the matched values. The given pattern must ensure that there are no leftovers between successive tests, i.e., the end of the previous match must
|
||||
* coincide with the beginning of the next.
|
||||
*
|
||||
* @param pattern
|
||||
* the regular expression pattern to match against to
|
||||
* @param input
|
||||
* the input string
|
||||
* @return a key/value map containing the matched values
|
||||
*/
|
||||
private Map<String, String> processKeyValuePattern(Pattern pattern, String input) {
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
int p = 0;
|
||||
Map<String, String> kvMap = new HashMap<>();
|
||||
while (matcher.find()) {
|
||||
if (matcher.start() != p) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class,
|
||||
Messages.getString("ConnectionString.4", new Object[] { input.substring(p) }));
|
||||
}
|
||||
String key = decode(safeTrim(matcher.group("key")));
|
||||
String value = decode(safeTrim(matcher.group("value")));
|
||||
if (!isNullOrEmpty(key)) {
|
||||
kvMap.put(key, value);
|
||||
} else if (!isNullOrEmpty(value)) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class,
|
||||
Messages.getString("ConnectionString.4", new Object[] { input.substring(p) }));
|
||||
}
|
||||
p = matcher.end();
|
||||
}
|
||||
if (p != input.length()) {
|
||||
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.4", new Object[] { input.substring(p) }));
|
||||
}
|
||||
return kvMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL-decode the given string.
|
||||
*
|
||||
* @param text
|
||||
* the string to decode
|
||||
* @return
|
||||
* the decoded string
|
||||
*/
|
||||
private static String decode(String text) {
|
||||
if (isNullOrEmpty(text)) {
|
||||
return text;
|
||||
}
|
||||
try {
|
||||
return URLDecoder.decode(text, StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Won't happen.
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* URL-decode the given string skipping all occurrences of the plus sign.
|
||||
*
|
||||
* @param text
|
||||
* the string to decode
|
||||
* @return
|
||||
* the decoded string
|
||||
*/
|
||||
private static String decodeSkippingPlusSign(String text) {
|
||||
if (isNullOrEmpty(text)) {
|
||||
return text;
|
||||
}
|
||||
text = text.replace("+", "%2B"); // Percent encode for "+" is "%2B".
|
||||
try {
|
||||
return URLDecoder.decode(text, StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Won't happen.
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the original database URL that produced this connection string parser.
|
||||
*
|
||||
* @return the original database URL
|
||||
*/
|
||||
@Override
|
||||
public String getDatabaseUrl() {
|
||||
return this.baseConnectionString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the scheme section.
|
||||
*
|
||||
* @return the scheme section
|
||||
*/
|
||||
public String getScheme() {
|
||||
return this.scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authority section.
|
||||
*
|
||||
* @return the authority section
|
||||
*/
|
||||
public String getAuthority() {
|
||||
return this.authority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path section.
|
||||
*
|
||||
* @return the path section
|
||||
*/
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query section.
|
||||
*
|
||||
* @return the query section
|
||||
*/
|
||||
public String getQuery() {
|
||||
return this.query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hosts information.
|
||||
*
|
||||
* @return the hosts information
|
||||
*/
|
||||
public List<HostInfo> getHosts() {
|
||||
if (this.parsedHosts == null) {
|
||||
this.parsedHosts = new ArrayList<>();
|
||||
parseAuthoritySection();
|
||||
}
|
||||
return this.parsedHosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the properties map contained in this connection string.
|
||||
*
|
||||
* @return the properties map
|
||||
*/
|
||||
public Map<String, String> getProperties() {
|
||||
if (this.parsedProperties == null) {
|
||||
parseQuerySection();
|
||||
}
|
||||
return Collections.unmodifiableMap(this.parsedProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*
|
||||
* @return a string representation of this object
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder asStr = new StringBuilder(super.toString());
|
||||
asStr.append(String.format(" :: {scheme: \"%s\", authority: \"%s\", path: \"%s\", query: \"%s\", parsedHosts: %s, parsedProperties: %s}", this.scheme,
|
||||
this.authority, this.path, this.query, this.parsedHosts, this.parsedProperties));
|
||||
return asStr.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is a simple container for two elements.
|
||||
*
|
||||
* @param <T>
|
||||
* left part type
|
||||
* @param <U>
|
||||
* right part type
|
||||
*/
|
||||
public static class Pair<T, U> {
|
||||
public final T left;
|
||||
public final U right;
|
||||
|
||||
public Pair(T left, U right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder asStr = new StringBuilder(super.toString());
|
||||
asStr.append(String.format(" :: { left: %s, right: %s }", this.left, this.right));
|
||||
return asStr.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.conf;
|
||||
|
||||
/**
|
||||
* Implementors of this class must be able to provide a database URL.
|
||||
*/
|
||||
public interface DatabaseUrlContainer {
|
||||
/**
|
||||
* Returns the original database URL that produced this connection string.
|
||||
*
|
||||
* @return the original database URL
|
||||
*/
|
||||
String getDatabaseUrl();
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.conf;
|
||||
|
||||
import static com.mysql.cj.util.StringUtils.isNullOrEmpty;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* This class holds the following MySQL host information:
|
||||
* <ul>
|
||||
* <li>host: an IP or host name.
|
||||
* <li>port: the port number or 0 if not known.
|
||||
* <li>user: the user name.
|
||||
* <li>password: the password.
|
||||
* <li>host properties: host specific connection arguments.
|
||||
* </ul>
|
||||
*/
|
||||
public class HostInfo implements DatabaseUrlContainer {
|
||||
public static final int NO_PORT = -1;
|
||||
private static final String HOST_PORT_SEPARATOR = ":";
|
||||
|
||||
private final DatabaseUrlContainer originalUrl;
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final String user;
|
||||
private final String password;
|
||||
private final Map<String, String> hostProperties = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructs an empty {@link HostInfo} instance.
|
||||
*/
|
||||
public HostInfo() {
|
||||
this(null, null, NO_PORT, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link HostInfo} instance initialized with the provided host, port and user info.
|
||||
*
|
||||
* @param url
|
||||
* a reference to the original database URL that produced this host info
|
||||
* @param host
|
||||
* the host ip or name
|
||||
* @param port
|
||||
* the port
|
||||
* @param user
|
||||
* the user name
|
||||
* @param password
|
||||
* the user's password
|
||||
*/
|
||||
public HostInfo(DatabaseUrlContainer url, String host, int port, String user, String password) {
|
||||
this(url, host, port, user, password, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link HostInfo} instance initialized with the provided host, port, user, password and connection arguments.
|
||||
*
|
||||
* @param url
|
||||
* a reference to the original database URL that produced this host info
|
||||
* @param host
|
||||
* the host ip or name
|
||||
* @param port
|
||||
* the port
|
||||
* @param user
|
||||
* the user name
|
||||
* @param password
|
||||
* this user's password
|
||||
* @param properties
|
||||
* a connection arguments map.
|
||||
*/
|
||||
public HostInfo(DatabaseUrlContainer url, String host, int port, String user, String password, Map<String, String> properties) {
|
||||
this.originalUrl = url;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
if (properties != null) {
|
||||
this.hostProperties.putAll(properties);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host.
|
||||
*
|
||||
* @return the host
|
||||
*/
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the port.
|
||||
*
|
||||
* @return the port
|
||||
*/
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a host:port representation of this host.
|
||||
*
|
||||
* @return the host:port representation of this host
|
||||
*/
|
||||
public String getHostPortPair() {
|
||||
return this.host + HOST_PORT_SEPARATOR + this.port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user name.
|
||||
*
|
||||
* @return the user name
|
||||
*/
|
||||
public String getUser() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password.
|
||||
*
|
||||
* @return the password
|
||||
*/
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the properties specific to this host.
|
||||
*
|
||||
* @return this host specific properties
|
||||
*/
|
||||
public Map<String, String> getHostProperties() {
|
||||
return Collections.unmodifiableMap(this.hostProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the connection argument for the given key.
|
||||
*
|
||||
* @param key
|
||||
* key
|
||||
*
|
||||
* @return the connection argument for the given key
|
||||
*/
|
||||
public String getProperty(String key) {
|
||||
return this.hostProperties.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to the database connection argument.
|
||||
*
|
||||
* @return the database name
|
||||
*/
|
||||
public String getDatabase() {
|
||||
String database = this.hostProperties.get(PropertyKey.DBNAME.getKeyName());
|
||||
return isNullOrEmpty(database) ? "" : database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exposes this host info as a single properties instance. The values for host, port, user and password are added to the properties map with their standard
|
||||
* keys.
|
||||
*
|
||||
* @return a {@link Properties} instance containing the full host information.
|
||||
*/
|
||||
public Properties exposeAsProperties() {
|
||||
Properties props = new Properties();
|
||||
this.hostProperties.entrySet().stream().forEach(e -> props.setProperty(e.getKey(), e.getValue() == null ? "" : e.getValue()));
|
||||
props.setProperty(PropertyKey.HOST.getKeyName(), getHost());
|
||||
props.setProperty(PropertyKey.PORT.getKeyName(), String.valueOf(getPort()));
|
||||
if (getUser() != null) {
|
||||
props.setProperty(PropertyKey.USER.getKeyName(), getUser());
|
||||
}
|
||||
if (getPassword() != null) {
|
||||
props.setProperty(PropertyKey.PASSWORD.getKeyName(), getPassword());
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the original database URL that produced this host info.
|
||||
*
|
||||
* @return the original database URL
|
||||
*/
|
||||
@Override
|
||||
public String getDatabaseUrl() {
|
||||
return this.originalUrl != null ? this.originalUrl.getDatabaseUrl() : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this {@link HostInfo} has the same host and port pair as the given {@link HostInfo}.
|
||||
*
|
||||
* @param hi
|
||||
* the {@link HostInfo} to compare with.
|
||||
* @return
|
||||
* <code>true</code> if both objects have equal host and port pairs, <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean equalHostPortPair(HostInfo hi) {
|
||||
return (getHost() != null && getHost().equals(hi.getHost()) || getHost() == null && hi.getHost() == null) && getPort() == hi.getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*
|
||||
* @return a string representation of this object
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder asStr = new StringBuilder(super.toString());
|
||||
asStr.append(String.format(" :: {host: \"%s\", port: %d, hostProperties: %s}", this.host, this.port, this.hostProperties));
|
||||
return asStr.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
package com.mysql.cj.conf;
|
||||
|
||||
/**
|
||||
* An enumeration that identifies the type of the view intended for getting hosts lists for multi-host connections.
|
||||
*/
|
||||
public enum HostsListView {
|
||||
ALL, SOURCES, REPLICAS;
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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.cj.conf;
|
||||
|
||||
import com.mysql.cj.exceptions.ExceptionInterceptor;
|
||||
|
||||
public interface PropertyDefinition<T> {
|
||||
|
||||
/**
|
||||
* Does the property have fixed values based constraints.
|
||||
*
|
||||
* @return true if property has fixed values based constraints.
|
||||
*/
|
||||
boolean hasValueConstraints();
|
||||
|
||||
/**
|
||||
* Returns true if property has range-based constraints
|
||||
*
|
||||
* @return true if property has range-based constraints
|
||||
*/
|
||||
boolean isRangeBased();
|
||||
|
||||
/**
|
||||
* Get the property key.
|
||||
*
|
||||
* @return {@link PropertyKey} or null if it's a custom property.
|
||||
*/
|
||||
PropertyKey getPropertyKey();
|
||||
|
||||
/**
|
||||
* Returns the property name.
|
||||
*
|
||||
* @return the property name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Returns the property camel-case alias.
|
||||
*
|
||||
* @return the property camel-case alias.
|
||||
*/
|
||||
String getCcAlias();
|
||||
|
||||
/**
|
||||
* Returns true if property has a camel-case alias.
|
||||
*
|
||||
* @return true if property has a camel-case alias.
|
||||
*/
|
||||
boolean hasCcAlias();
|
||||
|
||||
/**
|
||||
* Returns the default value.
|
||||
*
|
||||
* @return default value
|
||||
*/
|
||||
T getDefaultValue();
|
||||
|
||||
/**
|
||||
* May the property be changed after initialization.
|
||||
*
|
||||
* @return true if the property value may be changed after initialization.
|
||||
*/
|
||||
boolean isRuntimeModifiable();
|
||||
|
||||
/**
|
||||
* Returns the property description. Used for documentation.
|
||||
*
|
||||
* @return property description
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* Returns the driver version where the property was introduced first. Used for documentation.
|
||||
*
|
||||
* @return the driver version where the property was introduced first
|
||||
*/
|
||||
String getSinceVersion();
|
||||
|
||||
/**
|
||||
* Returns the property category.
|
||||
*
|
||||
* @return property category
|
||||
*/
|
||||
String getCategory();
|
||||
|
||||
/**
|
||||
* Returns the property order. Used as preferred property position in properties table in documentation.
|
||||
*
|
||||
* @return property order
|
||||
*/
|
||||
int getOrder();
|
||||
|
||||
/**
|
||||
* Returns the list of allowable values.
|
||||
*
|
||||
* @return the list of allowable values
|
||||
*/
|
||||
String[] getAllowableValues();
|
||||
|
||||
/**
|
||||
* The lowest possible value of range-based property
|
||||
*
|
||||
* @return the lowest possible value of range-based property
|
||||
*/
|
||||
int getLowerBound();
|
||||
|
||||
/**
|
||||
* The highest possible value of range-based property
|
||||
*
|
||||
* @return the highest possible value of range-based property
|
||||
*/
|
||||
int getUpperBound();
|
||||
|
||||
/**
|
||||
* Returns the value object parsed from it's string representation and checked against allowable values.
|
||||
*
|
||||
* @param value
|
||||
* value
|
||||
* @param exceptionInterceptor
|
||||
* exception interceptor
|
||||
*
|
||||
* @return the value object
|
||||
*/
|
||||
T parseObject(String value, ExceptionInterceptor exceptionInterceptor);
|
||||
|
||||
/**
|
||||
* Creates instance of ReadableProperty or ModifiableProperty depending on isRuntimeModifiable() result.
|
||||
*
|
||||
* @return {@link RuntimeProperty} instance
|
||||
*/
|
||||
RuntimeProperty<T> createRuntimeProperty();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,879 @@
|
||||
/*
|
||||
* 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.conf;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mysql.cj.Messages;
|
||||
import com.mysql.cj.PerConnectionLRUFactory;
|
||||
import com.mysql.cj.log.Log;
|
||||
import com.mysql.cj.log.StandardLogger;
|
||||
import com.mysql.cj.util.PerVmServerConfigCacheFactory;
|
||||
|
||||
public class PropertyDefinitions {
|
||||
/*
|
||||
* Built-in system properties.
|
||||
*/
|
||||
public static final String SYSP_line_separator = "line.separator";
|
||||
public static final String SYSP_java_vendor = "java.vendor";
|
||||
public static final String SYSP_java_version = "java.version";
|
||||
public static final String SYSP_java_vm_vendor = "java.vm.vendor";
|
||||
public static final String SYSP_os_name = "os.name";
|
||||
public static final String SYSP_os_arch = "os.arch";
|
||||
public static final String SYSP_os_version = "os.version";
|
||||
public static final String SYSP_file_encoding = "file.encoding";
|
||||
|
||||
/*
|
||||
* Operational system properties.
|
||||
*/
|
||||
public static final String SYSP_disableAbandonedConnectionCleanup = "com.mysql.cj.disableAbandonedConnectionCleanup";
|
||||
|
||||
/*
|
||||
* Testsuite system properties.
|
||||
*/
|
||||
public static final String SYSP_testsuite_url /* */ = "com.mysql.cj.testsuite.url";
|
||||
public final static String SYSP_testsuite_url_admin /* */ = "com.mysql.cj.testsuite.url.admin";
|
||||
public static final String SYSP_testsuite_url_cluster /* */ = "com.mysql.cj.testsuite.url.cluster";
|
||||
/** Connection string to server compiled with OpenSSL */
|
||||
public static final String SYSP_testsuite_url_openssl /* */ = "com.mysql.cj.testsuite.url.openssl";
|
||||
|
||||
public static final String SYSP_testsuite_url_mysqlx /* */ = "com.mysql.cj.testsuite.mysqlx.url";
|
||||
public static final String SYSP_testsuite_url_mysqlx_openssl /* */ = "com.mysql.cj.testsuite.mysqlx.url.openssl";
|
||||
|
||||
public static final String SYSP_testsuite_cantGrant /* */ = "com.mysql.cj.testsuite.cantGrant";
|
||||
public static final String SYSP_testsuite_disable_multihost_tests /* */ = "com.mysql.cj.testsuite.disable.multihost.tests"; // TODO should be more specific for different types of multi-host configs
|
||||
|
||||
public static final String SYSP_testsuite_unavailable_host /* */ = "com.mysql.cj.testsuite.unavailable.host";
|
||||
|
||||
/** Option to indicate that the server was installed without the test package */
|
||||
public static final String SYSP_testsuite_no_server_testsuite /* */ = "com.mysql.cj.testsuite.no.server.testsuite";
|
||||
|
||||
/** For testsuite.regression.DataSourceRegressionTest */
|
||||
public static final String SYSP_testsuite_ds_host /* */ = "com.mysql.cj.testsuite.ds.host";
|
||||
/** For testsuite.regression.DataSourceRegressionTest */
|
||||
public static final String SYSP_testsuite_ds_port /* */ = "com.mysql.cj.testsuite.ds.port";
|
||||
/** For testsuite.regression.DataSourceRegressionTest */
|
||||
public static final String SYSP_testsuite_ds_db /* */ = "com.mysql.cj.testsuite.ds.db";
|
||||
/** For testsuite.regression.DataSourceRegressionTest */
|
||||
public static final String SYSP_testsuite_ds_user /* */ = "com.mysql.cj.testsuite.ds.user";
|
||||
/** For testsuite.regression.DataSourceRegressionTest */
|
||||
public static final String SYSP_testsuite_ds_password /* */ = "com.mysql.cj.testsuite.ds.password";
|
||||
|
||||
/** For testsuite.perf.LoadStorePerfTest */
|
||||
public static final String SYSP_testsuite_loadstoreperf_tabletype /* */ = "com.mysql.cj.testsuite.loadstoreperf.tabletype"; // TODO document allowed types
|
||||
/** For testsuite.perf.LoadStorePerfTest */
|
||||
public static final String SYSP_testsuite_loadstoreperf_useBigResults /* */ = "com.mysql.cj.testsuite.loadstoreperf.useBigResults";
|
||||
|
||||
/** The system property that must exist to run the shutdown test in testsuite.simple.MiniAdminTest */
|
||||
public static final String SYSP_testsuite_miniAdminTest_runShutdown /* */ = "com.mysql.cj.testsuite.miniAdminTest.runShutdown";
|
||||
|
||||
/** Suppress debug output when running testsuite */
|
||||
public static final String SYSP_testsuite_noDebugOutput /* */ = "com.mysql.cj.testsuite.noDebugOutput";
|
||||
/** Don't remove database object created by tests */
|
||||
public static final String SYSP_testsuite_retainArtifacts /* */ = "com.mysql.cj.testsuite.retainArtifacts";
|
||||
public static final String SYSP_testsuite_runLongTests /* */ = "com.mysql.cj.testsuite.runLongTests";
|
||||
public static final String SYSP_testsuite_serverController_basedir /* */ = "com.mysql.cj.testsuite.serverController.basedir";
|
||||
|
||||
/*
|
||||
* Build system properties.
|
||||
*/
|
||||
public static final String SYSP_com_mysql_cj_build_verbose /* */ = "com.mysql.cj.build.verbose";
|
||||
|
||||
/*
|
||||
* Categories of connection properties.
|
||||
*/
|
||||
public static final String CATEGORY_AUTH = Messages.getString("ConnectionProperties.categoryAuthentication");
|
||||
public static final String CATEGORY_CONNECTION = Messages.getString("ConnectionProperties.categoryConnection");
|
||||
public static final String CATEGORY_SESSION = Messages.getString("ConnectionProperties.categorySession");
|
||||
public static final String CATEGORY_NETWORK = Messages.getString("ConnectionProperties.categoryNetworking");
|
||||
public static final String CATEGORY_SECURITY = Messages.getString("ConnectionProperties.categorySecurity");
|
||||
public static final String CATEGORY_STATEMENTS = Messages.getString("ConnectionProperties.categoryStatements");
|
||||
public static final String CATEGORY_PREPARED_STATEMENTS = Messages.getString("ConnectionProperties.categoryPreparedStatements");
|
||||
public static final String CATEGORY_RESULT_SETS = Messages.getString("ConnectionProperties.categoryResultSets");
|
||||
public static final String CATEGORY_METADATA = Messages.getString("ConnectionProperties.categoryMetadata");
|
||||
public static final String CATEGORY_BLOBS = Messages.getString("ConnectionProperties.categoryBlobs");
|
||||
public static final String CATEGORY_DATETIMES = Messages.getString("ConnectionProperties.categoryDatetimes");
|
||||
public static final String CATEGORY_HA = Messages.getString("ConnectionProperties.categoryHA");
|
||||
public static final String CATEGORY_PERFORMANCE = Messages.getString("ConnectionProperties.categoryPerformance");
|
||||
public static final String CATEGORY_DEBUGING_PROFILING = Messages.getString("ConnectionProperties.categoryDebuggingProfiling");
|
||||
public static final String CATEGORY_EXCEPTIONS = Messages.getString("ConnectionProperties.categoryExceptions");
|
||||
public static final String CATEGORY_INTEGRATION = Messages.getString("ConnectionProperties.categoryIntegration");
|
||||
public static final String CATEGORY_JDBC = Messages.getString("ConnectionProperties.categoryJDBC");
|
||||
public static final String CATEGORY_XDEVAPI = Messages.getString("ConnectionProperties.categoryXDevAPI");
|
||||
public static final String CATEGORY_USER_DEFINED = Messages.getString("ConnectionProperties.categoryUserDefined");
|
||||
|
||||
public static final String[] PROPERTY_CATEGORIES = new String[] { CATEGORY_AUTH, CATEGORY_CONNECTION, CATEGORY_SESSION, CATEGORY_NETWORK, CATEGORY_SECURITY,
|
||||
CATEGORY_STATEMENTS, CATEGORY_PREPARED_STATEMENTS, CATEGORY_RESULT_SETS, CATEGORY_METADATA, CATEGORY_BLOBS, CATEGORY_DATETIMES, CATEGORY_HA,
|
||||
CATEGORY_PERFORMANCE, CATEGORY_DEBUGING_PROFILING, CATEGORY_EXCEPTIONS, CATEGORY_INTEGRATION, CATEGORY_JDBC, CATEGORY_XDEVAPI };
|
||||
|
||||
/*
|
||||
* Property modifiers.
|
||||
*/
|
||||
public static final boolean DEFAULT_VALUE_TRUE = true;
|
||||
public static final boolean DEFAULT_VALUE_FALSE = false;
|
||||
public static final String DEFAULT_VALUE_NULL_STRING = null;
|
||||
public static final String NO_ALIAS = null;
|
||||
|
||||
/** is modifiable in run-time */
|
||||
public static final boolean RUNTIME_MODIFIABLE = true;
|
||||
|
||||
/** is not modifiable in run-time (will allow to set not-null value only once) */
|
||||
public static final boolean RUNTIME_NOT_MODIFIABLE = false;
|
||||
|
||||
/*
|
||||
* Property enums.
|
||||
*/
|
||||
public enum ZeroDatetimeBehavior { // zeroDateTimeBehavior
|
||||
CONVERT_TO_NULL, EXCEPTION, ROUND;
|
||||
}
|
||||
|
||||
public enum SslMode {
|
||||
PREFERRED, REQUIRED, VERIFY_CA, VERIFY_IDENTITY, DISABLED;
|
||||
}
|
||||
|
||||
public enum XdevapiSslMode {
|
||||
REQUIRED, VERIFY_CA, VERIFY_IDENTITY, DISABLED;
|
||||
}
|
||||
|
||||
public enum AuthMech { // xdevapi.auth
|
||||
PLAIN, MYSQL41, SHA256_MEMORY, EXTERNAL;
|
||||
}
|
||||
|
||||
public enum Compression { // xdevapi.compress
|
||||
PREFERRED, REQUIRED, DISABLED;
|
||||
}
|
||||
|
||||
public enum DatabaseTerm {
|
||||
CATALOG, SCHEMA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static unmodifiable {@link PropertyKey} -> {@link PropertyDefinition} map.
|
||||
*/
|
||||
public static final Map<PropertyKey, PropertyDefinition<?>> PROPERTY_KEY_TO_PROPERTY_DEFINITION;
|
||||
|
||||
static {
|
||||
String STANDARD_LOGGER_NAME = StandardLogger.class.getName();
|
||||
|
||||
PropertyDefinition<?>[] pdefs = new PropertyDefinition<?>[] {
|
||||
//
|
||||
// CATEGORY_AUTHENTICATION
|
||||
//
|
||||
new StringPropertyDefinition(PropertyKey.USER, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.Username"), Messages.getString("ConnectionProperties.allVersions"), CATEGORY_AUTH,
|
||||
Integer.MIN_VALUE + 1),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.PASSWORD, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.Password"), Messages.getString("ConnectionProperties.allVersions"), CATEGORY_AUTH,
|
||||
Integer.MIN_VALUE + 2),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.authenticationPlugins, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.authenticationPlugins"), "5.1.19", CATEGORY_AUTH, Integer.MIN_VALUE + 3),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.disabledAuthenticationPlugins, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.disabledAuthenticationPlugins"), "5.1.19", CATEGORY_AUTH, Integer.MIN_VALUE + 4),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.defaultAuthenticationPlugin, "mysql_native_password", RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.defaultAuthenticationPlugin"), "5.1.19", CATEGORY_AUTH, Integer.MIN_VALUE + 5),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.ldapServerHostname, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.ldapServerHostname"), "8.0.23", CATEGORY_AUTH, Integer.MIN_VALUE + 6),
|
||||
|
||||
//
|
||||
// CATEGORY_CONNECTION
|
||||
//
|
||||
new StringPropertyDefinition(PropertyKey.passwordCharacterEncoding, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.passwordCharacterEncoding"), "5.1.7", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.connectionAttributes, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.connectionAttributes"), "5.1.25", CATEGORY_CONNECTION, 7),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.clientInfoProvider, "com.mysql.cj.jdbc.CommentClientInfoProvider", RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.clientInfoProvider"), "5.1.0", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.connectionLifecycleInterceptors, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.connectionLifecycleInterceptors"), "5.1.4", CATEGORY_CONNECTION, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.createDatabaseIfNotExist, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.createDatabaseIfNotExist"), "3.1.9", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.interactiveClient, DEFAULT_VALUE_FALSE, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.interactiveClient"), "3.1.0", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.propertiesTransform, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.connectionPropertiesTransform"), "3.1.4", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.rollbackOnPooledClose, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.rollbackOnPooledClose"), "3.0.15", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.useConfigs, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useConfigs"), "3.1.5", CATEGORY_CONNECTION, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useAffectedRows, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useAffectedRows"), "5.1.7", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.disconnectOnExpiredPasswords, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.disconnectOnExpiredPasswords"), "5.1.23", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.detectCustomCollations, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.detectCustomCollations"), "5.1.29", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
new EnumPropertyDefinition<>(PropertyKey.databaseTerm, DatabaseTerm.CATALOG, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.databaseTerm"), "8.0.17", CATEGORY_CONNECTION, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_SESSION
|
||||
//
|
||||
new StringPropertyDefinition(PropertyKey.characterEncoding, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.characterEncoding"), "1.1g", CATEGORY_SESSION, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.characterSetResults, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.characterSetResults"), "3.0.13", CATEGORY_SESSION, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.customCharsetMapping, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.customCharsetMapping"), "8.0.26", CATEGORY_SESSION, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.connectionCollation, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.connectionCollation"), "3.0.13", CATEGORY_SESSION, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.sessionVariables, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.sessionVariables"), "3.1.8", CATEGORY_SESSION, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.trackSessionState, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.trackSessionState"), "8.0.26", CATEGORY_SESSION, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_NETWORK
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.useUnbufferedInput, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useUnbufferedInput"), "3.0.11", CATEGORY_NETWORK, Integer.MIN_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.connectTimeout, 0, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.connectTimeout"),
|
||||
"3.0.1", CATEGORY_NETWORK, 9, 0, Integer.MAX_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.localSocketAddress, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.localSocketAddress"), "5.0.5", CATEGORY_NETWORK, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.socketFactory, "com.mysql.cj.protocol.StandardSocketFactory", RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.socketFactory"), "3.0.3", CATEGORY_NETWORK, 4),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.socksProxyHost, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.socksProxyHost"), "5.1.34", CATEGORY_NETWORK, 1),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.socksProxyPort, 1080, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.socksProxyPort"),
|
||||
"5.1.34", CATEGORY_NETWORK, 2, 0, 65535),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.socketTimeout, 0, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.socketTimeout"),
|
||||
"3.0.1", CATEGORY_NETWORK, 10, 0, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.tcpNoDelay, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.tcpNoDelay"), "5.0.7", CATEGORY_NETWORK, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.tcpKeepAlive, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.tcpKeepAlive"), "5.0.7", CATEGORY_NETWORK, Integer.MIN_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.tcpRcvBuf, 0, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.tcpSoRcvBuf"), "5.0.7",
|
||||
CATEGORY_NETWORK, Integer.MIN_VALUE, 0, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.tcpSndBuf, 0, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.tcpSoSndBuf"), "5.0.7",
|
||||
CATEGORY_NETWORK, Integer.MIN_VALUE, 0, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.tcpTrafficClass, 0, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.tcpTrafficClass"),
|
||||
"5.0.7", CATEGORY_NETWORK, Integer.MIN_VALUE, 0, 255),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useCompression, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useCompression"), "3.0.17", CATEGORY_NETWORK, Integer.MIN_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.maxAllowedPacket, 65535, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.maxAllowedPacket"), "5.1.8", CATEGORY_NETWORK, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.dnsSrv, DEFAULT_VALUE_FALSE, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.dnsSrv"), "8.0.19", CATEGORY_NETWORK, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_SECURITY
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.paranoid, DEFAULT_VALUE_FALSE, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.paranoid"), "3.0.1", CATEGORY_SECURITY, 1),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.serverRSAPublicKeyFile, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.serverRSAPublicKeyFile"), "5.1.31", CATEGORY_SECURITY, 2),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.allowPublicKeyRetrieval, DEFAULT_VALUE_FALSE, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.allowPublicKeyRetrieval"), "5.1.31", CATEGORY_SECURITY, 3),
|
||||
|
||||
new EnumPropertyDefinition<>(PropertyKey.sslMode, SslMode.PREFERRED, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.sslMode"),
|
||||
"8.0.13", CATEGORY_SECURITY, 4),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.trustCertificateKeyStoreUrl, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.trustCertificateKeyStoreUrl"), "5.1.0", CATEGORY_SECURITY, 5),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.trustCertificateKeyStoreType, "JKS", RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.trustCertificateKeyStoreType"), "5.1.0", CATEGORY_SECURITY, 6),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.trustCertificateKeyStorePassword, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.trustCertificateKeyStorePassword"), "5.1.0", CATEGORY_SECURITY, 7),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.fallbackToSystemTrustStore, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.fallbackToSystemTrustStore"), "8.0.22", CATEGORY_SECURITY, 8),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.clientCertificateKeyStoreUrl, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.clientCertificateKeyStoreUrl"), "5.1.0", CATEGORY_SECURITY, 9),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.clientCertificateKeyStoreType, "JKS", RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.clientCertificateKeyStoreType"), "5.1.0", CATEGORY_SECURITY, 10),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.clientCertificateKeyStorePassword, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.clientCertificateKeyStorePassword"), "5.1.0", CATEGORY_SECURITY, 11),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.fallbackToSystemKeyStore, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.fallbackToSystemKeyStore"), "8.0.22", CATEGORY_SECURITY, 12),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.enabledSSLCipherSuites, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.enabledSSLCipherSuites"), "5.1.35", CATEGORY_SECURITY, 13),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.enabledTLSProtocols, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.enabledTLSProtocols"), "8.0.8", CATEGORY_SECURITY, 14),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.allowLoadLocalInfile, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadDataLocal"), "3.0.3", CATEGORY_SECURITY, Integer.MAX_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.allowLoadLocalInfileInPath, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadDataLocalInPath"), "8.0.22", CATEGORY_SECURITY, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.allowMultiQueries, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.allowMultiQueries"), "3.1.1", CATEGORY_SECURITY, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.allowUrlInLocalInfile, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.allowUrlInLoadLocal"), "3.1.4", CATEGORY_SECURITY, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useSSL, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.useSSL"),
|
||||
"3.0.2", CATEGORY_SECURITY, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.requireSSL, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.requireSSL"), "3.1.0", CATEGORY_SECURITY, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.verifyServerCertificate, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.verifyServerCertificate"), "5.1.6", CATEGORY_SECURITY, Integer.MAX_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_STATEMENTS
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.continueBatchOnError, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.continueBatchOnError"), "3.0.3", CATEGORY_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.dontTrackOpenResources, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.dontTrackOpenResources"), "3.1.7", CATEGORY_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.queryTimeoutKillsConnection, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.queryTimeoutKillsConnection"), "5.1.9", CATEGORY_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.queryInterceptors, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.queryInterceptors"), "8.0.7", CATEGORY_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.cacheDefaultTimeZone, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.cacheDefaultTimeZone"), "8.0.20", CATEGORY_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_PREPARED_STATEMENTS
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.allowNanAndInf, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.allowNANandINF"), "3.1.5", CATEGORY_PREPARED_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.autoClosePStmtStreams, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.autoClosePstmtStreams"), "3.1.12", CATEGORY_PREPARED_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.compensateOnDuplicateKeyUpdateCounts, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.compensateOnDuplicateKeyUpdateCounts"), "5.1.7", CATEGORY_PREPARED_STATEMENTS,
|
||||
Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useServerPrepStmts, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useServerPrepStmts"), "3.1.0", CATEGORY_PREPARED_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.emulateUnsupportedPstmts, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.emulateUnsupportedPstmts"), "3.1.7", CATEGORY_PREPARED_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.generateSimpleParameterMetadata, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.generateSimpleParameterMetadata"), "5.0.5", CATEGORY_PREPARED_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.processEscapeCodesForPrepStmts, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.processEscapeCodesForPrepStmts"), "3.1.12", CATEGORY_PREPARED_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useStreamLengthsInPrepStmts, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useStreamLengthsInPrepStmts"), "3.0.2", CATEGORY_PREPARED_STATEMENTS, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_RESULT_SETS
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.clobberStreamingResults, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.clobberStreamingResults"), "3.0.9", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.emptyStringsConvertToZero, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.emptyStringsConvertToZero"), "3.1.8", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.holdResultsOpenOverStatementClose, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.holdRSOpenOverStmtClose"), "3.1.7", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.jdbcCompliantTruncation, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.jdbcCompliantTruncation"), "3.1.2", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.maxRows, -1, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.maxRows"),
|
||||
Messages.getString("ConnectionProperties.allVersions"), CATEGORY_RESULT_SETS, Integer.MIN_VALUE, -1, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.netTimeoutForStreamingResults, 600, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.netTimeoutForStreamingResults"), "5.1.0", CATEGORY_RESULT_SETS, Integer.MIN_VALUE, 0,
|
||||
Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.padCharsWithSpace, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.padCharsWithSpace"), "5.0.6", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.populateInsertRowWithDefaultValues, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.populateInsertRowWithDefaultValues"), "5.0.5", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.strictUpdates, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.strictUpdates"), "3.0.4", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.tinyInt1isBit, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.tinyInt1isBit"), "3.0.16", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.transformedBitIsBoolean, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.transformedBitIsBoolean"), "3.1.9", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.scrollTolerantForwardOnly, DEFAULT_VALUE_FALSE, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.scrollTolerantForwardOnly"), "8.0.24", CATEGORY_RESULT_SETS, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_METADATA
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.noAccessToProcedureBodies, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.noAccessToProcedureBodies"), "5.0.3", CATEGORY_METADATA, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.nullDatabaseMeansCurrent, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.nullCatalogMeansCurrent"), "3.1.8", CATEGORY_METADATA, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useHostsInPrivileges, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useHostsInPrivileges"), "3.0.2", CATEGORY_METADATA, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useInformationSchema, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useInformationSchema"), "5.0.0", CATEGORY_METADATA, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.getProceduresReturnsFunctions, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.getProceduresReturnsFunctions"), "5.1.26", CATEGORY_METADATA, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_BLOBS
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.autoDeserialize, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.autoDeserialize"), "3.1.5", CATEGORY_BLOBS, Integer.MIN_VALUE),
|
||||
|
||||
new MemorySizePropertyDefinition(PropertyKey.blobSendChunkSize, 1024 * 1024, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.blobSendChunkSize"), "3.1.9", CATEGORY_BLOBS, Integer.MIN_VALUE, 0, 0),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.blobsAreStrings, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.blobsAreStrings"), "5.0.8", CATEGORY_BLOBS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.functionsNeverReturnBlobs, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.functionsNeverReturnBlobs"), "5.0.8", CATEGORY_BLOBS, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.clobCharacterEncoding, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.clobCharacterEncoding"), "5.0.0", CATEGORY_BLOBS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.emulateLocators, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.emulateLocators"), "3.1.0", CATEGORY_BLOBS, Integer.MIN_VALUE),
|
||||
|
||||
new MemorySizePropertyDefinition(PropertyKey.locatorFetchBufferSize, 1024 * 1024, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.locatorFetchBufferSize"), "3.2.1", CATEGORY_BLOBS, Integer.MIN_VALUE, 0, Integer.MAX_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_DATETIMES
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.noDatetimeStringSync, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.noDatetimeStringSync"), "3.1.7", CATEGORY_DATETIMES, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.connectionTimeZone, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.connectionTimeZone"), "3.0.2", CATEGORY_DATETIMES, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.forceConnectionTimeZoneToSession, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.forceConnectionTimeZoneToSession"), "8.0.23", CATEGORY_DATETIMES, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.preserveInstants, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.preserveInstants"), "8.0.23", CATEGORY_DATETIMES, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.treatUtilDateAsTimestamp, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.treatUtilDateAsTimestamp"), "5.0.5", CATEGORY_DATETIMES, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.sendFractionalSeconds, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.sendFractionalSeconds"), "5.1.37", CATEGORY_DATETIMES, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.sendFractionalSecondsForTime, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.sendFractionalSecondsForTime"), "8.0.23", CATEGORY_DATETIMES, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.yearIsDateType, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.yearIsDateType"), "3.1.9", CATEGORY_DATETIMES, Integer.MIN_VALUE),
|
||||
|
||||
new EnumPropertyDefinition<>(PropertyKey.zeroDateTimeBehavior, ZeroDatetimeBehavior.EXCEPTION, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.zeroDateTimeBehavior",
|
||||
new Object[] { ZeroDatetimeBehavior.EXCEPTION, ZeroDatetimeBehavior.ROUND, ZeroDatetimeBehavior.CONVERT_TO_NULL }),
|
||||
"3.1.4", CATEGORY_DATETIMES, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_HA
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.allowSourceDownConnections, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.allowSourceDownConnections"), "5.1.27", CATEGORY_HA, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.allowReplicaDownConnections, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.allowReplicaDownConnections"), "6.0.2", CATEGORY_HA, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.readFromSourceWhenNoReplicas, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.readFromSourceWhenNoReplicas"), "6.0.2", CATEGORY_HA, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.autoReconnect, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.autoReconnect"), "1.1", CATEGORY_HA, 0),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.autoReconnectForPools, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.autoReconnectForPools"), "3.1.3", CATEGORY_HA, 1),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.failOverReadOnly, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.failoverReadOnly"), "3.0.12", CATEGORY_HA, 2),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.initialTimeout, 2, RUNTIME_NOT_MODIFIABLE, Messages.getString("ConnectionProperties.initialTimeout"),
|
||||
"1.1", CATEGORY_HA, 5, 1, Integer.MAX_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.ha_loadBalanceStrategy, "random", RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalanceStrategy"), "5.0.6", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.loadBalanceBlocklistTimeout, 0, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalanceBlocklistTimeout"), "5.1.0", CATEGORY_HA, Integer.MIN_VALUE, 0, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.loadBalancePingTimeout, 0, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalancePingTimeout"), "5.1.13", CATEGORY_HA, Integer.MIN_VALUE, 0, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.loadBalanceValidateConnectionOnSwapServer, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalanceValidateConnectionOnSwapServer"), "5.1.13", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.loadBalanceConnectionGroup, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalanceConnectionGroup"), "5.1.13", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.loadBalanceExceptionChecker, "com.mysql.cj.jdbc.ha.StandardLoadBalanceExceptionChecker",
|
||||
RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.loadBalanceExceptionChecker"), "5.1.13", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.loadBalanceSQLStateFailover, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalanceSQLStateFailover"), "5.1.13", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.loadBalanceSQLExceptionSubclassFailover, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalanceSQLExceptionSubclassFailover"), "5.1.13", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.loadBalanceAutoCommitStatementRegex, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalanceAutoCommitStatementRegex"), "5.1.15", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.loadBalanceAutoCommitStatementThreshold, 0, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalanceAutoCommitStatementThreshold"), "5.1.15", CATEGORY_HA, Integer.MIN_VALUE, 0,
|
||||
Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.maxReconnects, 3, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.maxReconnects"), "1.1",
|
||||
CATEGORY_HA, 4, 1, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.retriesAllDown, 120, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.retriesAllDown"),
|
||||
"5.1.6", CATEGORY_HA, 4, 0, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.pinGlobalTxToPhysicalConnection, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.pinGlobalTxToPhysicalConnection"), "5.0.1", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.queriesBeforeRetrySource, 50, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.queriesBeforeRetrySource"), "3.0.2", CATEGORY_HA, 7, 0, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.reconnectAtTxEnd, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.reconnectAtTxEnd"), "3.0.10", CATEGORY_HA, 4),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.replicationConnectionGroup, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.replicationConnectionGroup"), "8.0.7", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.resourceId, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.resourceId"), "5.0.1", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.secondsBeforeRetrySource, 30, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.secondsBeforeRetrySource"), "3.0.2", CATEGORY_HA, 8, 0, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.selfDestructOnPingSecondsLifetime, 0, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.selfDestructOnPingSecondsLifetime"), "5.1.6", CATEGORY_HA, Integer.MAX_VALUE, 0,
|
||||
Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.selfDestructOnPingMaxOperations, 0, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.selfDestructOnPingMaxOperations"), "5.1.6", CATEGORY_HA, Integer.MAX_VALUE, 0,
|
||||
Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.ha_enableJMX, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.ha.enableJMX"), "5.1.27", CATEGORY_HA, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.loadBalanceHostRemovalGracePeriod, 15000, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.loadBalanceHostRemovalGracePeriod"), "6.0.3", CATEGORY_HA, Integer.MAX_VALUE, 0,
|
||||
Integer.MAX_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.serverAffinityOrder, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.serverAffinityOrder"), "8.0.8", CATEGORY_HA, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_PERFORMANCE
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.alwaysSendSetIsolation, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.alwaysSendSetIsolation"), "3.1.7", CATEGORY_PERFORMANCE, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.cacheCallableStmts, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.cacheCallableStatements"), "3.1.2", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.cachePrepStmts, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.cachePrepStmts"), "3.0.10", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.cacheResultSetMetadata, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.cacheRSMetadata"), "3.1.1", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.serverConfigCacheFactory, PerVmServerConfigCacheFactory.class.getName(), RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.serverConfigCacheFactory"), "5.1.1", CATEGORY_PERFORMANCE, 12),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.cacheServerConfiguration, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.cacheServerConfiguration"), "3.1.5", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.callableStmtCacheSize, 100, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.callableStmtCacheSize"), "3.1.2", CATEGORY_PERFORMANCE, 5, 0, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.defaultFetchSize, 0, RUNTIME_MODIFIABLE, Messages.getString("ConnectionProperties.defaultFetchSize"),
|
||||
"3.1.9", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.elideSetAutoCommits, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.eliseSetAutoCommit"), "3.1.3", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.enableQueryTimeouts, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.enableQueryTimeouts"), "5.0.6", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new MemorySizePropertyDefinition(PropertyKey.largeRowSizeThreshold, 2048, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.largeRowSizeThreshold"), "5.1.1", CATEGORY_PERFORMANCE, Integer.MIN_VALUE, 0,
|
||||
Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.maintainTimeStats, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.maintainTimeStats"), "3.1.9", CATEGORY_PERFORMANCE, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.metadataCacheSize, 50, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.metadataCacheSize"), "3.1.1", CATEGORY_PERFORMANCE, 5, 1, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.prepStmtCacheSize, 25, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.prepStmtCacheSize"), "3.0.10", CATEGORY_PERFORMANCE, 10, 0, Integer.MAX_VALUE),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.prepStmtCacheSqlLimit, 256, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.prepStmtCacheSqlLimit"), "3.0.10", CATEGORY_PERFORMANCE, 11, 1, Integer.MAX_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.parseInfoCacheFactory, PerConnectionLRUFactory.class.getName(), RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.parseInfoCacheFactory"), "5.1.1", CATEGORY_PERFORMANCE, 12),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.rewriteBatchedStatements, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.rewriteBatchedStatements"), "3.1.13", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useCursorFetch, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useCursorFetch"), "5.0.0", CATEGORY_PERFORMANCE, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useLocalSessionState, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useLocalSessionState"), "3.1.7", CATEGORY_PERFORMANCE, 5),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useLocalTransactionState, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useLocalTransactionState"), "5.1.7", CATEGORY_PERFORMANCE, 6),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useReadAheadInput, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useReadAheadInput"), "3.1.5", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.dontCheckOnDuplicateKeyUpdateInSQL, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.dontCheckOnDuplicateKeyUpdateInSQL"), "5.1.32", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.readOnlyPropagatesToServer, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.readOnlyPropagatesToServer"), "5.1.35", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.enableEscapeProcessing, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.enableEscapeProcessing"), "6.0.1", CATEGORY_PERFORMANCE, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_DEBUGING_PROFILING
|
||||
//
|
||||
new StringPropertyDefinition(PropertyKey.logger, STANDARD_LOGGER_NAME, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.logger", new Object[] { Log.class.getName(), STANDARD_LOGGER_NAME }), "3.1.1",
|
||||
CATEGORY_DEBUGING_PROFILING, 0),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.profilerEventHandler, "com.mysql.cj.log.LoggingProfilerEventHandler", RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.profilerEventHandler"), "5.1.6", CATEGORY_DEBUGING_PROFILING, 1),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useNanosForElapsedTime, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useNanosForElapsedTime"), "5.0.7", CATEGORY_DEBUGING_PROFILING, 2),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.maxQuerySizeToLog, 2048, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.maxQuerySizeToLog"), "3.1.3", CATEGORY_DEBUGING_PROFILING, 3, 0, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.profileSQL, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.profileSQL"), "3.1.0", CATEGORY_DEBUGING_PROFILING, 4),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.logSlowQueries, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.logSlowQueries"), "3.1.2", CATEGORY_DEBUGING_PROFILING, 5),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.slowQueryThresholdMillis, 2000, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.slowQueryThresholdMillis"), "3.1.2", CATEGORY_DEBUGING_PROFILING, 6, 0, Integer.MAX_VALUE),
|
||||
|
||||
new LongPropertyDefinition(PropertyKey.slowQueryThresholdNanos, 0, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.slowQueryThresholdNanos"), "5.0.7", CATEGORY_DEBUGING_PROFILING, 7),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.autoSlowLog, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.autoSlowLog"), "5.1.4", CATEGORY_DEBUGING_PROFILING, 8),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.explainSlowQueries, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.explainSlowQueries"), "3.1.2", CATEGORY_DEBUGING_PROFILING, 9),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.gatherPerfMetrics, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.gatherPerfMetrics"), "3.1.2", CATEGORY_DEBUGING_PROFILING, 10),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.reportMetricsIntervalMillis, 30000, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.reportMetricsIntervalMillis"), "3.1.2", CATEGORY_DEBUGING_PROFILING, 11, 0, Integer.MAX_VALUE), // TODO currently is not used !!!
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.logXaCommands, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.logXaCommands"), "5.0.5", CATEGORY_DEBUGING_PROFILING, 12),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.traceProtocol, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.traceProtocol"), "3.1.2", CATEGORY_DEBUGING_PROFILING, 13),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.enablePacketDebug, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.enablePacketDebug"), "3.1.3", CATEGORY_DEBUGING_PROFILING, 14),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.packetDebugBufferSize, 20, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.packetDebugBufferSize"), "3.1.3", CATEGORY_DEBUGING_PROFILING, 15, 1, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useUsageAdvisor, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useUsageAdvisor"), "3.1.1", CATEGORY_DEBUGING_PROFILING, 16),
|
||||
|
||||
new IntegerPropertyDefinition(PropertyKey.resultSetSizeThreshold, 100, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.resultSetSizeThreshold"), "5.0.5", CATEGORY_DEBUGING_PROFILING, 17),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.autoGenerateTestcaseScript, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.autoGenerateTestcaseScript"), "3.1.9", CATEGORY_DEBUGING_PROFILING, 18),
|
||||
|
||||
//
|
||||
// CATEGORY_EXCEPTIONS
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.dumpQueriesOnException, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.dumpQueriesOnException"), "3.1.3", CATEGORY_EXCEPTIONS, Integer.MIN_VALUE),
|
||||
|
||||
new StringPropertyDefinition(PropertyKey.exceptionInterceptors, DEFAULT_VALUE_NULL_STRING, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.exceptionInterceptors"), "5.1.8", CATEGORY_EXCEPTIONS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.includeInnodbStatusInDeadlockExceptions, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.includeInnodbStatusInDeadlockExceptions"), "5.0.7", CATEGORY_EXCEPTIONS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.includeThreadDumpInDeadlockExceptions, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.includeThreadDumpInDeadlockExceptions"), "5.1.15", CATEGORY_EXCEPTIONS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.includeThreadNamesAsStatementComment, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.includeThreadNamesAsStatementComment"), "5.1.15", CATEGORY_EXCEPTIONS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.ignoreNonTxTables, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.ignoreNonTxTables"), "3.0.9", CATEGORY_EXCEPTIONS, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useOnlyServerErrorMessages, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useOnlyServerErrorMessages"), "3.0.15", CATEGORY_EXCEPTIONS, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_INTEGRATION
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.overrideSupportsIntegrityEnhancementFacility, false, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.overrideSupportsIEF"), "3.1.12", CATEGORY_INTEGRATION, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.ultraDevHack, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.ultraDevHack"), "2.0.3", CATEGORY_INTEGRATION, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_JDBC
|
||||
//
|
||||
new BooleanPropertyDefinition(PropertyKey.pedantic, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.pedantic"), "3.0.0", CATEGORY_JDBC, Integer.MIN_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useColumnNamesInFindColumn, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useColumnNamesInFindColumn"), "5.1.7", CATEGORY_JDBC, Integer.MAX_VALUE),
|
||||
|
||||
new BooleanPropertyDefinition(PropertyKey.useOldAliasMetadataBehavior, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.useOldAliasMetadataBehavior"), "5.0.4", CATEGORY_JDBC, Integer.MIN_VALUE),
|
||||
|
||||
//
|
||||
// CATEGORY_XDEVAPI
|
||||
//
|
||||
new EnumPropertyDefinition<>(PropertyKey.xdevapiSslMode, XdevapiSslMode.REQUIRED, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiSslMode"), "8.0.7", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiTlsCiphersuites, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiTlsCiphersuites"), "8.0.19", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiTlsVersions, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiTlsVersions"), "8.0.19", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiSslKeyStoreUrl, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiSslKeyStoreUrl"), "8.0.22", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiSslKeyStorePassword, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiSslKeyStorePassword"), "8.0.22", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiSslKeyStoreType, "JKS", RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiSslKeyStoreType"), "8.0.22", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new BooleanPropertyDefinition(PropertyKey.xdevapiFallbackToSystemKeyStore, DEFAULT_VALUE_TRUE, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiFallbackToSystemKeyStore"), "8.0.22", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiSslTrustStoreUrl, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiSslTrustStoreUrl"), "6.0.6", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiSslTrustStorePassword, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiSslTrustStorePassword"), "6.0.6", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiSslTrustStoreType, "JKS", RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiSslTrustStoreType"), "6.0.6", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new BooleanPropertyDefinition(PropertyKey.xdevapiFallbackToSystemTrustStore, DEFAULT_VALUE_TRUE, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiFallbackToSystemTrustStore"), "8.0.22", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new EnumPropertyDefinition<>(PropertyKey.xdevapiAuth, AuthMech.PLAIN, RUNTIME_NOT_MODIFIABLE, Messages.getString("ConnectionProperties.auth"),
|
||||
"8.0.8", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new IntegerPropertyDefinition(PropertyKey.xdevapiConnectTimeout, 10000, RUNTIME_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiConnectTimeout"), "8.0.13", CATEGORY_XDEVAPI, Integer.MIN_VALUE, 0, Integer.MAX_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiConnectionAttributes, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiConnectionAttributes"), "8.0.16", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new BooleanPropertyDefinition(PropertyKey.xdevapiDnsSrv, DEFAULT_VALUE_FALSE, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiDnsSrv"), "8.0.19", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new EnumPropertyDefinition<>(PropertyKey.xdevapiCompression, Compression.PREFERRED, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiCompression"), "8.0.20", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiCompressionAlgorithms, "zstd_stream,lz4_message,deflate_stream", RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiCompressionAlgorithms"), "8.0.22", CATEGORY_XDEVAPI, Integer.MIN_VALUE),
|
||||
new StringPropertyDefinition(PropertyKey.xdevapiCompressionExtensions, DEFAULT_VALUE_NULL_STRING, RUNTIME_NOT_MODIFIABLE,
|
||||
Messages.getString("ConnectionProperties.xdevapiCompressionExtensions"), "8.0.22", CATEGORY_XDEVAPI, Integer.MIN_VALUE)
|
||||
//
|
||||
};
|
||||
|
||||
HashMap<PropertyKey, PropertyDefinition<?>> propertyKeyToPropertyDefinitionMap = new HashMap<>();
|
||||
for (PropertyDefinition<?> pdef : pdefs) {
|
||||
propertyKeyToPropertyDefinitionMap.put(pdef.getPropertyKey(), pdef);
|
||||
}
|
||||
PROPERTY_KEY_TO_PROPERTY_DEFINITION = Collections.unmodifiableMap(propertyKeyToPropertyDefinitionMap);
|
||||
}
|
||||
|
||||
public static PropertyDefinition<?> getPropertyDefinition(PropertyKey propertyKey) {
|
||||
return PROPERTY_KEY_TO_PROPERTY_DEFINITION.get(propertyKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
* 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.cj.conf;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* PropertyKey handles connection property names, their camel-case aliases and case sensitivity.
|
||||
*/
|
||||
public enum PropertyKey {
|
||||
/*
|
||||
* Properties individually managed after parsing connection string. These property keys are case insensitive.
|
||||
*/
|
||||
/** The database user name. */
|
||||
USER("user", false),
|
||||
/** The database user password. */
|
||||
PASSWORD("password", false),
|
||||
/** The hostname value from the properties instance passed to the driver. */
|
||||
HOST("host", false),
|
||||
/** The port number value from the properties instance passed to the driver. */
|
||||
PORT("port", false),
|
||||
/** The communications protocol. Possible values: "tcp" and "pipe". */
|
||||
PROTOCOL("protocol", false),
|
||||
/** The name pipes path to use when "protocol=pipe'. */
|
||||
PATH("path", "namedPipePath", false),
|
||||
/** The server type in a replication setup. Possible values: "source" and "replica". */
|
||||
TYPE("type", false),
|
||||
/** The address value ("host:port") from the properties instance passed to the driver. */
|
||||
ADDRESS("address", false),
|
||||
/** The host priority in a list of hosts. */
|
||||
PRIORITY("priority", false),
|
||||
/** The database value from the properties instance passed to the driver. */
|
||||
DBNAME("dbname", false), //
|
||||
|
||||
allowLoadLocalInfile("allowLoadLocalInfile", true), //
|
||||
allowLoadLocalInfileInPath("allowLoadLocalInfileInPath", true), //
|
||||
allowSourceDownConnections("allowSourceDownConnections", "allowMasterDownConnections", true), //
|
||||
allowMultiQueries("allowMultiQueries", true), //
|
||||
allowNanAndInf("allowNanAndInf", true), //
|
||||
allowPublicKeyRetrieval("allowPublicKeyRetrieval", true), //
|
||||
allowReplicaDownConnections("allowReplicaDownConnections", "allowSlaveDownConnections", true), //
|
||||
allowUrlInLocalInfile("allowUrlInLocalInfile", true), //
|
||||
alwaysSendSetIsolation("alwaysSendSetIsolation", true), //
|
||||
authenticationPlugins("authenticationPlugins", true), //
|
||||
autoClosePStmtStreams("autoClosePStmtStreams", true), //
|
||||
autoDeserialize("autoDeserialize", true), //
|
||||
autoGenerateTestcaseScript("autoGenerateTestcaseScript", true), //
|
||||
autoReconnect("autoReconnect", true), //
|
||||
autoReconnectForPools("autoReconnectForPools", true), //
|
||||
autoSlowLog("autoSlowLog", true), //
|
||||
blobsAreStrings("blobsAreStrings", true), //
|
||||
blobSendChunkSize("blobSendChunkSize", true), //
|
||||
cacheCallableStmts("cacheCallableStmts", true), //
|
||||
cacheDefaultTimeZone("cacheDefaultTimeZone", "cacheDefaultTimezone", true), //
|
||||
cachePrepStmts("cachePrepStmts", true), //
|
||||
cacheResultSetMetadata("cacheResultSetMetadata", true), //
|
||||
cacheServerConfiguration("cacheServerConfiguration", true), //
|
||||
callableStmtCacheSize("callableStmtCacheSize", true), //
|
||||
characterEncoding("characterEncoding", true), //
|
||||
characterSetResults("characterSetResults", true), //
|
||||
clientCertificateKeyStorePassword("clientCertificateKeyStorePassword", true), //
|
||||
clientCertificateKeyStoreType("clientCertificateKeyStoreType", true), //
|
||||
clientCertificateKeyStoreUrl("clientCertificateKeyStoreUrl", true), //
|
||||
clientInfoProvider("clientInfoProvider", true), //
|
||||
clobberStreamingResults("clobberStreamingResults", true), //
|
||||
clobCharacterEncoding("clobCharacterEncoding", true), //
|
||||
compensateOnDuplicateKeyUpdateCounts("compensateOnDuplicateKeyUpdateCounts", true), //
|
||||
connectionAttributes("connectionAttributes", true), //
|
||||
connectionCollation("connectionCollation", true), //
|
||||
connectionLifecycleInterceptors("connectionLifecycleInterceptors", true), //
|
||||
connectionTimeZone("connectionTimeZone", "serverTimezone", true), //
|
||||
connectTimeout("connectTimeout", true), //
|
||||
continueBatchOnError("continueBatchOnError", true), //
|
||||
createDatabaseIfNotExist("createDatabaseIfNotExist", true), //
|
||||
customCharsetMapping("customCharsetMapping", true), //
|
||||
databaseTerm("databaseTerm", true), //
|
||||
defaultAuthenticationPlugin("defaultAuthenticationPlugin", true), //
|
||||
defaultFetchSize("defaultFetchSize", true), //
|
||||
detectCustomCollations("detectCustomCollations", true), //
|
||||
disabledAuthenticationPlugins("disabledAuthenticationPlugins", true), //
|
||||
disconnectOnExpiredPasswords("disconnectOnExpiredPasswords", true), //
|
||||
dnsSrv("dnsSrv", true), //
|
||||
dontCheckOnDuplicateKeyUpdateInSQL("dontCheckOnDuplicateKeyUpdateInSQL", true), //
|
||||
dontTrackOpenResources("dontTrackOpenResources", true), //
|
||||
dumpQueriesOnException("dumpQueriesOnException", true), //
|
||||
elideSetAutoCommits("elideSetAutoCommits", true), //
|
||||
emptyStringsConvertToZero("emptyStringsConvertToZero", true), //
|
||||
emulateLocators("emulateLocators", true), //
|
||||
emulateUnsupportedPstmts("emulateUnsupportedPstmts", true), //
|
||||
enabledSSLCipherSuites("enabledSSLCipherSuites", true), //
|
||||
enabledTLSProtocols("enabledTLSProtocols", true), //
|
||||
enableEscapeProcessing("enableEscapeProcessing", true), //
|
||||
enablePacketDebug("enablePacketDebug", true), //
|
||||
enableQueryTimeouts("enableQueryTimeouts", true), //
|
||||
exceptionInterceptors("exceptionInterceptors", true), //
|
||||
explainSlowQueries("explainSlowQueries", true), //
|
||||
failOverReadOnly("failOverReadOnly", true), //
|
||||
fallbackToSystemKeyStore("fallbackToSystemKeyStore", true), //
|
||||
fallbackToSystemTrustStore("fallbackToSystemTrustStore", true), //
|
||||
functionsNeverReturnBlobs("functionsNeverReturnBlobs", true), //
|
||||
gatherPerfMetrics("gatherPerfMetrics", true), //
|
||||
generateSimpleParameterMetadata("generateSimpleParameterMetadata", true), //
|
||||
getProceduresReturnsFunctions("getProceduresReturnsFunctions", true), //
|
||||
holdResultsOpenOverStatementClose("holdResultsOpenOverStatementClose", true), //
|
||||
ha_enableJMX("ha.enableJMX", "haEnableJMX", true), //
|
||||
ha_loadBalanceStrategy("ha.loadBalanceStrategy", "haLoadBalanceStrategy", true), //
|
||||
ignoreNonTxTables("ignoreNonTxTables", true), //
|
||||
includeInnodbStatusInDeadlockExceptions("includeInnodbStatusInDeadlockExceptions", true), //
|
||||
includeThreadDumpInDeadlockExceptions("includeThreadDumpInDeadlockExceptions", true), //
|
||||
includeThreadNamesAsStatementComment("includeThreadNamesAsStatementComment", true), //
|
||||
initialTimeout("initialTimeout", true), //
|
||||
interactiveClient("interactiveClient", true), //
|
||||
jdbcCompliantTruncation("jdbcCompliantTruncation", true), //
|
||||
largeRowSizeThreshold("largeRowSizeThreshold", true), //
|
||||
ldapServerHostname("ldapServerHostname", true), //
|
||||
loadBalanceAutoCommitStatementRegex("loadBalanceAutoCommitStatementRegex", true), //
|
||||
loadBalanceAutoCommitStatementThreshold("loadBalanceAutoCommitStatementThreshold", true), //
|
||||
loadBalanceBlocklistTimeout("loadBalanceBlocklistTimeout", "loadBalanceBlacklistTimeout", true), //
|
||||
loadBalanceConnectionGroup("loadBalanceConnectionGroup", true), //
|
||||
loadBalanceExceptionChecker("loadBalanceExceptionChecker", true), //
|
||||
loadBalanceHostRemovalGracePeriod("loadBalanceHostRemovalGracePeriod", true), //
|
||||
loadBalancePingTimeout("loadBalancePingTimeout", true), //
|
||||
loadBalanceSQLStateFailover("loadBalanceSQLStateFailover", true), //
|
||||
loadBalanceSQLExceptionSubclassFailover("loadBalanceSQLExceptionSubclassFailover", true), //
|
||||
loadBalanceValidateConnectionOnSwapServer("loadBalanceValidateConnectionOnSwapServer", true), //
|
||||
localSocketAddress("localSocketAddress", true), //
|
||||
locatorFetchBufferSize("locatorFetchBufferSize", true), //
|
||||
logger("logger", true), //
|
||||
logSlowQueries("logSlowQueries", true), //
|
||||
logXaCommands("logXaCommands", true), //
|
||||
maintainTimeStats("maintainTimeStats", true), //
|
||||
maxAllowedPacket("maxAllowedPacket", true), //
|
||||
maxQuerySizeToLog("maxQuerySizeToLog", true), //
|
||||
maxReconnects("maxReconnects", true), //
|
||||
maxRows("maxRows", true), //
|
||||
metadataCacheSize("metadataCacheSize", true), //
|
||||
netTimeoutForStreamingResults("netTimeoutForStreamingResults", true), //
|
||||
noAccessToProcedureBodies("noAccessToProcedureBodies", true), //
|
||||
noDatetimeStringSync("noDatetimeStringSync", true), //
|
||||
nullDatabaseMeansCurrent("nullDatabaseMeansCurrent", "nullCatalogMeansCurrent", true), //
|
||||
overrideSupportsIntegrityEnhancementFacility("overrideSupportsIntegrityEnhancementFacility", true), //
|
||||
packetDebugBufferSize("packetDebugBufferSize", true), //
|
||||
padCharsWithSpace("padCharsWithSpace", true), //
|
||||
paranoid("paranoid", false), //
|
||||
parseInfoCacheFactory("parseInfoCacheFactory", true), //
|
||||
passwordCharacterEncoding("passwordCharacterEncoding", true), //
|
||||
pedantic("pedantic", true), //
|
||||
pinGlobalTxToPhysicalConnection("pinGlobalTxToPhysicalConnection", true), //
|
||||
populateInsertRowWithDefaultValues("populateInsertRowWithDefaultValues", true), //
|
||||
prepStmtCacheSize("prepStmtCacheSize", true), //
|
||||
prepStmtCacheSqlLimit("prepStmtCacheSqlLimit", true), //
|
||||
preserveInstants("preserveInstants", true), //
|
||||
processEscapeCodesForPrepStmts("processEscapeCodesForPrepStmts", true), //
|
||||
profilerEventHandler("profilerEventHandler", true), //
|
||||
profileSQL("profileSQL", true), //
|
||||
forceConnectionTimeZoneToSession("forceConnectionTimeZoneToSession", true), //
|
||||
propertiesTransform("propertiesTransform", true), //
|
||||
queriesBeforeRetrySource("queriesBeforeRetrySource", "queriesBeforeRetryMaster", true), //
|
||||
queryInterceptors("queryInterceptors", true), //
|
||||
queryTimeoutKillsConnection("queryTimeoutKillsConnection", true), //
|
||||
readFromSourceWhenNoReplicas("readFromSourceWhenNoReplicas", "readFromMasterWhenNoSlaves", true), //
|
||||
readOnlyPropagatesToServer("readOnlyPropagatesToServer", true), //
|
||||
reconnectAtTxEnd("reconnectAtTxEnd", true), //
|
||||
replicationConnectionGroup("replicationConnectionGroup", true), //
|
||||
reportMetricsIntervalMillis("reportMetricsIntervalMillis", true), //
|
||||
requireSSL("requireSSL", true), //
|
||||
resourceId("resourceId", true), //
|
||||
resultSetSizeThreshold("resultSetSizeThreshold", true), //
|
||||
retriesAllDown("retriesAllDown", true), //
|
||||
rewriteBatchedStatements("rewriteBatchedStatements", true), //
|
||||
rollbackOnPooledClose("rollbackOnPooledClose", true), //
|
||||
scrollTolerantForwardOnly("scrollTolerantForwardOnly", true), //
|
||||
secondsBeforeRetrySource("secondsBeforeRetrySource", "secondsBeforeRetryMaster", true), //
|
||||
selfDestructOnPingMaxOperations("selfDestructOnPingMaxOperations", true), //
|
||||
selfDestructOnPingSecondsLifetime("selfDestructOnPingSecondsLifetime", true), //
|
||||
sendFractionalSeconds("sendFractionalSeconds", true), //
|
||||
sendFractionalSecondsForTime("sendFractionalSecondsForTime", true), //
|
||||
serverAffinityOrder("serverAffinityOrder", true), //
|
||||
serverConfigCacheFactory("serverConfigCacheFactory", true), //
|
||||
serverRSAPublicKeyFile("serverRSAPublicKeyFile", true), //
|
||||
sessionVariables("sessionVariables", true), //
|
||||
trackSessionState("trackSessionState", true), //
|
||||
slowQueryThresholdMillis("slowQueryThresholdMillis", true), //
|
||||
slowQueryThresholdNanos("slowQueryThresholdNanos", true), //
|
||||
socketFactory("socketFactory", true), //
|
||||
socketTimeout("socketTimeout", true), //
|
||||
socksProxyHost("socksProxyHost", true), //
|
||||
socksProxyPort("socksProxyPort", true), //
|
||||
sslMode("sslMode", true), //
|
||||
strictUpdates("strictUpdates", true), //
|
||||
tcpKeepAlive("tcpKeepAlive", true), //
|
||||
tcpNoDelay("tcpNoDelay", true), //
|
||||
tcpRcvBuf("tcpRcvBuf", true), //
|
||||
tcpSndBuf("tcpSndBuf", true), //
|
||||
tcpTrafficClass("tcpTrafficClass", true), //
|
||||
tinyInt1isBit("tinyInt1isBit", true), //
|
||||
traceProtocol("traceProtocol", true), //
|
||||
transformedBitIsBoolean("transformedBitIsBoolean", true), //
|
||||
treatUtilDateAsTimestamp("treatUtilDateAsTimestamp", true), //
|
||||
trustCertificateKeyStorePassword("trustCertificateKeyStorePassword", true), //
|
||||
trustCertificateKeyStoreType("trustCertificateKeyStoreType", true), //
|
||||
trustCertificateKeyStoreUrl("trustCertificateKeyStoreUrl", true), //
|
||||
ultraDevHack("ultraDevHack", true), //
|
||||
useAffectedRows("useAffectedRows", true), //
|
||||
useColumnNamesInFindColumn("useColumnNamesInFindColumn", true), //
|
||||
useCompression("useCompression", true), //
|
||||
useConfigs("useConfigs", true), //
|
||||
useCursorFetch("useCursorFetch", true), //
|
||||
useHostsInPrivileges("useHostsInPrivileges", true), //
|
||||
useInformationSchema("useInformationSchema", true), //
|
||||
useLocalSessionState("useLocalSessionState", true), //
|
||||
useLocalTransactionState("useLocalTransactionState", true), //
|
||||
useNanosForElapsedTime("useNanosForElapsedTime", true), //
|
||||
useOldAliasMetadataBehavior("useOldAliasMetadataBehavior", true), //
|
||||
useOnlyServerErrorMessages("useOnlyServerErrorMessages", true), //
|
||||
useReadAheadInput("useReadAheadInput", true), //
|
||||
useServerPrepStmts("useServerPrepStmts", true), //
|
||||
useSSL("useSSL", true), //
|
||||
useStreamLengthsInPrepStmts("useStreamLengthsInPrepStmts", true), //
|
||||
useUnbufferedInput("useUnbufferedInput", true), //
|
||||
useUsageAdvisor("useUsageAdvisor", true), //
|
||||
verifyServerCertificate("verifyServerCertificate", true), //
|
||||
|
||||
xdevapiAsyncResponseTimeout("xdevapi.asyncResponseTimeout", "xdevapiAsyncResponseTimeout", true), //
|
||||
xdevapiAuth("xdevapi.auth", "xdevapiAuth", true), //
|
||||
xdevapiConnectTimeout("xdevapi.connect-timeout", "xdevapiConnectTimeout", true), //
|
||||
xdevapiConnectionAttributes("xdevapi.connection-attributes", "xdevapiConnectionAttributes", true), //
|
||||
xdevapiCompression("xdevapi.compression", "xdevapiCompression", true), //
|
||||
xdevapiCompressionAlgorithms("xdevapi.compression-algorithms", "xdevapiCompressionAlgorithms", true), //
|
||||
xdevapiCompressionExtensions("xdevapi.compression-extensions", "xdevapiCompressionExtensions", true), //
|
||||
xdevapiDnsSrv("xdevapi.dns-srv", "xdevapiDnsSrv", true), //
|
||||
xdevapiFallbackToSystemKeyStore("xdevapi.fallback-to-system-keystore", "xdevapiFallbackToSystemKeyStore", true), //
|
||||
xdevapiFallbackToSystemTrustStore("xdevapi.fallback-to-system-truststore", "xdevapiFallbackToSystemTrustStore", true), //
|
||||
xdevapiSslKeyStorePassword("xdevapi.ssl-keystore-password", "xdevapiSslKeystorePassword", true), //
|
||||
xdevapiSslKeyStoreType("xdevapi.ssl-keystore-type", "xdevapiSslKeystoreType", true), //
|
||||
xdevapiSslKeyStoreUrl("xdevapi.ssl-keystore", "xdevapiSslKeystore", true), //
|
||||
xdevapiSslMode("xdevapi.ssl-mode", "xdevapiSslMode", true), //
|
||||
xdevapiSslTrustStorePassword("xdevapi.ssl-truststore-password", "xdevapiSslTruststorePassword", true), //
|
||||
xdevapiSslTrustStoreType("xdevapi.ssl-truststore-type", "xdevapiSslTruststoreType", true), //
|
||||
xdevapiSslTrustStoreUrl("xdevapi.ssl-truststore", "xdevapiSslTruststore", true), //
|
||||
xdevapiTlsCiphersuites("xdevapi.tls-ciphersuites", "xdevapiTlsCiphersuites", true), //
|
||||
xdevapiTlsVersions("xdevapi.tls-versions", "xdevapiTlsVersions", true), //
|
||||
xdevapiUseAsyncProtocol("xdevapi.useAsyncProtocol", "xdevapiUseAsyncProtocol", true), //
|
||||
|
||||
yearIsDateType("yearIsDateType", true), //
|
||||
zeroDateTimeBehavior("zeroDateTimeBehavior", true) //
|
||||
;
|
||||
|
||||
private String keyName;
|
||||
private String ccAlias = null;
|
||||
private boolean isCaseSensitive = false;
|
||||
|
||||
private static Map<String, PropertyKey> caseInsensitiveValues = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
static {
|
||||
for (PropertyKey pk : values()) {
|
||||
if (!pk.isCaseSensitive) {
|
||||
caseInsensitiveValues.put(pk.getKeyName(), pk);
|
||||
if (pk.getCcAlias() != null) {
|
||||
caseInsensitiveValues.put(pk.getCcAlias(), pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes each enum element with the proper key name to be used in the connection string or properties maps.
|
||||
*
|
||||
* @param keyName
|
||||
* the key name for the enum element.
|
||||
* @param isCaseSensitive
|
||||
* is this name case sensitive
|
||||
*/
|
||||
PropertyKey(String keyName, boolean isCaseSensitive) {
|
||||
this.keyName = keyName;
|
||||
this.isCaseSensitive = isCaseSensitive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes each enum element with the proper key name to be used in the connection string or properties maps.
|
||||
*
|
||||
* @param keyName
|
||||
* the key name for the enum element.
|
||||
* @param alias
|
||||
* camel-case alias key name
|
||||
* @param isCaseSensitive
|
||||
* is this name case sensitive
|
||||
*/
|
||||
PropertyKey(String keyName, String alias, boolean isCaseSensitive) {
|
||||
this(keyName, isCaseSensitive);
|
||||
this.ccAlias = alias;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.keyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key name of this enum element.
|
||||
*
|
||||
* @return
|
||||
* the key name associated with the enum element.
|
||||
*/
|
||||
public String getKeyName() {
|
||||
return this.keyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the camel-case alias key name of this enum element.
|
||||
*
|
||||
* @return
|
||||
* the camel-case alias key name associated with the enum element or null.
|
||||
*/
|
||||
public String getCcAlias() {
|
||||
return this.ccAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for a {@link PropertyKey} that matches the given value as key name.
|
||||
*
|
||||
* @param value
|
||||
* the key name to look for.
|
||||
* @return
|
||||
* the {@link PropertyKey} element that matches the given key name value or <code>null</code> if none is found.
|
||||
*/
|
||||
public static PropertyKey fromValue(String value) {
|
||||
for (PropertyKey k : values()) {
|
||||
if (k.isCaseSensitive) {
|
||||
if (k.getKeyName().equals(value) || (k.getCcAlias() != null && k.getCcAlias().equals(value))) {
|
||||
return k;
|
||||
}
|
||||
} else {
|
||||
if (k.getKeyName().equalsIgnoreCase(value) || (k.getCcAlias() != null && k.getCcAlias().equalsIgnoreCase(value))) {
|
||||
return k;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that normalizes the case of the given key, if it is one of {@link PropertyKey} elements.
|
||||
*
|
||||
* @param keyName
|
||||
* the key name to normalize.
|
||||
* @return
|
||||
* the normalized key name if it belongs to this enum, otherwise returns the input unchanged.
|
||||
*/
|
||||
public static String normalizeCase(String keyName) {
|
||||
PropertyKey pk = caseInsensitiveValues.get(keyName);
|
||||
return pk == null ? keyName : pk.getKeyName();
|
||||
//return keyName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.cj.conf;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public interface PropertySet {
|
||||
|
||||
void addProperty(RuntimeProperty<?> prop);
|
||||
|
||||
void removeProperty(String name);
|
||||
|
||||
void removeProperty(PropertyKey key);
|
||||
|
||||
<T> RuntimeProperty<T> getProperty(String name);
|
||||
|
||||
<T> RuntimeProperty<T> getProperty(PropertyKey key);
|
||||
|
||||
RuntimeProperty<Boolean> getBooleanProperty(String name);
|
||||
|
||||
RuntimeProperty<Boolean> getBooleanProperty(PropertyKey key);
|
||||
|
||||
RuntimeProperty<Integer> getIntegerProperty(String name);
|
||||
|
||||
RuntimeProperty<Integer> getIntegerProperty(PropertyKey key);
|
||||
|
||||
RuntimeProperty<Long> getLongProperty(String name);
|
||||
|
||||
RuntimeProperty<Long> getLongProperty(PropertyKey key);
|
||||
|
||||
RuntimeProperty<Integer> getMemorySizeProperty(String name);
|
||||
|
||||
RuntimeProperty<Integer> getMemorySizeProperty(PropertyKey key);
|
||||
|
||||
RuntimeProperty<String> getStringProperty(String name);
|
||||
|
||||
RuntimeProperty<String> getStringProperty(PropertyKey key);
|
||||
|
||||
<T extends Enum<T>> RuntimeProperty<T> getEnumProperty(String name);
|
||||
|
||||
<T extends Enum<T>> RuntimeProperty<T> getEnumProperty(PropertyKey key);
|
||||
|
||||
/**
|
||||
* Initializes the property set with driver properties that come from URL or passed to
|
||||
* the driver manager.
|
||||
*
|
||||
* @param props
|
||||
* properties
|
||||
*/
|
||||
void initializeProperties(Properties props);
|
||||
|
||||
void postInitialization();
|
||||
|
||||
Properties exposeAsProperties();
|
||||
|
||||
/**
|
||||
* Reset all properties to their initial values.
|
||||
*/
|
||||
void reset();
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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.cj.conf;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.Reference;
|
||||
|
||||
import com.mysql.cj.exceptions.ExceptionInterceptor;
|
||||
|
||||
public interface RuntimeProperty<T> {
|
||||
|
||||
PropertyDefinition<T> getPropertyDefinition();
|
||||
|
||||
/**
|
||||
* Explicitly set value of this RuntimeProperty according to the self-titled property value contained in extractFrom.
|
||||
* This method is called during PropertySet initialization thus ignores the RUNTIME_NOT_MODIFIABLE flag.
|
||||
* <p>
|
||||
* This value will also be the initial one, i.e. {@link #resetValue()} will reset to this value, not the default one.
|
||||
* <p>
|
||||
* If extractFrom does not contain such property then this RuntimeProperty remains unchanged.
|
||||
*
|
||||
* @param extractFrom
|
||||
* {@link Properties} object containing key-value pairs usually passed from connection string.
|
||||
* @param exceptionInterceptor
|
||||
* exceptionInterceptor
|
||||
*/
|
||||
void initializeFrom(Properties extractFrom, ExceptionInterceptor exceptionInterceptor);
|
||||
|
||||
void initializeFrom(Reference ref, ExceptionInterceptor exceptionInterceptor);
|
||||
|
||||
/**
|
||||
* Reset to initial value (default or defined in connection string/Properties)
|
||||
*/
|
||||
void resetValue();
|
||||
|
||||
boolean isExplicitlySet();
|
||||
|
||||
/**
|
||||
* Add listener for this property changes.
|
||||
*
|
||||
* @param l
|
||||
* {@link RuntimePropertyListener}
|
||||
*/
|
||||
void addListener(RuntimePropertyListener l);
|
||||
|
||||
void removeListener(RuntimePropertyListener l);
|
||||
|
||||
@FunctionalInterface
|
||||
public static interface RuntimePropertyListener {
|
||||
void handlePropertyChange(RuntimeProperty<?> prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get internal value representation as Object.
|
||||
*
|
||||
* @return value
|
||||
*/
|
||||
T getValue();
|
||||
|
||||
/**
|
||||
* Get initial value (default or defined in connection string/Properties)
|
||||
*
|
||||
* @return value
|
||||
*/
|
||||
T getInitialValue();
|
||||
|
||||
/**
|
||||
* Get internal value representation as String.
|
||||
*
|
||||
* @return value
|
||||
*/
|
||||
String getStringValue();
|
||||
|
||||
/**
|
||||
* Set the object value of a property directly. Validation against allowable values will be performed.
|
||||
*
|
||||
* @param value
|
||||
* value
|
||||
*/
|
||||
void setValue(T value);
|
||||
|
||||
/**
|
||||
* Set the object value of a property directly. Validation against allowable values will be performed.
|
||||
*
|
||||
* @param value
|
||||
* value
|
||||
* @param exceptionInterceptor
|
||||
* exception interceptor
|
||||
*/
|
||||
void setValue(T value, ExceptionInterceptor exceptionInterceptor);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.exceptions;
|
||||
|
||||
import com.mysql.cj.Messages;
|
||||
|
||||
/**
|
||||
* Assertions for empty code paths that should never be executed.
|
||||
*/
|
||||
public class AssertionFailedException extends CJException {
|
||||
|
||||
private static final long serialVersionUID = 5832552608575043403L;
|
||||
|
||||
/**
|
||||
* Convenience method.
|
||||
*
|
||||
* @param ex
|
||||
* the exception that should never have been thrown.
|
||||
* @return {@link AssertionFailedException}
|
||||
* @throws AssertionFailedException
|
||||
* for the exception ex.
|
||||
*/
|
||||
public static AssertionFailedException shouldNotHappen(Exception ex) throws AssertionFailedException {
|
||||
throw new AssertionFailedException(ex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create (and caller should subsequently throw) an <code>AssertionFailedException</code>.
|
||||
*
|
||||
* <P>
|
||||
* Typical use is as follows:
|
||||
*
|
||||
* <PRE>
|
||||
* if (something == null) {
|
||||
* throw AssertionFailedException.shouldNotHappen("Something cannot be null");
|
||||
* }
|
||||
* </PRE>
|
||||
*
|
||||
* @param assertion
|
||||
* message
|
||||
* @return the exception. exception should be thrown by the caller to satisfy compiler checks for data-flow, etc
|
||||
* @throws AssertionFailedException
|
||||
* if exception occurs
|
||||
*/
|
||||
public static AssertionFailedException shouldNotHappen(String assertion) throws AssertionFailedException {
|
||||
return new AssertionFailedException(assertion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AssertionFailedException for the given exception that should
|
||||
* never have been thrown.
|
||||
*
|
||||
* @param ex
|
||||
* the exception that should never have been thrown.
|
||||
*/
|
||||
public AssertionFailedException(Exception ex) {
|
||||
super(Messages.getString("AssertionFailedException.0") + ex.toString() + Messages.getString("AssertionFailedException.1"), ex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AssertionFailedException for the reason given.
|
||||
*
|
||||
* @param assertion
|
||||
* a description of the assertion that failed
|
||||
*/
|
||||
public AssertionFailedException(String assertion) {
|
||||
super(Messages.getString("AssertionFailedException.2", new Object[] { assertion }));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.cj.exceptions;
|
||||
|
||||
import com.mysql.cj.conf.PropertySet;
|
||||
import com.mysql.cj.protocol.PacketReceivedTimeHolder;
|
||||
import com.mysql.cj.protocol.PacketSentTimeHolder;
|
||||
import com.mysql.cj.protocol.ServerSession;
|
||||
|
||||
public class CJCommunicationsException extends CJException {
|
||||
|
||||
private static final long serialVersionUID = 344035358493554245L;
|
||||
|
||||
public CJCommunicationsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CJCommunicationsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CJCommunicationsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CJCommunicationsException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
protected CJCommunicationsException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public void init(PropertySet propertySet, ServerSession serverSession, PacketSentTimeHolder packetSentTimeHolder,
|
||||
PacketReceivedTimeHolder packetReceivedTimeHolder) {
|
||||
this.exceptionMessage = ExceptionFactory.createLinkFailureMessageBasedOnHeuristics(propertySet, serverSession, packetSentTimeHolder,
|
||||
packetReceivedTimeHolder, getCause());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.cj.exceptions;
|
||||
|
||||
import com.mysql.cj.Messages;
|
||||
import com.mysql.cj.conf.PropertySet;
|
||||
import com.mysql.cj.protocol.PacketSentTimeHolder;
|
||||
import com.mysql.cj.protocol.ServerSession;
|
||||
|
||||
public class CJConnectionFeatureNotAvailableException extends CJCommunicationsException {
|
||||
|
||||
private static final long serialVersionUID = -4129847384681995107L;
|
||||
|
||||
public CJConnectionFeatureNotAvailableException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CJConnectionFeatureNotAvailableException(PropertySet propertySet, ServerSession serverSession, PacketSentTimeHolder packetSentTimeHolder,
|
||||
Exception underlyingException) {
|
||||
super(underlyingException);
|
||||
init(propertySet, serverSession, packetSentTimeHolder, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return Messages.getString("ConnectionFeatureNotAvailableException.0");
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user