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

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Jun 16 15:32:21 EDT 2010


Author: dan.j.allen
Date: 2010-06-16 15:32:21 -0400 (Wed, 16 Jun 2010)
New Revision: 13192

Modified:
   examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java
   examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java
Log:
optimizations


Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java	2010-06-16 19:23:00 UTC (rev 13191)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java	2010-06-16 19:32:21 UTC (rev 13192)
@@ -86,8 +86,7 @@
    @Begin
    public void selectHotel(final Long id)
    {
-      // NOTE get a fresh reference that's managed by the conversational
-      // persistence context
+      // NOTE get a fresh reference that's managed by the extended persistence context
       hotelSelection = em.find(Hotel.class, id);
       if (hotelSelection != null)
       {

Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java	2010-06-16 19:23:00 UTC (rev 13191)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java	2010-06-16 19:32:21 UTC (rev 13192)
@@ -80,24 +80,17 @@
    @Named("bookings")
    public List<Booking> getBookingsForCurrentUser()
    {
-      if (identity.isLoggedIn() && bookingsForUser == null)
+      if (bookingsForUser == null && identity.isLoggedIn())
       {
-         String username = currentUserInstance.get().getUsername();
-         CriteriaBuilder builder = em.getCriteriaBuilder();
-         CriteriaQuery<Booking> cquery = builder.createQuery(Booking.class);
-         Root<Booking> booking = cquery.from(Booking.class);
-         booking.fetch(Booking_.hotel, JoinType.INNER);
-         cquery.select(booking)
-               .where(builder.equal(booking.get(Booking_.user).get(User_.username), username))
-               .orderBy(builder.asc(booking.get(Booking_.checkinDate)));
-
-         bookingsForUser = em.createQuery(cquery).getResultList();
+         fetchBookingsForCurrentUser();
       }
       return bookingsForUser;
    }
 
-   public void afterBookingConfirmed(@Observes(during = TransactionPhase.AFTER_SUCCESS) @Confirmed final BookingEvent bookingEvent)
+   public void afterBookingConfirmed(@Observes(during = TransactionPhase.AFTER_SUCCESS)
+         @Confirmed final BookingEvent bookingEvent)
    {
+      // optimization, save the db call
       if (bookingsForUser != null)
       {
          bookingsForUser.add(bookingEvent.getBooking());
@@ -121,4 +114,18 @@
       bookingsForUser.remove(selectedBooking);
    }
 
+   private void fetchBookingsForCurrentUser()
+   {
+      String username = currentUserInstance.get().getUsername();
+      CriteriaBuilder builder = em.getCriteriaBuilder();
+      CriteriaQuery<Booking> cquery = builder.createQuery(Booking.class);
+      Root<Booking> booking = cquery.from(Booking.class);
+      booking.fetch(Booking_.hotel, JoinType.INNER);
+      cquery.select(booking)
+            .where(builder.equal(booking.get(Booking_.user).get(User_.username), username))
+            .orderBy(builder.asc(booking.get(Booking_.checkinDate)));
+
+      bookingsForUser = em.createQuery(cquery).getResultList();
+   }
+
 }



More information about the seam-commits mailing list