Search in sources :

Example 1 with PersonDao

use of dao.PersonDao in project ConsoElectric by anakkarsara.

the class DeletePerson method doPost.

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("dev");
    EntityManager manager = factory.createEntityManager();
    EntityTransaction tx = manager.getTransaction();
    tx.begin();
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    PersonDao pd = new PersonDao();
    pd.deleteById(Long.parseLong(request.getParameter("personToDelete")));
    tx.commit();
    out.println("<h2><a href=\"index.html\">Retour page d'acueil</a></h2>");
    out.println("<table border = 2 cellpadding = \"10\" cellspacing = \"10\" align= \"center\">  <tr>  <th>Prenom</th> <th>Nom</th>  <th>Email</th> ");
    DAO test = new DAO(manager);
    for (Person next : test.listPersons()) {
        out.println(" <tr>    <td>" + next.getFirstName() + "</td>   <td>" + next.getFamilyName() + "</td>   <td>" + next.getMail() + "</td> </tr>  ");
    }
    out.println("</table> ");
    manager.close();
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) PersonDao(dao.PersonDao) EntityManager(javax.persistence.EntityManager) DAO(jpa.DAO) EntityManagerFactory(javax.persistence.EntityManagerFactory) Person(entities.Person) PrintWriter(java.io.PrintWriter)

Aggregations

PersonDao (dao.PersonDao)1 Person (entities.Person)1 PrintWriter (java.io.PrintWriter)1 EntityManager (javax.persistence.EntityManager)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 EntityTransaction (javax.persistence.EntityTransaction)1 DAO (jpa.DAO)1