Skip to content

Commit

Permalink
Enhancement for code readability
Browse files Browse the repository at this point in the history
- no more useless comment (fix #4)
  • Loading branch information
Sylvain committed Jan 27, 2018
1 parent e763a52 commit e2f6874
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 85 deletions.
Binary file modified out/artifacts/library/library.war
Binary file not shown.
11 changes: 0 additions & 11 deletions src/ch/sylvainmuller/controller/BookController.java
Expand Up @@ -17,33 +17,22 @@
@WebServlet(urlPatterns = "/books")
public class BookController extends HttpServlet {

/** Universal version identifier for Serializable class */
private static final long serialVersionUID = 1L;

@EJB
private BookService bookService;

/**
* Fetch books list in DB and display it
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

/** Get id of item to delete */
String param = request.getParameter("id");
if (param != null && !param.isEmpty()) {
int id = Integer.parseInt(param);
bookService.deleteBook(id);
}

/** Get books collection */
List<Book> books = bookService.getBooks();

/** Set attribute and forward */
request.setAttribute("books", books);
request.getRequestDispatcher(WEBINF_PATH + "/book.jsp").forward(request, response);
}
Expand Down
1 change: 0 additions & 1 deletion src/ch/sylvainmuller/controller/LoginController.java
Expand Up @@ -12,7 +12,6 @@
@WebServlet(urlPatterns = "/login")
public class LoginController extends HttpServlet {

/** Universal version identifier for Serializable class */
private static final long serialVersionUID = 1L;

@Override
Expand Down
1 change: 0 additions & 1 deletion src/ch/sylvainmuller/controller/LogoutController.java
Expand Up @@ -13,7 +13,6 @@
@WebServlet(urlPatterns = "/logout")
public class LogoutController extends HttpServlet {

/** Universal version identifier for Serializable class */
private static final long serialVersionUID = 1L;

@Override
Expand Down
50 changes: 0 additions & 50 deletions src/ch/sylvainmuller/models/Book.java
Expand Up @@ -5,13 +5,9 @@
import java.io.Serializable;
import java.util.Date;

import static javax.persistence.GenerationType.IDENTITY;

@Entity
//@Table(name="Book")
public class Book implements Serializable {

/** Universal version identifier for Serializable class */
private static final long serialVersionUID = 1L;

@Id
Expand All @@ -26,12 +22,6 @@ public class Book implements Serializable {

private Date year;

/**
* @param title
* @param author
* @param editor
* @param year
*/
public Book(String title, String author, String editor, Date year) {
this.title = title;
this.author = author;
Expand All @@ -55,82 +45,42 @@ public Book(String title, String author, String editor) {

public Book() {}

/**
* Get id
* @return
*/
public Long getId() {
return id;
}

/**
* Set id
* @param id
*/
public void setId(Long id) {
this.id = id;
}

/**
* Get title
* @return
*/
public String getTitle() {
return title;
}

/**
* Set title
* @param title
*/
public void setTitle(String title) {
this.title = title;
}

/**
* Get author
* @return
*/
public String getAuthor() {
return author;
}

/**
* Set author
* @param author
*/
public void setAuthor(String author) {
this.author = author;
}

/**
* Get editor
* @return
*/
public String getEditor() {
return editor;
}

/**
* Set editor
* @param editor
*/
public void setEditor(String editor) {
this.editor = editor;
}

/**
* Get year
* @return
*/
public Date getYear() {
return year;
}

/**
* Set year
* @param year
*/
public void setYear(Date year) {
this.year = year;
}
Expand Down
22 changes: 0 additions & 22 deletions src/ch/sylvainmuller/services/BookService.java
Expand Up @@ -14,47 +14,25 @@ public class BookService {
@PersistenceContext(unitName="books-unit")
private EntityManager em;

/**
* Get a list of books
* @return
*/
public List<Book> getBooks() {
return em.createQuery("SELECT b FROM Book AS b").getResultList();
}

/**
* Create a new book
* @param book
* @return
*/
public void newBooks(Book book) {
em.persist(book);
}

/**
* Delete a book
* @param id
*/
public void deleteBook(int id) {
Book book = findBook(id);
if (book != null) {
em.remove(book);
}
}

/**
* Find a book
* @param id
* @return
*/
public Book findBook(int id) {
return em.find(Book.class, id);
}

/**
* Update a book
* @param book
*/
public void updateBook(Book book) {
em.merge(book);
}
Expand Down

0 comments on commit e2f6874

Please sign in to comment.