[seam-commits] Seam SVN: r13185 - examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Jun 16 12:53:35 EDT 2010


Author: dan.j.allen
Date: 2010-06-16 12:53:35 -0400 (Wed, 16 Jun 2010)
New Revision: 13185

Modified:
   examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetupBean.java
Log:
proper logging


Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetupBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetupBean.java	2010-06-16 16:49:35 UTC (rev 13184)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetupBean.java	2010-06-16 16:53:35 UTC (rev 13185)
@@ -7,6 +7,7 @@
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Alternative;
 import javax.faces.event.PostConstructApplicationEvent;
+import javax.inject.Inject;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import javax.validation.ConstraintViolation;
@@ -14,6 +15,7 @@
 
 import org.jboss.seam.examples.booking.model.Hotel;
 import org.jboss.seam.examples.booking.model.User;
+import org.slf4j.Logger;
 
 /**
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
@@ -25,6 +27,8 @@
    @PersistenceContext
    private EntityManager em;
 
+   @Inject Logger log;
+
    private final List<User> users = new ArrayList<User>();
    private final List<Hotel> hotels = new ArrayList<Hotel>();
 
@@ -65,25 +69,35 @@
    public void init(@Observes final PostConstructApplicationEvent event)
    {
       try {
+         persist(users);
+         persist(hotels);
+      }
+      catch (Exception e)
+      {
+         log.error("Encountered error seeding the database", e);
+      }
+   }
 
-         for (User u : users)
-         {
-            if (em.find(User.class, u.getUsername()) == null)
-            {
-               em.persist(u);
-            }
-         }
+   private void persist(List entities)
+   {
+      for (Object e : entities)
+      {
+         persist(e);
+      }
+   }
 
-         for (Hotel h : hotels)
-         {
-            em.persist(h);
-         }
+   private void persist(Object entity)
+   {
+      try
+      {
+         em.persist(entity);
       }
       catch (ConstraintViolationException e)
       {
          for (ConstraintViolation v : e.getConstraintViolations())
          {
-            System.out.println(v.getPropertyPath() + ": " + v.getMessage());
+            log.error("Cannot persist entity because it has validation errors " +
+                  v.getRootBean() + ": " + v.getPropertyPath() + " " + v.getMessage());
          }
       }
    }



More information about the seam-commits mailing list