[DEV] correct error management of interfaces

This commit is contained in:
Edouard DUPIN 2023-01-08 12:13:33 +01:00
parent b50dacc374
commit edfe9e8016
3 changed files with 20 additions and 11 deletions

View File

@ -395,7 +395,7 @@ public class SqlWrapper {
return insert(data);
}
public static <T> void update(Class<T> clazz, long id, String jsonData) throws Exception {
public static <T> int update(Class<T> clazz, long id, String jsonData) throws Exception {
ObjectMapper mapper = new ObjectMapper();
// parse the object to be sure the data are valid:
T data = mapper.readValue(jsonData, clazz);
@ -404,10 +404,19 @@ public class SqlWrapper {
List<String> keys = new ArrayList<>();
Iterator<String> iterator = root.fieldNames();
iterator.forEachRemaining(e -> keys.add(e));
update(data, id, keys);
return update(data, id, keys);
}
public static <T> void update(T data, long id, List<String> filterValue) throws Exception {
/**
*
* @param <T>
* @param data
* @param id
* @param filterValue
* @return the affected rows.
* @throws Exception
*/
public static <T> int update(T data, long id, List<String> filterValue) throws Exception {
Class<?> clazz = data.getClass();
//public static NodeSmall createNode(String typeInNode, String name, String description, Long parentId) {
@ -515,14 +524,14 @@ public class SqlWrapper {
ps.setLong(iii++, id);
// execute the request
int affectedRows = ps.executeUpdate();
// todo manage the list of element is valid ...
//ps.execute();
return affectedRows;
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
entry.close();
entry = null;
}
return 0;
}
static void addElement(PreparedStatement ps, Object value, int iii) throws Exception {

View File

@ -1,7 +1,5 @@
package org.kar.archidata.db;
import org.kar.archidata.model.User;
import java.io.Closeable;
import java.io.IOException;
import java.sql.*;
@ -10,16 +8,16 @@ public class DBEntry implements Closeable {
public DBConfig config;
public Connection connection;
public DBEntry(DBConfig config) {
public DBEntry(DBConfig config) throws IOException {
this.config = config;
connect();
}
public void connect() {
public void connect() throws IOException {
try {
connection = DriverManager.getConnection(config.getUrl(), config.getLogin(), config.getPassword());
} catch (SQLException ex) {
ex.printStackTrace();
throw new IOException("Connection db fail: " + ex.getMessage());
}
}
@ -42,7 +40,7 @@ public class DBEntry implements Closeable {
//connection.commit();
connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
throw new IOException("Dis-connection db fail: " + ex.getMessage());
}
}

View File

@ -26,10 +26,12 @@ public class GenericTable {
@SQLCreateTime
@SQLNotNull
@SQLComment("Create time of the object")
@SQLDefault("now()")
public Timestamp create_date = null;
@SQLNotRead
@SQLUpdateTime
@SQLNotNull
@SQLComment("When update the object")
@SQLDefault("now()")
public Timestamp modify_date = null;
}