JBPM的表使用了非常多的外键,通过外键实现数据的完整性约束。
当我们希望手工清除JBPM的数据时,这些外键就给我们带来了较大的困扰。
以下是根据经验整理出来的SQL,以备查(JBPM3.1.1版本):
- delete
- from jbpm_log
- where token_ in(
- select id_
- from jbpm_token
- where processinstance_ in(
- select id_
- from Jbpm_Processinstance
- where id_ in(select processid from biz_table where title like 'condition %')
- )
- );
- delete
- from jbpm_taskactorpool
- where taskinstance_ in(
- select id_
- from jbpm_taskinstance
- where token_ in(
- select id_
- from jbpm_token
- where processinstance_ in(
- select id_
- from Jbpm_Processinstance
- where id_ in(select processid from biz_table where title like 'condition %')
- )
- )
- );
- delete
- from jbpm_variableinstance
- where processinstance_ in(
- select id_
- from Jbpm_Processinstance
- where id_ in(select processid from biz_table where title like 'condition %')
- );
- delete
- from jbpm_timer
- where processinstance_ in(
- select id_
- from Jbpm_Processinstance
- where id_ in(select processid from biz_table where title like 'condition %')
- );
- delete
- from jbpm_taskinstance
- where token_ in(
- select id_
- from jbpm_token
- where processinstance_ in(
- select id_
- from Jbpm_Processinstance
- where id_ in(select processid from biz_table where title like 'condition %')
- )
- );
- delete
- from jbpm_tokenvariablemap
- where token_ in(
- select id_
- from jbpm_token
- where processinstance_ in(
- select id_
- from Jbpm_Processinstance
- where id_ in(select processid from biz_table where title like 'condition %')
- )
- );
- alter table JBPM_PROCESSINSTANCE disable constraint FK_PROCIN_ROOTTKN;
- delete
- from jbpm_token
- where processinstance_ in(
- select id_
- from Jbpm_Processinstance
- where id_ in(select processid from biz_table where title like 'condition %')
- );
- delete
- from jbpm_moduleinstance
- where processinstance_ in(
- select id_
- from Jbpm_Processinstance
- where id_ in(select processid from biz_table where title like 'condition %')
- );
- delete
- from Jbpm_Processinstance
- where id_ in(select processid from biz_table where title like 'condition %');
- alter table JBPM_PROCESSINSTANCE enable constraint FK_PROCIN_ROOTTKN;
- delete from biz_table where title like 'condition %';
- commit;
根据实际情况将条件部分的SQL替换掉。这些SQL会彻底清除JBPM中的数据。