Skip to content
Snippets Groups Projects
Commit 024beb24 authored by Félix  Sidokhine's avatar Félix Sidokhine
Browse files

fixed dao problem in contact storage

Change-Id: Ie27b52abd626291e3bfa0ac57be592e3b0b8b00d
parent 30de6a70
No related branches found
No related tags found
No related merge requests found
......@@ -65,17 +65,17 @@ public class ContactDao extends AbstractDao<Contact> {
String delete = "DELETE FROM contacts WHERE owner = ?";
PreparedStatement ps = connection.getConnection().prepareStatement(delete);
ps.setString(1, contactList.get(0).getOwner());
ps.executeQuery();
String insert = "INSERT INTO contacts (owner, uri, displayName, `timestamp`, status) VALUES " +
"(?, ?, ?, ?, ?)";
ps.executeUpdate();
String insert = "INSERT INTO contacts (owner, uri, displayName, timestamp, status,banned,confirmed) VALUES " +
"(?, ?, ?, ?, ?,?,?)";
for (Contact contact : contactList) {
ps = connection.getConnection().prepareStatement(insert);
contact.getInsert(ps);
ps.executeQuery();
ps.executeUpdate();
}
return true;
} catch (Exception e) {
log.error("Could not update contacts!");
log.error("Could not update contacts: {}",e.getMessage());
return false;
} finally {
DataStore.connectionPool.returnConnection(connection);
......
......@@ -155,8 +155,9 @@ public class ContactServlet extends HttpServlet {
statementList.addStatement(new StatementElement("owner","=",req.getAttribute("username").toString(),""));
List<Contact> localList = dataStore.getContactDao().getObjects(statementList);
List<Contact> remoteList = Arrays.asList(JsonIterator.deserialize(req.getInputStream().readAllBytes(),Contact[].class));
remoteList.forEach(contact -> contact.setOwner(req.getAttribute("username").toString()));
List<Contact> result = ContactMerger.mergeContacts(localList,remoteList);
if(!dataStore.getContactDao().storeContactList(result)) TomcatCustomErrorHandler.sendCustomError(resp,500,"Could not store contacts!");
resp.getOutputStream().write(JsonStream.serialize(result).getBytes());
else resp.getOutputStream().write(JsonStream.serialize(result).getBytes());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment