生成基于Oracle的JBPM数据库脚本

项目需要使用Oracle,发现jBPM没有提供基于Oracle 数据库的脚本。下面是步骤。这个是使用Ant来生成的。

 

1. 下载最新版本的 JBoss jBPM Starters kit。解压这个文件(注意解压目录不要包含中文),假设解压目录为 "${jbpm.starters.kit}",它的下面应该有 jbpm, jbpm-bpel,jbpm-db,jbpm-designer,jbpm-server 五个子目录。其中我们要用到的是 jbpm 和 jbpm-db两个目录。

2. 导航到 jbpm-db 子目录。在该目录下可以找到 build.properties 文件。这个文件需要作一定修改才能使用。

    找到下面的这段代码:

js 代码
  1. jbpm.3.location=C:/jbpm-X.X   
  2.   
  3. upgrade.hibernate.properties=hsqldb/hibernate.properties   
  4. upgrade.libdir=hsqldb/lib   
  5. upgrade.old.schema.script=hsqldb/upgrade.scripts/hsqldb.create.jbpm.3.0.2.sql   

      注意第一行,将 “C:/jbpm-x.x” 改成 "${jbpm.starters.kit}/jbpm。

3. 导航到 jbpm 子目录。在 jbpm/src/config.files 路径下可以找到 hibernate.cfg.xml 文件。这个文件需要修改和数据库连接相关的部分。

      找到下面这行代码:

xml 代码
  1. <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>  
  2. <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDrive</rproperty>  
  3. <property name="hibernate.connection.url">jdbc:hsqldb:mem:.;sql.enforce_strict_size=true</property>  
  4. <property name="hibernate.connection.username">sa</property>  
  5. <property name="hibernate.connection.password"></property>  

      将其修改成 Oracle 的格式:

xml 代码
  1.   
  2. <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>  
  3. <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>  
  4. <property name="hibernate.connection.url">jdbc:oracle:thin@localhost:1521:fred</property>  
  5. <property name="hibernate.connection.username">FiberSchedulerJBPM</property>  
  6. <property name="hibernate.connection.password">FiberSchedulerJBPM</property>  

 5. 导航到子目录 jbpm 下的路径 jbpm-db/oracle/lib,下载最新的 Oracle jdbc驱动程序(我使用的是 class14.jar),把它放在该路径下。

      其中 "localhost" 换成你自己的数据库所在的机器名(或者ip地址),"fred" 换成你自己的Oracle数据库的 SID 名字, 使用你自己的 Oracle 数据库用户名和密码来替换 "FiberSchedulerJBPM" 。

4. 导航到 jbpm-db 子目录,在 jbpm-db/oracle 路径下找到文件 hibernate.properties。

      找到下面这段代码:

js 代码
  1. hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver   
  2. hibernate.connection.url=jdbc:oracle:thin@HOST:PORT:SID   
  3. hibernate.connection.username=USER   
  4. hibernate.connection.password=PASSWORD   

      根据你的数据库配置修改,我的修改如下:

js 代码
  1. hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver   
  2. hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:fred   
  3. hibernate.connection.username=FiberSchedulerJBPM   
  4. hibernate.connection.password=FiberSchedulerJBPM  

5. 在目录  jbpm-db下找到ant脚本 build.xml 文件,这个ant 脚本中有这样一段代码是用来生成数据库脚本的:

xml 代码
  1. <target name="db.scripts" description="helper target to generate the database scripts" depends="prepare">  
  2.     <delete dir="build/${db}/scripts" />  
  3.   <mkdir dir="build/${db}/scripts" />  
  4.   <java classname="org.jbpm.db.JbpmSchema" fork="true">  
  5.     <classpath refid="classpath.${db}" />  
  6.     <arg value="scripts"/>    
  7.     <arg value="${basedir}/build/${db}/scripts"/>    
  8.     <arg value="${db}"/>    
  9.     <arg value="${jbpm.3.location}/src/config.files/hibernate.cfg.xml"/>    
  10.     <arg value="${basedir}/${db}/hibernate.properties"/>    
  11.   java>    
  12. target>  

      这段脚本将调用 jBPM的类 org.jbpm.db.JbpmSchema.java 的 main 方法,并给他传5个参数。我们在目录 jbpm 的路线 jbpm/src/java.jbpm/org/jbpm/db 下找到类 JbpmSchema,打开它找到这么一段代码:

java 代码
  1. public static void main(String[] args) {   
  2.   try {   
  3.     if ( (args==null) || (args.length==0) ) {   
  4.       throw new IllegalArgumentException();   
  5.     }   
  6.        
  7.     String cmd = args[0];   
  8.        
  9.     if ("create".equalsIgnoreCase(cmd)) {   
  10.       Configuration configuration = createConfiguration(args, 1);   
  11.       new JbpmSchema(configuration).createSchema();   
  12.     } else if ("drop".equalsIgnoreCase(cmd)) {   
  13.       Configuration configuration = createConfiguration(args, 1);   
  14.       new JbpmSchema(configuration).dropSchema();   
  15.     } else if ("clean".equalsIgnoreCase(cmd)) {   
  16.       Configuration configuration = createConfiguration(args, 1);   
  17.       new JbpmSchema(configuration).cleanSchema();   
  18.     } else if ("scripts".equalsIgnoreCase(cmd)) {   
  19.       Configuration configuration = createConfiguration(args, 3);   
  20.       new JbpmSchema(configuration).saveSqlScripts(args[1], args[2]);   
  21.     }  

      显然,它只使用了ant脚本传给它的前三个参数。当生成非基于 Oracle 的数据库脚本时,前三个脚本足够了。问题是当生成基于 Oracle 的数据库脚本时,需要使用后两个参数。所以,我们在这段代码的后面加上:

java 代码
  1. else if ((args != null) && (args.length > 3) && ("scripts".equalsIgnoreCase(cmd))) {   
  2.        new JbpmSchema(JbpmSessionFactory.createConfiguration()).saveSqlScripts(args[1], args[2]);   
  3.      }  

     现在这段代码应该是这个样子:

java 代码
  1. public static void main(String[] args) {   
  2.   try {   
  3.     if ( (args==null) || (args.length==0) ) {   
  4.       throw new IllegalArgumentException();   
  5.     }   
  6.        
  7.     String cmd = args[0];   
  8.        
  9.     if ("create".equalsIgnoreCase(cmd)) {   
  10.       Configuration configuration = createConfiguration(args, 1);   
  11.       new JbpmSchema(configuration).createSchema();   
  12.     } else if ("drop".equalsIgnoreCase(cmd)) {   
  13.       Configuration configuration = createConfiguration(args, 1);   
  14.       new JbpmSchema(configuration).dropSchema();   
  15.     } else if ("clean".equalsIgnoreCase(cmd)) {   
  16.       Configuration configuration = createConfiguration(args, 1);   
  17.       new JbpmSchema(configuration).cleanSchema();   
  18.     } else if ("scripts".equalsIgnoreCase(cmd)) {   
  19.       Configuration configuration = createConfiguration(args, 3);   
  20.       new JbpmSchema(configuration).saveSqlScripts(args[1], args[2]);   
  21.     } else if ((args != null) && (args.length > 3) && ("scripts".equalsIgnoreCase(cmd))) {   
  22.       new JbpmSchema(JbpmSessionFactory.createConfiguration()).saveSqlScripts(args[1], args[2]);   
  23.     }  

      好了,现在一切都完美了。我们接下来执行最后一步,生成我们需要的脚本。

6. 打开命令行提示符窗口并在命令行中导航到子目录 jbpm-db,键入命令  ant oracle.scripts。等命令执行完毕以后,会发现在路径 jbpm-db/build/oracle/scripts 下生成了我们需要的脚本文件:
oracle.clean.sql
oracle.create.sql
oracle.drop.create.sql
oracle.drop.sql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值