Skip to content

Commit 4fa895b

Browse files
committed
1 parent 5268415 commit 4fa895b

File tree

13 files changed

+94
-62
lines changed

13 files changed

+94
-62
lines changed

samples/airline/pom.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
<profiles>
1313
<profile>
1414
<id>hsqldb</id>
15-
<activation>
16-
<activeByDefault>true</activeByDefault>
17-
</activation>
1815
<dependencies>
1916
<dependency>
2017
<groupId>hsqldb</groupId>
@@ -30,6 +27,7 @@
3027
<jdbc.password></jdbc.password>
3128
<jdbc.url>jdbc:hsqldb:hsql://localhost/airline</jdbc.url>
3229
<hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
30+
<hibernate.hbm2ddl.auto></hibernate.hbm2ddl.auto>
3331
</properties>
3432
<build>
3533
<plugins>
@@ -73,6 +71,7 @@
7371
<jdbc.password>airline</jdbc.password>
7472
<jdbc.url>jdbc:mysql://localhost/airline</jdbc.url>
7573
<hibernate.dialect>org.hibernate.dialect.MySQLInnoDBDialect</hibernate.dialect>
74+
<hibernate.hbm2ddl.auto></hibernate.hbm2ddl.auto>
7675
</properties>
7776
<build>
7877
<plugins>
@@ -110,12 +109,13 @@
110109
</dependency>
111110
</dependencies>
112111
<properties>
113-
<!-- Change these properties to reflect your PostgreSQL connection settings -->
112+
<!-- Change these properties to reflect your PostgreSQL connection settings -->
114113
<jdbc.driverClassName>org.postgresql.Driver</jdbc.driverClassName>
115114
<jdbc.username>airline</jdbc.username>
116115
<jdbc.password>airline</jdbc.password>
117116
<jdbc.url>jdbc:postgresql://localhost/airline</jdbc.url>
118117
<hibernate.dialect>org.hibernate.dialect.PostgreSQLDialect</hibernate.dialect>
118+
<hibernate.hbm2ddl.auto></hibernate.hbm2ddl.auto>
119119
</properties>
120120
<build>
121121
<plugins>
@@ -144,6 +144,16 @@
144144
</build>
145145
</profile>
146146
</profiles>
147+
<properties>
148+
<!-- These properties are overriden by the profiles defined above.
149+
The following values are for using an in-memory database, which is used for testing -->
150+
<jdbc.driverClassName>org.hsqldb.jdbcDriver</jdbc.driverClassName>
151+
<jdbc.username>sa</jdbc.username>
152+
<jdbc.password></jdbc.password>
153+
<jdbc.url>jdbc:hsqldb:mem:airline</jdbc.url>
154+
<hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
155+
<hibernate.hbm2ddl.auto>create-drop</hibernate.hbm2ddl.auto>
156+
</properties>
147157
<build>
148158
<resources>
149159
<resource>
@@ -313,4 +323,4 @@
313323
<version>0.8</version>
314324
</dependency>
315325
</dependencies>
316-
</project>
326+
</project>

samples/airline/readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ To execute the sample with the supplied HSQLDB:
1919

2020
1. Start a command shell in the subdirectory hsqldb, and run "ant". This starts a HSQLDB server with a database named
2121
airline.
22-
2. Run "mvn sql:execute" to create the schema and insert data into the database.
23-
3. Run "mvn jetty:run" to run the sample in the Jetty6 Web container.
22+
2. Run "mvn -P hsqldb sql:execute" to create the schema and insert data into the database.
23+
3. Run "mvn -P hsqldb jetty:run" to run the sample in the Jetty6 Web container.
2424

2525
To execute the sample with MySQL or PostgreSQL:
2626

samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/FlightDao.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@
1818
import java.util.List;
1919

2020
import org.joda.time.DateTime;
21-
21+
import org.joda.time.Interval;
2222
import org.springframework.dao.DataAccessException;
2323
import org.springframework.ws.samples.airline.domain.Flight;
2424
import org.springframework.ws.samples.airline.domain.ServiceClass;
2525

2626
public interface FlightDao {
2727

28-
List findFlights(String fromAirportCode,
29-
String toAirportCode,
30-
DateTime startOfPeriod,
31-
DateTime endOfPeriod,
32-
ServiceClass serviceClass) throws DataAccessException;
28+
List findFlights(String fromAirportCode, String toAirportCode, Interval interval, ServiceClass serviceClass)
29+
throws DataAccessException;
3330

3431
Flight getFlight(String flightNumber, DateTime departureTime);
3532

samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDao.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.List;
1919

2020
import org.joda.time.DateTime;
21-
21+
import org.joda.time.Interval;
2222
import org.springframework.dao.DataAccessException;
2323
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
2424
import org.springframework.ws.samples.airline.dao.FlightDao;
@@ -38,15 +38,12 @@ public void update(Flight flight) {
3838
getHibernateTemplate().update(flight);
3939
}
4040

41-
public List findFlights(String fromAirportCode,
42-
String toAirportCode,
43-
DateTime startOfPeriod,
44-
DateTime endOfPeriod,
45-
ServiceClass serviceClass) throws DataAccessException {
41+
public List findFlights(String fromAirportCode, String toAirportCode, Interval interval, ServiceClass serviceClass)
42+
throws DataAccessException {
4643
return getHibernateTemplate().findByNamedParam("from Flight f where f.from.code = :from " +
4744
"and f.to.code = :to and " + "f.departureTime >= :start and f.departureTime <= :end and " +
4845
"f.serviceClass = :class", new String[]{"from", "to", "start", "end", "class"},
49-
new Object[]{fromAirportCode, toAirportCode, startOfPeriod, endOfPeriod, serviceClass});
46+
new Object[]{fromAirportCode, toAirportCode, interval.getStart(), interval.getEnd(), serviceClass});
5047
}
5148

5249
}

samples/airline/src/main/java/org/springframework/ws/samples/airline/service/AirlineService.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import java.util.List;
1919

2020
import org.joda.time.DateTime;
21-
import org.joda.time.YearMonthDay;
22-
21+
import org.joda.time.LocalDate;
2322
import org.springframework.ws.samples.airline.domain.ServiceClass;
2423
import org.springframework.ws.samples.airline.domain.Ticket;
2524

@@ -40,10 +39,7 @@ public interface AirlineService {
4039
* @return a list of flights
4140
* @see org.springframework.ws.samples.airline.domain.Flight
4241
*/
43-
List getFlights(String fromAirportCode,
44-
String toAirportCode,
45-
YearMonthDay departureDate,
46-
ServiceClass serviceClass);
42+
List getFlights(String fromAirportCode, String toAirportCode, LocalDate departureDate, ServiceClass serviceClass);
4743

4844
/**
4945
* Books a single flight for a number of passengers. Passengers can be either specified by name or by frequent flyer

samples/airline/src/main/java/org/springframework/ws/samples/airline/service/impl/AirlineServiceImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.commons.logging.Log;
2222
import org.apache.commons.logging.LogFactory;
2323
import org.joda.time.DateTime;
24+
import org.joda.time.LocalDate;
2425
import org.joda.time.YearMonthDay;
2526
import org.springframework.util.Assert;
2627
import org.springframework.ws.samples.airline.dao.FlightDao;
@@ -107,7 +108,7 @@ public int getFrequentFlyerMileage() {
107108

108109
public List getFlights(String fromAirportCode,
109110
String toAirportCode,
110-
YearMonthDay departureDate,
111+
LocalDate departureDate,
111112
ServiceClass serviceClass) {
112113
if (serviceClass == null) {
113114
serviceClass = ServiceClass.ECONOMY;
@@ -116,8 +117,6 @@ public List getFlights(String fromAirportCode,
116117
logger.debug(
117118
"Getting flights from '" + fromAirportCode + "' to '" + toAirportCode + "' on " + departureDate);
118119
}
119-
DateTime startOfPeriod = departureDate.toDateTimeAtMidnight();
120-
DateTime endOfPeriod = startOfPeriod.plusDays(1);
121-
return flightDao.findFlights(fromAirportCode, toAirportCode, startOfPeriod, endOfPeriod, serviceClass);
120+
return flightDao.findFlights(fromAirportCode, toAirportCode, departureDate.toInterval(), serviceClass);
122121
}
123122
}

samples/airline/src/main/java/org/springframework/ws/samples/airline/ws/GetFlightsEndpoint.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import java.util.Iterator;
1919
import java.util.List;
2020

21-
import org.joda.time.YearMonthDay;
21+
import org.joda.time.Chronology;
22+
import org.joda.time.DateTimeZone;
23+
import org.joda.time.LocalDate;
2224
import org.joda.time.chrono.ISOChronology;
2325
import org.springframework.ws.samples.airline.schema.Airport;
2426
import org.springframework.ws.samples.airline.schema.Flight;
@@ -48,7 +50,10 @@ public void setAirlineService(AirlineService airlineService) {
4850

4951
protected Object invokeInternal(Object requestObject) throws Exception {
5052
GetFlightsRequest request = (GetFlightsRequest) requestObject;
51-
YearMonthDay departureDate = new YearMonthDay(request.getDepartureDate(), ISOChronology.getInstance());
53+
54+
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(request.getDepartureDate().getTimeZone());
55+
Chronology chronology = ISOChronology.getInstance(dateTimeZone);
56+
LocalDate departureDate = new LocalDate(request.getDepartureDate(), chronology);
5257
if (logger.isDebugEnabled()) {
5358
logger.debug("Request for flights from '" + request.getFrom() + "' to '" + request.getTo() + "' on " +
5459
departureDate);
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Properties file with hibernate-related settings.
22

33
hibernate.dialect=${hibernate.dialect}
4+
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
45
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
5-
#hibernate.hbm2ddl.auto=create-drop
6-
#hibernate.show_sql=true

samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDaoTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919

2020
import org.joda.time.DateTime;
21+
import org.joda.time.Interval;
2122
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
2223
import org.springframework.ws.samples.airline.domain.Airport;
2324
import org.springframework.ws.samples.airline.domain.Flight;
@@ -35,6 +36,8 @@ public class HibernateFlightDaoTest extends AbstractTransactionalDataSourceSprin
3536

3637
private DateTime arrivalTime;
3738

39+
private Interval interval;
40+
3841
protected String[] getConfigLocations() {
3942
return new String[]{
4043
"classpath:org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml"};
@@ -47,6 +50,7 @@ public void setFlightDao(HibernateFlightDao flightDao) {
4750
protected void onSetUpBeforeTransaction() throws Exception {
4851
departureTime = new DateTime(2006, 1, 31, 10, 5, 0, 0);
4952
arrivalTime = new DateTime(2006, 1, 31, 12, 25, 0, 0);
53+
interval = new Interval(departureTime, arrivalTime);
5054
}
5155

5256
protected void onSetUpInTransaction() throws Exception {
@@ -60,7 +64,7 @@ public void testGetFlightsInPeriod() throws Exception {
6064
jdbcTemplate
6165
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
6266
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'business', 90, 10)");
63-
List flights = flightDao.findFlights("RTM", "OSL", departureTime, arrivalTime, ServiceClass.BUSINESS);
67+
List flights = flightDao.findFlights("RTM", "OSL", interval, ServiceClass.BUSINESS);
6468
assertNotNull("Invalid result", flights);
6569
assertEquals("Invalid amount of flights", 1, flights.size());
6670
}
@@ -70,7 +74,7 @@ public void testGetFlightsOutOfPeriod() throws Exception {
7074
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
7175
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'business', 90, 10)");
7276
DateTime dateTime = new DateTime(2006, 6, 1, 0, 0, 0, 0);
73-
List flights = flightDao.findFlights("RTM", "OSL", dateTime, dateTime, ServiceClass.BUSINESS);
77+
List flights = flightDao.findFlights("RTM", "OSL", new Interval(dateTime, dateTime), ServiceClass.BUSINESS);
7478
assertNotNull("Invalid result", flights);
7579
assertEquals("Invalid amount of flights", 0, flights.size());
7680
}

samples/airline/src/test/java/org/springframework/ws/samples/airline/service/impl/AirlineServiceImplTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
import junit.framework.TestCase;
2323
import org.easymock.MockControl;
2424
import org.joda.time.DateTime;
25-
import org.joda.time.YearMonthDay;
26-
25+
import org.joda.time.LocalDate;
2726
import org.springframework.ws.samples.airline.dao.FlightDao;
2827
import org.springframework.ws.samples.airline.dao.TicketDao;
2928
import org.springframework.ws.samples.airline.domain.Flight;
@@ -153,14 +152,12 @@ public void testBookFlightNoSuchFlight() throws Exception {
153152
public void testGetFlights() throws Exception {
154153
String toCode = "to";
155154
String fromCode = "from";
156-
YearMonthDay departureDate = new YearMonthDay(2006, 1, 31);
155+
LocalDate departureDate = new LocalDate(2006, 1, 31);
157156
Flight flight = new Flight();
158157
List flights = new ArrayList();
159158
flights.add(flight);
160-
DateTime startOfPeriod = new DateTime(2006, 1, 31, 0, 0, 0, 0);
161-
DateTime endOfPeriod = new DateTime(2006, 2, 1, 0, 0, 0, 0);
162159
flightDaoControl.expectAndReturn(
163-
flightDaoMock.findFlights(fromCode, toCode, startOfPeriod, endOfPeriod, ServiceClass.ECONOMY), flights);
160+
flightDaoMock.findFlights(fromCode, toCode, departureDate.toInterval(), ServiceClass.ECONOMY), flights);
164161
flightDaoControl.replay();
165162
ticketDaoControl.replay();
166163
securityServiceControl.replay();
@@ -172,14 +169,12 @@ public void testGetFlights() throws Exception {
172169
public void testGetFlightsDefaultServiceClass() throws Exception {
173170
String toCode = "to";
174171
String fromCode = "from";
175-
YearMonthDay departureDate = new YearMonthDay(2006, 1, 31);
172+
LocalDate departureDate = new LocalDate(2006, 1, 31);
176173
Flight flight = new Flight();
177174
List flights = new ArrayList();
178175
flights.add(flight);
179-
DateTime startOfPeriod = new DateTime(2006, 1, 31, 0, 0, 0, 0);
180-
DateTime endOfPeriod = new DateTime(2006, 2, 1, 0, 0, 0, 0);
181176
flightDaoControl.expectAndReturn(
182-
flightDaoMock.findFlights(fromCode, toCode, startOfPeriod, endOfPeriod, ServiceClass.ECONOMY), flights);
177+
flightDaoMock.findFlights(fromCode, toCode, departureDate.toInterval(), ServiceClass.ECONOMY), flights);
183178
flightDaoControl.replay();
184179
ticketDaoControl.replay();
185180
securityServiceControl.replay();

0 commit comments

Comments
 (0)