diff --git a/README.md b/README.md index fc56243..794a7fb 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,10 @@ 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 - Raises a new runtime exception `MysqlBackup4JException` if the required properties are not configured 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..107a418 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.6 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,46 +29,70 @@ 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 + + + 3.11.0 + 17 + + mysql mysql-connector-java - 8.0.21 + 8.0.33 org.zeroturnaround zt-zip - 1.12 + 1.16 jar - javax.mail - mail - 1.5.0-b01 + com.sun.mail + jakarta.mail + 2.0.1 org.slf4j slf4j-api - 1.7.25 + 2.0.9 org.slf4j slf4j-simple - 1.7.25 + 2.0.9 test org.junit.jupiter junit-jupiter-api - 5.7.0 + 5.10.0 + test + + + org.testcontainers + junit-jupiter + 1.17.6 + test + + + org.testcontainers + mysql + 1.17.6 test @@ -77,11 +100,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/ @@ -90,16 +113,16 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + ${maven.version} - 1.8 - 1.8 + ${java.version} + ${java.version} org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M5 + 3.1.2 Integration @@ -107,7 +130,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + 3.5.0 attach-javadocs @@ -120,7 +143,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.1 + 3.3.0 attach-sources @@ -133,7 +156,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 + 3.1.0 sign-artifacts @@ -147,12 +170,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 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/main/java/com/smattme/MysqlExportService.java b/src/main/java/com/smattme/MysqlExportService.java index 6dbcb79..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.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 || columnType == Types.BOOLEAN) { sql.append(rs.getInt(columnIndex)).append(", "); } else { 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 +}