Skip to content

Commit

Permalink
Java 17 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinAlpert committed Aug 10, 2021
1 parent a0561dd commit ae3afaa
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

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

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ please let me know.
If you are completely lost or have no idea how to use this library (or both), feel free
to [contact me](mailto:collinalpert@gmail.com). I would be happy to assist you with any problems you might have.

**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.\
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.
**Please note:** This is a Java 11 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.\
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.

## Introduction
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).\
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.collinalpert</groupId>
<artifactId>java2db</artifactId>
<version>6.0.1</version>
<version>6.1.0</version>
<packaging>jar</packaging>

<name>Java2DB</name>
Expand Down Expand Up @@ -35,7 +35,7 @@
<scm>
<connection>scm:git:git://github.com/CollinAlpert/Java2DB.git</connection>
<developerConnection>scm:git:ssh://github.com:CollinAlpert/Java2DB.git</developerConnection>
<url>http://github.com/CollinAlpert/Java2DB/tree/master</url>
<url>https://github.com/CollinAlpert/Java2DB/tree/master</url>
</scm>

<distributionManagement>
Expand All @@ -50,7 +50,7 @@
</distributionManagement>

<properties>
<java-version>13</java-version>
<java-version>11</java-version>
<jdk.version>${java-version}</jdk.version>
<maven.compiler.release>${java-version}</maven.compiler.release>
<maven.compiler.source>${java-version}</maven.compiler.source>
Expand All @@ -62,19 +62,19 @@
<dependency>
<groupId>com.github.collinalpert</groupId>
<artifactId>lambda2sql</artifactId>
<version>2.4.0</version>
<version>2.5.0</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
<version>8.0.26</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ public int getTimeout() {
return timeout;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.github.collinalpert.java2db.queries.*;
import com.github.collinalpert.java2db.queries.async.*;
import com.mysql.cj.exceptions.CJCommunicationsException;
import com.mysql.cj.jdbc.exceptions.CommunicationsException;

import java.io.Closeable;
import java.sql.*;
Expand All @@ -28,24 +27,28 @@ public class DBConnection implements Closeable {
*/
public static boolean LOG_QUERIES = true;

private Connection underlyingConnection;
static {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

private final Connection underlyingConnection;
private boolean isConnectionValid;

public DBConnection(ConnectionConfiguration configuration) {
try {
var connectionString = String.format("jdbc:mysql://%s:%d/%s?rewriteBatchedStatements=true", configuration.getHost(), configuration.getPort(), configuration.getDatabase());
Class.forName("com.mysql.cj.jdbc.Driver");
System.setProperty("user", configuration.getUsername());
System.setProperty("password", configuration.getPassword());
DriverManager.setLoginTimeout(configuration.getTimeout());
underlyingConnection = DriverManager.getConnection(connectionString, System.getProperties());
isConnectionValid = true;
} catch (CJCommunicationsException | CommunicationsException e) {
isConnectionValid = false;
throw new ConnectionFailedException();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
} catch (CJCommunicationsException | SQLException e) {
isConnectionValid = false;
throw new ConnectionFailedException(e);
}
}

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

try (var set = execute(String.format("select %s(%s);", functionName, joiner.toString()), arguments)) {
try (var set = execute(String.format("select %s(%s);", functionName, joiner), arguments)) {
return new FieldMapper<>(returnType).map(set);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
public class ConnectionFailedException extends RuntimeException {

public ConnectionFailedException() {
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.");
public ConnectionFailedException(Throwable cause) {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public final class IoC {
private static final Map<Class<? extends BaseEntity>, BaseService<? extends BaseEntity>> services;
private static final Map<Class<? extends BaseEntity>, Mappable<? extends BaseEntity>> mappers;


static {
services = new HashMap<>();
mappers = new HashMap<>();
Expand Down

0 comments on commit ae3afaa

Please sign in to comment.