Deleting users and deleting books are 2 different things. That's why the way to delete users is implemented and explained separately.

Let's suppose that the administrator needs to delete an user. How should we implement this feature ? We can just delete the corresponding persistent object from the database. But that wouldn't be enough. Why ? Because if we will delete an user who has borrowed some books - those books still will be considered borrowed after we'll delete the user. Those books won't be available to be borrowed in the future. That's why we should avoid this situation. We can do that by making the administrator able to delete only users that don't have borrowed books. You may practice and do it by yourself. We will just suppose that when an user is deleted , if he has borrowed any books, all those books are returned to the library automatically.

When the administrator clicks on the URL Delete User from the UserPanel - the current user is deleted.
The panel DeleteUserPanel deletes the current user from the database, returns all the books to the library and redirects you to the UserPanel.
Here it is:
public class DeleteUserPanel extends AbstractPanel {
    private final String null_id = "null_id";
    public static final String tableUserName = "obj_LibraryUser";
    public static final String tableBookName = "obj_Book";
    public static final String OBJECT_ID = "OBJECT_ID";
    public int delay = 3;

    public String show() {
        StringBuffer sb = new StringBuffer();
        SqlUtil.delete(tableUserName, new Pair[]{
            new Pair(OBJECT_ID, inOut.getValue("objectID"))});
        //User was deleted - all the books that he has borrowed are becoming available again
        SqlUtil.update(tableBookName, new Pair[]{new Pair("UserID", null_id)}new Pair[]{
            new Pair("UserID", inOut.getValue("objectID"))});
        sb.append("User was deleted. All the books were returned.<BR>");
        return sb.toString();
    }

    public String getHeader() {
        StringBuffer sb = new StringBuffer();
        sb.append("<HTML><HEAD>");
        sb.append("<META HTTP-EQUIV=\"Refresh\"");
        sb.append("CONTENT=\"" + delay + ";URL=main?panel=LibraryAdminPanel\">");
        sb.append("</HEAD><BODY>");
        return sb.toString();
    }
}

Previous page Tree of contents Next page