Upgrade to Spring Framework 4.0 and Mojara 2.2.4
This commit is contained in:
@@ -9,12 +9,12 @@
|
||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<springframework-version>3.2.1.RELEASE</springframework-version>
|
||||
<springframework-version>4.0.0.RELEASE</springframework-version>
|
||||
<springsecurity-version>3.1.3.RELEASE</springsecurity-version>
|
||||
<webflow-version>2.4.0.M1</webflow-version>
|
||||
<slf4j-version>1.5.10</slf4j-version>
|
||||
<mojarra-version>2.1.7</mojarra-version>
|
||||
<primefaces-version>3.1.1</primefaces-version>
|
||||
<webflow-version>2.4.0.BUILD-SNAPSHOT</webflow-version>
|
||||
<slf4j-version>1.6.1</slf4j-version>
|
||||
<mojarra-version>2.2.4</mojarra-version>
|
||||
<primefaces-version>4.0</primefaces-version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
@@ -29,6 +29,11 @@
|
||||
<url>http://repository.primefaces.org</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>SpringSource Repository</name>
|
||||
<url>http://repo.springsource.org/snapshot</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.springframework.webflow.samples.booking;
|
||||
|
||||
@@ -11,44 +11,63 @@ import org.primefaces.model.SortOrder;
|
||||
|
||||
public class HotelLazyDataModel extends LazyDataModel<Hotel> {
|
||||
|
||||
private static final long serialVersionUID = -8832831134966938627L;
|
||||
private static final long serialVersionUID = -8832831134966938627L;
|
||||
|
||||
SearchCriteria searchCriteria;
|
||||
SearchCriteria searchCriteria;
|
||||
|
||||
BookingService bookingService;
|
||||
BookingService bookingService;
|
||||
|
||||
private Hotel selected;
|
||||
private List<Hotel> hotels;
|
||||
|
||||
public HotelLazyDataModel(SearchCriteria searchCriteria, BookingService bookingService) {
|
||||
this.searchCriteria = searchCriteria;
|
||||
this.bookingService = bookingService;
|
||||
}
|
||||
private Hotel selected;
|
||||
|
||||
@Override
|
||||
public List<Hotel> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
|
||||
searchCriteria.setCurrentPage(first / pageSize + 1);
|
||||
return bookingService.findHotels(searchCriteria, first, sortField, sortOrder.equals(SortOrder.ASCENDING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return bookingService.getNumberOfHotels(searchCriteria);
|
||||
}
|
||||
public HotelLazyDataModel(SearchCriteria searchCriteria, BookingService bookingService) {
|
||||
this.searchCriteria = searchCriteria;
|
||||
this.bookingService = bookingService;
|
||||
}
|
||||
|
||||
public Hotel getSelected() {
|
||||
return selected;
|
||||
}
|
||||
@Override
|
||||
public List<Hotel> load(int first, int pageSize, String sortField, SortOrder order, Map<String, String> filters) {
|
||||
this.searchCriteria.setCurrentPage(first / pageSize + 1);
|
||||
this.hotels = bookingService.findHotels(searchCriteria, first, sortField, order.equals(SortOrder.ASCENDING));
|
||||
return hotels;
|
||||
}
|
||||
|
||||
public void setSelected(Hotel selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
@Override
|
||||
public Hotel getRowData(String rowKey) {
|
||||
for (Hotel hotel : this.hotels){
|
||||
if (hotel.getId().equals(rowKey)) {
|
||||
return hotel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getCurrentPage() {
|
||||
return this.searchCriteria.getCurrentPage();
|
||||
}
|
||||
@Override
|
||||
public Object getRowKey(Hotel hotel) {
|
||||
return hotel.getId();
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return this.searchCriteria.getPageSize();
|
||||
}
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return bookingService.getNumberOfHotels(searchCriteria);
|
||||
}
|
||||
|
||||
public Hotel getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(Hotel selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public int getCurrentPage() {
|
||||
return this.searchCriteria.getCurrentPage();
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return this.searchCriteria.getPageSize();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,90 +20,90 @@ import org.springframework.util.StringUtils;
|
||||
@Repository
|
||||
public class JpaBookingService implements BookingService, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private EntityManager em;
|
||||
private EntityManager em;
|
||||
|
||||
@PersistenceContext
|
||||
public void setEntityManager(EntityManager em) {
|
||||
this.em = em;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Booking> findBookings(String username) {
|
||||
if (username != null) {
|
||||
return em.createQuery("select b from Booking b where b.user.username = :username order by b.checkinDate")
|
||||
.setParameter("username", username).getResultList();
|
||||
} else {
|
||||
return null;
|
||||
@PersistenceContext
|
||||
public void setEntityManager(EntityManager em) {
|
||||
this.em = em;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Hotel> findHotels(SearchCriteria criteria, int firstResult, String orderBy, boolean ascending) {
|
||||
String pattern = getSearchPattern(criteria);
|
||||
orderBy = (orderBy != null) ? orderBy : "name";
|
||||
String orderDirection = (ascending) ? " ASC" : " DESC";
|
||||
return em
|
||||
.createQuery(
|
||||
"select h from Hotel h where lower(h.name) like :pattern or lower(h.city) like :pattern "
|
||||
+ "or lower(h.zip) like :pattern or lower(h.address) like :pattern order by h."
|
||||
+ orderBy + orderDirection).setParameter("pattern", pattern)
|
||||
.setMaxResults(criteria.getPageSize()).setFirstResult(firstResult).getResultList();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public int getNumberOfHotels(SearchCriteria criteria) {
|
||||
String pattern = getSearchPattern(criteria);
|
||||
Long count = (Long) em
|
||||
.createQuery(
|
||||
"select count(h.id) from Hotel h where lower(h.name) like :pattern or lower(h.city) like :pattern "
|
||||
+ "or lower(h.zip) like :pattern or lower(h.address) like :pattern")
|
||||
.setParameter("pattern", pattern).getSingleResult();
|
||||
return count.intValue();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Hotel findHotelById(Long id) {
|
||||
return em.find(Hotel.class, id);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Booking createBooking(Long hotelId, String username) {
|
||||
Hotel hotel = em.find(Hotel.class, hotelId);
|
||||
User user = findUser(username);
|
||||
Booking booking = new Booking(hotel, user);
|
||||
return booking;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void persistBooking(Booking booking) {
|
||||
em.persist(booking);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void cancelBooking(Booking booking) {
|
||||
booking = em.find(Booking.class, booking.getId());
|
||||
if (booking != null) {
|
||||
em.remove(booking);
|
||||
@Transactional(readOnly = true)
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Booking> findBookings(String username) {
|
||||
if (username != null) {
|
||||
return em.createQuery("select b from Booking b where b.user.username = :username order by b.checkinDate")
|
||||
.setParameter("username", username).getResultList();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
private String getSearchPattern(SearchCriteria criteria) {
|
||||
if (StringUtils.hasText(criteria.getSearchString())) {
|
||||
return "%" + criteria.getSearchString().toLowerCase().replace('*', '%') + "%";
|
||||
} else {
|
||||
return "%";
|
||||
@Transactional(readOnly = true)
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Hotel> findHotels(SearchCriteria criteria, int firstResult, String orderBy, boolean ascending) {
|
||||
String pattern = getSearchPattern(criteria);
|
||||
orderBy = (orderBy != null) ? orderBy : "name";
|
||||
String orderDirection = (ascending) ? " ASC" : " DESC";
|
||||
return em
|
||||
.createQuery(
|
||||
"select h from Hotel h where lower(h.name) like :pattern or lower(h.city) like :pattern "
|
||||
+ "or lower(h.zip) like :pattern or lower(h.address) like :pattern order by h."
|
||||
+ orderBy + orderDirection).setParameter("pattern", pattern)
|
||||
.setMaxResults(criteria.getPageSize()).setFirstResult(firstResult).getResultList();
|
||||
}
|
||||
}
|
||||
|
||||
private User findUser(String username) {
|
||||
return (User) em.createQuery("select u from User u where u.username = :username")
|
||||
.setParameter("username", username).getSingleResult();
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public int getNumberOfHotels(SearchCriteria criteria) {
|
||||
String pattern = getSearchPattern(criteria);
|
||||
Long count = (Long) em
|
||||
.createQuery(
|
||||
"select count(h.id) from Hotel h where lower(h.name) like :pattern or lower(h.city) like :pattern "
|
||||
+ "or lower(h.zip) like :pattern or lower(h.address) like :pattern")
|
||||
.setParameter("pattern", pattern).getSingleResult();
|
||||
return count.intValue();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Hotel findHotelById(Long id) {
|
||||
return em.find(Hotel.class, id);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Booking createBooking(Long hotelId, String username) {
|
||||
Hotel hotel = em.find(Hotel.class, hotelId);
|
||||
User user = findUser(username);
|
||||
Booking booking = new Booking(hotel, user);
|
||||
return booking;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void persistBooking(Booking booking) {
|
||||
em.persist(booking);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void cancelBooking(Booking booking) {
|
||||
booking = em.find(Booking.class, booking.getId());
|
||||
if (booking != null) {
|
||||
em.remove(booking);
|
||||
}
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
private String getSearchPattern(SearchCriteria criteria) {
|
||||
if (StringUtils.hasText(criteria.getSearchString())) {
|
||||
return "%" + criteria.getSearchString().toLowerCase().replace('*', '%') + "%";
|
||||
} else {
|
||||
return "%";
|
||||
}
|
||||
}
|
||||
|
||||
private User findUser(String username) {
|
||||
return (User) em.createQuery("select u from User u where u.username = :username")
|
||||
.setParameter("username", username).getSingleResult();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,57 +9,57 @@ import javax.faces.model.DataModel;
|
||||
*/
|
||||
public class SearchCriteria implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* The user-provided search criteria for finding Hotels.
|
||||
*/
|
||||
private String searchString = "";
|
||||
/**
|
||||
* The user-provided search criteria for finding Hotels.
|
||||
*/
|
||||
private String searchString = "";
|
||||
|
||||
/**
|
||||
* The maximum page size of the Hotel result list
|
||||
*/
|
||||
private int pageSize = 5;
|
||||
/**
|
||||
* The maximum page size of the Hotel result list
|
||||
*/
|
||||
private int pageSize = 5;
|
||||
|
||||
/**
|
||||
* The page the user is currently on.
|
||||
*/
|
||||
private int currentPage = 1;
|
||||
/**
|
||||
* The page the user is currently on.
|
||||
*/
|
||||
private int currentPage = 1;
|
||||
|
||||
/**
|
||||
* Returns a {@link DataModel} based on the search criteria.
|
||||
* @param bookingService the service to use to retrieve hotels.
|
||||
*/
|
||||
public DataModel<Hotel> getDataModel(BookingService bookingService) {
|
||||
return new HotelLazyDataModel(this, bookingService);
|
||||
}
|
||||
/**
|
||||
* Returns a {@link DataModel} based on the search criteria.
|
||||
* @param bookingService the service to use to retrieve hotels.
|
||||
*/
|
||||
public DataModel<Hotel> getDataModel(BookingService bookingService) {
|
||||
return new HotelLazyDataModel(this, bookingService);
|
||||
}
|
||||
|
||||
public String getSearchString() {
|
||||
return searchString;
|
||||
}
|
||||
public String getSearchString() {
|
||||
return searchString;
|
||||
}
|
||||
|
||||
public void setSearchString(String searchString) {
|
||||
this.searchString = searchString;
|
||||
}
|
||||
public void setSearchString(String searchString) {
|
||||
this.searchString = searchString;
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public int getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
public int getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(int currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
public void setCurrentPage(int currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[Search Criteria searchString = '" + searchString + "'";
|
||||
}
|
||||
public String toString() {
|
||||
return "[Search Criteria searchString = '" + searchString + "'";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user