Skip to content

Commit 8b8ebfb

Browse files
committed
Tried to add testing
1 parent 1ab7a51 commit 8b8ebfb

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<dependency>
5151
<groupId>mysql</groupId>
5252
<artifactId>mysql-connector-java</artifactId>
53-
<version>5.1.6</version>
53+
<version>8.0.22</version>
5454
<scope>test</scope>
5555
</dependency>
5656
<dependency>

src/main/java/org/javawebstack/orm/wrapper/BaseSQL.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ public abstract class BaseSQL implements SQL {
1818
public abstract Connection getConnection();
1919

2020
public int write(String queryString, Object... parameters) throws SQLException {
21+
Connection connection = getConnection();
2122
ORM.LOGGER.log(Level.ALL, queryString);
2223
ORM.LOGGER.log(Level.ALL, Arrays.stream(parameters).map(o -> o == null ? "null" : o.toString()).collect(Collectors.joining(",")));
2324
if (queryString.toLowerCase(Locale.ROOT).startsWith("insert")) {
24-
PreparedStatement ps = setParams(getConnection().prepareStatement(queryString, Statement.RETURN_GENERATED_KEYS), parameters);
25+
PreparedStatement ps = setParams(connection.prepareStatement(queryString, Statement.RETURN_GENERATED_KEYS), parameters);
2526
ps.executeUpdate();
2627
ResultSet rs = ps.getGeneratedKeys();
2728
int id = 0;
@@ -32,17 +33,18 @@ public int write(String queryString, Object... parameters) throws SQLException {
3233
ps.close();
3334
return id;
3435
} else {
35-
PreparedStatement ps = setParams(getConnection().prepareStatement(queryString), parameters);
36+
PreparedStatement ps = setParams(connection.prepareStatement(queryString), parameters);
3637
ps.executeUpdate();
3738
ps.close();
3839
}
3940
return 0;
4041
}
4142

4243
public ResultSet read(String queryString, Object... parameters) throws SQLException {
44+
Connection connection = getConnection();
4345
ORM.LOGGER.log(Level.ALL, queryString);
4446
ORM.LOGGER.log(Level.ALL, Arrays.stream(parameters).map(o -> o == null ? "null" : o.toString()).collect(Collectors.joining(",")));
45-
PreparedStatement ps = setParams(getConnection().prepareStatement(queryString), parameters);
47+
PreparedStatement ps = setParams(connection.prepareStatement(queryString), parameters);
4648
ResultSet rs = ps.executeQuery();
4749
statementMap.put(rs, ps);
4850
return rs;

src/main/java/org/javawebstack/orm/wrapper/MySQL.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.javawebstack.orm.wrapper;
22

3+
import org.javawebstack.orm.exception.ORMQueryException;
4+
5+
import java.io.IOException;
36
import java.sql.Connection;
47
import java.sql.DriverManager;
58
import java.sql.SQLException;
@@ -55,8 +58,8 @@ public Connection getConnection() {
5558
e.printStackTrace();
5659
}
5760
try {
58-
if (c != null && c.isClosed())
59-
return null;
61+
if (c == null || c.isClosed())
62+
throw new ORMQueryException("Connection failed!");
6063
} catch (SQLException e) {
6164
e.printStackTrace();
6265
}

0 commit comments

Comments
 (0)