JobRepository存储执行期的元数据,提供两种默认实现,一种是存放在内存中,默认实现类为:MapJobRepositoryFactoryBean。在xml中的配置如下:
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"> bean>
xml version="1.0" encoding="UTF-8"?><bean:beans xmlns="http://www.springframework.org/schema/batch" xmlns:bean="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd"> <job-repository id="jobRepository" data-source="dataSource" transaction-manager="transactionManager" isolation-level-for-create="SERIALIZABLE" table-prefix="BATCH_" max-varchar-length="1000" /> <bean:bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> <bean:property name="jobRepository" ref="jobRepository"/> bean:bean> <bean:bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <bean:property name="dataSource" ref="dataSource" /> bean:bean> <bean:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <bean:property name="driverClassName"> <bean:value>com.mysql.jdbc.Driverbean:value> bean:property> <bean:property name="url"> <bean:value>jdbc:mysql://localhost:3306/mydatabasebean:value> bean:property> <bean:property name="username" value="root">bean:property> <bean:property name="password" value="wbw123456">bean:property> bean:bean>bean:beans>
在这里我们选用schema-mysql.sql 具体的建表语句如下:
-- Autogenerated: do not edit this fileCREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT , JOB_NAME VARCHAR(100) NOT NULL, JOB_KEY VARCHAR(32) NOT NULL, constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY)) ENGINE=InnoDB;CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT , JOB_INSTANCE_ID BIGINT NOT NULL, CREATE_TIME DATETIME NOT NULL, START_TIME DATETIME DEFAULT NULL , END_TIME DATETIME DEFAULT NULL , STATUS VARCHAR(10) , EXIT_CODE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED DATETIME, JOB_CONFIGURATION_LOCATION VARCHAR(2500) NULL, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)) ENGINE=InnoDB;CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( JOB_EXECUTION_ID BIGINT NOT NULL , TYPE_CD VARCHAR(6) NOT NULL , KEY_NAME VARCHAR(100) NOT NULL , STRING_VAL VARCHAR(250) , DATE_VAL DATETIME DEFAULT NULL , LONG_VAL BIGINT , DOUBLE_VAL DOUBLE PRECISION , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)) ENGINE=InnoDB;CREATE TABLE BATCH_STEP_EXECUTION ( STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT NOT NULL, STEP_NAME VARCHAR(100) NOT NULL, JOB_EXECUTION_ID BIGINT NOT NULL, START_TIME DATETIME NOT NULL , END_TIME DATETIME DEFAULT NULL , STATUS VARCHAR(10) , COMMIT_COUNT BIGINT , READ_COUNT BIGINT , FILTER_COUNT BIGINT , WRITE_COUNT BIGINT , READ_SKIP_COUNT BIGINT , WRITE_SKIP_COUNT BIGINT , PROCESS_SKIP_COUNT BIGINT , ROLLBACK_COUNT BIGINT , EXIT_CODE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED DATETIME, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)) ENGINE=InnoDB;CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT TEXT , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID)) ENGINE=InnoDB;CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT TEXT , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)) ENGINE=InnoDB;CREATE TABLE BATCH_STEP_EXECUTION_SEQ ( ID BIGINT NOT NULL, UNIQUE_KEY CHAR(1) NOT NULL, constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)) ENGINE=InnoDB;INSERT INTO BATCH_STEP_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_STEP_EXECUTION_SEQ);CREATE TABLE BATCH_JOB_EXECUTION_SEQ ( ID BIGINT NOT NULL, UNIQUE_KEY CHAR(1) NOT NULL, constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)) ENGINE=InnoDB;INSERT INTO BATCH_JOB_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_EXECUTION_SEQ);CREATE TABLE BATCH_JOB_SEQ ( ID BIGINT NOT NULL, UNIQUE_KEY CHAR(1) NOT NULL, constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)) ENGINE=InnoDB;INSERT INTO BATCH_JOB_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_SEQ);
SpringBatch框架进行元数据的管理共有九张表:
下面分别对9张表的数据结构讲解哈:
BATCH_JOB_INSTANCE(作业实例表,存放JOB的实例信息)
字段名称 | 字段 类型 | 字段说明 |
JOB_INSTANCE_ID | bigint | 主键 ,作业实例编号,根据BATCH_JOB_SEQ自动生成 |
VERSION | bigint | 版本号 |
JOB_NAME | varchar |
作业名称 即在配置文件定义的JobId字段内容 |
JOB_KEY | varchar | 作业标识,根据作业参数序列化生成的标识,需要注意通过JOB_NAME+JOB_KEY能够唯一区分一个作业实例 |
BATCH_JOB_EXECUTION_PARAMS(作业参数表,用于存放每个JOB执行的时候的参数信息,即对于的JOB实例)
字段名称 | 字段类型 | 字段说明 |
JOB_EXECUTION_ID | bigint | 外键ID,作业执行器ID编号,一个作业实例可能又会多行参数记录 |
TYPE_CD | varchar | 参数的类型,总共有四种 String、Date、Double、Long |
KEY_NAME | varchar | 参数的名字 |
STRING_VAL | varchar | 参数如果是String,就存放String类型的参数值 |
DATE_VAL | datetime | 参数如果是Date,就存放Date类型的参数值 |
LONG_VAL | bigint | 参数如果是Long,就存放Long类型的参数值 |
DOUBLE_VAL | double | 参数如果是Double,就存放Double类型的参数值 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------
BATCH_JOB_EXECUTION(作业执行器表,存放当前作业的执行信息,创建时间、执行时间、执行结束时间、执行状态、执行Job实例等信息)
字段名称 | 字段类型 | 字段说明 |
JOB_EXECUTION_ID | bigint | 主键 |
VERSION | bigint | 版本号 |
JOB_INSTANCE_ID | bigint | 作业实例ID |
CREATE_TIME | datetime | 作业执行器创建时间 |
START_TIME | datetime | 作业执行器开始执行时间 |
END_TIME | datetime | 作业执行器结束时间 |
STATUS | varchar | 作业执行器执行的状态:COMPLETED、FAILED、STARTING、UNKNOW等 |
EXIT_CODE | varchar | 作业执行器退出代码 如:UNKNOW、EXECUTING、COMPLETED等 |
EXIT_MESSAGE | varchar | 作业执行器退出信息,通常存放异常信息 |
LAST_UPDATED | datetime | 本条记录上次更新时间 |
JOB_CONFIGURATION_LOCATION | varchar | 作业配置文件的位置 |
SELECT bi.JOB_NAME,bi.JOB_KEY,be.CREATE_TIME,be.START_TIME,be.END_TIME,be.`STATUS`FROM batch_job_instance biLEFT JOIN batch_job_execution be ON bi.JOB_INSTANCE_ID = be.JOB_INSTANCE_IDwhere bi.JOB_NAME='billJob'
BATCH_JOB_EXECUTION_CONTENXT(作业执行上下文表,存放上下文信息)
字段名称 | 字段类型 | 字段说明 |
JOB_EXECUTION_ID | bigint | 外键ID,作业执行器编号 |
SHORT_CONTEXT | varchar | 作业执行器上下文字符串格式 |
SERIALIZED_CONTEXT | text | 序列化的作业执行上下文 |
BATCH_JOB_SEQ表(用于BATCH_JOB_INSTNCE和BATCH_JOB_EXECUTION_PARAMS提供主键生成)
BATCH_STEP_EXECUTION(作业步执行器,存放每个Step执行器的信息:开始时间、执行完成时间、读/写次数等)
字段名称 | 字段类型 | 字段说明 |
STEP_EXECUTION_ID | bigint | 主键 |
VERSION | bigint | 版本 |
STEP_NAME | varchar | 作业步的名称 |
JOB_EXECUTION_ID | bigint | 作业执行器ID |
START_TIME | datetime | 作业步执行器执行开始时间 |
END_TIME | datetime | 作业步执行器执行结束时间 |
STATUS | varchar | 作业步执行器执行状态 COMPLETED, STARTING, STARTED, STOPPING, STOPPED, FAILED, ABANDONED, UNKNOWN 存在于org.springframework.batch.core.BatchStatus |
COMMIT_COUNT | bigint | 事务提交次数 |
READ_COUNT | bigint | 读数据次数 |
FILTER_COUNT | bigint | 过滤掉的数据次数 |
WRITE_COUNT | bigint | 写数据次数 |
READ_SKIP_COUNT | bigint | 读数据跳过的次数 |
WRITE_SKIP_COUNT | bigint | 写数据跳过的次数 |
PROCESS_SKIP_COUNT | bigint | 处理数据跳过的次数 |
ROLLBACK_COUNT | bigint | 事务回滚的次数 |
EXIT_CODE | varchar | 作业步执行器退出编码,状态码存在于org.springframework.batch.core.ExitStauts |
EXIT_MESSAGE | varchar | 作业步执行器退出描述,一般是异常信息 |
LAST_UPDATED | datetime | 本条记录上次更新时间 |
字段名称 | 字段类型 | 字段说明 |
STEP_EXECUTION_ID | bigint | 作业步执行器ID |
SHORT_CONTEXT | varchar | 作业步执行器上下文字符串格式 |
SERIALIZED_CONTEXT | text | 序列化作业步执行器上下文 |
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow