<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:p="http://www.springframework.org/schema/p"
	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-2.0.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

	<bean id="footballJob" parent="simpleJob">
		<property name="steps">
			<list>
				<bean id="playerload" parent="simpleStep">
					<property name="commitInterval" value="${job.commit.interval}" />
					<property name="startLimit" value="100" />
					<property name="itemReader"
						ref="playerFileItemReader" />
					<property name="itemWriter">
						<bean
							class="org.springframework.batch.sample.item.writer.PlayerItemWriter">
							<property name="playerDao">
								<bean
									class="org.springframework.batch.sample.dao.JdbcPlayerDao">
									<property name="dataSource"
										ref="dataSource" />
								</bean>
							</property>
						</bean>
					</property>
				</bean>
				<bean id="gameLoad" parent="simpleStep">
					<property name="itemReader"
						ref="gameFileItemReader" />
					<property name="itemWriter">
						<bean
							class="org.springframework.batch.sample.dao.JdbcGameDao">
							<property name="dataSource"
								ref="dataSource" />
						</bean>
					</property>
					<property name="commitInterval" value="${job.commit.interval}" />
				</bean>
				<bean id="playerSummarization" parent="simpleStep">
					<property name="commitInterval" value="${job.commit.interval}" />
					<property name="itemReader"
						ref="playerSummarizationSource" />
					<property name="itemWriter">
						<bean
							class="org.springframework.batch.sample.dao.JdbcPlayerSummaryDao">
							<property name="dataSource"
								ref="dataSource" />
						</bean>
					</property>
				</bean>
			</list>
		</property>
	</bean>

	<bean id="playerFileItemReader"
		class="org.springframework.batch.item.file.FlatFileItemReader">
		<property name="resource"
			value="classpath:data/footballjob/input/${player.file.name}" />
		<property name="lineTokenizer">
			<bean
				class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
				<property name="names"
					value="ID,lastName,firstName,position,birthYear,debutYear" />
			</bean>
		</property>
		<property name="fieldSetMapper">
			<bean
				class="org.springframework.batch.sample.mapping.PlayerMapper" />
		</property>
	</bean>

	<bean id="gameFileItemReader"
		class="org.springframework.batch.item.file.FlatFileItemReader">
		<property name="resource"
			value="classpath:data/footballjob/input/${games.file.name}" />
		<property name="lineTokenizer">
			<bean
				class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
				<property name="names"
					value="id,year,team,week,opponent,completes,attempts,passingYards,passingTd,interceptions,rushes,rushYards,receptions,receptionYards,totalTd" />
			</bean>
		</property>
		<property name="fieldSetMapper">
			<bean
				class="org.springframework.batch.sample.mapping.GameMapper" />
		</property>
	</bean>

	<bean id="playerSummarizationSource"
		class="org.springframework.batch.item.database.JdbcCursorItemReader">
		<property name="dataSource" ref="dataSource" />
		<property name="mapper">
			<bean
				class="org.springframework.batch.sample.mapping.PlayerSummaryMapper" />
		</property>
		<property name="sql">
			<value>
				SELECT games.player_id, games.year_no, SUM(COMPLETES),
				SUM(ATTEMPTS), SUM(PASSING_YARDS), SUM(PASSING_TD),
				SUM(INTERCEPTIONS), SUM(RUSHES), SUM(RUSH_YARDS),
				SUM(RECEPTIONS), SUM(RECEPTIONS_YARDS), SUM(TOTAL_TD)
				from games, players where players.player_id =
				games.player_id group by games.player_id, games.year_no
			</value>
		</property>
	</bean>

	<aop:config>
		<aop:aspect id="moduleLogging" ref="logAdvice">
			<aop:after
				pointcut="execution( * org.springframework.batch.item.ItemWriter+.write(Object)) and args(item)"
				method="doStronglyTypedLogging" />
		</aop:aspect>
		<aop:aspect ref="eventAdvice">
			<aop:before
				pointcut="execution( * org.springframework.batch..Step+.execute(..))"
				method="before" />
			<aop:after
				pointcut="execution( * org.springframework.batch..Step+.execute(..))"
				method="after" />
			<aop:after-throwing throwing="t" 
				pointcut="execution( * org.springframework.batch..Step+.execute(..))"
				method="onError" />
		</aop:aspect>
	</aop:config>

	<bean id="footbalProperties"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="properties">
			<value>
				games.file.name=games-small.csv
				player.file.name=player-small.csv
				job.commit.interval=2
			</value>
		</property>
		<property name="systemPropertiesModeName"
			value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
		<property name="ignoreUnresolvablePlaceholders" value="true" />
		<property name="order" value="1" />
	</bean>

</beans>