Skip to content
This repository was archived by the owner on Jul 4, 2024. It is now read-only.

Refacto/jakarta #1

Merged
merged 9 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions install-into-local-repo.bat
Original file line number Diff line number Diff line change
@@ -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"
79 changes: 51 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.smattme</groupId>
<groupId>fr.neolegal</groupId>
<artifactId>mysql-backup4j</artifactId>
<version>1.2.1</version>
<version>1.2.6</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
<description>
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,
</description>
<url>https://github.com/SeunMatt/mysql-backup4j</url>
<url>https://github.com/nicolasriousset/mysql-backup4j</url>

<licenses>
<license>
Expand All @@ -30,58 +29,82 @@
<organization>SmattMe</organization>
<organizationUrl>https://smattme.com</organizationUrl>
</developer>
<developer>
<name>Nicolas Riousset</name>
<email>nicolas@neolegal.fr</email>
<organization>NeoLegal</organization>
<organizationUrl>https://neolegal.fr</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/SeunMatt/mysql-backup4j.git</connection>
<developerConnection>scm:git:ssh://github.com:SeunMatt/mysql-backup4j.git</developerConnection>
<url>https://github.com/SeunMatt/mysql-backup4j/tree/master</url>
<connection>scm:git:git://github.com/nicolasriousset/mysql-backup4j.git</connection>
<developerConnection>scm:git:ssh://github.com:nicolasriousset/mysql-backup4j.git</developerConnection>
<url>https://github.com/nicolasriousset/mysql-backup4j/tree/master</url>
</scm>

<properties>

<maven.version>3.11.0</maven.version>
<java.version>17</java.version>
</properties>

<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-zip</artifactId>
<version>1.12</version>
<version>1.16</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.5.0-b01</version>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.17.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>1.17.6</version>
<scope>test</scope>
</dependency>
</dependencies>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<url>https://s01.oss.sonatype.org/content/repositories/releases/</url>
</repository>
</distributionManagement>

Expand All @@ -90,24 +113,24 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>${maven.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<version>3.1.2</version>
<configuration>
<excludedGroups>Integration</excludedGroups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<version>3.5.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -120,7 +143,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -133,7 +156,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<version>3.1.0</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -147,12 +170,12 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/smattme/EmailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/smattme/MysqlExportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 28 additions & 7 deletions src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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();

Expand All @@ -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)
Expand All @@ -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");
Expand Down Expand Up @@ -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)
Expand All @@ -135,12 +156,12 @@ 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();
resultSet.first();
assertTrue(resultSet.getLong("total") > 0);
}

}
}