[jboss-cvs] jboss-seam/examples/spring/src/org/jboss/seam/example/spring ...

Norman Richards norman.richards at jboss.com
Sun Feb 18 14:57:59 EST 2007


  User: nrichards
  Date: 07/02/18 14:57:59

  Added:       examples/spring/src/org/jboss/seam/example/spring     
                        Booking.java Hotel.java SeamBookingDao.java
                        SpringBookingDao.java User.java
  Log:
  add em test
  
  Revision  Changes    Path
  1.1      date: 2007/02/18 19:57:59;  author: nrichards;  state: Exp;jboss-seam/examples/spring/src/org/jboss/seam/example/spring/Booking.java
  
  Index: Booking.java
  ===================================================================
  package org.jboss.seam.example.spring;
  
  import java.io.Serializable;
  import java.text.DateFormat;
  import java.util.Date;
  
  import javax.persistence.Basic;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.ManyToOne;
  import javax.persistence.Temporal;
  import javax.persistence.TemporalType;
  import javax.persistence.Transient;
  
  import org.hibernate.validator.Length;
  import org.hibernate.validator.NotNull;
  import org.hibernate.validator.Pattern;
  
  @Entity
  public class Booking 
      implements Serializable
  {
     private Long id;
     private User user;
     private Hotel hotel;
     private Date checkinDate;
     private Date checkoutDate;
     private String creditCard;
     private String creditCardName;
     private int creditCardExpiryMonth;
     private int creditCardExpiryYear;
     private boolean smoking;
     private int beds;
     
     public Booking() {}
     
     public Booking(Hotel hotel, User user)
     {
        this.hotel = hotel;
        this.user = user;
     }
  
     @Id @GeneratedValue
     public Long getId()
     {
        return id;
     }
     public void setId(Long id)
     {
        this.id = id;
     }
     @NotNull
     @Basic @Temporal(TemporalType.DATE) 
     public Date getCheckinDate()
     {
        return checkinDate;
     }
     public void setCheckinDate(Date datetime)
     {
        this.checkinDate = datetime;
     }
  
     @ManyToOne @NotNull
     public Hotel getHotel()
     {
        return hotel;
     }
     public void setHotel(Hotel hotel)
     {
        this.hotel = hotel;
     }
     
     @ManyToOne @NotNull
     public User getUser()
     {
        return user;
     }
     public void setUser(User user)
     {
        this.user = user;
     }
     
     @Basic @Temporal(TemporalType.DATE) 
     @NotNull
     public Date getCheckoutDate()
     {
        return checkoutDate;
     }
     public void setCheckoutDate(Date checkoutDate)
     {
        this.checkoutDate = checkoutDate;
     }
     
     @NotNull(message="Credit card number is required")
     @Length(min=16, max=16, message="Credit card number must 16 digits long")
     @Pattern(regex="\\d*", message="Credit card number must be numeric")
     public String getCreditCard()
     {
        return creditCard;
     }
  
     public void setCreditCard(String creditCard)
     {
        this.creditCard = creditCard;
     }
     
     @Transient
     public String getDescription()
     {
        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
        return hotel.getName() + 
              ", " + df.format( getCheckinDate() ) + 
              " to " + df.format( getCheckoutDate() );
     }
     
     public boolean isSmoking()
     {
        return smoking;
     }
  
     public void setSmoking(boolean smoking)
     {
        this.smoking = smoking;
     }
     
     public int getBeds()
     {
        return beds;
     }
  
     public void setBeds(int beds)
     {
        this.beds = beds;
     }
     @NotNull(message="Credit card name is required")
     @Length(min=3, max=70, message="Credit card name is required")
     public String getCreditCardName()
     {
        return creditCardName;
     }
  
     public void setCreditCardName(String creditCardName)
     {
        this.creditCardName = creditCardName;
     }
  
     public int getCreditCardExpiryMonth()
     {
        return creditCardExpiryMonth;
     }
  
     public void setCreditCardExpiryMonth(int creditCardExpiryMonth)
     {
        this.creditCardExpiryMonth = creditCardExpiryMonth;
     }
  
     public int getCreditCardExpiryYear()
     {
        return creditCardExpiryYear;
     }
  
     public void setCreditCardExpiryYear(int creditCardExpiryYear)
     {
        this.creditCardExpiryYear = creditCardExpiryYear;
     }
     
     @Override
     public String toString()
     {
        return "Booking(" + user + ","+ hotel + ")";
     }
  }
  
  
  
  1.1      date: 2007/02/18 19:57:59;  author: nrichards;  state: Exp;jboss-seam/examples/spring/src/org/jboss/seam/example/spring/Hotel.java
  
  Index: Hotel.java
  ===================================================================
  package org.jboss.seam.example.spring;
  
  import java.io.Serializable;
  import java.math.BigDecimal;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  
  import org.hibernate.validator.Length;
  import org.hibernate.validator.NotNull;
  
  @Entity
  public class Hotel 
      implements Serializable
  {
      private Long id;
      private String name;
      private String address;
      private String city;
      private String state;
      private String zip;
      private String country;
      private BigDecimal price;
  
      @Id @GeneratedValue
      public Long getId()
      {
          return id;
      }
      public void setId(Long id)
      {
          this.id = id;
      }
  
      @Length(max=50) @NotNull
      public String getName()
      {
          return name;
      }
      public void setName(String name)
      {
          this.name = name;
      }
  
      @Length(max=100) @NotNull
      public String getAddress()
      {
          return address;
      }
      public void setAddress(String address)
      {
          this.address = address;
      }
  
      @Length(max=40) @NotNull
      public String getCity()
      {
          return city;
      }
      public void setCity(String city)
      {
          this.city = city;
      }
  
      @Length(min=4, max=6) @NotNull
      public String getZip()
      {
          return zip;
      }
      public void setZip(String zip)
      {
          this.zip = zip;
      }
  
      @Length(min=2, max=10) @NotNull
      public String getState()
      {
          return state;
      }
      public void setState(String state)
      {
          this.state = state;
      }
  
      @Length(min=2, max=40) @NotNull
      public String getCountry()
      {
          return country;
      }
      public void setCountry(String country)
      {
          this.country = country;
      }
  
      @Column(precision=6, scale=2)
      public BigDecimal getPrice()
      {
          return price;
      }
      public void setPrice(BigDecimal price)
      {
          this.price = price;
      }
  
      @Override
      public String toString()
      {
          return "Hotel(" + name + "," + address + "," + city + "," + zip + ")";
      }
  }
  
  
  
  1.1      date: 2007/02/18 19:57:59;  author: nrichards;  state: Exp;jboss-seam/examples/spring/src/org/jboss/seam/example/spring/SeamBookingDao.java
  
  Index: SeamBookingDao.java
  ===================================================================
  package org.jboss.seam.example.spring;
  
  import java.util.List;
  
  import javax.persistence.EntityManager;
  
  import org.jboss.seam.annotations.In;
  import org.jboss.seam.annotations.Name;
  
  @Name("seamBookingDao")
  public class SeamBookingDao {
      
      @In
      EntityManager em;
      
      @SuppressWarnings("unchecked")
      public List<Hotel> getHotels() {        
          return em.createQuery("select h from Hotel h").getResultList();
      }
      
  }
  
  
  
  1.1      date: 2007/02/18 19:57:59;  author: nrichards;  state: Exp;jboss-seam/examples/spring/src/org/jboss/seam/example/spring/SpringBookingDao.java
  
  Index: SpringBookingDao.java
  ===================================================================
  package org.jboss.seam.example.spring;
  
  import java.util.List;
  
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.PersistenceException;
  
  import org.springframework.dao.DataAccessException;
  import org.springframework.orm.jpa.JpaCallback;
  import org.springframework.orm.jpa.JpaTemplate;
  
  public class SpringBookingDao {
      private JpaTemplate jpaTemplate;
  
      public void setEntityManagerFactory(EntityManagerFactory emf) {
          jpaTemplate = new JpaTemplate(emf);
      }
  
      @SuppressWarnings("unchecked")
      public List<Hotel> getHotels() 
          throws DataAccessException 
      {
          return (List<Hotel>) jpaTemplate.execute(new JpaCallback() {        
              public Object doInJpa(EntityManager em) 
                  throws PersistenceException 
              {
                  return em.createQuery("from Product as p where p.category = :category").getResultList();
              }
          });
      }
  }
  
  
  1.1      date: 2007/02/18 19:57:59;  author: nrichards;  state: Exp;jboss-seam/examples/spring/src/org/jboss/seam/example/spring/User.java
  
  Index: User.java
  ===================================================================
  package org.jboss.seam.example.spring;
  
  import static org.jboss.seam.ScopeType.SESSION;
  
  import java.io.Serializable;
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import org.hibernate.validator.Length;
  import org.hibernate.validator.NotNull;
  
  @Entity
  public class User 
      implements Serializable
  {
     private String username;
     private String password;
     private String name;
     
     public User(String name, String password, String username)
     {
        this.name = name;
        this.password = password;
        this.username = username;
     }
     
     public User() {}
  
     @NotNull
     @Length(max=100)
     public String getName()
     {
        return name;
     }
     public void setName(String name)
     {
        this.name = name;
     }
     
     @NotNull
     @Length(min=5, max=15)
     public String getPassword()
     {
        return password;
     }
     public void setPassword(String password)
     {
        this.password = password;
     }
     
     @Id
     @Length(min=5, max=15)
     public String getUsername()
     {
        return username;
     }
     public void setUsername(String username)
     {
        this.username = username;
     }
     
     @Override
     public String toString() 
     {
        return "User(" + username + ")";
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list