[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);
|
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();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
// parse the object to be sure the data are valid:
|
// parse the object to be sure the data are valid:
|
||||||
T data = mapper.readValue(jsonData, clazz);
|
T data = mapper.readValue(jsonData, clazz);
|
||||||
@ -404,10 +404,19 @@ public class SqlWrapper {
|
|||||||
List<String> keys = new ArrayList<>();
|
List<String> keys = new ArrayList<>();
|
||||||
Iterator<String> iterator = root.fieldNames();
|
Iterator<String> iterator = root.fieldNames();
|
||||||
iterator.forEachRemaining(e -> keys.add(e));
|
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();
|
Class<?> clazz = data.getClass();
|
||||||
//public static NodeSmall createNode(String typeInNode, String name, String description, Long parentId) {
|
//public static NodeSmall createNode(String typeInNode, String name, String description, Long parentId) {
|
||||||
|
|
||||||
@ -515,14 +524,14 @@ public class SqlWrapper {
|
|||||||
ps.setLong(iii++, id);
|
ps.setLong(iii++, id);
|
||||||
// execute the request
|
// execute the request
|
||||||
int affectedRows = ps.executeUpdate();
|
int affectedRows = ps.executeUpdate();
|
||||||
// todo manage the list of element is valid ...
|
return affectedRows;
|
||||||
//ps.execute();
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
entry = null;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addElement(PreparedStatement ps, Object value, int iii) throws Exception {
|
static void addElement(PreparedStatement ps, Object value, int iii) throws Exception {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package org.kar.archidata.db;
|
package org.kar.archidata.db;
|
||||||
|
|
||||||
import org.kar.archidata.model.User;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
@ -10,16 +8,16 @@ public class DBEntry implements Closeable {
|
|||||||
public DBConfig config;
|
public DBConfig config;
|
||||||
public Connection connection;
|
public Connection connection;
|
||||||
|
|
||||||
public DBEntry(DBConfig config) {
|
public DBEntry(DBConfig config) throws IOException {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect() {
|
public void connect() throws IOException {
|
||||||
try {
|
try {
|
||||||
connection = DriverManager.getConnection(config.getUrl(), config.getLogin(), config.getPassword());
|
connection = DriverManager.getConnection(config.getUrl(), config.getLogin(), config.getPassword());
|
||||||
} catch (SQLException ex) {
|
} 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.commit();
|
||||||
connection.close();
|
connection.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
throw new IOException("Dis-connection db fail: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,12 @@ public class GenericTable {
|
|||||||
@SQLCreateTime
|
@SQLCreateTime
|
||||||
@SQLNotNull
|
@SQLNotNull
|
||||||
@SQLComment("Create time of the object")
|
@SQLComment("Create time of the object")
|
||||||
|
@SQLDefault("now()")
|
||||||
public Timestamp create_date = null;
|
public Timestamp create_date = null;
|
||||||
@SQLNotRead
|
@SQLNotRead
|
||||||
@SQLUpdateTime
|
@SQLUpdateTime
|
||||||
@SQLNotNull
|
@SQLNotNull
|
||||||
@SQLComment("When update the object")
|
@SQLComment("When update the object")
|
||||||
|
@SQLDefault("now()")
|
||||||
public Timestamp modify_date = null;
|
public Timestamp modify_date = null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user