From 2ce3fb0025316cf397e1f4f17d6db46d8be40eeb Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Thu, 22 Jun 2023 13:49:40 +0200 Subject: [PATCH 01/16] #30 added MAX_INSERT_SIZE property to split insert statements when they exceed a given size. Default value keeps the existing behaviour. --- .../java/com/smattme/MysqlExportService.java | 125 ++++++++++++------ 1 file changed, 82 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/smattme/MysqlExportService.java b/src/main/java/com/smattme/MysqlExportService.java index 005c46c..86d7201 100644 --- a/src/main/java/com/smattme/MysqlExportService.java +++ b/src/main/java/com/smattme/MysqlExportService.java @@ -68,6 +68,7 @@ public class MysqlExportService { public static final String JDBC_CONNECTION_STRING = "JDBC_CONNECTION_STRING"; public static final String JDBC_DRIVER_NAME = "JDBC_DRIVER_NAME"; public static final String SQL_FILE_NAME = "SQL_FILE_NAME"; + public static final String MAX_INSERT_SIZE = "MAX_INSERT_SIZE"; public MysqlExportService(Properties properties) { @@ -220,61 +221,33 @@ private String getDataInsertStatement(String table) throws SQLException { .append(MysqlBaseService.SQL_START_PATTERN).append(" table insert : ").append(table) .append("\n--\n"); - sql.append("INSERT INTO `").append(table).append("`("); - - ResultSetMetaData metaData = rs.getMetaData(); - int columnCount = metaData.getColumnCount(); - - //generate the column names that are present - //in the returned result set - //at this point the insert is INSERT INTO (`col1`, `col2`, ...) - for(int i = 0; i < columnCount; i++) { - sql.append("`") - .append(metaData.getColumnName( i + 1)) - .append("`, "); - } + final String queryStart = buildInsertQueryStart(table, rs); + Long maxInsertSize = getMaxInsertSize(); + int currentQueryStartPosition = sql.length(); - //remove the last whitespace and comma - sql.deleteCharAt(sql.length() - 1).deleteCharAt(sql.length() - 1).append(") VALUES \n"); //now we're going to build the values for data insertion rs.beforeFirst(); while(rs.next()) { - sql.append("("); - for(int i = 0; i < columnCount; i++) { - - int columnType = metaData.getColumnType(i + 1); - int columnIndex = i + 1; + String insertQueryValues = buildInsertQueryValues(rs); - //this is the part where the values are processed based on their type - if(Objects.isNull(rs.getObject(columnIndex))) { - sql.append("").append(rs.getObject(columnIndex)).append(", "); - } - else if( columnType == Types.INTEGER || columnType == Types.TINYINT || columnType == Types.BIT) { - sql.append(rs.getInt(columnIndex)).append(", "); - } - else { - - String val = rs.getString(columnIndex); - //escape the single quotes that might be in the value - val = val.replace("'", "\\'"); - - sql.append("'").append(val).append("', "); + int currentInsertQueryLength = sql.length() - currentQueryStartPosition; + boolean newInsertQueryRequired = currentInsertQueryLength == 0 || (maxInsertSize > 0 && currentInsertQueryLength >= maxInsertSize); + if (newInsertQueryRequired) { + if (currentInsertQueryLength > 0) { + sql.append(";\n"); } + currentQueryStartPosition = sql.length(); + sql.append(queryStart); } - - //now that we're done with a row - //let's remove the last whitespace and comma - sql.deleteCharAt(sql.length() - 1).deleteCharAt(sql.length() - 1); + sql.append(insertQueryValues); //if this is the last row, just append a closing //parenthesis otherwise append a closing parenthesis and a comma //for the next set of values - if(rs.isLast()) { - sql.append(")"); - } else { - sql.append("),\n"); - } + if(!rs.isLast()) { + sql.append(",\n"); + } } //now that we are done processing the entire row @@ -291,6 +264,72 @@ else if( columnType == Types.INTEGER || columnType == Types.TINYINT || columnTyp return sql.toString(); } + private String buildInsertQueryValues(ResultSet rs) throws SQLException { + StringBuilder sql = new StringBuilder(); + ResultSetMetaData metaData = rs.getMetaData(); + int columnCount = metaData.getColumnCount(); + sql.append("("); + for(int i = 0; i < columnCount; i++) { + + int columnType = metaData.getColumnType(i + 1); + int columnIndex = i + 1; + + //this is the part where the values are processed based on their type + if(Objects.isNull(rs.getObject(columnIndex))) { + sql.append("").append(rs.getObject(columnIndex)).append(", "); + } + else if( columnType == Types.INTEGER || columnType == Types.TINYINT || columnType == Types.BIT) { + sql.append(rs.getInt(columnIndex)).append(", "); + } + else { + + String val = rs.getString(columnIndex); + //escape the single quotes that might be in the value + val = val.replace("'", "\\'"); + + sql.append("'").append(val).append("', "); + } + } + + //now that we're done with a row + //let's remove the last whitespace and comma + sql.deleteCharAt(sql.length() - 1).deleteCharAt(sql.length() - 1); + + sql.append(")"); + + return sql.toString(); + } + + + private Long getMaxInsertSize() { + try { + String prop = properties.getProperty(MAX_INSERT_SIZE); + return prop != null ? Long.parseLong(prop) : 0L; + } catch (Exception e) { + return 0L; + } + } + + private String buildInsertQueryStart(String table, ResultSet rs) throws SQLException { + StringBuilder sql = new StringBuilder(); + sql.append("INSERT INTO `").append(table).append("`("); + + ResultSetMetaData metaData = rs.getMetaData(); + int columnCount = metaData.getColumnCount(); + + //generate the column names that are present + //in the returned result set + //at this point the insert is INSERT INTO (`col1`, `col2`, ...) + for(int i = 0; i < columnCount; i++) { + sql.append("`") + .append(metaData.getColumnName( i + 1)) + .append("`, "); + } + + //remove the last whitespace and comma + sql.deleteCharAt(sql.length() - 1).deleteCharAt(sql.length() - 1).append(") VALUES \n"); + return sql.toString(); + } /** * This is the entry function that'll From 4994826eb1d74345662ed2773cb8317b4b2b9f5c Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Thu, 22 Jun 2023 14:18:11 +0200 Subject: [PATCH 02/16] Added start and end pattern arround each insert statement, to solve max packet size exceeded error when importing using the library. --- .../java/com/smattme/MysqlExportService.java | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/smattme/MysqlExportService.java b/src/main/java/com/smattme/MysqlExportService.java index 86d7201..6dbcb79 100644 --- a/src/main/java/com/smattme/MysqlExportService.java +++ b/src/main/java/com/smattme/MysqlExportService.java @@ -137,9 +137,7 @@ private String getTableInsertStatement(String table) throws SQLException { while ( rs.next() ) { String qtbl = rs.getString(1); String query = rs.getString(2); - sql.append("\n\n--"); - sql.append("\n").append(MysqlBaseService.SQL_START_PATTERN).append(" table dump : ").append(qtbl); - sql.append("\n--\n\n"); + sql.append(buildStartPattern(" table dump : " + qtbl)); if(addIfNotExists) { query = query.trim().replace("CREATE TABLE", "CREATE TABLE IF NOT EXISTS"); @@ -148,9 +146,7 @@ private String getTableInsertStatement(String table) throws SQLException { sql.append(query).append(";\n\n"); } - sql.append("\n\n--"); - sql.append("\n").append(MysqlBaseService.SQL_END_PATTERN).append(" table dump : ").append(table); - sql.append("\n--\n\n"); + sql.append(buildEndPattern(" table dump : " + table)); } return sql.toString(); @@ -172,18 +168,14 @@ private String getCreateViewStatement(String view) throws SQLException { rs = stmt.executeQuery("SHOW CREATE VIEW " + "`" + view + "`;"); while ( rs.next() ) { String viewName = rs.getString(1); - String viewQuery = rs.getString(2); - sql.append("\n\n--"); - sql.append("\n").append(MysqlBaseService.SQL_START_PATTERN).append(" view dump : ").append(view); - sql.append("\n--\n\n"); + String viewQuery = rs.getString(2); + sql.append(buildStartPattern(" view dump : " + view)); String finalQuery = "CREATE OR REPLACE VIEW `" + viewName + "` " + (viewQuery.substring(viewQuery.indexOf("AS")).trim()); sql.append(finalQuery).append(";\n\n"); } - sql.append("\n\n--"); - sql.append("\n").append(MysqlBaseService.SQL_END_PATTERN).append(" view dump : ").append(view); - sql.append("\n--\n\n"); + sql.append(buildEndPattern(" view dump : " + view)); } return sql.toString(); @@ -217,10 +209,6 @@ private String getDataInsertStatement(String table) throws SQLException { //temporarily disable foreign key constraint sql.append("\n/*!40000 ALTER TABLE `").append(table).append("` DISABLE KEYS */;\n"); - sql.append("\n--\n") - .append(MysqlBaseService.SQL_START_PATTERN).append(" table insert : ").append(table) - .append("\n--\n"); - final String queryStart = buildInsertQueryStart(table, rs); Long maxInsertSize = getMaxInsertSize(); int currentQueryStartPosition = sql.length(); @@ -236,27 +224,22 @@ private String getDataInsertStatement(String table) throws SQLException { if (newInsertQueryRequired) { if (currentInsertQueryLength > 0) { sql.append(";\n"); - } + sql.append(buildEndPattern(" table insert : " + table)); + } + sql.append(buildStartPattern(" table insert : " + table)); currentQueryStartPosition = sql.length(); sql.append(queryStart); + } else { + sql.append(",\n"); } sql.append(insertQueryValues); - - //if this is the last row, just append a closing - //parenthesis otherwise append a closing parenthesis and a comma - //for the next set of values - if(!rs.isLast()) { - sql.append(",\n"); - } } //now that we are done processing the entire row //let's add the terminator sql.append(";"); - sql.append("\n--\n") - .append(MysqlBaseService.SQL_END_PATTERN).append(" table insert : ").append(table) - .append("\n--\n"); + sql.append(buildEndPattern(" table insert : " + table)); //enable FK constraint sql.append("\n/*!40000 ALTER TABLE `").append(table).append("` ENABLE KEYS */;\n"); @@ -264,6 +247,14 @@ private String getDataInsertStatement(String table) throws SQLException { return sql.toString(); } + String buildStartPattern(String comment) { + return "\n--\n" + MysqlBaseService.SQL_START_PATTERN + comment + "\n--\n"; + } + + String buildEndPattern(String comment) { + return "\n--\n" + MysqlBaseService.SQL_END_PATTERN + comment + "\n--\n"; + } + private String buildInsertQueryValues(ResultSet rs) throws SQLException { StringBuilder sql = new StringBuilder(); ResultSetMetaData metaData = rs.getMetaData(); From 272c8b364afa4610ad4d064f0696169b4eb05800 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 22 Jun 2023 17:34:54 +0200 Subject: [PATCH 03/16] =?UTF-8?q?Cr=C3=A9ating=20GitHub=20CI=20Actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/maven.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..f7367e0 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From 0b8688e575a414f54c85ebe54eaea8790251f55a Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Thu, 22 Jun 2023 17:54:13 +0200 Subject: [PATCH 04/16] Disabling integration tests execution, which fail during GitHub CI build. --- pom.xml | 4 +--- src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index b098d14..fca52eb 100644 --- a/pom.xml +++ b/pom.xml @@ -101,9 +101,7 @@ maven-surefire-plugin 3.0.0-M5 - - com.smattme.MysqlBackup4JIntegrationTest - + Integration diff --git a/src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java b/src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java index 9e07454..fbe754d 100644 --- a/src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java +++ b/src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java @@ -2,7 +2,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,6 +21,7 @@ * Created by seun_ on 10-Oct-20. * */ +@Tag("Integration") class MysqlBackup4JIntegrationTest { private Logger logger = LoggerFactory.getLogger(getClass()); From a2eaee4647c12e7cec9b0a0dfd17b7fa7e941211 Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Thu, 22 Jun 2023 18:03:11 +0200 Subject: [PATCH 05/16] Correction erreur CI build --- .github/workflows/maven.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index f7367e0..d3b3fb0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,7 +29,3 @@ jobs: cache: maven - name: Build with Maven run: mvn -B package --file pom.xml - - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - - name: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From d603164e7974b98c90c29aa036c1b93ef805b226 Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Fri, 23 Jun 2023 11:29:18 +0200 Subject: [PATCH 06/16] =?UTF-8?q?Mise=20=C3=A0=20jour=20des=20d=C3=A9penda?= =?UTF-8?q?nces,=20et=20d=C3=A9ploiement=20sur=20MavenCentral=20via=20sona?= =?UTF-8?q?type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install-into-local-repo.bat | 3 +++ pom.xml | 37 +++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 install-into-local-repo.bat diff --git a/install-into-local-repo.bat b/install-into-local-repo.bat new file mode 100644 index 0000000..bfb7432 --- /dev/null +++ b/install-into-local-repo.bat @@ -0,0 +1,3 @@ +call mvn install:install-file -Dfile="target/mysql-backup4j-1.2.2.jar" -DgroupId="com.smattme" -DartifactId="mysql-backup4j" -Dversion="1.2.2" -Dpackaging=jar -DlocalRepositoryPath="../bartleby/.m2" +certutil -hashfile "../bartleby/.m2/com/smattme/mysql-backup4j/1.2.2/mysql-backup4j-1.2.2.jar" MD5 > "../bartleby/.m2/com/smattme/mysql-backup4j/1.2.2/mysql-backup4j-1.2.2.jar.MD5" +certutil -hashfile "../bartleby/.m2/com/smattme/mysql-backup4j/1.2.2/mysql-backup4j-1.2.2.pom" MD5 > "../bartleby/.m2/com/smattme/mysql-backup4j/1.2.2/mysql-backup4j-1.2.2.pom.MD5" \ No newline at end of file diff --git a/pom.xml b/pom.xml index fca52eb..984edc9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,11 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.smattme + fr.neolegal mysql-backup4j - 1.2.1 + 1.2.2 jar ${project.groupId}:${project.artifactId} @@ -14,7 +13,7 @@ This is a simple library for backing up mysql databases and sending to emails, cloud storage and so on. It also provide a method for programmatically, importing SQL queries generated during the export process, - https://github.com/SeunMatt/mysql-backup4j + https://github.com/nicolasriousset/mysql-backup4j @@ -30,24 +29,30 @@ SmattMe https://smattme.com + + Nicolas Riousset + nicolas@neolegal.fr + NeoLegal + https://neolegal.fr + - scm:git:git://github.com/SeunMatt/mysql-backup4j.git - scm:git:ssh://github.com:SeunMatt/mysql-backup4j.git - https://github.com/SeunMatt/mysql-backup4j/tree/master + scm:git:git://github.com/nicolasriousset/mysql-backup4j.git + scm:git:ssh://github.com:nicolasriousset/mysql-backup4j.git + https://github.com/nicolasriousset/mysql-backup4j/tree/master - mysql - mysql-connector-java - 8.0.21 + com.mysql + mysql-connector-j + 8.0.33 org.zeroturnaround zt-zip - 1.12 + 1.15 jar @@ -90,7 +95,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.8.1 1.8 1.8 @@ -147,12 +152,12 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.8 + 1.6.13 true ossrh - https://oss.sonatype.org/ - false + https://s01.oss.sonatype.org/ + true From 1a0558286e97cecff20fe4bacb0fcb57c28b15ff Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Fri, 23 Jun 2023 11:50:30 +0200 Subject: [PATCH 07/16] =?UTF-8?q?Mise=20=C3=A0=20jour=20des=20d=C3=A9penda?= =?UTF-8?q?nces,=20passage=20en=20JAVA=2017.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 984edc9..0fa0ca3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ fr.neolegal mysql-backup4j - 1.2.2 + 1.2.3 jar ${project.groupId}:${project.artifactId} @@ -43,6 +43,12 @@ https://github.com/nicolasriousset/mysql-backup4j/tree/master + + + 3.11.0 + 17 + + com.mysql @@ -56,25 +62,25 @@ jar - javax.mail - mail - 1.5.0-b01 + com.sun.mail + javax.mail + 1.6.2 org.slf4j slf4j-api - 1.7.25 + 2.0.7 org.slf4j slf4j-simple - 1.7.25 + 2.0.7 test org.junit.jupiter junit-jupiter-api - 5.7.0 + 5.9.3 test @@ -82,11 +88,11 @@ ossrh - https://oss.sonatype.org/content/repositories/snapshots + https://s01.sonatype.org/content/repositories/snapshots ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ + https://s01.sonatype.org/service/local/staging/deploy/maven2/ @@ -95,10 +101,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + ${maven.version} - 1.8 - 1.8 + ${java.version} + ${java.version} From 0b0dff103ced634f7fd47ff66683fb9b68fdb044 Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Mon, 26 Jun 2023 09:55:44 +0200 Subject: [PATCH 08/16] =?UTF-8?q?D=C3=A9sactivation=20release=20automatiqu?= =?UTF-8?q?e=20=C3=A0=20MavenCentral?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 0fa0ca3..53f7a5f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ fr.neolegal mysql-backup4j - 1.2.3 + 1.2.4 jar ${project.groupId}:${project.artifactId} @@ -88,11 +88,11 @@ ossrh - https://s01.sonatype.org/content/repositories/snapshots + https://oss.sonatype.org/content/repositories/snapshots ossrh - https://s01.sonatype.org/service/local/staging/deploy/maven2/ + https://oss.sonatype.org/service/local/staging/deploy/maven2/ @@ -163,7 +163,7 @@ ossrh https://s01.oss.sonatype.org/ - true + false From 4c9e1debf5acb09185d13d264c11032f27f3d7b1 Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Mon, 26 Jun 2023 10:43:19 +0200 Subject: [PATCH 09/16] =?UTF-8?q?Mise=20=C3=A0=20jour=20des=20d=C3=A9penda?= =?UTF-8?q?nces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 53f7a5f..36e23d8 100644 --- a/pom.xml +++ b/pom.xml @@ -88,11 +88,11 @@ ossrh - https://oss.sonatype.org/content/repositories/snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ + https://s01.oss.sonatype.org/content/repositories/releases/ @@ -110,7 +110,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M5 + 3.1.2 Integration @@ -118,7 +118,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + 3.5.0 attach-javadocs @@ -131,7 +131,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.1 + 3.3.0 attach-sources @@ -144,7 +144,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 + 3.1.0 sign-artifacts From eb0f262974d76d1b36d5e59f2345025cff19cb7e Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Mon, 20 Nov 2023 12:11:37 +0100 Subject: [PATCH 10/16] Handling of BIGINT, SMALLINT, FLOAT, REAL, DOUBLE, NUMERIC, DECIMAL --- README.md | 2 ++ src/main/java/com/smattme/MysqlExportService.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc56243..2376dbf 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,8 @@ Supplying `false` to these functions will disable their respective actions. CHANGELOG ========= +V 1.2.4 + - Handling of BIGINT, SMALLINT, FLOAT, REAL, DOUBLE, NUMERIC, DECIMAL V 1.2.1 - Raises a new runtime exception `MysqlBackup4JException` if the required properties are not configured diff --git a/src/main/java/com/smattme/MysqlExportService.java b/src/main/java/com/smattme/MysqlExportService.java index 6dbcb79..5fecd92 100644 --- a/src/main/java/com/smattme/MysqlExportService.java +++ b/src/main/java/com/smattme/MysqlExportService.java @@ -269,7 +269,7 @@ private String buildInsertQueryValues(ResultSet rs) throws SQLException { if(Objects.isNull(rs.getObject(columnIndex))) { sql.append("").append(rs.getObject(columnIndex)).append(", "); } - else if( columnType == Types.INTEGER || columnType == Types.TINYINT || columnType == Types.BIT) { + else if( columnType == Types.BIGINT || columnType == Types.INTEGER || columnType == Types.SMALLINT || columnType == Types.TINYINT || columnType == Types.BIT || columnType == Types.FLOAT || columnType == Types.REAL || columnType == Types.DOUBLE || columnType == Types.NUMERIC || columnType == Types.DECIMAL) { sql.append(rs.getInt(columnIndex)).append(", "); } else { From 7e971eac610b2c113d5a19acf62c55792c641bd0 Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Mon, 20 Nov 2023 13:14:55 +0100 Subject: [PATCH 11/16] Increasing pom version to 1.2.5 in preparation of the next release. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 36e23d8..0ac1d4e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ fr.neolegal mysql-backup4j - 1.2.4 + 1.2.5 jar ${project.groupId}:${project.artifactId} From 72fcd356c1bd9a462ebbc986b579e8aea2e2a95a Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Fri, 19 Jan 2024 20:24:35 +0100 Subject: [PATCH 12/16] handling of boolean SQL type --- README.md | 2 ++ src/main/java/com/smattme/MysqlExportService.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2376dbf..794a7fb 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,8 @@ Supplying `false` to these functions will disable their respective actions. CHANGELOG ========= +V 1.2.5 + - Handling of BOOLEAN V 1.2.4 - Handling of BIGINT, SMALLINT, FLOAT, REAL, DOUBLE, NUMERIC, DECIMAL V 1.2.1 diff --git a/src/main/java/com/smattme/MysqlExportService.java b/src/main/java/com/smattme/MysqlExportService.java index 5fecd92..23e4cb4 100644 --- a/src/main/java/com/smattme/MysqlExportService.java +++ b/src/main/java/com/smattme/MysqlExportService.java @@ -262,14 +262,14 @@ private String buildInsertQueryValues(ResultSet rs) throws SQLException { sql.append("("); for(int i = 0; i < columnCount; i++) { - int columnType = metaData.getColumnType(i + 1); int columnIndex = i + 1; + int columnType = metaData.getColumnType(columnIndex); //this is the part where the values are processed based on their type if(Objects.isNull(rs.getObject(columnIndex))) { sql.append("").append(rs.getObject(columnIndex)).append(", "); } - else if( columnType == Types.BIGINT || columnType == Types.INTEGER || columnType == Types.SMALLINT || columnType == Types.TINYINT || columnType == Types.BIT || columnType == Types.FLOAT || columnType == Types.REAL || columnType == Types.DOUBLE || columnType == Types.NUMERIC || columnType == Types.DECIMAL) { + else if( columnType == Types.BIGINT || columnType == Types.INTEGER || columnType == Types.SMALLINT || columnType == Types.TINYINT || columnType == Types.BIT || columnType == Types.FLOAT || columnType == Types.REAL || columnType == Types.DOUBLE || columnType == Types.NUMERIC || columnType == Types.DECIMAL || columnType == Types.BOOLEAN) { sql.append(rs.getInt(columnIndex)).append(", "); } else { From 84a8ebf95d6a1091e3cfe7bed523409f8cbe68c8 Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Fri, 19 Jan 2024 20:51:37 +0100 Subject: [PATCH 13/16] passage en 1.2.6 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0ac1d4e..2d72a1a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ fr.neolegal mysql-backup4j - 1.2.5 + 1.2.6 jar ${project.groupId}:${project.artifactId} @@ -163,7 +163,7 @@ ossrh https://s01.oss.sonatype.org/ - false + true From 3fcf72c429f4d371f1ed6729839d61c77e036fef Mon Sep 17 00:00:00 2001 From: spinget Date: Thu, 14 Sep 2023 09:18:40 +0200 Subject: [PATCH 14/16] update du POM + testcontainer pour les IT + jakarta.mail --- pom.xml | 28 ++++++++++----- src/main/java/com/smattme/EmailService.java | 10 +++--- .../smattme/MysqlBackup4JIntegrationTest.java | 35 +++++++++++++++---- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 2d72a1a..107a418 100644 --- a/pom.xml +++ b/pom.xml @@ -51,36 +51,48 @@ - com.mysql - mysql-connector-j + mysql + mysql-connector-java 8.0.33 org.zeroturnaround zt-zip - 1.15 + 1.16 jar com.sun.mail - javax.mail - 1.6.2 + jakarta.mail + 2.0.1 org.slf4j slf4j-api - 2.0.7 + 2.0.9 org.slf4j slf4j-simple - 2.0.7 + 2.0.9 test org.junit.jupiter junit-jupiter-api - 5.9.3 + 5.10.0 + test + + + org.testcontainers + junit-jupiter + 1.17.6 + test + + + org.testcontainers + mysql + 1.17.6 test diff --git a/src/main/java/com/smattme/EmailService.java b/src/main/java/com/smattme/EmailService.java index b256ded..ccbb30c 100644 --- a/src/main/java/com/smattme/EmailService.java +++ b/src/main/java/com/smattme/EmailService.java @@ -3,11 +3,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.mail.*; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; +import jakarta.mail.*; +import jakarta.mail.internet.InternetAddress; +import jakarta.mail.internet.MimeBodyPart; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; import java.io.File; import java.util.Properties; diff --git a/src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java b/src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java index fbe754d..ce0834e 100644 --- a/src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java +++ b/src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java @@ -6,6 +6,9 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.io.File; import java.nio.file.Files; @@ -22,15 +25,31 @@ * */ @Tag("Integration") +@Testcontainers class MysqlBackup4JIntegrationTest { private Logger logger = LoggerFactory.getLogger(getClass()); private static final String TEST_DB = "mysqlbackup4j_test"; private static final String RESTORED_DB = "mysqlbackup4j_restored"; private static final String DB_USERNAME = "travis"; - private static final String DB_PASSWORD = ""; + private static final String DB_PASSWORD = "test"; private static final String DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver"; + @Container + private static final MySQLContainer mySQLContainer = new MySQLContainer<>("mysql:8.0.30") + .withDatabaseName(TEST_DB) + .withUsername(DB_USERNAME) + .withPassword(DB_PASSWORD) + .withExposedPorts(3306) + .withInitScript("sample_database.sql"); + + @Container + private static final MySQLContainer mySQLRestoredContainer = new MySQLContainer<>("mysql:8.0.30") + .withDatabaseName(RESTORED_DB) + .withUsername(DB_USERNAME) + .withPassword(DB_PASSWORD) + .withExposedPorts(3306); + @BeforeAll static void setUp() { System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug"); @@ -50,10 +69,12 @@ void givenDBCredentials_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore properties.setProperty(MysqlExportService.JDBC_DRIVER_NAME, DRIVER_CLASS_NAME); properties.setProperty(MysqlExportService.ADD_IF_NOT_EXISTS, "true"); - properties.setProperty(MysqlExportService.TEMP_DIR, new File("external").getPath()); properties.setProperty(MysqlExportService.SQL_FILE_NAME, "test_output_file_name"); + properties.setProperty(MysqlExportService.JDBC_CONNECTION_STRING, mySQLContainer.getJdbcUrl() + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false"); + + MysqlExportService mysqlExportService = new MysqlExportService(properties); mysqlExportService.export(); @@ -71,7 +92,7 @@ void givenDBCredentials_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore String sql = new String(Files.readAllBytes(sqlFile.toPath())); MysqlImportService res = MysqlImportService.builder() .setJdbcDriver("com.mysql.cj.jdbc.Driver") - .setDatabase(RESTORED_DB) + .setJdbcConnString(mySQLRestoredContainer.getJdbcUrl()) .setSqlString(sql) .setUsername(DB_USERNAME) .setPassword(DB_PASSWORD) @@ -92,7 +113,7 @@ void givenJDBCConString_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore properties.setProperty(MysqlExportService.DB_USERNAME, DB_USERNAME); properties.setProperty(MysqlExportService.DB_PASSWORD, DB_PASSWORD); properties.setProperty(MysqlExportService.DB_NAME, TEST_DB); - properties.setProperty(MysqlExportService.JDBC_CONNECTION_STRING, "jdbc:mysql://localhost:3306/" + TEST_DB + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false"); + properties.setProperty(MysqlExportService.JDBC_CONNECTION_STRING, mySQLContainer.getJdbcUrl() + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false"); properties.setProperty(MysqlExportService.PRESERVE_GENERATED_ZIP, "true"); properties.setProperty(MysqlExportService.PRESERVE_GENERATED_SQL_FILE, "true"); @@ -120,7 +141,7 @@ void givenJDBCConString_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore String sql = new String(Files.readAllBytes(sqlFile.toPath())); boolean res = MysqlImportService.builder() .setSqlString(sql) - .setJdbcConnString("jdbc:mysql://localhost:3306/" + RESTORED_DB + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false") + .setJdbcConnString(mySQLRestoredContainer.getJdbcUrl() + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false") .setUsername(DB_USERNAME) .setPassword(DB_PASSWORD) .setDatabase(RESTORED_DB) @@ -135,7 +156,7 @@ void givenJDBCConString_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore private void assertDatabaseBackedUp() throws Exception { - Connection connection = MysqlBaseService.connect(DB_USERNAME, DB_PASSWORD, RESTORED_DB, DRIVER_CLASS_NAME); + Connection connection = MysqlBaseService.connectWithURL(DB_USERNAME, DB_PASSWORD, mySQLRestoredContainer.getJdbcUrl(), DRIVER_CLASS_NAME); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); statement.execute("SELECT COUNT(1) as total FROM users"); ResultSet resultSet = statement.getResultSet(); @@ -143,4 +164,4 @@ private void assertDatabaseBackedUp() throws Exception { assertTrue(resultSet.getLong("total") > 0); } -} \ No newline at end of file +} From e18f15f37ae6b618bf0bdacb424381cb5f062280 Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Wed, 3 Apr 2024 10:32:06 +0200 Subject: [PATCH 15/16] =?UTF-8?q?Passage=20en=201.2.7=20suite=20=C3=A0=20m?= =?UTF-8?q?ise=20=C3=A0=20jour=20vers=20jakarta.mail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 107a418..3dfcff0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ fr.neolegal mysql-backup4j - 1.2.6 + 1.2.7 jar ${project.groupId}:${project.artifactId} @@ -175,7 +175,7 @@ ossrh https://s01.oss.sonatype.org/ - true + false From 1c92c161b6b39e3f04e224d41610aab85f03d0d4 Mon Sep 17 00:00:00 2001 From: Nicolas Riousset Date: Wed, 3 Apr 2024 10:52:37 +0200 Subject: [PATCH 16/16] passage environnement compilation en JAVA 17 --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index d3b3fb0..9e5bf12 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,10 +21,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'temurin' cache: maven - name: Build with Maven