[DEV] correct error management of interfaces
This commit is contained in:
parent
b50dacc374
commit
edfe9e8016
@ -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 {
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user