[jboss-cvs] JBossAS SVN: r96553 - in projects/snowdrop/trunk/documentation/samples/sportsclub: sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 19 02:09:28 EST 2009


Author: marius.bogoevici
Date: 2009-11-19 02:09:26 -0500 (Thu, 19 Nov 2009)
New Revision: 96553

Added:
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/BillingType.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/EquipmentType.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Invoice.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Membership.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Reservation.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/MembershipRepository.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/Repository.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateMembershipRepository.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateRepository.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/initializer/
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/initializer/DatabaseInitializer.java
Modified:
   projects/snowdrop/trunk/documentation/samples/sportsclub/database/db-setup.sql
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Account.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Equipment.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/AccountRepository.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/PersonRepository.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-ear/pom.xml
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-ejb/pom.xml
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateAccountRepository.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernatePersonRepository.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/resources/dao-context.xml
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/resources/hibernate/hibernate.cfg.xml
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/AccountCreate.java
   projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-web/src/main/webapp/createForm.xhtml
Log:
More additions to the Sport Club sample

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/database/db-setup.sql
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/database/db-setup.sql	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/database/db-setup.sql	2009-11-19 07:09:26 UTC (rev 96553)
@@ -45,7 +45,7 @@
 values ('Toronto', 'Ontario', '1 Yonge', 'Samuel', 'Vimes', '');
 
 insert into PUBLIC.PERSON (PERSON.CITY, PERSON.PROVINCEORSTATE, PERSON.STREETADDRESS, PERSON.FIRSTNAME, PERSON.LASTNAME, PERSON.MIDDLENAME)
-values ('Toronto', 'Ontario', '1 Bloor', 'Havelock', 'Vettinari', '');
+values ('Toronto', 'Ontario', '1 Bloor', 'Havelock', 'Vetinari', '');
 
 insert into PUBLIC.PERSON (PERSON.CITY, PERSON.PROVINCEORSTATE, PERSON.STREETADDRESS, PERSON.FIRSTNAME, PERSON.LASTNAME, PERSON.MIDDLENAME)
 values ('Toronto', 'Ontario', '1 Yonge', 'Sybil', 'Vimes', '');

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Account.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Account.java	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Account.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -2,10 +2,8 @@
 
 import org.jboss.snowdrop.samples.sportsclub.domain.entity.Person;
 
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.OneToOne;
+import javax.persistence.*;
+import java.util.Date;
 
 /**
  * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
@@ -19,7 +17,13 @@
    @OneToOne
    private Person subscriber;
 
+   private Date creationDate;
 
+   @ManyToOne
+   private Membership membership;
+
+   private BillingType billingType;
+
    public long getId()
    {
       return id;
@@ -34,4 +38,34 @@
    {
       this.subscriber = subscriber;
    }
+
+   public BillingType getBillingType()
+   {
+      return billingType;
+   }
+
+   public void setBillingType(BillingType billingType)
+   {
+      this.billingType = billingType;
+   }
+
+   public Date getCreationDate()
+   {
+      return creationDate;
+   }
+
+   public void setCreationDate(Date creationDate)
+   {
+      this.creationDate = creationDate;
+   }
+
+   public Membership getMembership()
+   {
+      return membership;
+   }
+
+   public void setMembership(Membership membership)
+   {
+      this.membership = membership;
+   }
 }

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/BillingType.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/BillingType.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/BillingType.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,13 @@
+package org.jboss.snowdrop.samples.sportsclub.domain.entity;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public enum BillingType
+{
+   MONTHLY,
+
+   BIWEEKLY,
+
+   WEEKLY
+}

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Equipment.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Equipment.java	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Equipment.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -14,10 +14,35 @@
    @Id
    private long id;
 
-   @Basic
    private String name;
 
-   @Basic
    private String description;
 
+   private EquipmentType equipmentType;
+
+
+   public long getId()
+   {
+      return id;
+   }
+
+   public String getDescription()
+   {
+      return description;
+   }
+
+   public void setDescription(String description)
+   {
+      this.description = description;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
 }

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/EquipmentType.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/EquipmentType.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/EquipmentType.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,11 @@
+package org.jboss.snowdrop.samples.sportsclub.domain.entity;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public enum EquipmentType
+{
+   THREADMILL,
+   STEPPER,
+   COURT
+}

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Invoice.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Invoice.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Invoice.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,60 @@
+package org.jboss.snowdrop.samples.sportsclub.domain.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import java.math.BigDecimal;
+import java.sql.Date;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+ at Entity
+public class Invoice
+{
+
+   @Id
+   private long id;
+
+   @ManyToOne
+   private Account account;
+
+   private Date date;
+
+   private BigDecimal amount;
+
+   public long getId()
+   {
+      return id;
+   }
+
+   public Account getAccount()
+   {
+      return account;
+   }
+
+   public void setAccount(Account account)
+   {
+      this.account = account;
+   }
+
+   public BigDecimal getAmount()
+   {
+      return amount;
+   }
+
+   public void setAmount(BigDecimal amount)
+   {
+      this.amount = amount;
+   }
+
+   public Date getDate()
+   {
+      return date;
+   }
+
+   public void setDate(Date date)
+   {
+      this.date = date;
+   }
+}

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Membership.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Membership.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Membership.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,54 @@
+package org.jboss.snowdrop.samples.sportsclub.domain.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import java.math.BigDecimal;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+ at Entity
+public class Membership
+{
+
+   @Id
+   private String code;
+
+   private BigDecimal annualFee;
+
+   private boolean active;
+
+   private Membership()
+   {}
+
+   public Membership(String code)
+   {
+      this.code = code;
+   }
+
+   public String getCode()
+   {
+      return code;
+   }
+
+   public BigDecimal getAnnualFee()
+   {
+      return annualFee;
+   }
+
+   public void setAnnualFee(BigDecimal annualFee)
+   {
+      this.annualFee = annualFee;
+   }
+
+   public boolean isActive()
+   {
+      return active;
+   }
+
+   public void setActive(boolean active)
+   {
+      this.active = active;
+   }
+}

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Reservation.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Reservation.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Reservation.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,73 @@
+package org.jboss.snowdrop.samples.sportsclub.domain.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import java.util.Date;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+ at Entity
+public class Reservation
+{
+
+   @Id
+   private long id;
+
+   private Date from;
+
+   private Date to;
+
+   @ManyToOne
+   private Equipment equipment;
+
+   @ManyToOne
+   private Account account;
+
+
+   public long getId()
+   {
+      return id;
+   }
+
+   public Account getAccount()
+   {
+      return account;
+   }
+
+   public void setAccount(Account account)
+   {
+      this.account = account;
+   }
+
+   public Equipment getEquipment()
+   {
+      return equipment;
+   }
+
+   public void setEquipment(Equipment equipment)
+   {
+      this.equipment = equipment;
+   }
+
+   public Date getFrom()
+   {
+      return from;
+   }
+
+   public void setFrom(Date from)
+   {
+      this.from = from;
+   }
+
+   public Date getTo()
+   {
+      return to;
+   }
+
+   public void setTo(Date to)
+   {
+      this.to = to;
+   }
+}

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/AccountRepository.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/AccountRepository.java	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/AccountRepository.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -7,9 +7,7 @@
 /**
  * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
  */
-public interface AccountRepository
+public interface AccountRepository extends Repository<Account, Integer>
 {
    List<Account> findByPersonName(String name);
-
-   void save(Account account);
 }

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/MembershipRepository.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/MembershipRepository.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/MembershipRepository.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,13 @@
+package org.jboss.snowdrop.samples.sportsclub.domain.repository;
+
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Membership;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public interface MembershipRepository extends Repository<Membership, Integer>
+{
+   List<Membership> findAllActiveMembershipTypes();
+}

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/PersonRepository.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/PersonRepository.java	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/PersonRepository.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -5,7 +5,7 @@
 /**
  * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
  */
-public interface PersonRepository
+public interface PersonRepository extends Repository<Person, Integer>
 {
-   void save(Person person);
+
 }

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/Repository.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/Repository.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/Repository.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,17 @@
+package org.jboss.snowdrop.samples.sportsclub.domain.repository;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public interface Repository<T, I>
+{
+   T findById(I id);
+
+   void save(T object);
+
+   void delete(T object);
+
+   Collection<T> findAll();
+}

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-ear/pom.xml
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-ear/pom.xml	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-ear/pom.xml	2009-11-19 07:09:26 UTC (rev 96553)
@@ -26,6 +26,18 @@
             <type>war</type>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.jboss.snowdrop.samples.sportsclub</groupId>
+            <artifactId>sportsclub-domain</artifactId>
+            <type>jar</type>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.snowdrop.samples.sportsclub</groupId>
+            <artifactId>sportsclub-hibernate-dao</artifactId>
+            <type>jar</type>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
     <build>
@@ -45,6 +57,14 @@
                             <artifactId>sportsclub-web</artifactId>
                             <contextRoot>/sportsclub</contextRoot>
                         </webModule>
+                        <module>
+                            <groupId>org.jboss.snowdrop.samples.sportsclub</groupId>
+                            <artifactId>sportsclub-domain</artifactId>
+                        </module>
+                        <module>
+                            <groupId>org.jboss.snowdrop.samples.sportsclub</groupId>
+                            <artifactId>sportsclub-hibernate-dao</artifactId>
+                        </module>
                     </modules>
                 </configuration>
             </plugin>

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-ejb/pom.xml
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-ejb/pom.xml	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-ejb/pom.xml	2009-11-19 07:09:26 UTC (rev 96553)
@@ -17,13 +17,15 @@
         <dependency>
             <groupId>org.jboss.snowdrop.samples.sportsclub</groupId>
             <artifactId>sportsclub-domain</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
         </dependency>
 
          <dependency>
             <groupId>org.jboss.snowdrop.samples.sportsclub</groupId>
             <artifactId>sportsclub-hibernate-dao</artifactId>
             <version>${project.version}</version>
-            <scope>runtime</scope>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateAccountRepository.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateAccountRepository.java	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateAccountRepository.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -11,14 +11,12 @@
 /**
  * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
  */
-public class HibernateAccountRepository implements AccountRepository
+public class HibernateAccountRepository extends HibernateRepository<Account, Integer> implements AccountRepository
 {
 
-   private SessionFactory sessionFactory;
-
-   public void setSessionFactory(SessionFactory sessionFactory)
+   public HibernateAccountRepository()
    {
-      this.sessionFactory = sessionFactory;
+      super(Account.class);
    }
 
    public List<Account> findByPersonName(String name)
@@ -30,9 +28,4 @@
       query.setString("name", "%" + name + "%");
       return (List<Account>)query.list();
    }
-
-   public void save(Account account)
-   {
-      this.sessionFactory.getCurrentSession().saveOrUpdate(account);
-   }
 }

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateMembershipRepository.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateMembershipRepository.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateMembershipRepository.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,25 @@
+package org.jboss.snowdrop.samples.stayfit.dao.hibernate;
+
+import org.hibernate.Query;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Membership;
+import org.jboss.snowdrop.samples.sportsclub.domain.repository.MembershipRepository;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public class HibernateMembershipRepository extends HibernateRepository<Membership, Integer> implements MembershipRepository
+{
+
+   public HibernateMembershipRepository()
+   {
+      super(Membership.class);
+   }
+
+   public List<Membership> findAllActiveMembershipTypes()
+   {
+      Query query = getCurrentSession().createQuery("from Membership m where m.active");
+      return query.list();
+   }
+}

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernatePersonRepository.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernatePersonRepository.java	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernatePersonRepository.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -7,17 +7,12 @@
 /**
  * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
  */
-public class HibernatePersonRepository implements PersonRepository
+public class HibernatePersonRepository extends HibernateRepository<Person, Integer> implements PersonRepository
 {
-   private SessionFactory sessionFactory;
 
-   public void setSessionFactory(SessionFactory sessionFactory)
+   public HibernatePersonRepository()
    {
-      this.sessionFactory = sessionFactory;
+      super(Person.class);
    }
 
-   public void save(Person person)
-   {
-      sessionFactory.getCurrentSession().saveOrUpdate(person);
-   }
 }

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateRepository.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateRepository.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/HibernateRepository.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,54 @@
+package org.jboss.snowdrop.samples.stayfit.dao.hibernate;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.jboss.snowdrop.samples.sportsclub.domain.repository.Repository;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public class HibernateRepository<T, I extends Serializable> implements Repository<T, I>
+{
+   protected SessionFactory sessionFactory;
+
+   Class<T> clazz;
+
+   public HibernateRepository(Class<T> clazz)
+   {
+      this.clazz = clazz;
+   }
+
+   public void setSessionFactory(SessionFactory sessionFactory)
+   {
+      this.sessionFactory = sessionFactory;
+   }
+
+   protected Session getCurrentSession()
+   {
+      return this.sessionFactory.getCurrentSession();
+   }
+
+   public T findById(I id)
+   {
+      return (T)getCurrentSession().get(clazz, id);
+   }
+
+   public void save(T object)
+   {
+      getCurrentSession().saveOrUpdate(object);
+   }
+
+   public void delete(T object)
+   {
+      getCurrentSession().delete(object);
+   }
+
+   public Collection<T> findAll()
+   {
+      return (Collection<T>)getCurrentSession().createCriteria(clazz).list();
+   }
+
+}

Added: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/initializer/DatabaseInitializer.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/initializer/DatabaseInitializer.java	                        (rev 0)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/stayfit/dao/hibernate/initializer/DatabaseInitializer.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -0,0 +1,109 @@
+package org.jboss.snowdrop.samples.stayfit.dao.hibernate.initializer;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.*;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+
+import javax.annotation.PostConstruct;
+import java.lang.reflect.Member;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public class DatabaseInitializer implements InitializingBean
+{
+
+   private SessionFactory sessionFactory;
+
+   private PlatformTransactionManager transactionManager;
+
+   public void setSessionFactory(SessionFactory sessionFactory)
+   {
+      this.sessionFactory = sessionFactory;
+   }
+
+   public void setTransactionManager(PlatformTransactionManager transactionManager)
+   {
+      this.transactionManager = transactionManager;
+   }
+
+   public void afterPropertiesSet() throws Exception
+   {
+      new TransactionTemplate(transactionManager).execute(new TransactionCallback()
+      {
+         public Object doInTransaction(TransactionStatus status)
+         {
+            Session session = sessionFactory.getCurrentSession();
+
+            Membership silverMembership = createMembership("SILVER", "600.0");
+            save(session, silverMembership);
+            Membership goldMembership = createMembership("GOLD", "900.0");
+            save(session, goldMembership);
+            Membership platinumMembership = createMembership("PLATINUM", "1200.0");
+            save(session, platinumMembership);
+
+
+            Person person = createPerson("Samuel", "Vimes", "1 Yonge", "Toronto", "Ontario", "Canada");
+            save(session, person);
+            save(session,createAccount(silverMembership, BillingType.MONTHLY, person));
+
+            person = createPerson("Sibyl", "Vimes", "1 Yonge", "Toronto", "Ontario", "Canada");
+            save(session,person);
+            save(session, createAccount(goldMembership, BillingType.WEEKLY, person));
+
+            person = createPerson("Havelock", "Vetinari", "1 Bloor", "Toronto", "Ontario", "Canada");
+            save(session, person);
+            save(session, createAccount(goldMembership, BillingType.BIWEEKLY, person));
+
+            return null;
+         }
+      });
+   }
+
+   private static void save(Session session, Object entity)
+   {
+      session.save(entity);
+      session.flush();
+   }
+
+   private static Account createAccount(Membership silverMembership, BillingType billingType, Person person)
+   {
+      Account account = new Account();
+      account.setSubscriber(person);
+      account.setCreationDate(new Date());
+      account.setBillingType(billingType);
+      account.setMembership(silverMembership);
+      return account;
+   }
+
+   private static Person createPerson(String firstname, String lastname, String street, String city, String province, String country)
+   {
+      Person person = new Person();
+      person.setName(new Name());
+      person.setAddress(new Address());
+
+      person.getName().setFirstName(firstname);
+      person.getName().setLastName(lastname);
+      person.getAddress().setStreetAddress(street);
+      person.getAddress().setCity(city);
+      person.getAddress().setProvinceOrState(province);
+      person.getAddress().setCountry(country);
+      person.getAddress().setPostalCode("H0H0H0");
+      return person;
+   }
+
+   private static Membership createMembership(String code, String amount)
+   {
+      Membership membership = new Membership(code);
+      membership.setActive(true);
+      membership.setAnnualFee(new BigDecimal(amount));
+      return membership;
+   }
+}

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/resources/dao-context.xml
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/resources/dao-context.xml	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/resources/dao-context.xml	2009-11-19 07:09:26 UTC (rev 96553)
@@ -1,31 +1,31 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:jee="http://www.springframework.org/schema/jee"
+       xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/jee
-       http://www.springframework.org/schema/jee/spring-jee.xsd">
+       http://www.springframework.org/schema/jee/spring-jee.xsd
+       http://www.springframework.org/schema/tx
+       http://www.springframework.org/schema/tx/spring-tx.xsd">
 
     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
         <property name="dataSource" ref="stayFitDS"/>
         <property name="configLocation" value="classpath:/hibernate/hibernate.cfg.xml"/>
         <property name="hibernateProperties">
             <value>
-                hibernate.hbm2ddl.auto=validate
+                hibernate.hbm2ddl.auto=create-drop
             </value>
         </property>
-        <!--<property name="annotatedClasses">-->
-           <!--<list>-->
-               <!--<value>org.jboss.snowdrop.samples.sportsclub.domain.entity.Account</value>-->
-               <!--<value>org.jboss.snowdrop.samples.sportsclub.domain.entity.Person</value>-->
-               <!--<value>org.jboss.snowdrop.samples.sportsclub.domain.entity.Name</value>-->
-               <!--<value>org.jboss.snowdrop.samples.sportsclub.domain.entity.Address</value>-->
-               <!--<value>org.jboss.snowdrop.samples.sportsclub.domain.entity.Equipment</value>-->
-           <!--</list>-->
-        <!--</property>-->
     </bean>
 
+    <bean class="org.jboss.snowdrop.samples.stayfit.dao.hibernate.initializer.DatabaseInitializer">
+        <property name="sessionFactory" ref="sessionFactory"/>
+        <property name="transactionManager" ref="transactionManager"/>
+
+    </bean>
+
     <bean id="accountRepository" class="org.jboss.snowdrop.samples.stayfit.dao.hibernate.HibernateAccountRepository">
         <property name="sessionFactory" ref="sessionFactory"/>
     </bean>
@@ -34,6 +34,12 @@
         <property name="sessionFactory" ref="sessionFactory"/>
     </bean>
 
+    <bean id="membershipRepository" class="org.jboss.snowdrop.samples.stayfit.dao.hibernate.HibernateMembershipRepository">
+        <property name="sessionFactory" ref="sessionFactory"/>
+    </bean>
+
     <jee:jndi-lookup jndi-name="java:/StayFitDS" id="stayFitDS"/>
 
+    <tx:jta-transaction-manager/>
+
 </beans>
\ No newline at end of file

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/resources/hibernate/hibernate.cfg.xml
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/resources/hibernate/hibernate.cfg.xml	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-hibernate-dao/src/main/resources/hibernate/hibernate.cfg.xml	2009-11-19 07:09:26 UTC (rev 96553)
@@ -10,12 +10,6 @@
     <!-- hibernate dialect -->
     <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
 
-
-
-    <!-- Automatic schema creation (begin) -->
-    <property name="hibernate.hbm2ddl.auto">create-drop</property>
-    <!-- Automatic schema creation (end) -->
-
     <!-- Simple memory-only cache -->
     <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
 
@@ -33,6 +27,7 @@
     <mapping class="org.jboss.snowdrop.samples.sportsclub.domain.entity.Equipment"/>
     <mapping class="org.jboss.snowdrop.samples.sportsclub.domain.entity.Name"/>
     <mapping class="org.jboss.snowdrop.samples.sportsclub.domain.entity.Person"/>
+    <mapping class="org.jboss.snowdrop.samples.sportsclub.domain.entity.Membership"/>
 
 </session-factory>
 </hibernate-configuration>
\ No newline at end of file

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/AccountCreate.java
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/AccountCreate.java	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/AccountCreate.java	2009-11-19 07:09:26 UTC (rev 96553)
@@ -83,7 +83,7 @@
       return account;
    }
 
-   public void create()
+   public String create()
    {
       Person person = new Person();
       person.setAddress(new Address());
@@ -98,6 +98,7 @@
       person.getAddress().setStreetAddress(address);
 
 
-      subscriptionService.createAccountForPerson(person);
+      account = subscriptionService.createAccountForPerson(person);
+      return "success";
    }
 }

Modified: projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-web/src/main/webapp/createForm.xhtml
===================================================================
--- projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-web/src/main/webapp/createForm.xhtml	2009-11-19 07:05:31 UTC (rev 96552)
+++ projects/snowdrop/trunk/documentation/samples/sportsclub/sportsclub-web/src/main/webapp/createForm.xhtml	2009-11-19 07:09:26 UTC (rev 96553)
@@ -6,6 +6,7 @@
 	xmlns:a4j="http://richfaces.org/a4j"
 	template="layout/template.xhtml">
 	<ui:define name="content">
+        <rich:panel>
         <h:form>
         First name: <h:inputText value="#{accountCreate.firstName}" label="First name"/>
         Last name: <h:inputText value="#{accountCreate.lastName}" label="Last name"/><p/>
@@ -14,5 +15,6 @@
         Province: <h:inputText value="#{accountCreate.provinceOrState}" label="ProvinceOrState"/><p/>
         <h:commandButton value="Save" action="#{accountCreate.create}" />
         </h:form>
+        </rich:panel>
 	</ui:define>
 </ui:composition>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list