public String deleteUser() { if (selectedUser != null) { if (!"admin".equals(selectedUser.getLoginName())) { List<Account> accountList = accountService.getAllByUser(selectedUser); for (Account account : accountList) { account.setDestroy(true); account.setUser(null); accountService.updateAccount(account); } List<Topic> topicList = messageService.findByUser(selectedUser); for (Topic topic : topicList) { List<Message> messageList = messageService.findByTopic(topic); topic.setLastMessage(null); messageService.editTopic(topic); for (Message message : messageList) { message.setSender(null); message.setTopic(null); messageService.removeMessage(message); } messageList.clear(); messageService.removeTopic(topic); } topicList.clear(); userService.removeUser(selectedUser); selectedUser = new User(); return "listUser?faces-redirect=true"; } else { FacesContext.getCurrentInstance() .addMessage( null, new FacesMessage( FacesMessage.SEVERITY_INFO, "Deleting error", "This user has leaded projects or you tried to delete admin! >> nice try! ")); return "listUser?faces-redirect=false"; } } else { FacesContext.getCurrentInstance() .addMessage( null, new FacesMessage( FacesMessage.SEVERITY_INFO, "User has not selected", "You did not select any user!")); return "listUser?faces-redirect=false"; } }
public static synchronized Message execute_query(Connection con, String receiver, String sender) { CallableStatement callFunction = null; Message newMessage = new Message(); try { // checking if the connection that is returning is not closed if (!con.isClosed()) { // System.out.println("conencted!!"); // prepare callable function callFunction = con.prepareCall(callableFunction); // setting the parameter for the callable function callFunction.setString(1, receiver); callFunction.setString(2, sender); callFunction.execute(); ResultSet result = callFunction.getResultSet(); result.next(); if (result.getInt(7) == 1) { System.out.println("No message found!"); } else { System.out.println(result.getString(1)); newMessage.message = result.getString(1); newMessage.sender = result.getString(2); newMessage.reciever = result.getString(3); newMessage.messageID = UUID.fromString(result.getString(4)); newMessage.timestamp = Timestamp.valueOf(result.getString(5)); } return newMessage; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // close the database connection if (callFunction != null) { try { callFunction.close(); // System.out.println("Call function closed"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return null; }