public Car save(Car car) {
return carRepository.save(car);
}
public void updateCarAgeJob() {
// Update age of cars
List<Car> cars = findAll();
DateTime currentDate = DateTime.now();
int age;
logger.info("");
logger.info("Car age update job started");
for (Car car: cars) {
age = new Period(car.getManufactureDate(), currentDate,
PeriodType.years()).getYears();
car.setAge(age);
save(car);
logger.info("Car age update--- " + car);
}
logger.info("Car age update job completed successfully");
logger.info("");
}
}
Two methods were provided; one retrieves information about all cars, and the other persists an
updated Car object. The third method, updateCarAgeJob(), is the job that needs to be run regularly to
update the age of the car based on the manufacture date of the car and the current date.
Listing 15-7 shows the Spring configuration to support the car application (car-job-app-
context.xml).
Listing 15-7. The car-job-app-context.xml File
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=http://www.springframework.org/schema/beans
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:repository="http://www.springframework.org/schema/data/repository"
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-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
http://www.springframework.org/schema/data/repository
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home