清除JBPM数据的SQL

来源:互联网 发布:linux命令文件大小变化 编辑:程序博客网 时间:2024/06/05 06:07

JBPM的表使用了非常多的外键,通过外键实现数据的完整性约束。

 

当我们希望手工清除JBPM的数据时,这些外键就给我们带来了较大的困扰。

以下是根据经验整理出来的SQL,以备查(JBPM3.1.1版本):

    

  1. delete
  2.   from jbpm_log
  3.   where token_ in(
  4.         select id_ 
  5.         from jbpm_token
  6.         where processinstance_ in(
  7.           select id_
  8.           from Jbpm_Processinstance
  9.           where id_ in(select processid from biz_table where title like 'condition %')
  10.         )
  11.   );
  12. delete
  13. from jbpm_taskactorpool
  14. where taskinstance_ in(
  15.   select id_
  16.   from jbpm_taskinstance
  17.   where token_ in(
  18.     select id_ 
  19.     from jbpm_token
  20.     where processinstance_ in(
  21.       select id_
  22.       from Jbpm_Processinstance
  23.       where id_ in(select processid from biz_table where title like 'condition %')
  24.     )
  25.   )
  26. );
  27. delete
  28. from jbpm_variableinstance
  29. where processinstance_ in(
  30.   select id_
  31.   from Jbpm_Processinstance
  32.   where id_ in(select processid from biz_table where title like 'condition %')
  33. );
  34. delete
  35. from jbpm_timer
  36. where processinstance_ in(
  37.   select id_
  38.   from Jbpm_Processinstance
  39.   where id_ in(select processid from biz_table where title like 'condition %')
  40. );
  41. delete
  42. from jbpm_taskinstance
  43. where token_ in(
  44.   select id_ 
  45.   from jbpm_token
  46.   where processinstance_ in(
  47.     select id_
  48.     from Jbpm_Processinstance
  49.     where id_ in(select processid from biz_table where title like 'condition %')
  50.   )
  51. );
  52. delete
  53. from jbpm_tokenvariablemap
  54. where token_ in(
  55. select id_ 
  56.   from jbpm_token
  57.   where processinstance_ in(
  58.     select id_
  59.     from Jbpm_Processinstance
  60.     where id_ in(select processid from biz_table where title like 'condition %')
  61.   )
  62. );
  63. alter table JBPM_PROCESSINSTANCE disable constraint FK_PROCIN_ROOTTKN;
  64. delete 
  65. from jbpm_token
  66. where processinstance_ in(
  67.   select id_
  68.   from Jbpm_Processinstance
  69.   where id_ in(select processid from biz_table where title like 'condition %')
  70. );
  71. delete
  72. from jbpm_moduleinstance
  73. where processinstance_ in(
  74.   select id_
  75.   from Jbpm_Processinstance
  76.   where id_ in(select processid from biz_table where title like 'condition %')
  77. );
  78. delete 
  79. from Jbpm_Processinstance
  80. where id_ in(select processid from biz_table where title like 'condition %');
  81. alter table JBPM_PROCESSINSTANCE enable constraint FK_PROCIN_ROOTTKN;
  82. delete from biz_table where title like 'condition %';
  83. commit;

根据实际情况将条件部分的SQL替换掉。这些SQL会彻底清除JBPM中的数据。