[DEBUG] correct some missing unconnect and remove deprecated logs

This commit is contained in:
Edouard DUPIN 2023-01-02 00:09:28 +01:00
parent e090943f49
commit 15c9ab83db
5 changed files with 53 additions and 32 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>kangaroo-and-rabbit</groupId> <groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId> <artifactId>archidata</artifactId>
<version>0.1.4</version> <version>0.1.5</version>
<properties> <properties>
<jaxrs.version>2.1</jaxrs.version> <jaxrs.version>2.1</jaxrs.version>
<jersey.version>2.32</jersey.version> <jersey.version>2.32</jersey.version>

View File

@ -7,7 +7,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.sql.*; import java.sql.*;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -307,7 +306,7 @@ public class SqlWrapper {
query.append("?"); query.append("?");
} }
query.append(")"); query.append(")");
System.out.println("generate the querry: '" + query.toString() + "'"); // System.out.println("generate the querry: '" + query.toString() + "'");
// prepare the request: // prepare the request:
PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS); PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
Field primaryKeyField = null; Field primaryKeyField = null;
@ -382,6 +381,9 @@ public class SqlWrapper {
//ps.execute(); //ps.execute();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
} finally {
entry.close();
entry = null;
} }
return data; return data;
} }
@ -466,7 +468,7 @@ public class SqlWrapper {
query.append(primaryKeyField.getName()); query.append(primaryKeyField.getName());
query.append("` = ?"); query.append("` = ?");
firstField = true; firstField = true;
System.out.println("generate the querry: '" + query.toString() + "'"); // System.out.println("generate the querry: '" + query.toString() + "'");
// prepare the request: // prepare the request:
PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS); PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
int iii = 1; int iii = 1;
@ -517,6 +519,9 @@ public class SqlWrapper {
//ps.execute(); //ps.execute();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
} finally {
entry.close();
entry = null;
} }
} }
@ -626,7 +631,7 @@ public class SqlWrapper {
query.append(".deleted = false "); query.append(".deleted = false ");
*/ */
firstField = true; firstField = true;
System.out.println("generate the querry: '" + query.toString() + "'"); //System.out.println("generate the querry: '" + query.toString() + "'");
// prepare the request: // prepare the request:
PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS); PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
int iii = 1; int iii = 1;
@ -664,12 +669,16 @@ public class SqlWrapper {
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
} } finally {
entry.disconnect(); entry.close();
entry = null; entry = null;
}
return out; return out;
} }
public static <T> List<T> getsWhere(Class<T> clazz, String key, String operator, Object value ) throws Exception { public static <T> List<T> getsWhere(Class<T> clazz, String key, String operator, Object value ) throws Exception {
return getsWhere(clazz, key, operator, value, false);
}
public static <T> List<T> getsWhere(Class<T> clazz, String key, String operator, Object value, boolean full ) throws Exception {
DBEntry entry = new DBEntry(GlobalConfiguration.dbConfig); DBEntry entry = new DBEntry(GlobalConfiguration.dbConfig);
List<T> outs = new ArrayList<>(); List<T> outs = new ArrayList<>();
// real add in the BDD: // real add in the BDD:
@ -689,12 +698,12 @@ public class SqlWrapper {
continue; continue;
} }
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0; boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
if (createTime) { if (!full && createTime) {
continue; continue;
} }
String name = elem.getName(); String name = elem.getName();
boolean updateTime = elem.getDeclaredAnnotationsByType(SQLUpdateTime.class).length != 0; boolean updateTime = elem.getDeclaredAnnotationsByType(SQLUpdateTime.class).length != 0;
if (updateTime) { if (!full && updateTime) {
continue; continue;
} }
count++; count++;
@ -741,12 +750,12 @@ public class SqlWrapper {
continue; continue;
} }
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0; boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
if (createTime) { if (!full && createTime) {
continue; continue;
} }
String name = elem.getName(); String name = elem.getName();
boolean updateTime = elem.getDeclaredAnnotationsByType(SQLUpdateTime.class).length != 0; boolean updateTime = elem.getDeclaredAnnotationsByType(SQLUpdateTime.class).length != 0;
if (updateTime) { if (!full && updateTime) {
continue; continue;
} }
//this.name = rs.getString(iii++); //this.name = rs.getString(iii++);
@ -761,9 +770,10 @@ public class SqlWrapper {
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
} } finally {
entry.disconnect(); entry.close();
entry = null; entry = null;
}
return outs; return outs;
} }
@ -929,9 +939,10 @@ public class SqlWrapper {
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
} } finally {
entry.disconnect(); entry.close();
entry = null; entry = null;
}
return out; return out;
} }
@ -970,7 +981,8 @@ public class SqlWrapper {
ex.printStackTrace(); ex.printStackTrace();
throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage()); throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage());
} finally { } finally {
entry.disconnect(); entry.close();
entry = null;
} }
} }
public static void removeLink(Class<?> clazz, long localKey, String table, long remoteKey) throws Exception { public static void removeLink(Class<?> clazz, long localKey, String table, long remoteKey) throws Exception {
@ -987,7 +999,8 @@ public class SqlWrapper {
ex.printStackTrace(); ex.printStackTrace();
throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage()); throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage());
} finally { } finally {
entry.disconnect(); entry.close();
entry = null;
} }
} }
@ -1041,7 +1054,8 @@ public class SqlWrapper {
ex.printStackTrace(); ex.printStackTrace();
throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage()); throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage());
} finally { } finally {
entry.disconnect(); entry.close();
entry = null;
} }
} }
public static void unsetDelete(Class<?> clazz, long id) throws Exception { public static void unsetDelete(Class<?> clazz, long id) throws Exception {
@ -1057,7 +1071,8 @@ public class SqlWrapper {
ex.printStackTrace(); ex.printStackTrace();
throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage()); throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage());
} finally { } finally {
entry.disconnect(); entry.close();
entry = null;
} }
} }

View File

@ -3,6 +3,7 @@ package org.kar.archidata;
import org.kar.archidata.db.DBEntry; import org.kar.archidata.db.DBEntry;
import org.kar.archidata.model.User; import org.kar.archidata.model.User;
import java.io.IOException;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@ -25,7 +26,7 @@ public class UserDB {
return getUsers(userId); return getUsers(userId);
} }
private static void createUsersInfoFromOAuth(long userId, String login) { private static void createUsersInfoFromOAuth(long userId, String login) throws IOException {
DBEntry entry = new DBEntry(GlobalConfiguration.dbConfig); DBEntry entry = new DBEntry(GlobalConfiguration.dbConfig);
String query = "INSERT INTO `user` (`id`, `login`, `lastConnection`, `admin`, `blocked`, `removed`) VALUE (?,?,now(3),'0','0','0')"; String query = "INSERT INTO `user` (`id`, `login`, `lastConnection`, `admin`, `blocked`, `removed`) VALUE (?,?,now(3),'0','0','0')";
try { try {
@ -35,8 +36,9 @@ public class UserDB {
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException throwables) { } catch (SQLException throwables) {
throwables.printStackTrace(); throwables.printStackTrace();
} finally {
entry.close();
} }
entry.disconnect();
} }
} }

View File

@ -2,9 +2,11 @@ package org.kar.archidata.db;
import org.kar.archidata.model.User; import org.kar.archidata.model.User;
import java.io.Closeable;
import java.io.IOException;
import java.sql.*; import java.sql.*;
public class DBEntry { public class DBEntry implements Closeable {
public DBConfig config; public DBConfig config;
public Connection connection; public Connection connection;
@ -21,15 +23,6 @@ public class DBEntry {
} }
} }
public void disconnect() {
try {
//connection.commit();
connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
/* /*
public void test() throws SQLException { public void test() throws SQLException {
String query = "SELECT * FROM user"; String query = "SELECT * FROM user";
@ -42,4 +35,15 @@ public class DBEntry {
} }
} }
*/ */
@Override
public void close() throws IOException {
try {
//connection.commit();
connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
} }

View File

@ -59,7 +59,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
//Access allowed for all //Access allowed for all
if( method.isAnnotationPresent(PermitAll.class)) { if( method.isAnnotationPresent(PermitAll.class)) {
System.out.println(" ==> permit all " + requestContext.getUriInfo().getPath()); //System.out.println(" ==> permit all " + requestContext.getUriInfo().getPath());
// no control ... // no control ...
return; return;
} }