├── spring-batch-example ├── .gitignore ├── src │ ├── test │ │ ├── resources │ │ │ └── deleteme.txt │ │ └── java │ │ │ └── test │ │ │ └── com │ │ │ └── juxtapose │ │ │ └── example │ │ │ ├── ch04 │ │ │ └── JobLaunchScheduler.java │ │ │ ├── ch07 │ │ │ ├── JobLaunchJMS.java │ │ │ ├── JobLaunchJDBC.java │ │ │ ├── JobLaunchFlatFile.java │ │ │ ├── JobLaunchIbatis.java │ │ │ ├── JobLaunchXml.java │ │ │ ├── JobLaunchJavaMail.java │ │ │ ├── JobLaunchComposite.java │ │ │ ├── JobLaunchFileSets.java │ │ │ ├── JobLaunchListener.java │ │ │ ├── JobLaunchFileSetsExt.java │ │ │ ├── JobLaunchHibernate.java │ │ │ ├── JobLaunchListenerMerge.java │ │ │ ├── JobLaunchErrorListener.java │ │ │ ├── JobLaunchXmlCallback.java │ │ │ ├── JobLaunchCustomItemWriter.java │ │ │ ├── JobLaunchFlatFileCallback.java │ │ │ ├── JobLaunchReuseServiceWrite.java │ │ │ ├── JobLaunchClassifierComposite.java │ │ │ ├── JobLaunchJpa.java │ │ │ ├── JobLaunchFlatFileCustomLineAggregator.java │ │ │ ├── JobLaunchRestartableCustomItemWriter.java │ │ │ └── JobLaunchReuseServicePropertyExtractWrite.java │ │ │ ├── ch10 │ │ │ ├── JobLaunchSkip.java │ │ │ ├── JobLaunchRetry.java │ │ │ ├── JobLaunchSkipListener.java │ │ │ ├── JobLaunchRetryPolicy.java │ │ │ ├── JobLaunchCacheCapacity.java │ │ │ ├── JobLaunchRetryTasklet.java │ │ │ └── JobLaunchRetryListener.java │ │ │ ├── ch08 │ │ │ ├── JobLaunchFilter.java │ │ │ ├── JobLaunchTranslate.java │ │ │ ├── JobLaunchListener.java │ │ │ ├── JobLaunchPartTranslate.java │ │ │ ├── JobLaunchReuseService.java │ │ │ ├── JobLaunchErrorListener.java │ │ │ ├── JobLaunchListenerMerge.java │ │ │ ├── JobLaunchComposite.java │ │ │ └── JobLaunchValidate.java │ │ │ ├── ch06 │ │ │ ├── JobLaunchListener.java │ │ │ ├── JobLaunchListenerMerge.java │ │ │ ├── JobLaunchErrorListener.java │ │ │ └── JobLaunchReuseServiceRead.java │ │ │ ├── ch11 │ │ │ ├── JobLaunchChunkRemote.java │ │ │ ├── JobLaunchMultiThread.java │ │ │ ├── JobLaunchPartitionDB.java │ │ │ ├── JobLaunchPartitionFile.java │ │ │ ├── JobLaunchChunkRemoteOther.java │ │ │ ├── JobLaunchPartitionRemote.java │ │ │ ├── JobLaunchMultiThreadJdbcError.java │ │ │ ├── JobLaunchMultiThreadJdbcSynchronized.java │ │ │ └── JobLaunchMultiThreadJdbcSynchronizedRestart.java │ │ │ ├── ch09 │ │ │ ├── JobLaunchConditionalStop.java │ │ │ ├── JobLaunchSplit.java │ │ │ ├── JobLaunchSequential.java │ │ │ ├── JobLaunchConditional.java │ │ │ ├── JobLaunchExternalFlow.java │ │ │ ├── JobLaunchExternalJobStep.java │ │ │ ├── JobLaunchConditionalDecider.java │ │ │ ├── JobLaunchConditionalEnd.java │ │ │ ├── JobLaunchConditionalFail.java │ │ │ └── JobLaunchExternalFlowStep.java │ │ │ ├── ch02 │ │ │ ├── JobLaunch.java │ │ │ └── JobLaunchTest.java │ │ │ └── JobLaunchBase.java │ └── main │ │ ├── resources │ │ ├── ch06 │ │ │ ├── db │ │ │ │ └── create-stored-procedure-mysql.sql │ │ │ ├── data │ │ │ │ ├── flat │ │ │ │ │ ├── filesets │ │ │ │ │ │ ├── credit-card-bill-201304.csv │ │ │ │ │ │ ├── credit-card-bill-201305.csv │ │ │ │ │ │ └── credit-card-bill-201303.csv │ │ │ │ │ ├── credit-card-bill-201303.csv │ │ │ │ │ ├── credit-card-bill-multiline-201303.csv │ │ │ │ │ ├── credit-card-bill-fixed-length-201303.csv │ │ │ │ │ ├── credit-card-bill-heterogonous-201303.csv │ │ │ │ │ ├── credit-card-bill-201303-complex.csv │ │ │ │ │ ├── credit-card-bill-delimited-201303.csv │ │ │ │ │ └── credit-card-bill-201303.json │ │ │ │ └── xml │ │ │ │ │ └── credit-card-bill-201303.xml │ │ │ ├── properties │ │ │ │ └── batch-mysql.properties │ │ │ ├── ibatis │ │ │ │ ├── ibatis-config.xml │ │ │ │ └── ibatis-credit.xml │ │ │ ├── cfg │ │ │ │ └── hibernate.cfg.xml │ │ │ └── jpa │ │ │ │ └── persistence.xml │ │ ├── ch09 │ │ │ ├── data │ │ │ │ ├── credit-card-bill-201310.zip │ │ │ │ ├── credit-card-bill-201310-notexist.zip │ │ │ │ └── credit-card-bill-201311.csv │ │ │ └── properties │ │ │ │ └── batch-mysql.properties │ │ ├── ch07 │ │ │ ├── properties │ │ │ │ ├── batch-mail.properties │ │ │ │ └── batch-mysql.properties │ │ │ ├── ibatis │ │ │ │ ├── ibatis-config.xml │ │ │ │ ├── ibatis-credit.xml │ │ │ │ └── ibatis-destcredit.xml │ │ │ ├── data │ │ │ │ ├── flat │ │ │ │ │ └── credit-card-bill-201310.csv │ │ │ │ └── xml │ │ │ │ │ └── credit-card-bill-201310.xml │ │ │ ├── cfg │ │ │ │ └── hibernate.cfg.xml │ │ │ └── jpa │ │ │ │ └── persistence.xml │ │ ├── ch08 │ │ │ ├── properties │ │ │ │ └── batch-mysql.properties │ │ │ └── data │ │ │ │ └── flat │ │ │ │ ├── credit-card-bill-201310.csv │ │ │ │ └── credit-card-bill-201311.csv │ │ ├── ch03 │ │ │ ├── properties │ │ │ │ └── batch-mysql.properties │ │ │ └── data │ │ │ │ ├── credit-card-bill-201303-bad.csv │ │ │ │ └── credit-card-bill-201303.csv │ │ ├── ch04 │ │ │ ├── properties │ │ │ │ └── batch-mysql.properties │ │ │ ├── webapp │ │ │ │ └── batchapp │ │ │ │ │ └── WEB-INF │ │ │ │ │ ├── lib │ │ │ │ │ ├── junit-4.8.2.jar │ │ │ │ │ ├── xstream-1.3.jar │ │ │ │ │ ├── jettison-1.1.jar │ │ │ │ │ ├── log4j-1.2.14.jar │ │ │ │ │ ├── aopalliance-1.0.jar │ │ │ │ │ ├── servlet-api-2.5.jar │ │ │ │ │ ├── spring-aop-2.5.6.jar │ │ │ │ │ ├── xpp3_min-1.1.4c.jar │ │ │ │ │ ├── commons-logging-1.1.1.jar │ │ │ │ │ ├── spring-asm-3.0.5.RELEASE.jar │ │ │ │ │ ├── spring-batch-example-1.0.jar │ │ │ │ │ ├── spring-tx-3.0.5.RELEASE.jar │ │ │ │ │ ├── spring-web-3.0.5.RELEASE.jar │ │ │ │ │ ├── mysql-connector-java-5.1.2.jar │ │ │ │ │ ├── spring-beans-3.0.5.RELEASE.jar │ │ │ │ │ ├── spring-core-3.0.5.RELEASE.jar │ │ │ │ │ ├── spring-jdbc-3.0.5.RELEASE.jar │ │ │ │ │ ├── spring-test-3.0.5.RELEASE.jar │ │ │ │ │ ├── spring-context-3.0.5.RELEASE.jar │ │ │ │ │ ├── spring-webmvc-3.0.5.RELEASE.jar │ │ │ │ │ ├── spring-batch-core-2.1.9.RELEASE.jar │ │ │ │ │ ├── spring-expression-3.0.5.RELEASE.jar │ │ │ │ │ ├── spring-context-support-3.0.5.RELEASE.jar │ │ │ │ │ └── spring-batch-infrastructure-2.1.9.RELEASE.jar │ │ │ │ │ ├── applicationContext.xml │ │ │ │ │ ├── batchapp-servlet.xml │ │ │ │ │ └── web.xml │ │ │ ├── data │ │ │ │ ├── credit-card-bill-201303-restart.csv │ │ │ │ └── credit-card-bill-201303.csv │ │ │ └── command.txt │ │ ├── ch05 │ │ │ ├── properties │ │ │ │ └── batch-mysql.properties │ │ │ ├── db │ │ │ │ ├── create-table-skipbills.sql │ │ │ │ └── create-tables.sql │ │ │ └── data │ │ │ │ └── credit-card-bill-201303.csv │ │ ├── ch10 │ │ │ ├── properties │ │ │ │ └── batch-mysql.properties │ │ │ └── db │ │ │ │ ├── create-table-skipbills.sql │ │ │ │ └── create-tables.sql │ │ ├── ch11 │ │ │ ├── properties │ │ │ │ └── batch-mysql.properties │ │ │ └── data │ │ │ │ ├── credit-card-bill-201310.csv │ │ │ │ ├── credit-card-bill-201311.csv │ │ │ │ └── credit-card-bill-201312.csv │ │ ├── log4j.properties │ │ ├── db │ │ │ └── mysql-truncate-all-table.sql │ │ └── ch02 │ │ │ └── data │ │ │ └── credit-card-bill-201303.csv │ │ └── java │ │ └── com │ │ └── juxtapose │ │ └── example │ │ ├── ch05 │ │ ├── HelloWorldService.java │ │ ├── CreditBillProcessor.java │ │ ├── MockARuntimeException.java │ │ ├── MockBRuntimeException.java │ │ ├── ConsoleWriter.java │ │ ├── RadomExceptionItemProcessor.java │ │ ├── step │ │ │ └── listener │ │ │ │ ├── SystemOutItemReadListener.java │ │ │ │ ├── SystemOutSkipListener.java │ │ │ │ ├── SystemOutItemProcessListener.java │ │ │ │ ├── SystemOutItemWriteListener.java │ │ │ │ ├── SystemOutJobExecutionListener.java │ │ │ │ ├── SystemOutStepExecutionListener.java │ │ │ │ ├── DBSkipListener.java │ │ │ │ └── SystemOutChunkListener.java │ │ ├── TransactionItemProcessor.java │ │ ├── AlwaysExceptionItemProcessor.java │ │ ├── listener │ │ │ ├── SystemOut.java │ │ │ ├── ErrorStepExecutionListener.java │ │ │ └── SystemOutStepExecutionListener.java │ │ ├── AutoReader.java │ │ └── RadomExceptionAutoReader.java │ │ ├── ch02 │ │ └── CreditBillProcessor.java │ │ ├── ch03 │ │ └── CreditBillProcessor.java │ │ ├── ch04 │ │ ├── CreditBillProcessor.java │ │ ├── stop │ │ │ ├── ConsoleWriter.java │ │ │ ├── AutoReader.java │ │ │ └── StopStepListener.java │ │ ├── listener │ │ │ ├── SystemOut.java │ │ │ └── SystemOutJobExecutionListener.java │ │ ├── exitstatus │ │ │ └── CustomerExitCodeMapper.java │ │ └── scheduler │ │ │ └── SchedulerLauncher.java │ │ ├── ch06 │ │ ├── CreditBillProcessor.java │ │ ├── ibatis │ │ │ ├── CreditBillProcessor.java │ │ │ └── DummyCreditItemWriter.java │ │ ├── hibernate │ │ │ ├── CreditBillProcessor.java │ │ │ └── DummyCreditItemWriter.java │ │ ├── jpa │ │ │ ├── CreditBillProcessor.java │ │ │ └── DummyCreditItemWriter.java │ │ ├── flat │ │ │ ├── DefaultLineCallbackHandler.java │ │ │ ├── CopyHeaderLineCallbackHandler.java │ │ │ ├── DebitBillFieldSetMapper.java │ │ │ ├── CreditBillFieldSetMapper.java │ │ │ └── WrappedJsonLineMapper.java │ │ ├── DummyCreditItemWriter.java │ │ ├── db │ │ │ ├── CreditBillPreparedStatementSetter.java │ │ │ └── CreditBillRowMapper.java │ │ ├── listener │ │ │ ├── SystemOutItemReadlistener.java │ │ │ ├── ErrorItemReadListener.java │ │ │ └── SystemOutAnnotation.java │ │ ├── reuse │ │ │ ├── ExistService.java │ │ │ └── CreditBillServiceAdapter.java │ │ ├── jms │ │ │ └── TransactionItemProcessor.java │ │ ├── cust │ │ │ └── itemreader │ │ │ │ └── CustomCreditBillItemReader.java │ │ └── DummyCreditItemReader.java │ │ ├── ch07 │ │ ├── CreditBillProcessor.java │ │ ├── classifiercomposite │ │ │ └── CreditBillRouterClassifier.java │ │ ├── DummyCreditItemWriter.java │ │ ├── flat │ │ │ ├── DefaultFlatFileFooterCallback.java │ │ │ ├── DefaultFlatFileHeaderCallback.java │ │ │ ├── CreditBillFieldSetMapper.java │ │ │ └── CustomLineAggregator.java │ │ ├── jpa │ │ │ └── CreditBillProcessor.java │ │ ├── db │ │ │ └── CreditBillProcessor.java │ │ ├── hibernate │ │ │ └── CreditBillProcessor.java │ │ ├── cust │ │ │ └── itemwriter │ │ │ │ └── CustomCreditBillItemWriter.java │ │ ├── reuse │ │ │ └── ExistService.java │ │ ├── listener │ │ │ ├── SystemOutItemWriteListener.java │ │ │ ├── ErrorItemWriteListener.java │ │ │ └── SystemOutAnnotation.java │ │ ├── jdbc │ │ │ └── DestCreditBillItemPreparedStatementSetter.java │ │ ├── xml │ │ │ └── HeaderStaxWriterCallback.java │ │ ├── mail │ │ │ └── MailItemProcessor.java │ │ └── DummyCreditItemReader.java │ │ ├── ch09 │ │ ├── chunk │ │ │ ├── CreditBillProcessor.java │ │ │ └── CreditBillFieldSetMapper.java │ │ ├── Constant.java │ │ ├── CreditService.java │ │ ├── tasklet │ │ │ └── CleanTasklet.java │ │ └── listener │ │ │ └── VerifyStepExecutionListener.java │ │ ├── ch10 │ │ ├── retry │ │ │ ├── MockARuntimeException.java │ │ │ ├── MockBRuntimeException.java │ │ │ ├── ConsoleWriter.java │ │ │ ├── template │ │ │ │ ├── DefaultRecoveryCallback.java │ │ │ │ ├── BackOffContextImpl.java │ │ │ │ ├── CountHelper.java │ │ │ │ ├── DefaultRetryCallback.java │ │ │ │ └── DefaultBackoffPolicy.java │ │ │ ├── RadomExceptionItemProcessor.java │ │ │ ├── AlwaysExceptionItemProcessor.java │ │ │ └── AutoReader.java │ │ └── skip │ │ │ ├── ConsoleWriter.java │ │ │ ├── RadomExceptionItemProcessor.java │ │ │ ├── AutoReader.java │ │ │ └── DBSkipListener.java │ │ ├── ch08 │ │ ├── FilterItemProcessor.java │ │ ├── PartTranslateItemProcessor.java │ │ ├── ExistService.java │ │ ├── CreditBillValidator.java │ │ ├── SkipCountStepExecutionListener.java │ │ ├── FilterCountStepExecutionListener.java │ │ ├── TranslateItemProcessor.java │ │ ├── CreditBillFieldSetMapper.java │ │ └── listener │ │ │ ├── SystemOutItemProcessListener.java │ │ │ ├── ErrorItemProcessListener.java │ │ │ └── SystemOutAnnotation.java │ │ └── ch11 │ │ ├── partition │ │ ├── remote │ │ │ └── MessageTransformer.java │ │ ├── db │ │ │ ├── PartitionStepExecutionListener.java │ │ │ └── CreditBillRowMapper.java │ │ ├── CreditBillProcessor.java │ │ ├── PartitionStepExecutionListener.java │ │ └── CreditBillFieldSetMapper.java │ │ └── multithread │ │ ├── ConsoleWriter.java │ │ ├── DestCreditBillItemPreparedStatementSetter.java │ │ └── AutoReader.java ├── lib │ └── spring-batch-retry.jar ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.core.resources.prefs │ ├── org.maven.ide.eclipse.prefs │ └── org.eclipse.jdt.core.prefs └── .project └── README.md /spring-batch-example/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/resources/deleteme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SpringBatchSample 2 | ================= 3 | 4 | Spring Batch Sample 4 book 5 | 6 | 本项目是图书《Spring Batch批处理框架》的配套源代码。 7 | 8 | -------------------------------------------------------------------------------- /spring-batch-example/lib/spring-batch-retry.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/lib/spring-batch-retry.jar -------------------------------------------------------------------------------- /spring-batch-example/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/db/create-stored-procedure-mysql.sql: -------------------------------------------------------------------------------- 1 | DROP PROCEDURE IF EXISTS query_credit; 2 | CREATE PROCEDURE query_credit() SELECT * FROM t_credit; -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/filesets/credit-card-bill-201304.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 2 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/filesets/credit-card-bill-201305.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 2 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch09/data/credit-card-bill-201310.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch09/data/credit-card-bill-201310.zip -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/filesets/credit-card-bill-201303.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch07/properties/batch-mail.properties: -------------------------------------------------------------------------------- 1 | mail.smtp.host=smtp.163.com 2 | mail.smtp.username=springbatchexample 3 | mail.smtp.password=springbatch 4 | mail.smtp.auth=true 5 | mail.smtp.timeout=25000 -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch07/properties/batch-mysql.properties: -------------------------------------------------------------------------------- 1 | datasource.driver=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://127.0.0.1:3306/test1289 3 | datasource.username=root 4 | datasource.password=000000 -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch08/properties/batch-mysql.properties: -------------------------------------------------------------------------------- 1 | datasource.driver=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://127.0.0.1:3306/test1289 3 | datasource.username=root 4 | datasource.password=000000 -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch09/data/credit-card-bill-201310-notexist.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch09/data/credit-card-bill-201310-notexist.zip -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch09/properties/batch-mysql.properties: -------------------------------------------------------------------------------- 1 | datasource.driver=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://127.0.0.1:3306/test1289 3 | datasource.username=root 4 | datasource.password=000000 -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch03/properties/batch-mysql.properties: -------------------------------------------------------------------------------- 1 | datasource.driver=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://127.0.0.1:3306/test1289 3 | datasource.username=root 4 | datasource.password=000000 5 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/properties/batch-mysql.properties: -------------------------------------------------------------------------------- 1 | datasource.driver=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://127.0.0.1:3306/test1289 3 | datasource.username=root 4 | datasource.password=000000 5 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/junit-4.8.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/junit-4.8.2.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/xstream-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/xstream-1.3.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch05/properties/batch-mysql.properties: -------------------------------------------------------------------------------- 1 | datasource.driver=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://127.0.0.1:3306/test1289 3 | datasource.username=root 4 | datasource.password=000000 5 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/properties/batch-mysql.properties: -------------------------------------------------------------------------------- 1 | datasource.driver=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://127.0.0.1:3306/test1289 3 | datasource.username=root 4 | datasource.password=000000 5 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch10/properties/batch-mysql.properties: -------------------------------------------------------------------------------- 1 | datasource.driver=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://127.0.0.1:3306/test1289 3 | datasource.username=root 4 | datasource.password=000000 5 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch11/properties/batch-mysql.properties: -------------------------------------------------------------------------------- 1 | datasource.driver=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://127.0.0.1:3306/test1289 3 | datasource.username=root 4 | datasource.password=000000 5 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/jettison-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/jettison-1.1.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/log4j-1.2.14.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/log4j-1.2.14.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/aopalliance-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/aopalliance-1.0.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/servlet-api-2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/servlet-api-2.5.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-aop-2.5.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-aop-2.5.6.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/xpp3_min-1.1.4c.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/xpp3_min-1.1.4c.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-asm-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-asm-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-batch-example-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-batch-example-1.0.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-tx-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-tx-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-web-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-web-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/mysql-connector-java-5.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/mysql-connector-java-5.1.2.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-beans-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-beans-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-core-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-core-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-jdbc-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-jdbc-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-test-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-test-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-context-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-context-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-webmvc-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-webmvc-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding//src/test/resources=UTF-8 6 | encoding/=UTF-8 7 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-batch-core-2.1.9.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-batch-core-2.1.9.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-expression-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-expression-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=info, stdout 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 4 | log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-context-support-3.0.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-context-support-3.0.5.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-batch-infrastructure-2.1.9.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jxtaliu/SpringBatchSample/HEAD/spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/lib/spring-batch-infrastructure-2.1.9.RELEASE.jar -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch05/db/create-table-skipbills.sql: -------------------------------------------------------------------------------- 1 | drop table if exists skipbills; 2 | 3 | create table skipbills 4 | ( 5 | line character(9) not null, 6 | content character varying(512), 7 | constraint skipbills_pkey primary key (line) 8 | ); 9 | 10 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch10/db/create-table-skipbills.sql: -------------------------------------------------------------------------------- 1 | drop table if exists skipbills; 2 | 3 | create table skipbills 4 | ( 5 | line character(9) not null, 6 | content character varying(512), 7 | constraint skipbills_pkey primary key (line) 8 | ); 9 | 10 | -------------------------------------------------------------------------------- /spring-batch-example/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | fullBuildGoals=process-test-resources 4 | resolveWorkspaceProjects=true 5 | resourceFilterGoals=process-resources resources\:testResources 6 | skipCompilerPlugin=true 7 | version=1 8 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch05/db/create-tables.sql: -------------------------------------------------------------------------------- 1 | drop table if exists counter; 2 | 3 | create table counter 4 | ( 5 | id character(9) not null, 6 | name character varying(50), 7 | description character varying(128), 8 | constraint counter_pkey primary key (id) 9 | ); 10 | 11 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch10/db/create-tables.sql: -------------------------------------------------------------------------------- 1 | drop table if exists counter; 2 | 3 | create table counter 4 | ( 5 | id character(9) not null, 6 | name character varying(50), 7 | description character varying(128), 8 | constraint counter_pkey primary key (id) 9 | ); 10 | 11 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/db/mysql-truncate-all-table.sql: -------------------------------------------------------------------------------- 1 | TRUNCATE TABLE batch_step_execution_context; 2 | TRUNCATE TABLE batch_step_execution; 3 | TRUNCATE TABLE batch_job_execution_params; 4 | TRUNCATE TABLE batch_job_execution_context; 5 | TRUNCATE TABLE batch_job_execution; 6 | TRUNCATE TABLE batch_job_instance; -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/ibatis/ibatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch07/ibatis/ibatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch03/data/credit-card-bill-201303-bad.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,793.20,2013-2-9 15:15:37 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/data/credit-card-bill-201303-restart.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,793.20,2013-2-9 15:15:37 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch02/data/credit-card-bill-201303.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch03/data/credit-card-bill-201303.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/data/credit-card-bill-201303.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch05/data/credit-card-bill-201303.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/credit-card-bill-201303.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch07/data/flat/credit-card-bill-201310.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch08/data/flat/credit-card-bill-201310.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch09/data/credit-card-bill-201311.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,-674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,-793.20,2013-2-9 15:15:37,Longyang road 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,-893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch08/data/flat/credit-card-bill-201311.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 3 | 4047390012345678,tom,-674.70,2013-2-6 16:26:49,South Linyi road 4 | 4047390012345678,tom,-793.20,2013-2-9 15:15:37,Longyang road 5 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 6 | 4047390012345678,tom,-893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch11/data/credit-card-bill-201310.csv: -------------------------------------------------------------------------------- 1 | 1,4047390012345678,tom,100.00,2013-10-2 12:00:08,Lu Jia Zui road 2 | 2,4047390012345678,tom,320.00,2013-10-3 10:35:21,Lu Jia Zui road 3 | 3,4047390012345678,tom,674.70,2013-10-6 16:26:49,South Linyi road 4 | 4,4047390012345678,tom,793.20,2013-10-9 15:15:37,Longyang road 5 | 5,4047390012345678,tom,360.00,2013-10-11 11:12:38,Longyang road 6 | 6,4047390012345678,tom,893.00,2013-10-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch11/data/credit-card-bill-201311.csv: -------------------------------------------------------------------------------- 1 | 7,4047390012345678,tom,100.00,2013-11-2 12:00:08,Lu Jia Zui road 2 | 8,4047390012345678,tom,320.00,2013-11-3 10:35:21,Lu Jia Zui road 3 | 9,4047390012345678,tom,674.70,2013-11-6 16:26:49,South Linyi road 4 | 10,4047390012345678,tom,793.20,2013-11-9 15:15:37,Longyang road 5 | 11,4047390012345678,tom,360.00,2013-11-11 11:12:38,Longyang road 6 | 12,4047390012345678,tom,893.00,2013-11-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch11/data/credit-card-bill-201312.csv: -------------------------------------------------------------------------------- 1 | 13,4047390012345678,tom,100.00,2013-12-2 12:00:08,Lu Jia Zui road 2 | 14,4047390012345678,tom,320.00,2013-12-3 10:35:21,Lu Jia Zui road 3 | 15,4047390012345678,tom,674.70,2013-12-6 16:26:49,South Linyi road 4 | 16,4047390012345678,tom,793.20,2013-12-9 15:15:37,Longyang road 5 | 17,4047390012345678,tom,360.00,2013-12-11 11:12:38,Longyang road 6 | 18,4047390012345678,tom,893.00,2013-12-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/cfg/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch07/cfg/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/credit-card-bill-multiline-201303.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08 2 | ,Lu Jia Zui road 3 | 4047390012345678,tom,320.00,2013-2-3 10:35:21 4 | ,Lu Jia Zui road 5 | 4047390012345678,tom,674.70,2013-2-6 16:26:49 6 | ,South Linyi road 7 | 4047390012345678,tom,793.20,2013-2-9 15:15:37 8 | ,Longyang road 9 | 4047390012345678,tom,360.00,2013-2-11 11:12:38 10 | ,Longyang road 11 | 4047390012345678,tom,893.00,2013-2-28 20:34:19 12 | ,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/credit-card-bill-fixed-length-201303.csv: -------------------------------------------------------------------------------- 1 | 4041390012345678tom 00100.002013-02-02 12:00:08 Lu Jia Zui road 2 | 4042390012345678tom 00320.002013-02-03 10:35:21 Lu Jia Zui road 3 | 4043390012345678jerry 00674.702013-02-06 16:26:49 South Linyi road 4 | 4044390012345678rose 00793.202013-02-09 15:15:37 Longyang road 5 | 4045390012345678bruce 00360.002013-02-11 11:12:38 Longyang road 6 | 4046390012345678rachle 00893.002013-02-28 20:34:19 Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/HelloWorldService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | import org.springframework.batch.repeat.RepeatStatus; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-3-23上午12:46:34 11 | */ 12 | public class HelloWorldService { 13 | 14 | public RepeatStatus hello() throws Exception { 15 | System.out.println("***---HelloWorldService.hello()---***"); 16 | return RepeatStatus.FINISHED; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-batch-example/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu Nov 20 21:48:41 CST 2014 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 8 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 9 | org.eclipse.jdt.core.compiler.source=1.6 10 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/batchapp-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch02/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch02; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-1-6下午09:55:38 11 | */ 12 | public class CreditBillProcessor implements 13 | ItemProcessor { 14 | 15 | public CreditBill process(CreditBill bill) throws Exception { 16 | System.out.println(bill.toString()); 17 | return bill; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch03/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch03; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-1-6下午09:55:38 11 | */ 12 | public class CreditBillProcessor implements 13 | ItemProcessor { 14 | 15 | public CreditBill process(CreditBill bill) throws Exception { 16 | System.out.println(bill.toString()); 17 | return bill; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch04/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch04; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-1-6下午09:55:38 11 | */ 12 | public class CreditBillProcessor implements 13 | ItemProcessor { 14 | 15 | public CreditBill process(CreditBill bill) throws Exception { 16 | System.out.println(bill.toString()); 17 | return bill; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-1-6下午09:55:38 11 | */ 12 | public class CreditBillProcessor implements 13 | ItemProcessor { 14 | 15 | public CreditBill process(CreditBill bill) throws Exception { 16 | System.out.println(bill.toString()); 17 | return bill; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-1-6下午09:55:38 11 | */ 12 | public class CreditBillProcessor implements 13 | ItemProcessor { 14 | 15 | public CreditBill process(CreditBill bill) throws Exception { 16 | System.out.println(bill.toString()); 17 | return bill; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/jpa/persistence.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | com.juxtapose.example.ch06.jpa.CreditBill 7 | true 8 | 9 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2013-9-19下午01:15:37 12 | */ 13 | public class CreditBillProcessor implements 14 | ItemProcessor { 15 | 16 | public CreditBill process(CreditBill bill) throws Exception { 17 | System.out.println(bill.toString()); 18 | return bill; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/ibatis/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.ibatis; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-1-6下午09:55:38 11 | */ 12 | public class CreditBillProcessor implements 13 | ItemProcessor { 14 | 15 | public CreditBill process(CreditBill bill) throws Exception { 16 | System.out.println(bill.toString()); 17 | return bill; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/MockARuntimeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | /** 7 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 8 | * 2013-3-25下午10:28:35 9 | */ 10 | public class MockARuntimeException extends RuntimeException { 11 | 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = -3841087497940611523L; 16 | public MockARuntimeException(){ 17 | super(); 18 | } 19 | public MockARuntimeException(String message){ 20 | super(message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/MockBRuntimeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | /** 7 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 8 | * 2013-3-25下午10:28:35 9 | */ 10 | public class MockBRuntimeException extends RuntimeException { 11 | 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = -3841087497940611523L; 16 | public MockBRuntimeException(){ 17 | super(); 18 | } 19 | public MockBRuntimeException(String message){ 20 | super(message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/hibernate/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.hibernate; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-1-6下午09:55:38 11 | */ 12 | public class CreditBillProcessor implements 13 | ItemProcessor { 14 | 15 | public CreditBill process(CreditBill bill) throws Exception { 16 | System.out.println(bill.toString()); 17 | return bill; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/jpa/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.jpa; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2013-9-1上午09:04:49 12 | */ 13 | public class CreditBillProcessor implements 14 | ItemProcessor { 15 | 16 | public CreditBill process(CreditBill bill) throws Exception { 17 | System.out.println(bill.toString()); 18 | return bill; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch09/chunk/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch09.chunk; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2013-9-19下午01:15:37 12 | */ 13 | public class CreditBillProcessor implements 14 | ItemProcessor { 15 | 16 | public CreditBill process(CreditBill bill) throws Exception { 17 | System.out.println(bill.toString()); 18 | return bill; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/MockARuntimeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry; 5 | 6 | /** 7 | * 8 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 9 | * 2013-10-21下午10:09:35 10 | */ 11 | public class MockARuntimeException extends RuntimeException { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = -3841087497940611523L; 17 | public MockARuntimeException(){ 18 | super(); 19 | } 20 | public MockARuntimeException(String message){ 21 | super(message); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/MockBRuntimeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry; 5 | 6 | /** 7 | * 8 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 9 | * 2013-10-21下午10:09:41 10 | */ 11 | public class MockBRuntimeException extends RuntimeException { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = -3841087497940611523L; 17 | public MockBRuntimeException(){ 18 | super(); 19 | } 20 | public MockBRuntimeException(String message){ 21 | super(message); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/FilterItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-9-30下午02:42:12 11 | */ 12 | public class FilterItemProcessor implements ItemProcessor { 13 | 14 | @Override 15 | public CreditBill process(CreditBill item) throws Exception { 16 | if(item.getAmount()> 500){ 17 | return null; 18 | }else{ 19 | return item; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/credit-card-bill-heterogonous-201303.csv: -------------------------------------------------------------------------------- 1 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | 3047390012345671,249.10,rose,2013/4/1 11:34:56 3 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 4 | 3047390012345671,249.10,rose,2013/4/1 11:34:56 5 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 6 | 3047390012345673,840.20,marry,2013/4/3 3:21:43 7 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 8 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 9 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/PartTranslateItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | 9 | /** 10 | * 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-9-30上午10:34:34 13 | */ 14 | public class PartTranslateItemProcessor implements 15 | ItemProcessor { 16 | 17 | public CreditBill process(CreditBill bill) throws Exception { 18 | bill.setAddress(bill.getAddress() + "," + bill.getName()); 19 | return bill; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/ExistService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08; 5 | 6 | import org.springframework.batch.item.validator.ValidationException; 7 | 8 | 9 | /** 10 | * 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-9-30下午11:04:52 13 | */ 14 | public class ExistService { 15 | public CreditBill validate(CreditBill creditBill) throws ValidationException { 16 | if(Double.compare(0, creditBill.getAmount()) >0) { 17 | throw new ValidationException("Credit bill cannot be negative!"); 18 | } 19 | return creditBill; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/credit-card-bill-201303-complex.csv: -------------------------------------------------------------------------------- 1 | accountID,name,amount,date,address 2 | ## this line is first comment 3 | 4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 4 | ## maybe address is not right 5 | 4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 6 | $$ this line is comment, begin with && 7 | 4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 8 | 4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 9 | 4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 10 | ## maybe time is not right 11 | 4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch07/jpa/persistence.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | com.juxtapose.example.ch07.jpa.CreditBill 7 | com.juxtapose.example.ch07.jpa.DestinationCreditBill 8 | true 9 | 10 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch11/partition/remote/MessageTransformer.java: -------------------------------------------------------------------------------- 1 | package com.juxtapose.example.ch11.partition.remote; 2 | 3 | import java.util.Collection; 4 | 5 | import org.springframework.batch.core.StepExecution; 6 | import org.springframework.integration.Message; 7 | 8 | /** 9 | * 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2014-3-23下午06:16:21 12 | */ 13 | public class MessageTransformer { 14 | @SuppressWarnings("unchecked") 15 | public Message> extract(Message inMessage) { 16 | return (Message>)inMessage; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch09/Constant.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch09; 5 | 6 | /** 7 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 8 | * 2013-10-7下午02:03:46 9 | */ 10 | public interface Constant { 11 | public static final String READ_FILE_NAME = "readFileName"; 12 | public static final String READ_FILE = "readFile"; 13 | public static final String WORK_DIRECTORY = "workDirectory"; 14 | public static final String WRITE_FILE = "writeFile"; 15 | public static final String WRITE_TARGET = "writeTarget"; 16 | 17 | public static final String VERITY_STATUS = "Verity_Status"; 18 | } 19 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/credit-card-bill-delimited-201303.csv: -------------------------------------------------------------------------------- 1 | credit,4047390012345678,tom,100.00,2013-2-2 12:00:08,Lu Jia Zui road 2 | debit,3047390012345671,249.10,rose,2013/4/1 11:34:56 3 | credit,4047390012345678,tom,320.00,2013-2-3 10:35:21,Lu Jia Zui road 4 | debit,3047390012345671,249.10,rose,2013/4/1 11:34:56 5 | credit,4047390012345678,tom,674.70,2013-2-6 16:26:49,South Linyi road 6 | debit,3047390012345673,840.20,marry,2013/4/3 3:21:43 7 | credit,4047390012345678,tom,793.20,2013-2-9 15:15:37,Longyang road 8 | credit,4047390012345678,tom,360.00,2013-2-11 11:12:38,Longyang road 9 | credit,4047390012345678,tom,893.00,2013-2-28 20:34:19,Hunan road -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/ConsoleWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.item.ItemWriter; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-19下午08:56:21 13 | */ 14 | public class ConsoleWriter implements ItemWriter { 15 | 16 | public void write(List items) throws Exception { 17 | System.out.println("Write begin:"); 18 | for(String item : items){ 19 | System.out.print(item + ","); 20 | } 21 | System.out.println("Write end!!"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/classifiercomposite/CreditBillRouterClassifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.classifiercomposite; 5 | 6 | 7 | import org.springframework.classify.annotation.Classifier; 8 | 9 | import com.juxtapose.example.ch07.CreditBill; 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-9-23上午08:25:06 13 | */ 14 | public class CreditBillRouterClassifier{ 15 | @Classifier 16 | public String classify(CreditBill classifiable) { 17 | if(classifiable.getAmount() > 500){ 18 | return "large"; 19 | }else{ 20 | return "small"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch04/stop/ConsoleWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch04.stop; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.item.ItemWriter; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-19下午08:56:21 13 | */ 14 | public class ConsoleWriter implements ItemWriter { 15 | 16 | public void write(List items) throws Exception { 17 | System.out.println("Write begin:"); 18 | for(String item : items){ 19 | System.out.print(item + ","); 20 | } 21 | System.out.println("Write end!!"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/flat/DefaultLineCallbackHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.flat; 5 | 6 | import org.springframework.batch.item.file.LineCallbackHandler; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-4-3上午09:41:08 11 | */ 12 | public class DefaultLineCallbackHandler implements LineCallbackHandler { 13 | 14 | /* (non-Javadoc) 15 | * @see org.springframework.batch.item.file.LineCallbackHandler#handleLine(java.lang.String) 16 | */ 17 | public void handleLine(String line) { 18 | System.out.println("Skipped line content:" + line); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/skip/ConsoleWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.skip; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.item.ItemWriter; 9 | 10 | /** 11 | * 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-10-20下午10:06:38 14 | */ 15 | public class ConsoleWriter implements ItemWriter { 16 | 17 | public void write(List items) throws Exception { 18 | System.out.println("Write begin:"); 19 | for(String item : items){ 20 | System.out.print(item + ","); 21 | } 22 | System.out.println("Write end!!"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/ConsoleWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.item.ItemWriter; 9 | 10 | /** 11 | * 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-10-21下午10:11:53 14 | */ 15 | public class ConsoleWriter implements ItemWriter { 16 | 17 | public void write(List items) throws Exception { 18 | System.out.println("Write begin:"); 19 | for(String item : items){ 20 | System.out.print(item + ","); 21 | } 22 | System.out.println("Write end!!"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch04/JobLaunchScheduler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch04; 5 | 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.support.ClassPathXmlApplicationContext; 8 | 9 | /** 10 | * 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-2-28下午08:34:48 13 | */ 14 | public class JobLaunchScheduler { 15 | 16 | /** 17 | * @param args 18 | */ 19 | public static void main(String[] args) { 20 | @SuppressWarnings("unused") 21 | ApplicationContext context = new ClassPathXmlApplicationContext("ch04/job/job-spring-scheduler.xml"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchJMS.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-21下午05:25:54 16 | */ 17 | public class JobLaunchJMS { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-jms.xml", "jmsWriteJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch10/JobLaunchSkip.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch10; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-2-28下午08:34:48 16 | */ 17 | public class JobLaunchSkip { 18 | /** 19 | * @param args 20 | */ 21 | public static void main(String[] args) { 22 | JobLaunchBase.executeJob("ch10/job/job-step-skip.xml", "skipJob", 23 | new JobParametersBuilder().addDate("date", new Date())); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchJDBC.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchJDBC { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-db-jdbc.xml", "dbWriteJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch08/JobLaunchFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch08; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchFilter { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch08/job/job-filter.xml", "filterJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch10/JobLaunchRetry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch10; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-21下午10:14:09 16 | */ 17 | public class JobLaunchRetry { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch10/job/job-step-retry.xml", "retryJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/CreditBillValidator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08; 5 | 6 | import org.springframework.batch.item.validator.ValidationException; 7 | import org.springframework.batch.item.validator.Validator; 8 | 9 | /** 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2013-9-30下午04:36:12 12 | */ 13 | public class CreditBillValidator implements Validator { 14 | 15 | @Override 16 | public void validate(CreditBill creditBill) throws ValidationException { 17 | if(Double.compare(0, creditBill.getAmount()) >0) { 18 | throw new ValidationException("Credit bill cannot be negative!"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchFlatFile.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-2-28下午08:34:48 16 | */ 17 | public class JobLaunchFlatFile { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-flatfile.xml", "flatFileJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchIbatis.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchIbatis { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-db-ibatis.xml", "ibatisWriteJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchXml.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-2-28下午08:34:48 16 | */ 17 | public class JobLaunchXml { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-xml.xml", "xmlFileReadAndWriterJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchJavaMail.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-2-28下午08:34:48 16 | */ 17 | public class JobLaunchJavaMail { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-java-mail.xml", "javaMailJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch08/JobLaunchTranslate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch08; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:02 16 | */ 17 | public class JobLaunchTranslate { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch08/job/job-translate.xml", "translateJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch06/JobLaunchListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch06; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchListener extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch06/job/job-listener.xml", "itemReadJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchComposite.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-23上午08:06:09 16 | */ 17 | public class JobLaunchComposite { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-composite.xml", "compositeWriteJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchFileSets.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-21下午05:25:54 16 | */ 17 | public class JobLaunchFileSets { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-filesets.xml", "filesetsWriterJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchListener extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch07/job/job-listener.xml", "itemReadJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch08/JobLaunchListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch08; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-1上午12:10:57 16 | */ 17 | public class JobLaunchListener extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch08/job/job-listener.xml", "translateJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch10/JobLaunchSkipListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch10; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-2-28下午08:34:48 16 | */ 17 | public class JobLaunchSkipListener { 18 | /** 19 | * @param args 20 | */ 21 | public static void main(String[] args) { 22 | JobLaunchBase.executeJob("ch10/job/job-step-skip-listener.xml", "dbSkipJob", 23 | new JobParametersBuilder().addDate("date", new Date())); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/template/DefaultRecoveryCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry.template; 5 | 6 | import org.junit.Assert; 7 | import org.springframework.retry.RecoveryCallback; 8 | import org.springframework.retry.RetryContext; 9 | 10 | /** 11 | * 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-10-21下午11:00:17 14 | * @param 15 | */ 16 | public class DefaultRecoveryCallback implements RecoveryCallback { 17 | 18 | public T recover(RetryContext context) throws Exception { 19 | Assert.assertNotNull(context.getAttribute("count")); 20 | CountHelper.decrement(); 21 | return null; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchFileSetsExt.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-21下午05:25:54 16 | */ 17 | public class JobLaunchFileSetsExt { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-filesets.xml", "extFilesetsWriterJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchHibernate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchHibernate { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-db-hibernate.xml", "hibernateWriteJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch11/JobLaunchChunkRemote.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch11; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2014-3-23下午08:05:38 16 | */ 17 | public class JobLaunchChunkRemote { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch11/job/job-chunk-remote.xml", "remoteChunkJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch11/JobLaunchMultiThread.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch11; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-11-16下午10:59:46 16 | */ 17 | public class JobLaunchMultiThread { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch11/job/job-multithreade.xml", "multiThreadJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch11/JobLaunchPartitionDB.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch11; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-11-16下午10:59:46 16 | */ 17 | public class JobLaunchPartitionDB { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch11/job/job-partition-db.xml", "partitionJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch06/JobLaunchListenerMerge.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch06; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchListenerMerge extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch06/job/job-listener.xml", "mergeChunkJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchListenerMerge.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchListenerMerge extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch07/job/job-listener.xml", "mergeChunkJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch08/JobLaunchPartTranslate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch08; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchPartTranslate { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch08/job/job-translate.xml", "partTranslateJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch08/JobLaunchReuseService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch08; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchReuseService { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch08/job/job-reuse-service.xml", "reuseServiceJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch10/JobLaunchRetryPolicy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch10; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-21下午10:30:00 16 | */ 17 | 18 | public class JobLaunchRetryPolicy { 19 | 20 | /** 21 | * @param args 22 | */ 23 | public static void main(String[] args) { 24 | JobLaunchBase.executeJob("ch10/job/job-step-retry.xml", "retryPolicyJob", 25 | new JobParametersBuilder().addDate("date", new Date())); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch11/JobLaunchPartitionFile.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch11; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-11-16下午10:59:46 16 | */ 17 | public class JobLaunchPartitionFile { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch11/job/job-partition-file.xml", "partitionJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/DummyCreditItemWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.springframework.batch.item.ItemWriter; 10 | 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午03:18:17 16 | */ 17 | public class DummyCreditItemWriter implements ItemWriter { 18 | 19 | public List creditBills = new ArrayList(); 20 | 21 | public void write(List items) throws Exception { 22 | creditBills.addAll(items); 23 | } 24 | 25 | public List getCredits() { 26 | return creditBills; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/jpa/DummyCreditItemWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.jpa; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.springframework.batch.item.ItemWriter; 10 | 11 | /** 12 | * 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-9-1上午09:04:55 15 | */ 16 | public class DummyCreditItemWriter implements ItemWriter { 17 | 18 | public List creditBills = new ArrayList(); 19 | 20 | public void write(List items) throws Exception { 21 | creditBills.addAll(items); 22 | } 23 | 24 | public List getCredits() { 25 | return creditBills; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/DummyCreditItemWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.springframework.batch.item.ItemWriter; 10 | 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-29下午02:27:58 16 | */ 17 | public class DummyCreditItemWriter implements ItemWriter { 18 | 19 | public List creditBills = new ArrayList(); 20 | 21 | public void write(List items) throws Exception { 22 | creditBills.addAll(items); 23 | } 24 | 25 | public List getCredits() { 26 | return creditBills; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch06/JobLaunchErrorListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch06; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchErrorListener extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch06/job/job-listener.xml", "errorItemReadJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchErrorListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchErrorListener extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch07/job/job-listener.xml", "errorItemReadJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchXmlCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-2-28下午08:34:48 16 | */ 17 | public class JobLaunchXmlCallback { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-xml-callback.xml", "xmlFileReadAndWriterJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch08/JobLaunchErrorListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch08; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-1上午12:10:50 16 | */ 17 | public class JobLaunchErrorListener extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch08/job/job-listener.xml", "errorTranslateJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch08/JobLaunchListenerMerge.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch08; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-1上午12:11:03 16 | */ 17 | public class JobLaunchListenerMerge extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch08/job/job-listener.xml", "mergeTranslateJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch10/JobLaunchCacheCapacity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch10; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-21下午10:31:59 16 | */ 17 | public class JobLaunchCacheCapacity { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch10/job/job-step-retry.xml", "retryCacheCapacityJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch10/JobLaunchRetryTasklet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch10; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-21下午10:14:09 16 | */ 17 | public class JobLaunchRetryTasklet { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch10/job/job-step-retry-tasklet.xml", "retryTaskletJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch10/JobLaunchRetryListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch10; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-21下午10:14:09 16 | */ 17 | public class JobLaunchRetryListener { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch10/job/job-step-retry-listener.xml", "retryListener2Job", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch11/JobLaunchChunkRemoteOther.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch11; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2014-3-23下午08:05:38 16 | */ 17 | public class JobLaunchChunkRemoteOther { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch11/job/job-chunk-remote-other.xml", "remoteChunkJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch11/JobLaunchPartitionRemote.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch11; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-11-16下午10:59:46 16 | */ 17 | public class JobLaunchPartitionRemote { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch11/job/job-partition-remote.xml", "partitionRemoteJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/ibatis/DummyCreditItemWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.ibatis; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.springframework.batch.item.ItemWriter; 10 | 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午03:18:17 16 | */ 17 | public class DummyCreditItemWriter implements ItemWriter { 18 | 19 | public List creditBills = new ArrayList(); 20 | 21 | public void write(List items) throws Exception { 22 | creditBills.addAll(items); 23 | } 24 | 25 | public List getCredits() { 26 | return creditBills; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchCustomItemWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-29下午12:36:33 16 | */ 17 | public class JobLaunchCustomItemWriter { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-custom-itemwriter.xml", "customItemWriteJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchFlatFileCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-2-28下午08:34:48 16 | */ 17 | public class JobLaunchFlatFileCallback { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-flatfile-callback.xml", "flatFileComplexJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchReuseServiceWrite.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchReuseServiceWrite extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch07/job/job-reuse-service.xml", "reuseServiceJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch11/JobLaunchMultiThreadJdbcError.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch11; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-11-16下午10:59:46 16 | */ 17 | public class JobLaunchMultiThreadJdbcError { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch11/job/job-multithreade-db.xml", "dbErrorJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch06/JobLaunchReuseServiceRead.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch06; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchReuseServiceRead extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch06/job/job-reuse-service.xml", "reuseServiceReadJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/hibernate/DummyCreditItemWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.hibernate; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.springframework.batch.item.ItemWriter; 10 | 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午03:18:17 16 | */ 17 | public class DummyCreditItemWriter implements ItemWriter { 18 | 19 | public List creditBills = new ArrayList(); 20 | 21 | public void write(List items) throws Exception { 22 | creditBills.addAll(items); 23 | } 24 | 25 | public List getCredits() { 26 | return creditBills; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch08/JobLaunchComposite.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch08; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchComposite { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch08/job/job-composite.xml", "compositeJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("filter", "true")); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch08/JobLaunchValidate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch08; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchValidate { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch08/job/job-validate.xml", "validateJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("filter", "false")); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchClassifierComposite.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-23上午08:06:09 16 | */ 17 | public class JobLaunchClassifierComposite { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-composite-classify.xml", "classifierCompositeWriteJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/RadomExceptionItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | import java.util.Random; 7 | 8 | import org.springframework.batch.item.ItemProcessor; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-22下午04:50:05 13 | */ 14 | public class RadomExceptionItemProcessor implements ItemProcessor { 15 | Random ra = new Random(); 16 | 17 | public String process(String item) throws Exception { 18 | int i = ra.nextInt(10); 19 | System.out.println("Process " + item + "; Random i=" + i); 20 | if(i%2 == 0){ 21 | throw new RuntimeException("make error!"); 22 | }else{ 23 | return item; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchJpa.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchJpa { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-db-jpa.xml", "jpaWriteJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("id_begin", "1").addString("id_end", "5")); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch11/JobLaunchMultiThreadJdbcSynchronized.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch11; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-11-16下午10:59:46 16 | */ 17 | public class JobLaunchMultiThreadJdbcSynchronized { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch11/job/job-multithreade-db.xml", "dbSynchronizedJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchFlatFileCustomLineAggregator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-2-28下午08:34:48 16 | */ 17 | public class JobLaunchFlatFileCustomLineAggregator { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-flatfile-custom-aggregator.xml", "flatFileJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch04/stop/AutoReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch04.stop; 5 | 6 | import org.springframework.batch.item.ItemReader; 7 | import org.springframework.batch.item.NonTransientResourceException; 8 | import org.springframework.batch.item.ParseException; 9 | import org.springframework.batch.item.UnexpectedInputException; 10 | 11 | /** 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-3-19下午08:54:49 14 | */ 15 | public class AutoReader implements ItemReader { 16 | private int count = 0; 17 | 18 | public String read() throws Exception, UnexpectedInputException, 19 | ParseException, NonTransientResourceException { 20 | return ++count + ""; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/db/CreditBillPreparedStatementSetter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.db; 5 | 6 | import java.sql.PreparedStatement; 7 | import java.sql.SQLException; 8 | 9 | import org.springframework.jdbc.core.PreparedStatementSetter; 10 | 11 | /** 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-8-17上午06:59:58 14 | */ 15 | public class CreditBillPreparedStatementSetter implements 16 | PreparedStatementSetter { 17 | 18 | /* (non-Javadoc) 19 | * @see org.springframework.jdbc.core.PreparedStatementSetter#setValues(java.sql.PreparedStatement) 20 | */ 21 | public void setValues(PreparedStatement ps) throws SQLException { 22 | ps.setString(1, "5"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/flat/DefaultFlatFileFooterCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.flat; 5 | 6 | import java.io.IOException; 7 | import java.io.Writer; 8 | 9 | import org.springframework.batch.item.file.FlatFileFooterCallback; 10 | 11 | /** 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-9-20上午09:14:05 14 | */ 15 | public class DefaultFlatFileFooterCallback implements FlatFileFooterCallback { 16 | 17 | /* (non-Javadoc) 18 | * @see org.springframework.batch.item.file.FlatFileFooterCallback#writeFooter(java.io.Writer) 19 | */ 20 | @Override 21 | public void writeFooter(Writer writer) throws IOException { 22 | writer.write("##credit 201310 end."); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch11/multithread/ConsoleWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch11.multithread; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.item.ItemWriter; 9 | 10 | /** 11 | * 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-11-16下午10:58:20 14 | */ 15 | public class ConsoleWriter implements ItemWriter { 16 | 17 | public void write(List items) throws Exception { 18 | System.out.print("Write begin:"); 19 | for(String item : items){ 20 | System.out.print(item + ","); 21 | } 22 | System.out.print("Write end!!"); 23 | System.out.println("Job Write Thread name: " + Thread.currentThread().getName()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchRestartableCustomItemWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-29下午12:36:33 16 | */ 17 | public class JobLaunchRestartableCustomItemWriter { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch07/job/job-custom-itemwriter.xml", "restartableCustomItemWriteJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/step/listener/SystemOutItemReadListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.step.listener; 5 | 6 | import org.springframework.batch.core.ItemReadListener; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2012-9-1上午08:09:37 11 | */ 12 | public class SystemOutItemReadListener implements ItemReadListener { 13 | 14 | public void beforeRead() { 15 | System.out.println("ItemReadListener.beforeRead()"); 16 | } 17 | 18 | public void afterRead(String item) { 19 | System.out.println("ItemReadListener.afterRead()"); 20 | } 21 | 22 | public void onReadError(Exception ex) { 23 | System.out.println("ItemReadListener.onReadError()"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/flat/DefaultFlatFileHeaderCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.flat; 5 | 6 | import java.io.IOException; 7 | import java.io.Writer; 8 | 9 | import org.springframework.batch.item.file.FlatFileHeaderCallback; 10 | 11 | /** 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-9-20上午09:11:41 14 | */ 15 | public class DefaultFlatFileHeaderCallback implements FlatFileHeaderCallback { 16 | 17 | /* (non-Javadoc) 18 | * @see org.springframework.batch.item.file.FlatFileHeaderCallback#writeHeader(java.io.Writer) 19 | */ 20 | @Override 21 | public void writeHeader(Writer writer) throws IOException { 22 | writer.write("##credit 201310 begin."); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/SkipCountStepExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.StepExecution; 8 | import org.springframework.batch.core.listener.StepExecutionListenerSupport; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-9-30下午03:20:11 13 | */ 14 | public class SkipCountStepExecutionListener extends StepExecutionListenerSupport { 15 | @Override 16 | public ExitStatus afterStep(StepExecution stepExecution) { 17 | int skipCount = stepExecution.getSkipCount(); 18 | System.out.println("Skip count=" + skipCount); 19 | return stepExecution.getExitStatus(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/RadomExceptionItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry; 5 | 6 | import java.util.Random; 7 | 8 | import org.springframework.batch.item.ItemProcessor; 9 | 10 | /** 11 | * 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-10-21下午10:12:01 14 | */ 15 | public class RadomExceptionItemProcessor implements ItemProcessor { 16 | Random ra = new Random(); 17 | 18 | public String process(String item) throws Exception { 19 | int i = ra.nextInt(10); 20 | System.out.println("Process " + item + "; Random i=" + i); 21 | if(i%2 == 0){ 22 | throw new RuntimeException("make error!"); 23 | }else{ 24 | return item; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/skip/RadomExceptionItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.skip; 5 | 6 | import java.util.Random; 7 | 8 | import org.springframework.batch.item.ItemProcessor; 9 | 10 | /** 11 | * 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-10-20下午10:06:48 14 | */ 15 | public class RadomExceptionItemProcessor implements ItemProcessor { 16 | Random ra = new Random(); 17 | 18 | public String process(String item) throws Exception { 19 | int i = ra.nextInt(10); 20 | System.out.println("Process " + item + "; Random i=" + i); 21 | if(i%2 == 0){ 22 | throw new RuntimeException("make error!"); 23 | }else{ 24 | return item; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch11/JobLaunchMultiThreadJdbcSynchronizedRestart.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch11; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-11-16下午10:59:46 16 | */ 17 | public class JobLaunchMultiThreadJdbcSynchronizedRestart { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch11/job/job-multithreade-db.xml", "dbRestartSynchronizedJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch07/JobLaunchReuseServicePropertyExtractWrite.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch07; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午09:09:42 16 | */ 17 | public class JobLaunchReuseServicePropertyExtractWrite extends JobLaunchBase{ 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | executeJob("ch07/job/job-reuse-service.xml", "reuseServicePropertyExtractJob", 24 | new JobParametersBuilder().addDate("date", new Date())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/FilterCountStepExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.StepExecution; 8 | import org.springframework.batch.core.listener.StepExecutionListenerSupport; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-9-30下午03:20:11 13 | */ 14 | public class FilterCountStepExecutionListener extends StepExecutionListenerSupport { 15 | @Override 16 | public ExitStatus afterStep(StepExecution stepExecution) { 17 | int filterCount = stepExecution.getFilterCount(); 18 | System.out.println("Filter count=" + filterCount); 19 | return stepExecution.getExitStatus(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/flat/CopyHeaderLineCallbackHandler.java: -------------------------------------------------------------------------------- 1 | package com.juxtapose.example.ch06.flat; 2 | 3 | import java.io.IOException; 4 | import java.io.Writer; 5 | 6 | import org.springframework.batch.item.file.FlatFileHeaderCallback; 7 | import org.springframework.batch.item.file.LineCallbackHandler; 8 | 9 | /** 10 | * 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-4-3下午08:01:45 13 | */ 14 | public class CopyHeaderLineCallbackHandler implements LineCallbackHandler, 15 | FlatFileHeaderCallback { 16 | private String header = ""; 17 | 18 | public void handleLine(String line) { 19 | this.header = line; 20 | } 21 | 22 | public void writeHeader(Writer writer) throws IOException { 23 | writer.write(header); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/webapp/batchapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | SpringBatch 7 | 8 | org.springframework.web.context.ContextLoaderListener 9 | 10 | 11 | batchapp 12 | org.springframework.web.servlet.DispatcherServlet 13 | 14 | 15 | batchapp 16 | /* 17 | 18 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/step/listener/SystemOutSkipListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.step.listener; 5 | 6 | import org.springframework.batch.core.SkipListener; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2012-9-1上午08:18:40 11 | */ 12 | public class SystemOutSkipListener implements SkipListener { 13 | 14 | public void onSkipInRead(Throwable t) { 15 | System.out.println("SkipListener.onSkipInRead()"); 16 | } 17 | 18 | public void onSkipInWrite(String item, Throwable t) { 19 | System.out.println("SkipListener.onSkipInWrite()"); 20 | } 21 | 22 | public void onSkipInProcess(String item, Throwable t) { 23 | System.out.println("SkipListener.onSkipInProcess()"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch09/CreditService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch09; 5 | 6 | 7 | /** 8 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 9 | * 2013-10-7上午10:06:37 10 | */ 11 | public interface CreditService { 12 | 13 | /** 14 | * 解压缩文件 15 | * @param inputFile 16 | * @param outputDirectory 17 | */ 18 | void decompress(String inputFile,String outputDirectory); 19 | 20 | /** 21 | * 校验文件 22 | * @param outputDirectory 23 | */ 24 | String verify(String outputDirectory, String readFileName); 25 | 26 | /** 27 | * 清空临时作业空间 28 | * @param outputDirectory 29 | */ 30 | void clean(String outputDirectory); 31 | 32 | 33 | /** 34 | * 检查文件是否存在 35 | * @param file 36 | * @return 37 | */ 38 | boolean exists(String file); 39 | } 40 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/listener/SystemOutItemReadlistener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.listener; 5 | 6 | import org.springframework.batch.core.ItemReadListener; 7 | 8 | import com.juxtapose.example.ch06.CreditBill; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-9-16下午05:47:05 13 | */ 14 | public class SystemOutItemReadlistener implements ItemReadListener { 15 | public void beforeRead() { 16 | System.out.println("SystemOutItemReadlistener.beforeRead()"); 17 | } 18 | 19 | public void afterRead(CreditBill item) { 20 | System.out.println("SystemOutItemReadlistener.afterRead()"); 21 | } 22 | 23 | public void onReadError(Exception ex) { 24 | System.out.println("SystemOutItemReadlistener.onReadError()"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/template/BackOffContextImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry.template; 5 | 6 | import org.springframework.retry.RetryContext; 7 | import org.springframework.retry.backoff.BackOffContext; 8 | 9 | /** 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2013-10-22下午12:43:00 12 | */ 13 | public class BackOffContextImpl implements BackOffContext { 14 | private RetryContext retryContext; 15 | 16 | public BackOffContextImpl(){} 17 | public BackOffContextImpl(RetryContext retryContext){ 18 | this.retryContext = retryContext; 19 | } 20 | 21 | public RetryContext getRetryContext() { 22 | return retryContext; 23 | } 24 | public void setRetryContext(RetryContext retryContext) { 25 | this.retryContext = retryContext; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/step/listener/SystemOutItemProcessListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.step.listener; 5 | 6 | import org.springframework.batch.core.ItemProcessListener; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2012-9-1上午08:08:21 11 | */ 12 | public class SystemOutItemProcessListener implements ItemProcessListener { 13 | 14 | public void beforeProcess(String item) { 15 | System.out.println("ItemProcessListener.beforeProcess()"); 16 | } 17 | 18 | public void afterProcess(String item, String result) { 19 | System.out.println("ItemProcessListener.afterProcess()"); 20 | } 21 | 22 | public void onProcessError(String item, Exception e) { 23 | System.out.println("ItemProcessListener.onProcessError()"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/listener/ErrorItemReadListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.listener; 5 | 6 | import org.springframework.batch.core.ItemReadListener; 7 | 8 | import com.juxtapose.example.ch06.CreditBill; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-9-16下午06:22:13 13 | */ 14 | public class ErrorItemReadListener implements ItemReadListener { 15 | @SuppressWarnings("unused") 16 | public void beforeRead() { 17 | int i = 1/0; 18 | System.out.println("ErrorItemReadListener.beforeRead()"); 19 | } 20 | 21 | public void afterRead(CreditBill item) { 22 | System.out.println("ErrorItemReadListener.afterRead()"); 23 | } 24 | 25 | public void onReadError(Exception ex) { 26 | System.out.println("ErrorItemReadListener.onReadError()"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/xml/credit-card-bill-201303.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4047390012345678 5 | tom 6 | 100.00 7 | 2013-2-2 12:00:08 8 |
Lu Jia Zui road
9 |
10 | 11 | 4047390012345678 12 | tom 13 | 320.00 14 | 2013-2-3 10:35:21 15 |
Lu Jia Zui road
16 |
17 | 18 | 4047390012345678 19 | tom 20 | 674.70 21 | 2013-2-6 16:26:49 22 |
South Linyi road
23 |
24 |
25 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch07/data/xml/credit-card-bill-201310.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4047390012345678 5 | tom 6 | 100.00 7 | 2013-2-2 12:00:08 8 |
Lu Jia Zui road
9 |
10 | 11 | 4047390012345678 12 | tom 13 | 320.00 14 | 2013-2-3 10:35:21 15 |
Lu Jia Zui road
16 |
17 | 18 | 4047390012345678 19 | tom 20 | 674.70 21 | 2013-2-6 16:26:49 22 |
South Linyi road
23 |
24 |
25 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch04/listener/SystemOut.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch04.listener; 5 | 6 | import org.springframework.batch.core.JobExecution; 7 | import org.springframework.batch.core.annotation.AfterJob; 8 | import org.springframework.batch.core.annotation.BeforeJob; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-10上午07:38:39 13 | */ 14 | public class SystemOut { 15 | @BeforeJob 16 | public void beforeJob(JobExecution jobExecution) { 17 | System.out.println("Annotation: JobExecution creat time:" + jobExecution.getCreateTime()); 18 | // throw new RuntimeException("listener make error!"); 19 | } 20 | 21 | @AfterJob 22 | public void afterJob(JobExecution jobExecution) { 23 | System.out.println("Annotation: Job execute state:" + jobExecution.getStatus().toString()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/TransactionItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-3-25下午11:59:14 11 | */ 12 | public class TransactionItemProcessor implements ItemProcessor { 13 | private String errorCount = "3"; 14 | 15 | public String process(String item) throws Exception { 16 | System.out.println("TransactionItemProcessor.process() item is:" + item); 17 | if(errorCount.equals(item)){ 18 | throw new RuntimeException("make error!"); 19 | } 20 | return item; 21 | } 22 | 23 | public String getErrorCount() { 24 | return errorCount; 25 | } 26 | 27 | public void setErrorCount(String errorCount) { 28 | this.errorCount = errorCount; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/db/CreditBillRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.db; 5 | 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | 9 | import org.springframework.jdbc.core.RowMapper; 10 | 11 | import com.juxtapose.example.ch06.CreditBill; 12 | 13 | /** 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-8-16下午03:30:08 16 | */ 17 | public class CreditBillRowMapper implements RowMapper { 18 | 19 | public CreditBill mapRow(ResultSet rs, int rowNum) throws SQLException { 20 | CreditBill bill = new CreditBill(); 21 | bill.setAccountID(rs.getString("ACCOUNTID")); 22 | bill.setAddress(rs.getString("ADDRESS")); 23 | bill.setAmount(rs.getDouble("AMOUNT")); 24 | bill.setDate(rs.getString("DATE")); 25 | bill.setName(rs.getString("NAME")); 26 | return bill; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch11/partition/db/PartitionStepExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch11.partition.db; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.StepExecution; 8 | import org.springframework.batch.core.StepExecutionListener; 9 | 10 | 11 | /** 12 | * 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2014-3-22上午10:11:29 15 | */ 16 | public class PartitionStepExecutionListener implements StepExecutionListener { 17 | @Override 18 | public void beforeStep(StepExecution stepExecution) { 19 | System.out.println("ThreadName=" + Thread.currentThread().getName() + "; " 20 | + "StepName=" + stepExecution.getStepName() + ";"); 21 | } 22 | 23 | @Override 24 | public ExitStatus afterStep(StepExecution stepExecution) { 25 | return null; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/step/listener/SystemOutItemWriteListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.step.listener; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.core.ItemWriteListener; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2012-9-1上午08:11:52 13 | */ 14 | public class SystemOutItemWriteListener implements ItemWriteListener { 15 | 16 | public void beforeWrite(List items) { 17 | System.out.println("ItemWriteListener.beforeWrite()"); 18 | } 19 | 20 | public void afterWrite(List items) { 21 | System.out.println("ItemWriteListener.afterWrite()"); 22 | } 23 | 24 | public void onWriteError(Exception exception, List items) { 25 | System.out.println("ItemWriteListener.onWriteError()"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/TranslateItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | 9 | /** 10 | * 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-9-30上午10:34:34 13 | */ 14 | public class TranslateItemProcessor implements 15 | ItemProcessor { 16 | 17 | public DestinationCreditBill process(CreditBill bill) throws Exception { 18 | DestinationCreditBill destCreditBill = new DestinationCreditBill(); 19 | destCreditBill.setAccountID(bill.getAccountID()); 20 | destCreditBill.setAddress(bill.getAddress()); 21 | destCreditBill.setAmount(bill.getAmount()); 22 | destCreditBill.setDate(bill.getDate()); 23 | destCreditBill.setId(bill.getId()); 24 | destCreditBill.setName(bill.getName()); 25 | return destCreditBill; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/AlwaysExceptionItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | import java.util.Random; 7 | 8 | import org.springframework.batch.item.ItemProcessor; 9 | 10 | 11 | /** 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-3-25上午05:16:21 14 | */ 15 | public class AlwaysExceptionItemProcessor implements ItemProcessor { 16 | Random ra = new Random(); 17 | public String process(String item) throws Exception { 18 | int i = ra.nextInt(10); 19 | if(i%2 == 0){ 20 | System.out.println("Process " + item + "; Random i=" + i +"; Exception:MockARuntimeException"); 21 | throw new MockARuntimeException("make error!"); 22 | }else{ 23 | System.out.println("Process " + item + "; Random i=" + i +"; Exception:MockBRuntimeException"); 24 | throw new MockBRuntimeException("make error!"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/template/CountHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry.template; 5 | 6 | import java.util.concurrent.atomic.AtomicInteger; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-10-22下午10:58:15 11 | */ 12 | public class CountHelper { 13 | private static AtomicInteger count = new AtomicInteger(0); 14 | public static void init(){ 15 | count = new AtomicInteger(0); 16 | } 17 | 18 | public static int getCount(){ 19 | return count.get(); 20 | } 21 | 22 | public static void increment(){ 23 | count.incrementAndGet(); 24 | } 25 | public static int incrementAndGet(){ 26 | return count.incrementAndGet(); 27 | } 28 | 29 | public static void decrement(){ 30 | count.decrementAndGet(); 31 | } 32 | 33 | public static int decrementAndGet(){ 34 | return count.decrementAndGet(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/jpa/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.jpa; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-1-6下午09:55:38 11 | */ 12 | public class CreditBillProcessor implements 13 | ItemProcessor { 14 | 15 | public DestinationCreditBill process(CreditBill bill) throws Exception { 16 | System.out.println(bill.toString()); 17 | DestinationCreditBill destCreditBill = new DestinationCreditBill(); 18 | destCreditBill.setAccountID(bill.getAccountID()); 19 | destCreditBill.setAddress(bill.getAddress()); 20 | destCreditBill.setAmount(bill.getAmount()); 21 | destCreditBill.setDate(bill.getDate()); 22 | destCreditBill.setId(bill.getId()); 23 | destCreditBill.setName(bill.getName()); 24 | return destCreditBill; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/data/flat/credit-card-bill-201303.json: -------------------------------------------------------------------------------- 1 | { "accountID": "4047390012345678", 2 | "name": "tom", 3 | "amount": 100.00, 4 | "date": "2013-2-2 12:00:08", 5 | "address": "Lu Jia Zui road"} 6 | { "accountID": "4047390012345678", 7 | "name": "tom", 8 | "amount": 320.00, 9 | "date": "2013-2-3 10:35", 10 | "address": "Lu Jia Zui road"} 11 | { "accountID": "4047390012345678", 12 | "name": "tom", 13 | "amount": 674.70, 14 | "date": "2013-2-6 16:26:49", 15 | "address": "South Linyi road"} 16 | { "accountID": "4047390012345678", 17 | "name": "tom", 18 | "amount": 793.20, 19 | "date": "2013-2-9 15:15:37", 20 | "address": "Longyang road"} 21 | { "accountID": "4047390012345678", 22 | "name": "tom", 23 | "amount": 360.00, 24 | "date": "2013-2-11 11:12:38", 25 | "address": "Longyang road"} 26 | { "accountID": "4047390012345678", 27 | "name": "tom", 28 | "amount": 893.00, 29 | "date": "2013-2-28 20:34:19", 30 | "address": "Hunan road"} -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/reuse/ExistService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.reuse; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import com.juxtapose.example.ch06.CreditBill; 10 | 11 | /** 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-9-7下午01:37:54 14 | */ 15 | public class ExistService { 16 | private static List list = new ArrayList(); 17 | static{ 18 | list.add(new CreditBill("4047390012345678","tom",100.00,"2013-2-2 12:00:08","Lu Jia Zui road")); 19 | list.add(new CreditBill("4047390012345678","tom",320,"2013-2-3 10:35:21","Lu Jia Zui road")); 20 | list.add(new CreditBill("4047390012345678","tom",360.00,"2013-2-11 11:12:38","Longyang road")); 21 | } 22 | /** 23 | * 24 | * @return 25 | */ 26 | public List queryAllCreditBill(){ 27 | //business service 28 | return list; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/AlwaysExceptionItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry; 5 | 6 | import java.util.Random; 7 | 8 | import org.springframework.batch.item.ItemProcessor; 9 | 10 | 11 | /** 12 | * 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-10-21下午10:11:38 15 | */ 16 | public class AlwaysExceptionItemProcessor implements ItemProcessor { 17 | Random ra = new Random(); 18 | public String process(String item) throws Exception { 19 | int i = ra.nextInt(10); 20 | if(i%2 == 0){ 21 | System.out.println("Process " + item + "; Random i=" + i +"; Exception:MockARuntimeException"); 22 | throw new MockARuntimeException("make error!"); 23 | }else{ 24 | System.out.println("Process " + item + "; Random i=" + i +"; Exception:MockBRuntimeException"); 25 | throw new MockBRuntimeException("make error!"); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch04/exitstatus/CustomerExitCodeMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch04.exitstatus; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.launch.support.ExitCodeMapper; 8 | 9 | /** 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2013-3-18下午10:14:50 12 | */ 13 | public class CustomerExitCodeMapper implements ExitCodeMapper { 14 | 15 | /* (non-Javadoc) 16 | * @see org.springframework.batch.core.launch.support.ExitCodeMapper#intValue(java.lang.String) 17 | */ 18 | public int intValue(String exitCode) { 19 | if (ExitStatus.COMPLETED.getExitCode().equals(exitCode)) { 20 | return 1; 21 | } else if (ExitStatus.FAILED.getExitCode().equals(exitCode)) { 22 | return 2; 23 | } else if (ExitStatus.STOPPED.getExitCode().equals(exitCode)) { 24 | return 3; 25 | } else { 26 | return 4; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/listener/SystemOutAnnotation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.listener; 5 | 6 | import org.springframework.batch.core.annotation.AfterRead; 7 | import org.springframework.batch.core.annotation.BeforeRead; 8 | import org.springframework.batch.core.annotation.OnReadError; 9 | 10 | import com.juxtapose.example.ch06.CreditBill; 11 | 12 | /** 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-9-16下午05:47:05 15 | */ 16 | public class SystemOutAnnotation { 17 | @BeforeRead 18 | public void beforeRead() { 19 | System.out.println("SystemOutAnnotation.beforeRead()"); 20 | } 21 | 22 | @AfterRead 23 | public void afterRead(CreditBill item) { 24 | System.out.println("SystemOutAnnotation.afterRead()"); 25 | } 26 | 27 | @OnReadError 28 | public void onReadError(Exception ex) { 29 | System.out.println("SystemOutAnnotation.onReadError()"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/db/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.db; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2013-9-19下午01:15:37 12 | */ 13 | public class CreditBillProcessor implements 14 | ItemProcessor { 15 | 16 | public DestinationCreditBill process(CreditBill bill) throws Exception { 17 | System.out.println(bill.toString()); 18 | DestinationCreditBill destCreditBill = new DestinationCreditBill(); 19 | destCreditBill.setAccountID(bill.getAccountID()); 20 | destCreditBill.setAddress(bill.getAddress()); 21 | destCreditBill.setAmount(bill.getAmount()); 22 | destCreditBill.setDate(bill.getDate()); 23 | destCreditBill.setId(bill.getId()); 24 | destCreditBill.setName(bill.getName()); 25 | return destCreditBill; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/hibernate/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.hibernate; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 10 | * 2013-1-6下午09:55:38 11 | */ 12 | public class CreditBillProcessor implements 13 | ItemProcessor { 14 | 15 | public DestinationCreditBill process(CreditBill bill) throws Exception { 16 | System.out.println(bill.toString()); 17 | DestinationCreditBill destCreditBill = new DestinationCreditBill(); 18 | destCreditBill.setAccountID(bill.getAccountID()); 19 | destCreditBill.setAddress(bill.getAddress()); 20 | destCreditBill.setAmount(bill.getAmount()); 21 | destCreditBill.setDate(bill.getDate()); 22 | destCreditBill.setId(bill.getId()); 23 | destCreditBill.setName(bill.getName()); 24 | return destCreditBill; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch11/multithread/DestCreditBillItemPreparedStatementSetter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch11.multithread; 5 | 6 | import java.sql.PreparedStatement; 7 | import java.sql.SQLException; 8 | 9 | import org.springframework.batch.item.database.ItemPreparedStatementSetter; 10 | 11 | /** 12 | * 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-11-17上午07:35:23 15 | */ 16 | public class DestCreditBillItemPreparedStatementSetter implements 17 | ItemPreparedStatementSetter { 18 | 19 | public void setValues(DestinationCreditBill item, PreparedStatement ps) 20 | throws SQLException { 21 | ps.setString(1, item.getId()); 22 | ps.setString(2, item.getAccountID()); 23 | ps.setString(3, item.getName()); 24 | ps.setDouble(4, item.getAmount()); 25 | ps.setString(5, item.getDate()); 26 | ps.setString(6, item.getAddress()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/flat/DebitBillFieldSetMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.flat; 5 | 6 | import org.springframework.batch.item.file.mapping.FieldSetMapper; 7 | import org.springframework.batch.item.file.transform.FieldSet; 8 | import org.springframework.validation.BindException; 9 | 10 | import com.juxtapose.example.ch06.DebitBill; 11 | 12 | /** 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-4-6上午07:13:55 15 | */ 16 | public class DebitBillFieldSetMapper implements FieldSetMapper { 17 | 18 | public DebitBill mapFieldSet(FieldSet fieldSet) throws BindException { 19 | DebitBill result = new DebitBill(); 20 | result.setAccountID(fieldSet.readString("accountID")); 21 | result.setName(fieldSet.readString("name")); 22 | result.setAmount(fieldSet.readDouble("amount")); 23 | result.setDate(fieldSet.readString("date")); 24 | return result; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/CreditBillFieldSetMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08; 5 | 6 | import org.springframework.batch.item.file.mapping.FieldSetMapper; 7 | import org.springframework.batch.item.file.transform.FieldSet; 8 | import org.springframework.validation.BindException; 9 | 10 | /** 11 | * 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-9-19下午01:13:17 14 | */ 15 | public class CreditBillFieldSetMapper implements FieldSetMapper { 16 | 17 | public CreditBill mapFieldSet(FieldSet fieldSet) throws BindException { 18 | CreditBill result = new CreditBill(); 19 | result.setAccountID(fieldSet.readString("accountID")); 20 | result.setName(fieldSet.readString("name")); 21 | result.setAmount(fieldSet.readDouble("amount")); 22 | result.setDate(fieldSet.readString("date")); 23 | result.setAddress(fieldSet.readString("address")); 24 | return result; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/cust/itemwriter/CustomCreditBillItemWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.cust.itemwriter; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.item.ItemWriter; 9 | import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; 10 | 11 | import com.juxtapose.example.ch07.CreditBill; 12 | 13 | 14 | /** 15 | * 16 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 17 | * 2013-9-29下午12:18:47 18 | */ 19 | public class CustomCreditBillItemWriter implements ItemWriter { 20 | private List result = TransactionAwareProxyFactory.createTransactionalList(); 21 | 22 | @Override 23 | public void write(List items) throws Exception { 24 | for(CreditBill item : items){ 25 | result.add(item); 26 | } 27 | } 28 | 29 | public List getResult() { 30 | return result; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch11/partition/CreditBillProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch11.partition; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | /** 9 | * 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2014-1-11下午02:38:01 12 | */ 13 | public class CreditBillProcessor implements 14 | ItemProcessor { 15 | 16 | public DestinationCreditBill process(CreditBill bill) throws Exception { 17 | System.out.println(bill.toString()); 18 | DestinationCreditBill destCreditBill = new DestinationCreditBill(); 19 | destCreditBill.setAccountID(bill.getAccountID()); 20 | destCreditBill.setAddress(bill.getAddress()); 21 | destCreditBill.setAmount(bill.getAmount()); 22 | destCreditBill.setDate(bill.getDate()); 23 | destCreditBill.setId(bill.getId()); 24 | destCreditBill.setName(bill.getName()); 25 | return destCreditBill; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchConditionalStop.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import org.springframework.batch.core.JobParametersBuilder; 7 | 8 | import test.com.juxtapose.example.JobLaunchBase; 9 | 10 | /** 11 | * 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-9-30上午11:11:09 14 | */ 15 | public class JobLaunchConditionalStop { 16 | 17 | /** 18 | * @param args 19 | */ 20 | public static void main(String[] args) { 21 | JobLaunchBase.executeJob("ch09/job/job-conditional-stop.xml", "conditionalStopJob", 22 | new JobParametersBuilder() 23 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310.zip") 24 | .addString("readFileName", "credit-card-bill-201310.csv") 25 | .addString("workDirectory", "file:target/ch09/work/") 26 | .addString("writeTarget","file:target/ch09/conditional_stop/outputFile.csv")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/reuse/ExistService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.reuse; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import com.juxtapose.example.ch07.CreditBill; 10 | 11 | 12 | /** 13 | * 模拟存在的服务.
14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-29上午10:30:23 16 | */ 17 | public class ExistService { 18 | List billList = new ArrayList(); 19 | 20 | public void insert(CreditBill creditBill){ 21 | billList.add(creditBill); 22 | System.out.println("ExistService insert:" + creditBill.toString()); 23 | } 24 | 25 | public void insert(String accountID, String name, double amount, 26 | String date, String address) { 27 | CreditBill creditBill = new CreditBill(accountID, name, amount, date, address); 28 | billList.add(creditBill); 29 | System.out.println("ExistService insert:" + creditBill.toString()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch11/partition/db/CreditBillRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch11.partition.db; 5 | 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | 9 | import org.springframework.jdbc.core.RowMapper; 10 | 11 | import com.juxtapose.example.ch11.partition.CreditBill; 12 | 13 | 14 | /** 15 | * 16 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 17 | * 2014-1-11下午03:10:28 18 | */ 19 | public class CreditBillRowMapper implements RowMapper { 20 | 21 | public CreditBill mapRow(ResultSet rs, int rowNum) throws SQLException { 22 | CreditBill bill = new CreditBill(); 23 | bill.setId(rs.getString("ID")); 24 | bill.setAccountID(rs.getString("ACCOUNTID")); 25 | bill.setAddress(rs.getString("ADDRESS")); 26 | bill.setAmount(rs.getDouble("AMOUNT")); 27 | bill.setDate(rs.getString("DATE")); 28 | bill.setName(rs.getString("NAME")); 29 | return bill; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch09/chunk/CreditBillFieldSetMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch09.chunk; 5 | 6 | import org.springframework.batch.item.file.mapping.FieldSetMapper; 7 | import org.springframework.batch.item.file.transform.FieldSet; 8 | import org.springframework.validation.BindException; 9 | 10 | /** 11 | * 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-9-19下午01:13:17 14 | */ 15 | public class CreditBillFieldSetMapper implements FieldSetMapper { 16 | 17 | public CreditBill mapFieldSet(FieldSet fieldSet) throws BindException { 18 | CreditBill result = new CreditBill(); 19 | result.setAccountID(fieldSet.readString("accountID")); 20 | result.setName(fieldSet.readString("name")); 21 | result.setAmount(fieldSet.readDouble("amount")); 22 | result.setDate(fieldSet.readString("date")); 23 | result.setAddress(fieldSet.readString("address")); 24 | return result; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch11/partition/PartitionStepExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch11.partition; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.StepExecution; 8 | import org.springframework.batch.core.StepExecutionListener; 9 | 10 | 11 | /** 12 | * 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2014-3-22上午10:11:29 15 | */ 16 | public class PartitionStepExecutionListener implements StepExecutionListener { 17 | @Override 18 | public void beforeStep(StepExecution stepExecution) { 19 | System.out.println("ThreadName=" + Thread.currentThread().getName() + "; " 20 | + "StepName=" + stepExecution.getStepName() + "; " 21 | + "FileName=" 22 | + stepExecution.getExecutionContext().getString("fileName")); 23 | } 24 | 25 | @Override 26 | public ExitStatus afterStep(StepExecution stepExecution) { 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/listener/SystemOut.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.listener; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.StepExecution; 8 | import org.springframework.batch.core.annotation.AfterStep; 9 | import org.springframework.batch.core.annotation.BeforeStep; 10 | 11 | /** 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-3-21下午10:52:28 14 | */ 15 | public class SystemOut { 16 | @BeforeStep 17 | public void beforeStep(StepExecution stepExecution) { 18 | System.out.println("SystemOut.beforeStep();" + 19 | "JobExecution creat time:" + stepExecution.getJobExecution().getCreateTime()); 20 | } 21 | 22 | @AfterStep 23 | public ExitStatus afterStep(StepExecution stepExecution) { 24 | System.out.println("SystemOut.afterStep();" + 25 | "Job execute state:" + stepExecution.getStatus().toString()); 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchSplit.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchSplit { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch09/job/job-split.xml", "splitJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310.zip") 26 | .addString("readFileName", "credit-card-bill-201310.csv") 27 | .addString("workDirectory", "file:target/ch09/work/") 28 | .addString("writeTarget","file:target/ch09/split/outputFile_10.csv")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/listener/SystemOutItemWriteListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.listener; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.core.ItemWriteListener; 9 | 10 | import com.juxtapose.example.ch07.CreditBill; 11 | 12 | 13 | /** 14 | * 15 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 16 | * 2013-9-29下午01:50:36 17 | */ 18 | public class SystemOutItemWriteListener implements ItemWriteListener { 19 | public void beforeWrite(List items) { 20 | System.out.println("SystemOutItemWriteListener.beforeWrite()"); 21 | } 22 | 23 | public void afterWrite(List items) { 24 | System.out.println("SystemOutItemWriteListener.afterWrite()"); 25 | } 26 | 27 | public void onWriteError(Exception exception, 28 | List items) { 29 | System.out.println("SystemOutItemWriteListener.onWriteError()"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/listener/SystemOutItemProcessListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08.listener; 5 | 6 | import org.springframework.batch.core.ItemProcessListener; 7 | 8 | import com.juxtapose.example.ch08.CreditBill; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-9-30下午11:59:52 13 | */ 14 | public class SystemOutItemProcessListener implements ItemProcessListener { 15 | 16 | @Override 17 | public void beforeProcess(CreditBill item) { 18 | System.out.println("SystemOutItemProcessListener.beforeProcess()"); 19 | } 20 | 21 | @Override 22 | public void afterProcess(CreditBill item, CreditBill result) { 23 | System.out.println("SystemOutItemProcessListener.afterProcess()"); 24 | } 25 | 26 | @Override 27 | public void onProcessError(CreditBill item, Exception e) { 28 | System.out.println("SystemOutItemProcessListener.onProcessError()"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/jdbc/DestCreditBillItemPreparedStatementSetter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.jdbc; 5 | 6 | import java.sql.PreparedStatement; 7 | import java.sql.SQLException; 8 | 9 | import org.springframework.batch.item.database.ItemPreparedStatementSetter; 10 | 11 | import com.juxtapose.example.ch07.db.DestinationCreditBill; 12 | 13 | /** 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-23下午10:33:20 16 | */ 17 | public class DestCreditBillItemPreparedStatementSetter implements 18 | ItemPreparedStatementSetter { 19 | 20 | public void setValues(DestinationCreditBill item, PreparedStatement ps) 21 | throws SQLException { 22 | ps.setString(1, item.getId()); 23 | ps.setString(2, item.getAccountID()); 24 | ps.setString(3, item.getName()); 25 | ps.setDouble(4, item.getAmount()); 26 | ps.setString(5, item.getDate()); 27 | ps.setString(6, item.getAddress()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchSequential.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchSequential { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch09/job/job-sequential.xml", "sequentialJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310.zip") 26 | .addString("readFileName", "credit-card-bill-201310.csv") 27 | .addString("workDirectory", "file:target/ch09/work/") 28 | .addString("writeTarget","file:target/ch09/sequential/outputFile.csv")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchConditional.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchConditional { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch09/job/job-conditional.xml", "conditionalJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310.zip") 26 | .addString("readFileName", "credit-card-bill-201310.csv") 27 | .addString("workDirectory", "file:target/ch09/work/") 28 | .addString("writeTarget","file:target/ch09/conditional/outputFile.csv")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/listener/ErrorItemProcessListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08.listener; 5 | 6 | import org.springframework.batch.core.ItemProcessListener; 7 | 8 | import com.juxtapose.example.ch08.CreditBill; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-10-1上午12:04:10 13 | */ 14 | public class ErrorItemProcessListener implements ItemProcessListener { 15 | 16 | @SuppressWarnings("unused") 17 | @Override 18 | public void beforeProcess(CreditBill item) { 19 | int i = 1/0; 20 | System.out.println("ErrorItemReadListener.beforeProcess()"); 21 | } 22 | 23 | @Override 24 | public void afterProcess(CreditBill item, CreditBill result) { 25 | System.out.println("ErrorItemReadListener.afterRead()"); 26 | } 27 | 28 | @Override 29 | public void onProcessError(CreditBill item, Exception e) { 30 | System.out.println("ErrorItemReadListener.onReadError()"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchExternalFlow.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchExternalFlow { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch09/job/job-external-flow.xml", "externalFlowJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310.zip") 26 | .addString("readFileName", "credit-card-bill-201310.csv") 27 | .addString("workDirectory", "file:target/ch09/work/") 28 | .addString("writeTarget","file:target/ch09/externalFlow/outputFile.csv")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/template/DefaultRetryCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry.template; 5 | 6 | import org.springframework.retry.RetryCallback; 7 | import org.springframework.retry.RetryContext; 8 | 9 | /** 10 | * 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-10-21下午11:00:27 13 | */ 14 | public class DefaultRetryCallback implements RetryCallback { 15 | private long sleepTime = 0L; 16 | 17 | public DefaultRetryCallback(){} 18 | public DefaultRetryCallback(long sleepTime){ 19 | this.sleepTime = sleepTime; 20 | } 21 | 22 | public String doWithRetry(RetryContext context) throws Exception { 23 | Integer count = (Integer)context.getAttribute("count"); 24 | if(count == null){ 25 | count = new Integer(0); 26 | } 27 | count++; 28 | context.setAttribute("count", count); 29 | Thread.sleep(sleepTime); 30 | throw new RuntimeException("Mock make exception on business logic."); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/flat/CreditBillFieldSetMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.flat; 5 | 6 | import org.springframework.batch.item.file.mapping.FieldSetMapper; 7 | import org.springframework.batch.item.file.transform.FieldSet; 8 | import org.springframework.validation.BindException; 9 | 10 | import com.juxtapose.example.ch06.CreditBill; 11 | 12 | /** 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-4-3下午03:13:55 15 | */ 16 | public class CreditBillFieldSetMapper implements FieldSetMapper { 17 | 18 | public CreditBill mapFieldSet(FieldSet fieldSet) throws BindException { 19 | CreditBill result = new CreditBill(); 20 | result.setAccountID(fieldSet.readString("accountID")); 21 | result.setName(fieldSet.readString("name")); 22 | result.setAmount(fieldSet.readDouble("amount")); 23 | result.setDate(fieldSet.readString("date")); 24 | result.setAddress(fieldSet.readString("address")); 25 | return result; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchExternalJobStep.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchExternalJobStep { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch09/job/job-external-job.xml", "externalJobJobStep", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310.zip") 26 | .addString("readFileName", "credit-card-bill-201310.csv") 27 | .addString("workDirectory", "file:target/ch09/work/") 28 | .addString("writeTarget","file:target/ch09/externalJob/outputFile.csv")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/jms/TransactionItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.jms; 5 | 6 | import org.springframework.batch.item.ItemProcessor; 7 | 8 | import com.juxtapose.example.ch06.CreditBill; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-25下午11:59:14 13 | */ 14 | public class TransactionItemProcessor implements ItemProcessor { 15 | private String errorCount = "3"; 16 | private int index = 0; 17 | 18 | public CreditBill process(CreditBill item) throws Exception { 19 | index ++; 20 | if(errorCount.equals(""+index)){ 21 | index = 0; 22 | throw new RuntimeException("make error!"); 23 | } 24 | System.out.println("TransactionItemProcessor.process() item is:" + index); 25 | return item; 26 | } 27 | 28 | public String getErrorCount() { 29 | return errorCount; 30 | } 31 | 32 | public void setErrorCount(String errorCount) { 33 | this.errorCount = errorCount; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/flat/CreditBillFieldSetMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.flat; 5 | 6 | import org.springframework.batch.item.file.mapping.FieldSetMapper; 7 | import org.springframework.batch.item.file.transform.FieldSet; 8 | import org.springframework.validation.BindException; 9 | 10 | import com.juxtapose.example.ch07.CreditBill; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-19下午01:13:17 16 | */ 17 | public class CreditBillFieldSetMapper implements FieldSetMapper { 18 | 19 | public CreditBill mapFieldSet(FieldSet fieldSet) throws BindException { 20 | CreditBill result = new CreditBill(); 21 | result.setAccountID(fieldSet.readString("accountID")); 22 | result.setName(fieldSet.readString("name")); 23 | result.setAmount(fieldSet.readDouble("amount")); 24 | result.setDate(fieldSet.readString("date")); 25 | result.setAddress(fieldSet.readString("address")); 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchConditionalDecider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchConditionalDecider { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch09/job/job-conditional-decider.xml", "conditionalDeciderJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310.zip") 26 | .addString("readFileName", "credit-card-bill-201310.csv") 27 | .addString("workDirectory", "file:target/ch09/work/") 28 | .addString("writeTarget","file:target/ch09/decider/outputFile.csv")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchConditionalEnd.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchConditionalEnd { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch09/job/job-conditional-end.xml", "conditionalEndJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310-notexist.zip") 26 | .addString("readFileName", "credit-card-bill-201310.csv") 27 | .addString("workDirectory", "file:target/ch09/work/") 28 | .addString("writeTarget","file:target/ch09/conditional_end/outputFile.csv")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch08/listener/SystemOutAnnotation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch08.listener; 5 | 6 | import org.springframework.batch.core.annotation.AfterProcess; 7 | import org.springframework.batch.core.annotation.BeforeProcess; 8 | import org.springframework.batch.core.annotation.OnProcessError; 9 | 10 | import com.juxtapose.example.ch08.CreditBill; 11 | 12 | /** 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-10-1上午12:01:33 15 | */ 16 | public class SystemOutAnnotation { 17 | @BeforeProcess 18 | public void beforeProcess(CreditBill item) { 19 | System.out.println("SystemOutAnnotation.beforeProcess()"); 20 | } 21 | 22 | @AfterProcess 23 | public void afterProcess(CreditBill item, CreditBill result) { 24 | System.out.println("SystemOutAnnotation.afterProcess()"); 25 | } 26 | 27 | @OnProcessError 28 | public void onProcessError(CreditBill item, Exception e) { 29 | System.out.println("SystemOutAnnotation.onProcessError()"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchConditionalFail.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchConditionalFail { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch09/job/job-conditional-fail.xml", "conditionalFailJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310-notexist.zip") 26 | .addString("readFileName", "credit-card-bill-201310.csv") 27 | .addString("workDirectory", "file:target/ch09/work/") 28 | .addString("writeTarget","file:target/ch09/conditional_fail/outputFile.csv")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch09/JobLaunchExternalFlowStep.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch09; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.JobParametersBuilder; 9 | 10 | import test.com.juxtapose.example.JobLaunchBase; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-30上午11:11:09 16 | */ 17 | public class JobLaunchExternalFlowStep { 18 | 19 | /** 20 | * @param args 21 | */ 22 | public static void main(String[] args) { 23 | JobLaunchBase.executeJob("ch09/job/job-external-flow-step.xml", "externalFlowStepJob", 24 | new JobParametersBuilder().addDate("date", new Date()) 25 | .addString("inputFile", "classpath:ch09/data/credit-card-bill-201310.zip") 26 | .addString("readFileName", "credit-card-bill-201310.csv") 27 | .addString("workDirectory", "file:target/ch09/work/") 28 | .addString("writeTarget","file:target/ch09/externalFlowStep/outputFile.csv")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/xml/HeaderStaxWriterCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.xml; 5 | 6 | import java.io.IOException; 7 | 8 | import javax.xml.stream.XMLEventFactory; 9 | import javax.xml.stream.XMLEventWriter; 10 | import javax.xml.stream.XMLStreamException; 11 | 12 | import org.springframework.batch.item.xml.StaxWriterCallback; 13 | 14 | /** 15 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 16 | * 2013-9-21下午03:47:06 17 | */ 18 | public class HeaderStaxWriterCallback implements StaxWriterCallback { 19 | 20 | /* (non-Javadoc) 21 | * @see org.springframework.batch.item.xml.StaxWriterCallback#write(javax.xml.stream.XMLEventWriter) 22 | */ 23 | @Override 24 | public void write(XMLEventWriter writer) throws IOException { 25 | XMLEventFactory factory = XMLEventFactory.newInstance(); 26 | try { 27 | writer.add(factory.createComment("credit 201310 begin.")); 28 | } catch (XMLStreamException e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch11/partition/CreditBillFieldSetMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch11.partition; 5 | 6 | import org.springframework.batch.item.file.mapping.FieldSetMapper; 7 | import org.springframework.batch.item.file.transform.FieldSet; 8 | import org.springframework.validation.BindException; 9 | 10 | 11 | /** 12 | * 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2014-1-11下午02:29:42 15 | */ 16 | public class CreditBillFieldSetMapper implements FieldSetMapper { 17 | 18 | public CreditBill mapFieldSet(FieldSet fieldSet) throws BindException { 19 | CreditBill result = new CreditBill(); 20 | result.setId(fieldSet.readString("id")); 21 | result.setAccountID(fieldSet.readString("accountID")); 22 | result.setName(fieldSet.readString("name")); 23 | result.setAmount(fieldSet.readDouble("amount")); 24 | result.setDate(fieldSet.readString("date")); 25 | result.setAddress(fieldSet.readString("address")); 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/step/listener/SystemOutJobExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.step.listener; 5 | 6 | import org.springframework.batch.core.JobExecution; 7 | import org.springframework.batch.core.JobExecutionListener; 8 | 9 | /** 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2012-9-1上午08:24:11 12 | */ 13 | public class SystemOutJobExecutionListener implements JobExecutionListener { 14 | 15 | /* (non-Javadoc) 16 | * @see org.springframework.batch.core.JobExecutionListener#beforeJob(org.springframework.batch.core.JobExecution) 17 | */ 18 | public void beforeJob(JobExecution jobExecution) { 19 | System.out.println("JobExecutionListener.beforeJob()"); 20 | } 21 | 22 | /* (non-Javadoc) 23 | * @see org.springframework.batch.core.JobExecutionListener#afterJob(org.springframework.batch.core.JobExecution) 24 | */ 25 | public void afterJob(JobExecution jobExecution) { 26 | System.out.println("JobExecutionListener.afterJob()"); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/AutoReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | import org.springframework.batch.item.ItemReader; 7 | import org.springframework.batch.item.NonTransientResourceException; 8 | import org.springframework.batch.item.ParseException; 9 | import org.springframework.batch.item.UnexpectedInputException; 10 | 11 | /** 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-3-19下午08:54:49 14 | */ 15 | public class AutoReader implements ItemReader { 16 | private int count = 0; 17 | private int maxCount = 30; 18 | 19 | public String read() throws Exception, UnexpectedInputException, 20 | ParseException, NonTransientResourceException { 21 | System.out.println("Read:" + count); 22 | if(count > maxCount){ 23 | return null; 24 | }else{ 25 | return ++count + ""; 26 | } 27 | } 28 | 29 | public int getMaxCount() { 30 | return maxCount; 31 | } 32 | 33 | public void setMaxCount(int maxCount) { 34 | this.maxCount = maxCount; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/listener/ErrorItemWriteListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.listener; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.core.ItemWriteListener; 9 | 10 | import com.juxtapose.example.ch07.CreditBill; 11 | 12 | 13 | /** 14 | * 15 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 16 | * 2013-9-29下午01:46:28 17 | */ 18 | public class ErrorItemWriteListener implements ItemWriteListener { 19 | @SuppressWarnings("unused") 20 | @Override 21 | public void beforeWrite(List items) { 22 | int i = 1/0; 23 | System.out.println("ErrorItemReadListener.beforeRead()"); 24 | } 25 | 26 | @Override 27 | public void afterWrite(List items) { 28 | System.out.println("ErrorItemReadListener.afterRead()"); 29 | } 30 | 31 | @Override 32 | public void onWriteError(Exception exception, 33 | List items) { 34 | System.out.println("ErrorItemReadListener.onReadError()"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch07/ibatis/ibatis-credit.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 25 | 26 | -------------------------------------------------------------------------------- /spring-batch-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | spring-batch-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.iam.jdt.core.mavenIncrementalBuilder 15 | 16 | 17 | 18 | 19 | org.maven.ide.eclipse.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.m2e.core.maven2Nature 31 | org.maven.ide.eclipse.maven2Nature 32 | org.eclipse.iam.jdt.core.mavenNature 33 | org.eclipse.jdt.core.javanature 34 | 35 | 36 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch06/ibatis/ibatis-credit.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 25 | 26 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/mail/MailItemProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.mail; 5 | 6 | import java.text.SimpleDateFormat; 7 | import java.util.Calendar; 8 | 9 | import org.springframework.batch.item.ItemProcessor; 10 | import org.springframework.mail.SimpleMailMessage; 11 | 12 | import com.juxtapose.example.ch07.CreditBill; 13 | 14 | /** 15 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 16 | * 2013-9-29下午08:15:18 17 | */ 18 | public class MailItemProcessor implements ItemProcessor { 19 | @Override 20 | public SimpleMailMessage process(CreditBill item) throws Exception { 21 | SimpleMailMessage msg = new SimpleMailMessage(); 22 | msg.setFrom("springbatchexample@163.com"); 23 | msg.setTo("springbatchexample@163.com"); 24 | msg.setSubject("Credit detail " + 25 | new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒"). 26 | format(Calendar.getInstance().getTime())); 27 | msg.setText("Credit details: " + item.toString()); 28 | return msg; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/AutoReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry; 5 | 6 | import org.springframework.batch.item.ItemReader; 7 | import org.springframework.batch.item.NonTransientResourceException; 8 | import org.springframework.batch.item.ParseException; 9 | import org.springframework.batch.item.UnexpectedInputException; 10 | 11 | /** 12 | * 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-10-21下午10:11:45 15 | */ 16 | public class AutoReader implements ItemReader { 17 | private int count = 0; 18 | private int maxCount = 30; 19 | 20 | public String read() throws Exception, UnexpectedInputException, 21 | ParseException, NonTransientResourceException { 22 | System.out.println("Read:" + count); 23 | if(count > maxCount){ 24 | return null; 25 | }else{ 26 | return ++count + ""; 27 | } 28 | } 29 | 30 | public int getMaxCount() { 31 | return maxCount; 32 | } 33 | 34 | public void setMaxCount(int maxCount) { 35 | this.maxCount = maxCount; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/skip/AutoReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.skip; 5 | 6 | import org.springframework.batch.item.ItemReader; 7 | import org.springframework.batch.item.NonTransientResourceException; 8 | import org.springframework.batch.item.ParseException; 9 | import org.springframework.batch.item.UnexpectedInputException; 10 | 11 | /** 12 | * 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-10-20下午10:06:32 15 | */ 16 | public class AutoReader implements ItemReader { 17 | private int count = 0; 18 | private int maxCount = 30; 19 | 20 | public String read() throws Exception, UnexpectedInputException, 21 | ParseException, NonTransientResourceException { 22 | System.out.println("Read:" + count); 23 | if(count > maxCount){ 24 | return null; 25 | }else{ 26 | return ++count + ""; 27 | } 28 | } 29 | 30 | public int getMaxCount() { 31 | return maxCount; 32 | } 33 | 34 | public void setMaxCount(int maxCount) { 35 | this.maxCount = maxCount; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/listener/ErrorStepExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.listener; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.StepExecution; 8 | import org.springframework.batch.core.StepExecutionListener; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-21下午11:34:43 13 | */ 14 | public class ErrorStepExecutionListener implements StepExecutionListener { 15 | 16 | /* (non-Javadoc) 17 | * @see org.springframework.batch.core.StepExecutionListener#beforeStep(org.springframework.batch.core.StepExecution) 18 | */ 19 | public void beforeStep(StepExecution stepExecution) { 20 | int i = 1/0; 21 | System.out.println(i); 22 | } 23 | 24 | /* (non-Javadoc) 25 | * @see org.springframework.batch.core.StepExecutionListener#afterStep(org.springframework.batch.core.StepExecution) 26 | */ 27 | public ExitStatus afterStep(StepExecution stepExecution) { 28 | // TODO Auto-generated method stub 29 | return null; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/reuse/CreditBillServiceAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.reuse; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.beans.factory.InitializingBean; 9 | 10 | import com.juxtapose.example.ch06.CreditBill; 11 | 12 | /** 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-9-7下午01:40:07 15 | */ 16 | public class CreditBillServiceAdapter implements InitializingBean{ 17 | private ExistService existService; 18 | List creditBillList; 19 | 20 | @Override 21 | public void afterPropertiesSet() throws Exception { 22 | this.creditBillList = existService.queryAllCreditBill(); 23 | } 24 | 25 | public CreditBill nextCreditBill() { 26 | if (creditBillList.size() > 0) { 27 | return creditBillList.remove(0); 28 | } else { 29 | return null; 30 | } 31 | } 32 | 33 | public ExistService getExistService() { 34 | return existService; 35 | } 36 | 37 | public void setExistService(ExistService existService) { 38 | this.existService = existService; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/listener/SystemOutAnnotation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.listener; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.batch.core.annotation.AfterWrite; 9 | import org.springframework.batch.core.annotation.BeforeWrite; 10 | import org.springframework.batch.core.annotation.OnWriteError; 11 | 12 | import com.juxtapose.example.ch07.CreditBill; 13 | 14 | 15 | /** 16 | * 17 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 18 | * 2013-9-29下午01:48:24 19 | */ 20 | public class SystemOutAnnotation { 21 | @BeforeWrite 22 | public void beforeWrite(List items) { 23 | System.out.println("SystemOutAnnotation.beforeWrite()"); 24 | } 25 | 26 | @AfterWrite 27 | public void afterWrite(List items) { 28 | System.out.println("SystemOutAnnotation.afterWrite()"); 29 | } 30 | 31 | @OnWriteError 32 | public void onWriteError(Exception exception, 33 | List items) { 34 | System.out.println("SystemOutAnnotation.onWriteError()"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch04/listener/SystemOutJobExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch04.listener; 5 | 6 | import org.springframework.batch.core.JobExecution; 7 | import org.springframework.batch.core.JobExecutionListener; 8 | 9 | /** 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2013-3-9下午08:46:28 12 | */ 13 | public class SystemOutJobExecutionListener implements JobExecutionListener { 14 | 15 | /* (non-Javadoc) 16 | * @see org.springframework.batch.core.JobExecutionListener#beforeJob(org.springframework.batch.core.JobExecution) 17 | */ 18 | public void beforeJob(JobExecution jobExecution) { 19 | System.out.println("JobExecution creat time:" + jobExecution.getCreateTime()); 20 | // throw new RuntimeException("listener make error!"); 21 | } 22 | 23 | /* (non-Javadoc) 24 | * @see org.springframework.batch.core.JobExecutionListener#afterJob(org.springframework.batch.core.JobExecution) 25 | */ 26 | public void afterJob(JobExecution jobExecution) { 27 | System.out.println("Job execute state:" + jobExecution.getStatus().toString()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/step/listener/SystemOutStepExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.step.listener; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.StepExecution; 8 | import org.springframework.batch.core.StepExecutionListener; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-21下午10:52:28 13 | */ 14 | public class SystemOutStepExecutionListener implements StepExecutionListener { 15 | 16 | /* (non-Javadoc) 17 | * @see org.springframework.batch.core.StepExecutionListener#beforeStep(org.springframework.batch.core.StepExecution) 18 | */ 19 | public void beforeStep(StepExecution stepExecution) { 20 | System.out.println("StepExecutionListener.beforeStep()"); 21 | } 22 | 23 | /* (non-Javadoc) 24 | * @see org.springframework.batch.core.StepExecutionListener#afterStep(org.springframework.batch.core.StepExecution) 25 | */ 26 | public ExitStatus afterStep(StepExecution stepExecution) { 27 | System.out.println("StepExecutionListener.afterStep()"); 28 | return null; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/cust/itemreader/CustomCreditBillItemReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.cust.itemreader; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.springframework.batch.item.ItemReader; 10 | import org.springframework.batch.item.NonTransientResourceException; 11 | import org.springframework.batch.item.ParseException; 12 | import org.springframework.batch.item.UnexpectedInputException; 13 | 14 | import com.juxtapose.example.ch06.CreditBill; 15 | 16 | /** 17 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 18 | * 2013-9-7下午02:12:56 19 | */ 20 | public class CustomCreditBillItemReader implements ItemReader { 21 | private List list = new ArrayList(); 22 | 23 | public CustomCreditBillItemReader(List list){ 24 | this.list = list; 25 | } 26 | 27 | @Override 28 | public CreditBill read() throws Exception, UnexpectedInputException, ParseException, 29 | NonTransientResourceException { 30 | if (!list.isEmpty()) { 31 | return list.remove(0); 32 | } 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch02/JobLaunch.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.com.juxtapose.example.ch02; 5 | 6 | import org.springframework.batch.core.Job; 7 | import org.springframework.batch.core.JobExecution; 8 | import org.springframework.batch.core.JobParameters; 9 | import org.springframework.batch.core.launch.JobLauncher; 10 | import org.springframework.context.ApplicationContext; 11 | import org.springframework.context.support.ClassPathXmlApplicationContext; 12 | 13 | /** 14 | * 15 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 16 | * 2013-2-28下午08:34:48 17 | */ 18 | public class JobLaunch { 19 | 20 | /** 21 | * @param args 22 | */ 23 | public static void main(String[] args) { 24 | ApplicationContext context = new ClassPathXmlApplicationContext( 25 | "ch02/job/job.xml"); 26 | JobLauncher launcher = (JobLauncher) context.getBean("jobLauncher"); 27 | Job job = (Job) context.getBean("billJob"); 28 | try { 29 | JobExecution result = launcher.run(job, new JobParameters()); 30 | System.out.println(result.toString()); 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch09/tasklet/CleanTasklet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch09.tasklet; 5 | 6 | import org.springframework.batch.core.StepContribution; 7 | import org.springframework.batch.core.scope.context.ChunkContext; 8 | import org.springframework.batch.core.step.tasklet.Tasklet; 9 | import org.springframework.batch.repeat.RepeatStatus; 10 | 11 | import com.juxtapose.example.ch09.CreditService; 12 | 13 | /** 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-7上午10:15:27 16 | */ 17 | public class CleanTasklet implements Tasklet{ 18 | private CreditService creditService; 19 | private String outputDirectory; 20 | 21 | @Override 22 | public RepeatStatus execute(StepContribution contribution, 23 | ChunkContext chunkContext) throws Exception { 24 | creditService.clean(outputDirectory); 25 | return RepeatStatus.FINISHED; 26 | } 27 | 28 | public void setCreditService(CreditService creditService) { 29 | this.creditService = creditService; 30 | } 31 | 32 | public void setOutputDirectory(String outputDirectory) { 33 | this.outputDirectory = outputDirectory; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch11/multithread/AutoReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch11.multithread; 5 | 6 | import org.springframework.batch.item.ItemReader; 7 | import org.springframework.batch.item.NonTransientResourceException; 8 | import org.springframework.batch.item.ParseException; 9 | import org.springframework.batch.item.UnexpectedInputException; 10 | 11 | /** 12 | * 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-11-16下午10:58:12 15 | */ 16 | public class AutoReader implements ItemReader { 17 | private int count = 0; 18 | private int maxCount = 30; 19 | 20 | public String read() throws Exception, UnexpectedInputException, 21 | ParseException, NonTransientResourceException { 22 | if(count > maxCount){ 23 | return null; 24 | }else{ 25 | System.out.print("Read:" + count + ";"); 26 | System.out.println("Job Read Thread name: " + Thread.currentThread().getName()); 27 | return count++ + ""; 28 | } 29 | } 30 | 31 | public int getMaxCount() { 32 | return maxCount; 33 | } 34 | 35 | public void setMaxCount(int maxCount) { 36 | this.maxCount = maxCount; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch04/stop/StopStepListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch04.stop; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.ItemReadListener; 8 | import org.springframework.batch.core.StepExecution; 9 | import org.springframework.batch.core.StepExecutionListener; 10 | 11 | /** 12 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 13 | * 2013-3-20下午10:19:47 14 | */ 15 | public class StopStepListener implements StepExecutionListener, ItemReadListener { 16 | private StepExecution stepExecution; 17 | private Boolean stop = Boolean.FALSE; 18 | 19 | public void beforeStep(StepExecution stepExecution) { 20 | this.stepExecution = stepExecution; 21 | } 22 | 23 | public void beforeRead() { 24 | if(isStop()) { 25 | this.stepExecution.setTerminateOnly(); 26 | } 27 | } 28 | 29 | public ExitStatus afterStep(StepExecution stepExecution) { 30 | return null; 31 | } 32 | 33 | public void afterRead(T item) {} 34 | 35 | public void onReadError(Exception ex) {} 36 | 37 | public Boolean isStop() { 38 | return stop; 39 | } 40 | 41 | public void setStop(Boolean stop) { 42 | this.stop = stop; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch09/listener/VerifyStepExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch09.listener; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.StepExecution; 8 | import org.springframework.batch.core.StepExecutionListener; 9 | 10 | import com.juxtapose.example.ch09.Constant; 11 | 12 | /** 13 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 14 | * 2013-10-7下午03:33:22 15 | */ 16 | public class VerifyStepExecutionListener implements StepExecutionListener { 17 | 18 | /* (non-Javadoc) 19 | * @see org.springframework.batch.core.StepExecutionListener#beforeStep(org.springframework.batch.core.StepExecution) 20 | */ 21 | @Override 22 | public void beforeStep(StepExecution stepExecution) { } 23 | 24 | /* (non-Javadoc) 25 | * @see org.springframework.batch.core.StepExecutionListener#afterStep(org.springframework.batch.core.StepExecution) 26 | */ 27 | @Override 28 | public ExitStatus afterStep(StepExecution stepExecution) { 29 | String status = stepExecution.getExecutionContext().getString(Constant.VERITY_STATUS); 30 | if(null != status){ 31 | return new ExitStatus(status); 32 | } 33 | return stepExecution.getExitStatus(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/JobLaunchBase.java: -------------------------------------------------------------------------------- 1 | package test.com.juxtapose.example; 2 | 3 | import org.springframework.batch.core.Job; 4 | import org.springframework.batch.core.JobExecution; 5 | import org.springframework.batch.core.JobParametersBuilder; 6 | import org.springframework.batch.core.launch.JobLauncher; 7 | import org.springframework.context.ApplicationContext; 8 | import org.springframework.context.support.ClassPathXmlApplicationContext; 9 | /** 10 | * 11 | */ 12 | 13 | /** 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-9-7下午01:57:02 16 | */ 17 | public class JobLaunchBase { 18 | /** 19 | * 执行批处理作业.
20 | * @param jobPath 作业配置文件 21 | * @param jobName 作业名 22 | * @param builder 作业参数构造器 23 | */ 24 | public static void executeJob(String jobPath, String jobName, JobParametersBuilder builder) { 25 | ApplicationContext context = new ClassPathXmlApplicationContext(jobPath); 26 | JobLauncher launcher = (JobLauncher) context.getBean("jobLauncher"); 27 | Job job = (Job) context.getBean(jobName); 28 | try { 29 | JobExecution result = launcher.run(job, builder.toJobParameters()); 30 | System.out.println(result.toString()); 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/skip/DBSkipListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.skip; 5 | 6 | import org.springframework.batch.core.SkipListener; 7 | import org.springframework.batch.item.file.FlatFileParseException; 8 | import org.springframework.jdbc.core.JdbcTemplate; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-29上午08:02:00 13 | */ 14 | public class DBSkipListener implements SkipListener { 15 | private JdbcTemplate jdbcTemplate; 16 | 17 | public void onSkipInRead(Throwable t) { 18 | if (t instanceof FlatFileParseException) { 19 | jdbcTemplate.update("insert into skipbills " 20 | + "(line,content) values (?,?)", 21 | ((FlatFileParseException) t).getLineNumber(), 22 | ((FlatFileParseException) t).getInput()); 23 | } 24 | } 25 | 26 | public void onSkipInWrite(String item, Throwable t) { 27 | // TODO Auto-generated method stub 28 | } 29 | 30 | public void onSkipInProcess(String item, Throwable t) { 31 | // TODO Auto-generated method stub 32 | } 33 | 34 | public JdbcTemplate getJdbcTemplate() { 35 | return jdbcTemplate; 36 | } 37 | 38 | public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { 39 | this.jdbcTemplate = jdbcTemplate; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch07/ibatis/ibatis-destcredit.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 24 | 25 | 26 | insert into t_destcredit values(#id#, #accountID#, #name#, #amount#, #date#, #address#) 27 | 28 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/flat/WrappedJsonLineMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06.flat; 5 | 6 | import java.util.Map; 7 | 8 | import org.springframework.batch.item.file.LineMapper; 9 | import org.springframework.batch.item.file.mapping.JsonLineMapper; 10 | 11 | import com.juxtapose.example.ch06.CreditBill; 12 | 13 | /** 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-4-3上午10:57:50 16 | */ 17 | public class WrappedJsonLineMapper implements LineMapper { 18 | private JsonLineMapper delegate; 19 | 20 | public CreditBill mapLine(String line, int lineNumber) throws Exception { 21 | CreditBill result = new CreditBill(); 22 | Map creditBillMap = delegate.mapLine(line, lineNumber); 23 | result.setAccountID((String)creditBillMap.get("accountID")); 24 | result.setName((String)creditBillMap.get("name")); 25 | result.setAmount((Double)creditBillMap.get("amount")); 26 | result.setDate((String)creditBillMap.get("date")); 27 | result.setAddress((String)creditBillMap.get("address")); 28 | return result; 29 | } 30 | 31 | public JsonLineMapper getDelegate() { 32 | return delegate; 33 | } 34 | 35 | public void setDelegate(JsonLineMapper delegate) { 36 | this.delegate = delegate; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch04/scheduler/SchedulerLauncher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch04.scheduler; 5 | 6 | import java.util.Date; 7 | 8 | import org.springframework.batch.core.Job; 9 | import org.springframework.batch.core.JobParameters; 10 | import org.springframework.batch.core.JobParametersBuilder; 11 | import org.springframework.batch.core.launch.JobLauncher; 12 | 13 | /** 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-3-19下午03:53:39 16 | */ 17 | public class SchedulerLauncher { 18 | private Job job; 19 | private JobLauncher jobLauncher; 20 | 21 | public void launch() throws Exception { 22 | JobParameters jobParams = createJobParameters(); 23 | jobLauncher.run(job, jobParams); 24 | } 25 | 26 | private JobParameters createJobParameters() { 27 | JobParameters jobParams = new JobParametersBuilder().addDate("executeDate", new Date()).toJobParameters(); 28 | return jobParams; 29 | } 30 | 31 | public Job getJob() { 32 | return job; 33 | } 34 | 35 | public void setJob(Job job) { 36 | this.job = job; 37 | } 38 | 39 | public JobLauncher getJobLauncher() { 40 | return jobLauncher; 41 | } 42 | 43 | public void setJobLauncher(JobLauncher jobLauncher) { 44 | this.jobLauncher = jobLauncher; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/listener/SystemOutStepExecutionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.listener; 5 | 6 | import org.springframework.batch.core.ExitStatus; 7 | import org.springframework.batch.core.StepExecution; 8 | import org.springframework.batch.core.StepExecutionListener; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-21下午10:52:28 13 | */ 14 | public class SystemOutStepExecutionListener implements StepExecutionListener { 15 | 16 | /* (non-Javadoc) 17 | * @see org.springframework.batch.core.StepExecutionListener#beforeStep(org.springframework.batch.core.StepExecution) 18 | */ 19 | public void beforeStep(StepExecution stepExecution) { 20 | System.out.println("SystemOutStepExecutionListener.beforeStep();" + 21 | "JobExecution creat time:" + stepExecution.getJobExecution().getCreateTime()); 22 | } 23 | 24 | /* (non-Javadoc) 25 | * @see org.springframework.batch.core.StepExecutionListener#afterStep(org.springframework.batch.core.StepExecution) 26 | */ 27 | public ExitStatus afterStep(StepExecution stepExecution) { 28 | System.out.println("SystemOutStepExecutionListener.afterStep();" + 29 | "Job execute state:" + stepExecution.getStatus().toString()); 30 | return null; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/step/listener/DBSkipListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.step.listener; 5 | 6 | import org.springframework.batch.core.SkipListener; 7 | import org.springframework.batch.item.file.FlatFileParseException; 8 | import org.springframework.jdbc.core.JdbcTemplate; 9 | 10 | /** 11 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 12 | * 2013-3-29上午08:02:00 13 | */ 14 | public class DBSkipListener implements SkipListener { 15 | private JdbcTemplate jdbcTemplate; 16 | 17 | public void onSkipInRead(Throwable t) { 18 | if (t instanceof FlatFileParseException) { 19 | jdbcTemplate.update("insert into skipbills " 20 | + "(line,content) values (?,?)", 21 | ((FlatFileParseException) t).getLineNumber(), 22 | ((FlatFileParseException) t).getInput()); 23 | } 24 | } 25 | 26 | public void onSkipInWrite(String item, Throwable t) { 27 | // TODO Auto-generated method stub 28 | } 29 | 30 | public void onSkipInProcess(String item, Throwable t) { 31 | // TODO Auto-generated method stub 32 | } 33 | 34 | public JdbcTemplate getJdbcTemplate() { 35 | return jdbcTemplate; 36 | } 37 | 38 | public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { 39 | this.jdbcTemplate = jdbcTemplate; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/DummyCreditItemReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.springframework.batch.item.ItemReader; 10 | import org.springframework.batch.item.NonTransientResourceException; 11 | import org.springframework.batch.item.ParseException; 12 | import org.springframework.batch.item.UnexpectedInputException; 13 | 14 | 15 | /** 16 | * 17 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 18 | * 2013-9-29下午02:27:52 19 | */ 20 | public class DummyCreditItemReader implements ItemReader { 21 | private static List list = new ArrayList(); 22 | static{ 23 | list.add(new CreditBill("1","tom",100.00,"2013-2-2 12:00:08","Lu Jia Zui road")); 24 | list.add(new CreditBill("2","tom",320,"2013-2-3 10:35:21","Lu Jia Zui road")); 25 | list.add(new CreditBill("3","tom",360.00,"2013-2-11 11:12:38","Longyang road")); 26 | } 27 | 28 | public DummyCreditItemReader(){ 29 | } 30 | 31 | @Override 32 | public CreditBill read() throws Exception, UnexpectedInputException, ParseException, 33 | NonTransientResourceException { 34 | if (!list.isEmpty()) { 35 | return list.remove(0); 36 | } 37 | return null; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/step/listener/SystemOutChunkListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05.step.listener; 5 | 6 | import org.springframework.batch.core.ChunkListener; 7 | import org.springframework.batch.core.scope.context.ChunkContext; 8 | 9 | /** 10 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 11 | * 2012-9-1上午08:07:17 12 | */ 13 | public class SystemOutChunkListener implements ChunkListener { 14 | 15 | // /* (non-Javadoc) 16 | // * @see org.springframework.batch.core.ChunkListener#beforeChunk() 17 | // */ 18 | // public void beforeChunk() { 19 | // System.out.println("ChunkListener.beforeChunk()"); 20 | // } 21 | // 22 | // /* (non-Javadoc) 23 | // * @see org.springframework.batch.core.ChunkListener#afterChunk() 24 | // */ 25 | // public void afterChunk() { 26 | // System.out.println("ChunkListener.afterChunk()"); 27 | // } 28 | 29 | @Override 30 | public void beforeChunk(ChunkContext context) { 31 | System.out.println("ChunkListener.beforeChunk()"); 32 | } 33 | 34 | @Override 35 | public void afterChunk(ChunkContext context) { 36 | System.out.println("ChunkListener.afterChunk()"); 37 | } 38 | 39 | @Override 40 | public void afterChunkError(ChunkContext context) { 41 | System.out.println("ChunkListener.afterChunkError()"); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch07/flat/CustomLineAggregator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch07.flat; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import org.springframework.batch.item.file.transform.ExtractorLineAggregator; 11 | import org.springframework.util.Assert; 12 | import org.springframework.util.StringUtils; 13 | 14 | /** 15 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 16 | * 2013-9-20上午10:00:03 17 | */ 18 | public class CustomLineAggregator extends ExtractorLineAggregator { 19 | private String delimiter = ";"; 20 | private String[] names; 21 | 22 | public void setDelimiter(String delimiter) { 23 | this.delimiter = delimiter; 24 | } 25 | 26 | public void setNames(String[] names) { 27 | Assert.notNull(names, "Names must be non-null"); 28 | this.names = Arrays.asList(names).toArray(new String[names.length]); 29 | } 30 | 31 | @Override 32 | protected String doAggregate(Object[] fields) { 33 | List fieldList = new ArrayList(); 34 | for (int i = 0; i < names.length; i++) { 35 | fieldList.add(names[i] + "=" + fields[i]); 36 | } 37 | return StringUtils 38 | .arrayToDelimitedString( 39 | fieldList.toArray(new String[fieldList.size()]), 40 | this.delimiter); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch06/DummyCreditItemReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch06; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.springframework.batch.item.ItemReader; 10 | import org.springframework.batch.item.NonTransientResourceException; 11 | import org.springframework.batch.item.ParseException; 12 | import org.springframework.batch.item.UnexpectedInputException; 13 | 14 | import com.juxtapose.example.ch06.CreditBill; 15 | 16 | /** 17 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 18 | * 2013-9-7下午02:12:56 19 | */ 20 | public class DummyCreditItemReader implements ItemReader { 21 | private static List list = new ArrayList(); 22 | static{ 23 | list.add(new CreditBill("1","tom",100.00,"2013-2-2 12:00:08","Lu Jia Zui road")); 24 | list.add(new CreditBill("2","tom",320,"2013-2-3 10:35:21","Lu Jia Zui road")); 25 | list.add(new CreditBill("3","tom",360.00,"2013-2-11 11:12:38","Longyang road")); 26 | } 27 | 28 | public DummyCreditItemReader(){ 29 | } 30 | 31 | @Override 32 | public CreditBill read() throws Exception, UnexpectedInputException, ParseException, 33 | NonTransientResourceException { 34 | if (!list.isEmpty()) { 35 | return list.remove(0); 36 | } 37 | return null; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch10/retry/template/DefaultBackoffPolicy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch10.retry.template; 5 | 6 | import org.junit.Assert; 7 | import org.springframework.retry.RetryContext; 8 | import org.springframework.retry.backoff.BackOffContext; 9 | import org.springframework.retry.backoff.BackOffInterruptedException; 10 | import org.springframework.retry.backoff.BackOffPolicy; 11 | 12 | /** 13 | * 14 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 15 | * 2013-10-21下午10:59:56 16 | */ 17 | public class DefaultBackoffPolicy implements BackOffPolicy { 18 | 19 | /* (non-Javadoc) 20 | * @see org.springframework.batch.retry.backoff.BackOffPolicy#start(org.springframework.batch.retry.RetryContext) 21 | */ 22 | public BackOffContext start(RetryContext context) { 23 | BackOffContextImpl backOffContext = new BackOffContextImpl(context); 24 | return backOffContext; 25 | } 26 | 27 | /* (non-Javadoc) 28 | * @see org.springframework.batch.retry.backoff.BackOffPolicy#backOff(org.springframework.batch.retry.backoff.BackOffContext) 29 | */ 30 | public void backOff(BackOffContext backOffContext) 31 | throws BackOffInterruptedException { 32 | Assert.assertNotNull(((BackOffContextImpl)backOffContext).getRetryContext().getAttribute("count")); 33 | CountHelper.decrement(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-batch-example/src/test/java/test/com/juxtapose/example/ch02/JobLaunchTest.java: -------------------------------------------------------------------------------- 1 | package test.com.juxtapose.example.ch02; 2 | 3 | 4 | import org.junit.After; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.batch.core.Job; 9 | import org.springframework.batch.core.JobExecution; 10 | import org.springframework.batch.core.JobParameters; 11 | import org.springframework.batch.core.launch.JobLauncher; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.beans.factory.annotation.Qualifier; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | @ContextConfiguration(locations={ 19 | "/ch02/job/job.xml" 20 | }) 21 | public class JobLaunchTest { 22 | @Autowired 23 | private JobLauncher jobLauncher; 24 | @Autowired@Qualifier("billJob") 25 | private Job job; 26 | 27 | @Before 28 | public void setUp() throws Exception { 29 | } 30 | 31 | @After 32 | public void tearDown() throws Exception { 33 | } 34 | 35 | @Test 36 | public void billJob() throws Exception { 37 | JobExecution result = jobLauncher.run(job, new JobParameters()); 38 | System.out.println(result.toString()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/resources/ch04/command.txt: -------------------------------------------------------------------------------- 1 | 1、执行Maven的Locally Install Artifact 2 | 2、调出命令行,进入目录:/spring-batch-example/target 3 | 3、第二章HelloWorld中的命令行: 4 | java -classpath "./dependency/*;spring-batch-example-1.0.jar" org.springframework.batch.core.launch.support.CommandLineJobRunner ch02/job/job.xml billJob 5 | 4、控制台输出如下内容: 6 | 2013-03-18 20:29:52,397 INFO [org.springframework.batch.core.job.SimpleStepHandler] - Executing step: [billStep] 7 | accountID=4047390012345678;name=tom;amount=100.0;date=2013-2-2 12:00:08;address=Lu Jia Zui road 8 | accountID=4047390012345678;name=tom;amount=320.0;date=2013-2-3 10:35:21;address=Lu Jia Zui road 9 | accountID=4047390012345678;name=tom;amount=674.7;date=2013-2-6 16:26:49;address=South Linyi road 10 | accountID=4047390012345678;name=tom;amount=793.2;date=2013-2-9 15:15:37;address=Longyang road 11 | accountID=4047390012345678;name=tom;amount=360.0;date=2013-2-11 11:12:38;address=Longyang road 12 | accountID=4047390012345678;name=tom;amount=893.0;date=2013-2-28 20:34:19;address=Hunan road 13 | 14 | 5、执行ch04/job/job-exitstatus.xml中的billJob任务 15 | java -classpath "./dependency/*;spring-batch-example-1.0.jar" org.springframework.batch.core.launch.support.CommandLineJobRunner ch04/job/job-exitstatus.xml billJob inputResource(string)=ch04/data/credit-card-bill-201303.csv outputResource(string)=file:target/ch04/exitstatus/outputFile.csv date(string)=2013/03/18 16 | -------------------------------------------------------------------------------- /spring-batch-example/src/main/java/com/juxtapose/example/ch05/RadomExceptionAutoReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.juxtapose.example.ch05; 5 | 6 | import java.util.Random; 7 | 8 | import org.springframework.batch.item.ItemReader; 9 | import org.springframework.batch.item.NonTransientResourceException; 10 | import org.springframework.batch.item.ParseException; 11 | import org.springframework.batch.item.UnexpectedInputException; 12 | import org.springframework.batch.item.file.FlatFileParseException; 13 | 14 | /** 15 | * @author bruce.liu(mailto:jxta.liu@gmail.com) 16 | * 2013-3-19下午08:54:49 17 | */ 18 | public class RadomExceptionAutoReader implements ItemReader { 19 | private int count = 0; 20 | private int maxCount = 30; 21 | private Random ra = new Random(); 22 | 23 | public String read() throws Exception, UnexpectedInputException, 24 | ParseException, NonTransientResourceException { 25 | int i = ra.nextInt(10); 26 | String target = null; 27 | if(count > maxCount){ 28 | return target; 29 | }else{ 30 | target = ++count+ ""; 31 | if(i%2 == 0){ 32 | throw new FlatFileParseException(target, target, count); 33 | }else{ 34 | return target; 35 | } 36 | } 37 | } 38 | 39 | public int getMaxCount() { 40 | return maxCount; 41 | } 42 | 43 | public void setMaxCount(int maxCount) { 44 | this.maxCount = maxCount; 45 | } 46 | 47 | } 48 | --------------------------------------------------------------------------------