diff --git a/pom.xml b/pom.xml index 009b32b..3af0e32 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 kangaroo-and-rabbit archidata - 0.1.4 + 0.1.5 2.1 2.32 diff --git a/src/org/kar/archidata/SqlWrapper.java b/src/org/kar/archidata/SqlWrapper.java index 93c759e..871517a 100644 --- a/src/org/kar/archidata/SqlWrapper.java +++ b/src/org/kar/archidata/SqlWrapper.java @@ -7,7 +7,6 @@ import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; import java.sql.*; -import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -307,7 +306,7 @@ public class SqlWrapper { query.append("?"); } query.append(")"); - System.out.println("generate the querry: '" + query.toString() + "'"); + // System.out.println("generate the querry: '" + query.toString() + "'"); // prepare the request: PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS); Field primaryKeyField = null; @@ -382,6 +381,9 @@ public class SqlWrapper { //ps.execute(); } catch (SQLException ex) { ex.printStackTrace(); + } finally { + entry.close(); + entry = null; } return data; } @@ -466,7 +468,7 @@ public class SqlWrapper { query.append(primaryKeyField.getName()); query.append("` = ?"); firstField = true; - System.out.println("generate the querry: '" + query.toString() + "'"); + // System.out.println("generate the querry: '" + query.toString() + "'"); // prepare the request: PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS); int iii = 1; @@ -517,6 +519,9 @@ public class SqlWrapper { //ps.execute(); } catch (SQLException ex) { ex.printStackTrace(); + } finally { + entry.close(); + entry = null; } } @@ -626,7 +631,7 @@ public class SqlWrapper { query.append(".deleted = false "); */ firstField = true; - System.out.println("generate the querry: '" + query.toString() + "'"); + //System.out.println("generate the querry: '" + query.toString() + "'"); // prepare the request: PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS); int iii = 1; @@ -664,12 +669,16 @@ public class SqlWrapper { } catch (SQLException ex) { ex.printStackTrace(); + } finally { + entry.close(); + entry = null; } - entry.disconnect(); - entry = null; return out; } public static List getsWhere(Class clazz, String key, String operator, Object value ) throws Exception { + return getsWhere(clazz, key, operator, value, false); + } + public static List getsWhere(Class clazz, String key, String operator, Object value, boolean full ) throws Exception { DBEntry entry = new DBEntry(GlobalConfiguration.dbConfig); List outs = new ArrayList<>(); // real add in the BDD: @@ -689,12 +698,12 @@ public class SqlWrapper { continue; } boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0; - if (createTime) { + if (!full && createTime) { continue; } String name = elem.getName(); boolean updateTime = elem.getDeclaredAnnotationsByType(SQLUpdateTime.class).length != 0; - if (updateTime) { + if (!full && updateTime) { continue; } count++; @@ -741,12 +750,12 @@ public class SqlWrapper { continue; } boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0; - if (createTime) { + if (!full && createTime) { continue; } String name = elem.getName(); boolean updateTime = elem.getDeclaredAnnotationsByType(SQLUpdateTime.class).length != 0; - if (updateTime) { + if (!full && updateTime) { continue; } //this.name = rs.getString(iii++); @@ -761,9 +770,10 @@ public class SqlWrapper { } catch (SQLException ex) { ex.printStackTrace(); + } finally { + entry.close(); + entry = null; } - entry.disconnect(); - entry = null; return outs; } @@ -929,9 +939,10 @@ public class SqlWrapper { } catch (SQLException ex) { ex.printStackTrace(); + } finally { + entry.close(); + entry = null; } - entry.disconnect(); - entry = null; return out; } @@ -970,7 +981,8 @@ public class SqlWrapper { ex.printStackTrace(); throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage()); } finally { - entry.disconnect(); + entry.close(); + entry = null; } } public static void removeLink(Class clazz, long localKey, String table, long remoteKey) throws Exception { @@ -987,7 +999,8 @@ public class SqlWrapper { ex.printStackTrace(); throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage()); } finally { - entry.disconnect(); + entry.close(); + entry = null; } } @@ -1041,7 +1054,8 @@ public class SqlWrapper { ex.printStackTrace(); throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage()); } finally { - entry.disconnect(); + entry.close(); + entry = null; } } public static void unsetDelete(Class clazz, long id) throws Exception { @@ -1057,7 +1071,8 @@ public class SqlWrapper { ex.printStackTrace(); throw new ExceptionDBInterface(500, "SQL error: " + ex.getMessage()); } finally { - entry.disconnect(); + entry.close(); + entry = null; } } diff --git a/src/org/kar/archidata/UserDB.java b/src/org/kar/archidata/UserDB.java index aacf29b..2a6ecd7 100755 --- a/src/org/kar/archidata/UserDB.java +++ b/src/org/kar/archidata/UserDB.java @@ -3,6 +3,7 @@ package org.kar.archidata; import org.kar.archidata.db.DBEntry; import org.kar.archidata.model.User; +import java.io.IOException; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -25,7 +26,7 @@ public class UserDB { 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); String query = "INSERT INTO `user` (`id`, `login`, `lastConnection`, `admin`, `blocked`, `removed`) VALUE (?,?,now(3),'0','0','0')"; try { @@ -35,8 +36,9 @@ public class UserDB { ps.executeUpdate(); } catch (SQLException throwables) { throwables.printStackTrace(); + } finally { + entry.close(); } - entry.disconnect(); } } diff --git a/src/org/kar/archidata/db/DBEntry.java b/src/org/kar/archidata/db/DBEntry.java index 32c9f05..7818d02 100644 --- a/src/org/kar/archidata/db/DBEntry.java +++ b/src/org/kar/archidata/db/DBEntry.java @@ -2,9 +2,11 @@ package org.kar.archidata.db; import org.kar.archidata.model.User; +import java.io.Closeable; +import java.io.IOException; import java.sql.*; -public class DBEntry { +public class DBEntry implements Closeable { public DBConfig config; 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 { 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(); + } + + } } diff --git a/src/org/kar/archidata/filter/AuthenticationFilter.java b/src/org/kar/archidata/filter/AuthenticationFilter.java index 896069d..7ac1e2b 100644 --- a/src/org/kar/archidata/filter/AuthenticationFilter.java +++ b/src/org/kar/archidata/filter/AuthenticationFilter.java @@ -59,7 +59,7 @@ public class AuthenticationFilter implements ContainerRequestFilter { //Access allowed for all if( method.isAnnotationPresent(PermitAll.class)) { - System.out.println(" ==> permit all " + requestContext.getUriInfo().getPath()); + //System.out.println(" ==> permit all " + requestContext.getUriInfo().getPath()); // no control ... return; }