`

jBPM(五): 部署jBPM所用表到数据库_2

阅读更多

        在jBPM(四) 中, 笔者介绍了如何通过ant命令来生成建表语句并手工地往数据库里建表.这篇接着来看两种方式: 如何利用ant命令来自动建表,通过Java代码自动建表.

        先看
如何利用ant命令来自动建表. 应该说这方式在实际中更方便,也最常用. 具体步骤如下:
        1, 在JBPM_HOME
\jbpm\lib下新建mysql文件夹, 并将Mysql的驱动包拷到这里.
        2,
在JBPM_HOME \jbpm\src\resources下新建mysqldb文件夹. 并将 JBPM_HOME \jbpm \src\resources\hsqldb下的两个文件"create.db.hibernate.properties" 和"identity.db.xml"拷到新建的mysqldb文件夹下. 修改create.db.hibernate.properties文件,内容如下:

            hibernate.dialect=org.hibernate.dialect.MySQLDialect
            hibernate.connection.driver_class= com.mysql.jdbc.Driver
            hibernate.connection.url=jdbc:mysql://localhost:3306/jbpm
            hibernate.connection.username=root
            hibernate.connection.password=yourmysqlrootpw
            hibernate.show_sql=false

            hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider

        3, 修改 JBPM_HOME\build.deploy.xml文件. 新增一个target,内容如下:

<target name="create.mysql.db" depends="declare.jbpm.tasks, db.clean" 
  description="creates a hypersonic database with the jbpm tables and loads the processes in there">
    <jbpmschema actions="create"
                cfg="${basedir}/src/config.files/hibernate.cfg.xml"
                properties="${basedir}/src/resources/mysqldb/create.db.hibernate.properties"/>
    <loadidentities file="${basedir}/src/resources/mysqldb/identity.db.xml"
                cfg="${basedir}/src/config.files/hibernate.cfg.xml"
                properties="${basedir}/src/resources/mysqldb/create.db.hibernate.properties"/>
    <ant antfile="build.xml" target="build.processes" inheritall="false" />
    <deployprocess cfg="${basedir}/src/config.files/hibernate.cfg.xml"
                   properties="${basedir}/src/resources/mysqldb/create.db.hibernate.properties">
      <fileset dir="build" includes="*.process" />
    </deployprocess>
  </target>


        4, 启动MySQL数据库,在JBPM_HOME \jbpm 目录下运行"ant create.mysql.db -buildfile build.deploy.xml"命令. 这样又是一段更长的"唰唰唰唰...."后,进到jbpm这个database下, 再show tables,跟上篇介绍的方法一样, 又看到33个表建成了.

        我们来简短地看下最后一个方法: 利用Java代码自动建表. 由于这个很不常用, 我也就偷下懒, 大家如有兴趣,可借鉴下"jbpm\src\java.examples\org\jbpm\tutorial\db"目录下 HelloWorldDbTest.java类中的方法"jbpmConfiguration.createSchema();". 更好的方式是采用jBPM(三) 里搭建好的Eclipse环境,直接运行HelloWorldDbTest.java.

2
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics