Skip to content

Commit a64f9d3

Browse files
committed
Fixed logSqlErrors setting not effective.
1 parent 6ddfefb commit a64f9d3

6 files changed

Lines changed: 16 additions & 24 deletions

File tree

api/src/main/java/me/zort/sqllib/api/SQLConnection.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.jetbrains.annotations.Nullable;
44

5-
import java.io.Closeable;
65
import java.sql.Connection;
76

87
/**
@@ -12,8 +11,7 @@
1211
*
1312
* @author ZorTik
1413
*/
15-
@SuppressWarnings("closeable")
16-
public interface SQLConnection extends Closeable {
14+
public interface SQLConnection {
1715

1816
/**
1917
* Tries to connect to remote SQL server.
@@ -26,9 +24,7 @@ public interface SQLConnection extends Closeable {
2624
/**
2725
* Tries to disconnect from remote SQL server.
2826
*/
29-
@Deprecated
3027
void disconnect();
31-
void close();
3228

3329
/**
3430
* Returns current running connection with

core/src/main/java/me/zort/sqllib/SQLConnectionBuilder.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.sql.DriverManager;
1616
import java.sql.SQLException;
1717
import java.util.Objects;
18-
import java.util.Optional;
1918

2019
public final class SQLConnectionBuilder implements Cloneable {
2120

@@ -113,7 +112,7 @@ public static class BuilderSQLConnectionFactory implements SQLConnectionFactory
113112

114113
@Nullable
115114
@Override
116-
public Connection connect() {
115+
public Connection connect() throws SQLException {
117116
try {
118117
Class.forName(driver);
119118
} catch (ClassNotFoundException e) {
@@ -122,12 +121,7 @@ public Connection connect() {
122121
String jdbc = builder.jdbc;
123122
String usr = builder.endpoint.getUsername();
124123
String pwd = builder.endpoint.getPassword();
125-
try {
126-
return DriverManager.getConnection(jdbc, usr, pwd);
127-
} catch (SQLException e) {
128-
e.printStackTrace();
129-
return null;
130-
}
124+
return DriverManager.getConnection(jdbc, usr, pwd);
131125
}
132126

133127
}

core/src/main/java/me/zort/sqllib/SQLDatabaseConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.jetbrains.annotations.ApiStatus;
1212
import org.jetbrains.annotations.Nullable;
1313

14+
import java.io.Closeable;
1415
import java.sql.Connection;
1516
import java.sql.SQLException;
1617

@@ -21,7 +22,7 @@
2122
* @author ZorTik
2223
*/
2324
@SuppressWarnings("unused")
24-
public abstract class SQLDatabaseConnection implements SQLConnection {
25+
public abstract class SQLDatabaseConnection implements SQLConnection, Closeable {
2526

2627
private final SQLConnectionFactory connectionFactory;
2728
@Getter(onMethod_ = {@Nullable})

core/src/main/java/me/zort/sqllib/SQLDatabaseConnectionImpl.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ public <T> QueryRowsResult<T> query(Query query, Class<T> typeClass) {
263263
*/
264264
@Override
265265
public QueryRowsResult<Row> query(Query query) {
266-
return doQuery(query, false);
266+
return query(query, false);
267267
}
268268

269-
private QueryRowsResult<Row> doQuery(Query query, boolean isRetry) {
269+
private QueryRowsResult<Row> query(Query query, boolean isRetry) {
270270
Objects.requireNonNull(query);
271271

272272
if(!handleAutoReconnect()) {
@@ -294,7 +294,7 @@ private QueryRowsResult<Row> doQuery(Query query, boolean isRetry) {
294294
} catch (SQLException e) {
295295
if (!isRetry && e.getMessage().contains("database connection closed")) {
296296
reconnect();
297-
return doQuery(query, true);
297+
return query(query, true);
298298
}
299299

300300
logSqlError(e);
@@ -314,10 +314,10 @@ private QueryRowsResult<Row> doQuery(Query query, boolean isRetry) {
314314
* about success state of the request.
315315
*/
316316
public QueryResult exec(Query query) {
317-
return doExec(query, false);
317+
return exec(query, false);
318318
}
319319

320-
private QueryResult doExec(Query query, boolean isRetry) {
320+
private QueryResult exec(Query query, boolean isRetry) {
321321
if(!handleAutoReconnect()) {
322322
return new QueryResultImpl(false, "Cannot connect to database!");
323323
}
@@ -327,7 +327,7 @@ private QueryResult doExec(Query query, boolean isRetry) {
327327
} catch (SQLException e) {
328328
if (!isRetry && e.getMessage().contains("database connection closed")) {
329329
reconnect();
330-
return doExec(query, true);
330+
return exec(query, true);
331331
}
332332

333333
logSqlError(e);
@@ -359,9 +359,7 @@ public QueryResult save(String table, Object obj) { // by default, it creates an
359359

360360
public QueryResult insert(String table, Object obj) {
361361
Pair<String[], UnknownValueWrapper[]> data = buildDefsVals(obj);
362-
363-
if (data == null)
364-
return new QueryResultImpl(false);
362+
if (data == null) return new QueryResultImpl(false);
365363

366364
InsertQuery query = insert().into(table, data.getFirst());
367365
for (UnknownValueWrapper valueWrapper : data.getSecond()) {

core/src/main/java/me/zort/sqllib/pool/PooledSQLDatabaseConnection.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import me.zort.sqllib.internal.factory.SQLConnectionFactory;
66
import org.jetbrains.annotations.Nullable;
77

8-
public abstract class PooledSQLDatabaseConnection extends SQLDatabaseConnection {
8+
import java.io.Closeable;
9+
10+
public abstract class PooledSQLDatabaseConnection extends SQLDatabaseConnection implements Closeable {
911

1012
private SQLConnectionPool assignedPool = null;
1113
@Getter(onMethod_ = {@Nullable})

src/test/java/me/zort/sqllib/test/TestCase1.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public void test6_Pool() {
170170
assertEquals(0, pool.size());
171171
}
172172

173+
173174
@Timeout(5)
174175
@Test
175176
public void test7_Close() {

0 commit comments

Comments
 (0)