Skip to content

Commit ae3afaa

Browse files
committed
Java 17 support.
1 parent a0561dd commit ae3afaa

File tree

7 files changed

+26
-23
lines changed

7 files changed

+26
-23
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
55
You may obtain a copy of the License at
66

7-
http://www.apache.org/licenses/LICENSE-2.0
7+
https://www.apache.org/licenses/LICENSE-2.0.txt
88

99
Unless required by applicable law or agreed to in writing, software
1010
distributed under the License is distributed on an "AS IS" BASIS,

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ please let me know.
1111
If you are completely lost or have no idea how to use this library (or both), feel free
1212
to [contact me](mailto:collinalpert@gmail.com). I would be happy to assist you with any problems you might have.
1313

14-
**Please note:** This is a Java 13 library. Make sure you have Java 13 installed when using this library. This library is not suitable for projects requiring complex SQL queries, although it does offer some advanced features.\
15-
It is meant for projects which want to interact with their database in a simple, but easy way, without bloating the source code with SQL queries.
14+
**Please note:** This is a Java 11 library. Make sure you have Java 13 installed when using this library. This library
15+
is not suitable for projects requiring complex SQL queries, although it does offer some advanced features.\
16+
It is meant for projects which want to interact with their database in a simple, but easy way, without bloating the
17+
source code with SQL queries.
1618

1719
## Introduction
1820
POJOs imitate tables on the database where every field in the POJO is equivalent to a table column. Every class has a corresponding service class, which acts as a data service and interacts with the database. It is possible to define custom methods in the respective service classes to retrieve specific data. The service classes will fill the POJO with values from the database using a default mapper. The mapping functionality is explained [further down](#custom-mapping).\

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.collinalpert</groupId>
88
<artifactId>java2db</artifactId>
9-
<version>6.0.1</version>
9+
<version>6.1.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Java2DB</name>
@@ -35,7 +35,7 @@
3535
<scm>
3636
<connection>scm:git:git://github.com/CollinAlpert/Java2DB.git</connection>
3737
<developerConnection>scm:git:ssh://github.com:CollinAlpert/Java2DB.git</developerConnection>
38-
<url>http://github.com/CollinAlpert/Java2DB/tree/master</url>
38+
<url>https://github.com/CollinAlpert/Java2DB/tree/master</url>
3939
</scm>
4040

4141
<distributionManagement>
@@ -50,7 +50,7 @@
5050
</distributionManagement>
5151

5252
<properties>
53-
<java-version>13</java-version>
53+
<java-version>11</java-version>
5454
<jdk.version>${java-version}</jdk.version>
5555
<maven.compiler.release>${java-version}</maven.compiler.release>
5656
<maven.compiler.source>${java-version}</maven.compiler.source>
@@ -62,19 +62,19 @@
6262
<dependency>
6363
<groupId>com.github.collinalpert</groupId>
6464
<artifactId>lambda2sql</artifactId>
65-
<version>2.4.0</version>
65+
<version>2.5.0</version>
6666
</dependency>
6767

6868
<dependency>
6969
<groupId>mysql</groupId>
7070
<artifactId>mysql-connector-java</artifactId>
71-
<version>8.0.22</version>
71+
<version>8.0.26</version>
7272
</dependency>
7373

7474
<dependency>
7575
<groupId>org.junit.jupiter</groupId>
7676
<artifactId>junit-jupiter-api</artifactId>
77-
<version>5.7.0</version>
77+
<version>5.7.2</version>
7878
<scope>test</scope>
7979
</dependency>
8080
</dependencies>

src/main/java/com/github/collinalpert/java2db/database/ConnectionConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,4 @@ public int getTimeout() {
7575
return timeout;
7676
}
7777

78-
79-
}
78+
}

src/main/java/com/github/collinalpert/java2db/database/DBConnection.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.github.collinalpert.java2db.queries.*;
66
import com.github.collinalpert.java2db.queries.async.*;
77
import com.mysql.cj.exceptions.CJCommunicationsException;
8-
import com.mysql.cj.jdbc.exceptions.CommunicationsException;
98

109
import java.io.Closeable;
1110
import java.sql.*;
@@ -28,24 +27,28 @@ public class DBConnection implements Closeable {
2827
*/
2928
public static boolean LOG_QUERIES = true;
3029

31-
private Connection underlyingConnection;
30+
static {
31+
try {
32+
Class.forName("com.mysql.cj.jdbc.Driver");
33+
} catch (ClassNotFoundException e) {
34+
e.printStackTrace();
35+
}
36+
}
37+
38+
private final Connection underlyingConnection;
3239
private boolean isConnectionValid;
3340

3441
public DBConnection(ConnectionConfiguration configuration) {
3542
try {
3643
var connectionString = String.format("jdbc:mysql://%s:%d/%s?rewriteBatchedStatements=true", configuration.getHost(), configuration.getPort(), configuration.getDatabase());
37-
Class.forName("com.mysql.cj.jdbc.Driver");
3844
System.setProperty("user", configuration.getUsername());
3945
System.setProperty("password", configuration.getPassword());
4046
DriverManager.setLoginTimeout(configuration.getTimeout());
4147
underlyingConnection = DriverManager.getConnection(connectionString, System.getProperties());
4248
isConnectionValid = true;
43-
} catch (CJCommunicationsException | CommunicationsException e) {
44-
isConnectionValid = false;
45-
throw new ConnectionFailedException();
46-
} catch (ClassNotFoundException | SQLException e) {
47-
e.printStackTrace();
49+
} catch (CJCommunicationsException | SQLException e) {
4850
isConnectionValid = false;
51+
throw new ConnectionFailedException(e);
4952
}
5053
}
5154

@@ -181,7 +184,7 @@ public <T> Optional<T> callFunction(Class<T> returnType, String functionName, Ob
181184
joiner.add("?");
182185
}
183186

184-
try (var set = execute(String.format("select %s(%s);", functionName, joiner.toString()), arguments)) {
187+
try (var set = execute(String.format("select %s(%s);", functionName, joiner), arguments)) {
185188
return new FieldMapper<>(returnType).map(set);
186189
}
187190
}

src/main/java/com/github/collinalpert/java2db/exceptions/ConnectionFailedException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
public class ConnectionFailedException extends RuntimeException {
77

8-
public ConnectionFailedException() {
9-
super("The connection to the database failed. Please check your host/ip address, if the MySQL server is reachable and if you have an internet connection.");
8+
public ConnectionFailedException(Throwable cause) {
9+
super("The connection to the database failed. Please check your host/ip address, if the MySQL server is reachable and if you have an internet connection.", cause);
1010
}
1111
}

src/main/java/com/github/collinalpert/java2db/utilities/IoC.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public final class IoC {
1818
private static final Map<Class<? extends BaseEntity>, BaseService<? extends BaseEntity>> services;
1919
private static final Map<Class<? extends BaseEntity>, Mappable<? extends BaseEntity>> mappers;
2020

21-
2221
static {
2322
services = new HashMap<>();
2423
mappers = new HashMap<>();

0 commit comments

Comments
 (0)