[seam-commits] Seam SVN: r10713 - in examples/trunk/booking: ejb-jar and 13 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Apr 29 02:33:46 EDT 2009
Author: dan.j.allen
Date: 2009-04-29 02:33:45 -0400 (Wed, 29 Apr 2009)
New Revision: 10713
Added:
examples/trunk/booking/ejb-jar/
examples/trunk/booking/ejb-jar/pom.xml
examples/trunk/booking/ejb-jar/src/
examples/trunk/booking/ejb-jar/src/main/
examples/trunk/booking/ejb-jar/src/main/java/
examples/trunk/booking/ejb-jar/src/main/java/org/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/binding/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Booking.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/User.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgent.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearch.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java
examples/trunk/booking/ejb-jar/src/main/resources/
examples/trunk/booking/ejb-jar/src/main/resources/META-INF/
examples/trunk/booking/ejb-jar/src/main/resources/META-INF/beans.xml
examples/trunk/booking/ejb-jar/src/main/resources/META-INF/persistence.xml
examples/trunk/booking/ejb-jar/src/main/resources/import.sql
examples/trunk/booking/ejb-jar/src/test/
examples/trunk/booking/ejb-jar/src/test/java/
Log:
recover from SVN move disaster
Property changes on: examples/trunk/booking/ejb-jar
___________________________________________________________________
Name: svn:ignore
+ target
Added: examples/trunk/booking/ejb-jar/pom.xml
===================================================================
--- examples/trunk/booking/ejb-jar/pom.xml (rev 0)
+++ examples/trunk/booking/ejb-jar/pom.xml 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,281 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.seam.examples</groupId>
+ <artifactId>seam-booking</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>seam-booking-ejb</artifactId>
+ <packaging>ejb</packaging>
+ <name>Seam Booking Example (EJB module)</name>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/resources/test-suite.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <classifier>jdk15</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>${webbeans.groupId}</groupId>
+ <artifactId>webbeans-core-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.test-harness</groupId>
+ <artifactId>jboss-test-harness</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>${seam.groupId}</groupId>
+ <artifactId>seam-faces</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>${webbeans.groupId}</groupId>
+ <artifactId>jsr299-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>${webbeans.groupId}</groupId>
+ <artifactId>webbeans-logging</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>${webbeans.groupId}</groupId>
+ <artifactId>webbeans-logger</artifactId>
+ <version>1.0.0-SNAPSHOT</version> <!-- TODO push to version-matrix -->
+ </dependency>
+
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>integration-tests</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-integration-test-dependencies</id>
+ <phase>generate-test-sources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <stripVersion>true</stripVersion>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jboss.test-harness</groupId>
+ <artifactId>jboss-test-harness</artifactId>
+ <version>1.0.0-SNAPSHOT</version> <!-- inheritence isn't working here -->
+ <overWrite>true</overWrite>
+ <outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
+ </artifactItem>
+ <!--
+ <artifactItem>
+ <groupId>javax.el</groupId>
+ <artifactId>el-ri</artifactId>
+ <overWrite>true</overWrite>
+ <outputDirectory>${project.build.directory}/dependency/lib</outputDirectory>
+ </artifactItem>
+ -->
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/resources/test-suite.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ <systemProperties>
+ <property>
+ <name>jboss.home</name>
+ <value>${jboss.home}</value>
+ </property>
+ <property>
+ <name>org.jboss.testharness.standalone</name>
+ <value>false</value>
+ </property>
+ <property>
+ <name>org.jboss.testharness.container.extraConfigurationDir</name>
+ <value>../../</value>
+ </property>
+ <property>
+ <name>org.jboss.testharness.container.forceRestart</name>
+ <value>false</value>
+ </property>
+ <property>
+ <name>org.jboss.testharness.runIntegrationTests</name>
+ <value>true</value>
+ </property>
+ <property>
+ <name>org.jboss.testharness.libraryDirectory</name>
+ <value>${project.build.directory}/dependency/lib</value>
+ </property>
+ <property>
+ <name>org.jboss.testharness.outputDirectory</name>
+ <value>${project.build.directory}</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+
+ <!--
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <version>3.1.0-Alpha1</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>jboss-jaxrpc</artifactId>
+ <groupId>jbossws</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jboss-transaction-api</artifactId>
+ <groupId>org.jboss.javaee</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jboss-jaxrpc</artifactId>
+ <groupId>jboss.jbossws</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ -->
+
+ <dependency>
+ <groupId>org.jboss.test-harness</groupId>
+ <artifactId>jboss-test-harness-jboss-as-50</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+ </profile>
+
+ <profile>
+ <id>dump-test-artifacts</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-test-artifacts</id>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>org.jboss.testharness.api.TCK</mainClass>
+ <classpathScope>test</classpathScope>
+ <systemProperties>
+ <systemProperty>
+ <key>dumpArtifacts</key>
+ <value>true</value>
+ </systemProperty>
+ <systemProperty>
+ <key>org.jboss.testharness.testPackage</key>
+ <value>${project.groupId}</value>
+ </systemProperty>
+ <systemProperty>
+ <key>org.jboss.testharness.outputDirectory</key>
+ <value>${project.build.directory}/test-artifacts</value>
+ </systemProperty>
+ <systemProperty>
+ <key>org.jboss.testharness.libraryDirectory</key>
+ <value>${project.build.directory}/dependency/lib</value>
+ </systemProperty>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ </profiles>
+</project>
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Booking.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Booking.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Booking.java 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,229 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.model;
+
+import static javax.persistence.TemporalType.DATE;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.text.DateFormat;
+import java.util.Date;
+
+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 javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+/**
+ * <p><strong>Booking</strong> is the model/entity class that represents a hotel
+ * booking.</p>
+ *
+ * @author Gavin King
+ * @author Dan Allen
+ */
+public
+ at Entity
+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
+ @Temporal(DATE)
+ public Date getCheckinDate()
+ {
+ return checkinDate;
+ }
+
+ public void setCheckinDate(Date datetime)
+ {
+ this.checkinDate = datetime;
+ }
+
+ @NotNull
+ @ManyToOne
+ public Hotel getHotel()
+ {
+ return hotel;
+ }
+
+ public void setHotel(Hotel hotel)
+ {
+ this.hotel = hotel;
+ }
+
+ @NotNull
+ @ManyToOne
+ public User getUser()
+ {
+ return user;
+ }
+
+ public void setUser(User user)
+ {
+ this.user = user;
+ }
+
+ @NotNull
+ @Temporal(TemporalType.DATE)
+ public Date getCheckoutDate()
+ {
+ return checkoutDate;
+ }
+
+ public void setCheckoutDate(Date checkoutDate)
+ {
+ this.checkoutDate = checkoutDate;
+ }
+
+ @NotNull(message = "Credit card number is required")
+ @Size(min = 16, max = 16, message = "Credit card number must 16 digits long")
+ @Pattern(regexp = "^\\d*$", message = "Credit card number must be numeric")
+ public String getCreditCard()
+ {
+ return creditCard;
+ }
+
+ public void setCreditCard(String creditCard)
+ {
+ this.creditCard = creditCard;
+ }
+
+ 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")
+ @Size(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;
+ }
+
+ @Transient
+ public String getDescription()
+ {
+ DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
+ return hotel == null ? null : hotel.getName() +
+ ", " + df.format(getCheckinDate()) +
+ " to " + df.format(getCheckoutDate());
+ }
+
+ @Transient
+ public BigDecimal getTotal()
+ {
+ return hotel.getPrice().multiply(new BigDecimal(getNights()));
+ }
+
+ @Transient
+ public int getNights()
+ {
+ return (int) (checkoutDate.getTime() - checkinDate.getTime()) / 1000 / 60 / 60 / 24;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Booking(" + user + ", " + hotel + ")";
+ }
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.model;
+
+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 javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * <p><strong>Hotel</strong> is the model/entity class that represents a hotel.</p>
+ *
+ * @author Gavin King
+ * @author Dan Allen
+ */
+public
+ at Entity
+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;
+ }
+
+ @Size(max = 50)
+ @NotNull
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ @Size(max = 100)
+ @NotNull
+ public String getAddress()
+ {
+ return address;
+ }
+
+ public void setAddress(String address)
+ {
+ this.address = address;
+ }
+
+ @Size(max = 40)
+ @NotNull
+ public String getCity()
+ {
+ return city;
+ }
+
+ public void setCity(String city)
+ {
+ this.city = city;
+ }
+
+ @Size(min = 4, max = 6)
+ @NotNull
+ public String getZip()
+ {
+ return zip;
+ }
+
+ public void setZip(String zip)
+ {
+ this.zip = zip;
+ }
+
+ @Size(min = 2, max = 10)
+ @NotNull
+ public String getState()
+ {
+ return state;
+ }
+
+ public void setState(String state)
+ {
+ this.state = state;
+ }
+
+ @Size(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 + ")";
+ }
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/User.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/User.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/User.java 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+/**
+ * <p><strong>User</strong> is the model/entity class that represents a customer
+ * who may book a hotel.</p>
+ *
+ * @author Gavin King
+ * @author Dan Allen
+ */
+public
+ at Entity
+ at Table(name = "Customer")
+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
+ @Size(max = 100)
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ @NotNull
+ @Size(min = 5, max = 15)
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ @Id
+ @Size(min = 4, max = 15)
+ @Pattern(regexp = "^\\w*$", message = "not a valid username")
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public void setUsername(String username)
+ {
+ this.username = username;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "User(" + username + ")";
+ }
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgent.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgent.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgent.java 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.session;
+
+import javax.ejb.Local;
+import org.jboss.seam.examples.booking.model.Booking;
+import org.jboss.seam.examples.booking.model.Hotel;
+
+/**
+ * @author Dan Allen
+ */
+public
+ at Local
+interface BookingAgent
+{
+ void selectHotel(Hotel hotel);
+
+ void bookHotel();
+
+ void validateBooking();
+
+ void cancel();
+
+ void confirm();
+
+ Hotel getHotelSelection();
+
+ Booking getBooking();
+
+ boolean isBookingValid();
+
+ void destroy();
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.session;
+
+import java.util.Calendar;
+import static javax.persistence.PersistenceContextType.EXTENDED;
+import javax.annotation.Named;
+import javax.context.Conversation;
+import javax.context.ConversationScoped;
+import javax.context.RequestScoped;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.seam.examples.booking.model.Booking;
+import org.jboss.seam.examples.booking.model.Hotel;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.international.StatusMessages;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logger;
+
+public
+ at Named("bookingAgent")
+ at Stateful
+ at ConversationScoped
+class BookingAgentBean implements BookingAgent
+{
+ //private @Logger Log log;
+
+ @PersistenceContext(type = EXTENDED) EntityManager em;
+
+ @Current Conversation conversation;
+
+ @Current StatusMessages statusMessages;
+
+ private Hotel hotelSelection;
+
+ private Booking booking;
+
+ private boolean bookingValid;
+
+ public void selectHotel(Hotel hotel)
+ {
+ conversation.begin();
+ // get a fresh reference that's managed by the conversational persistence context
+ hotelSelection = em.find(Hotel.class, hotel.getId());
+ }
+
+ public void bookHotel()
+ {
+ // FIXME use current user
+ User user = em.find(User.class, "dan");
+ booking = new Booking(hotelSelection, user);
+ // push logic into Booking?
+ Calendar calendar = Calendar.getInstance();
+ booking.setCheckinDate(calendar.getTime());
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
+ booking.setCheckoutDate(calendar.getTime());
+ hotelSelection = null;
+ statusMessages.add("You've initiated a booking at {0}.", booking.getHotel().getName());
+ }
+
+ public void validateBooking()
+ {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
+ if (booking.getCheckinDate().before(calendar.getTime()))
+ {
+ statusMessages.addToControl("booking:checkinDate:input", "Check in date must be a future date");
+ bookingValid = false;
+ }
+ else if (!booking.getCheckinDate().before(booking.getCheckoutDate()))
+ {
+ statusMessages.addToControl("booking:checkoutDate:input", "Check out date must be after check in date");
+ bookingValid = false;
+ }
+ else
+ {
+ bookingValid = true;
+ }
+ }
+
+ public void confirm()
+ {
+ em.persist(booking);
+ //log.info("New booking confirmed for...");
+ statusMessages.add("You're booked!");
+ conversation.end();
+ }
+
+ public void cancel()
+ {
+ booking = null;
+ hotelSelection = null;
+ conversation.end();
+ }
+
+ public
+ @Produces
+ @Named
+ @ConversationScoped
+ Booking getBooking()
+ {
+ return booking;
+ }
+
+ public
+ @Produces
+ @Named("hotel")
+ @RequestScoped
+ Hotel getHotelSelection()
+ {
+ return booking != null ? booking.getHotel() : hotelSelection;
+ }
+
+ public boolean isBookingValid()
+ {
+ return bookingValid;
+ }
+
+ @Remove
+ public void destroy()
+ {
+ }
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearch.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearch.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearch.java 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.session;
+
+import java.util.List;
+import javax.ejb.Local;
+import org.jboss.seam.examples.booking.model.Hotel;
+
+public
+ at Local
+interface HotelSearch
+{
+ public void find();
+
+ public void previousPage();
+
+ public void nextPage();
+
+ public List<Hotel> getHotels();
+
+ public boolean isNextPageAvailable();
+
+ public boolean isPreviousPageAvailable();
+
+ public void destroy();
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.session;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Named;
+import javax.context.SessionScoped;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.inject.manager.Manager;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.seam.examples.booking.model.Hotel;
+
+public
+ at Named("hotelSearch")
+ at Stateful
+ at SessionScoped
+class HotelSearchBean implements HotelSearch
+{
+ @Current Manager manager;
+ @Current SearchCriteria criteria;
+
+ private @PersistenceContext EntityManager em;
+ private boolean nextPageAvailable = false;
+ private List<Hotel> hotels = new ArrayList<Hotel>();
+
+ public void find()
+ {
+ criteria.firstPage();
+ queryHotels(criteria);
+ }
+
+ public void nextPage()
+ {
+ criteria.nextPage();
+ queryHotels(criteria);
+ }
+
+ public void previousPage()
+ {
+ criteria.previousPage();
+ queryHotels(criteria);
+ }
+
+ public
+ @Produces
+ @Named
+ //@RequestScoped // if enabled, variable doesn't get updated after the action is executed w/o a redirect
+ List<Hotel> getHotels()
+ {
+ return hotels;
+ }
+
+ public boolean isNextPageAvailable()
+ {
+ return nextPageAvailable;
+ }
+
+ public boolean isPreviousPageAvailable()
+ {
+ return criteria.getPage() > 0;
+ }
+
+ @Remove
+ public void destroy()
+ {
+ }
+
+ private void queryHotels(SearchCriteria criteria)
+ {
+ List<Hotel> results = 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").
+ setParameter("pattern", criteria.getSearchPattern()).setMaxResults(criteria.getPageSize() + 1).setFirstResult(criteria.getPage() * criteria.getPageSize()).
+ getResultList();
+
+ System.out.println("Found " + results.size() + " hotels");
+ nextPageAvailable = results.size() > criteria.getPageSize();
+ if (nextPageAvailable)
+ {
+ hotels = new ArrayList<Hotel>(results.subList(0, criteria.getPageSize()));
+ }
+ else
+ {
+ hotels = results;
+ }
+ }
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.session;
+
+import java.io.Serializable;
+import javax.annotation.Named;
+import javax.context.SessionScoped;
+
+public
+ at Named
+ at SessionScoped
+class SearchCriteria implements Serializable
+{
+ private static final char SQL_WILDCARD_CHAR = '%';
+ private static final String SQL_WILDCARD_STR = String.valueOf(SQL_WILDCARD_CHAR);
+ private static final String REPEAT_SQL_WIDCARD_REGEX = SQL_WILDCARD_STR + "+";
+ private static final char HUMAN_WILDCARD_CHAR = '*';
+
+ private String searchString = "";
+ private int pageSize = 5;
+ private int page = 0;
+
+ public String getSearchPattern()
+ {
+ if (searchString == null || searchString.length() == 0)
+ {
+ return SQL_WILDCARD_STR;
+ }
+
+ StringBuilder pattern = new StringBuilder();
+ pattern.append(searchString.toLowerCase().replace(HUMAN_WILDCARD_CHAR, SQL_WILDCARD_CHAR).replaceAll(REPEAT_SQL_WIDCARD_REGEX, SQL_WILDCARD_STR));
+ if (pattern.length() == 0 || pattern.charAt(0) != SQL_WILDCARD_CHAR)
+ {
+ pattern.insert(0, SQL_WILDCARD_CHAR);
+ }
+ if (pattern.length() > 1 && pattern.charAt(pattern.length() - 1) != SQL_WILDCARD_CHAR)
+ {
+ pattern.append(SQL_WILDCARD_CHAR);
+ }
+ return pattern.toString();
+ }
+
+ public int getPage()
+ {
+ return page;
+ }
+
+ public void setPage(int page)
+ {
+ this.page = page;
+ }
+
+ public int getPageSize()
+ {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize)
+ {
+ this.pageSize = pageSize;
+ }
+
+ public String getSearchString()
+ {
+ return searchString;
+ }
+
+ public void setSearchString(String searchString)
+ {
+ this.searchString = (searchString != null ? searchString.trim() : null);
+ }
+
+ public void nextPage()
+ {
+ page++;
+ }
+
+ public void previousPage()
+ {
+ if (page > 0)
+ {
+ page--;
+ }
+ }
+
+ public void firstPage()
+ {
+ page = 0;
+ }
+}
Added: examples/trunk/booking/ejb-jar/src/main/resources/META-INF/beans.xml
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/resources/META-INF/beans.xml (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/resources/META-INF/beans.xml 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,8 @@
+<Beans xmlns="urn:java:ee"
+ xmlns:faces="urn:java:org.jboss.seam.faces">
+ <Deploy>
+ <Standard/>
+ <Production/>
+ <faces:Faces/>
+ </Deploy>
+</Beans>
Added: examples/trunk/booking/ejb-jar/src/main/resources/META-INF/persistence.xml
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/resources/META-INF/persistence.xml (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/resources/META-INF/persistence.xml 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+ version="1.0">
+ <persistence-unit name="booking">
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <jta-data-source>bookingDatasource</jta-data-source>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ <property name="hibernate.show_sql" value="true"/>
+ <!-- These are the default for JBoss EJB 3, but not for Hibernate EntityManager -->
+ <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
+ <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
+ </properties>
+ </persistence-unit>
+</persistence>
Added: examples/trunk/booking/ejb-jar/src/main/resources/import.sql
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/resources/import.sql (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/resources/import.sql 2009-04-29 06:33:45 UTC (rev 10713)
@@ -0,0 +1,24 @@
+insert into Customer (username, password, name) values ('gavin', 'mexico', 'Gavin King')
+insert into Customer (username, password, name) values ('pete', 'edinburgh', 'Pete Muir')
+insert into Customer (username, password, name) values ('shane', 'brisbane', 'Shane Bryzak')
+insert into Customer (username, password, name) values ('dan', 'maryland', 'Dan Allen')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (1, 120, 'Marriott Courtyard', 'Tower Place, Buckhead', 'Atlanta', 'GA', '30305', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (2, 180, 'Doubletree', 'Tower Place, Buckhead', 'Atlanta', 'GA', '30305', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (3, 450, 'W Hotel', 'Union Square, Manhattan', 'NY', 'NY', '10011', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (4, 450, 'W Hotel', 'Lexington Ave, Manhattan', 'NY', 'NY', '10011', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (5, 250, 'Hotel Rouge', '1315 16th Street NW', 'Washington', 'DC', '20036', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (6, 300, '70 Park Avenue Hotel', '70 Park Avenue', 'NY', 'NY', '10011', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (8, 300, 'Conrad Miami', '1395 Brickell Ave', 'Miami', 'FL', '33131', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (9, 80, 'Sea Horse Inn', '2106 N Clairemont Ave', 'Eau Claire', 'WI', '54703', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (10, 90, 'Super 8 Eau Claire Campus Area', '1151 W Macarthur Ave', 'Eau Claire', 'WI', '54701', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (11, 160, 'Marriot Downtown', '55 Fourth Street', 'San Francisco', 'CA', '94103', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (12, 200, 'Hilton Diagonal Mar', 'Passeig del Taulat 262-264', 'Barcelona', 'Catalunya', '08019', 'Spain')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (13, 210, 'Hilton Tel Aviv', 'Independence Park', 'Tel Aviv', '', '63405', 'Israel')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (14, 240, 'InterContinental Tokyo Bay', 'Takeshiba Pier', 'Tokyo', '', '105', 'Japan')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (15, 130, 'Hotel Beaulac', ' Esplanade Léopold-Robert 2', 'Neuchatel', '', '2000', 'Switzerland')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (16, 140, 'Conrad Treasury Place', 'William & George Streets', 'Brisbane', 'QLD', '4001', 'Australia')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (17, 230, 'Ritz Carlton', '1228 Sherbrooke St', 'West Montreal', 'Quebec', 'H3G1H6', 'Canada')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (18, 460, 'Ritz Carlton', 'Peachtree Rd, Buckhead', 'Atlanta', 'GA', '30326', 'USA')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (19, 220, 'Swissotel', '68 Market Street', 'Sydney', 'NSW', '2000', 'Australia')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (20, 250, 'Meliá White House', 'Albany Street', 'Regents Park London', '', 'NW13UP', 'Great Britain')
+insert into Hotel (id, price, name, address, city, state, zip, country) values (21, 210, 'Hotel Allegro', '171 West Randolph Street', 'Chicago', 'IL', '60601', 'USA')
More information about the seam-commits
mailing list