• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

institut-de-genomique/hibernatetools-gradle-plugin: Hibernate tools plugin to re ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

institut-de-genomique/hibernatetools-gradle-plugin

开源软件地址(OpenSource Url):

https://github.com/institut-de-genomique/hibernatetools-gradle-plugin

开源编程语言(OpenSource Language):

Groovy 100.0%

开源软件介绍(OpenSource Introduction):

Hibernatetools-gradle-plugins

Purpose

This plugin intend to ease hibernatetools through gradle. It offer three tasks:

  • hibernate-config: to generate hibernate config files
  • hbm2java: to generate java classes
  • hbm2dao: to generate DAO classes

Usage

Inside your build.gradle file add this:

Build script snippet

For Gradle 2.1 and after:

plugins {
      id "org.hibernate.gradle.tools" version "1.2.4"
    }

For older Gradle release:

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.org.hibernate.gradle.tools:hibernatetools-gradle-plugin:1.2.4"
  }
}

apply plugin: "org.hibernate.gradle.tools"

Fallback to hibernate-tools 5.2

This project has been updated to use hibernate-tools-5.3.4.Final but 5.2.x is still supported. To override the hibernate-tools version add:

    reveng ('org.hibernate:hibernate-tools:5.2.11.Final') {
        force = true
    }

to your build.gradle's main dependencies section (not the buildscript/dependencies section).

Configure the database

Now you have only to configure the database, by using database section inside build.gradle file. Example:

If using domain,

database{
    basePackage = "com.project.database.model"
    url         = "jdbc:mysql://myDB.domain.fr"
}

If using host,

database{
    basePackage = "com.project.database.model"
    url         = "jdbc:mysql://host"
    dbName      = "myDB"
}

This plugin allow to specify multiple catalog using:

import org.hibernate.gradle.tools.*

database{
    catalog = [ "catalog1": new Schema("schemaY", [".*"])), "catalog2": new Schema("schemaX", [".*"]) ]
    basePackage = "org.foo.bar"
}

This plugin allow to specify multiple schema using:

database{
    catalog = [ "catalog1": new Schema("schemaX", ["tableY"]), "catalog2": new Schema("schemaY", [".*"]) ]
    basePackage = "org.foo.bar"
}

This plugin allow to specify multiple tables using:

database{
    catalog = [ "catalog1": new Schema("schemaX", ["tableY","tableZ"]), "catalog2": new Schema("schemaY", [".*"]) ]
    basePackage = "org.foo.bar"
}

The symbol '.*' means any characters repeated 0 on n times. In given example class will be mapped from foo and bar tables and also any table where name start with other

The config files hibernate-tools needs are generated by the hibernate-config task, alternatively you can provide them by setting these properties:

database{
    configXml               = "/tmp/hibernate.cfg.xml"     // <<---- path to config file for hibernate-tools 5.2.x
    hibernatePropertiesFile = "/tmp/hibernate.properties"  // <<---- path to config properties file for hibernate-tools 5.3.x
    revEngXml               = "/tmp/hibernate.reveng.xml"  // <<---- path to reveng file
}

by default database section are defined as:

class Database {
    def catalog         = [".*":new Schema(".*", ".*")] // Schema parameter are: schema pattern name, table pattern name
    String  user        = ""
    String  password    = ""
    String  url         = "jdbc:mysql://127.0.0.1"
    Integer port        = 3306
    String  dbName      = ""
    String  driver      = "com.mysql.jdbc.Driver"
    String  dialect     = "org.hibernate.dialect.MySQLDialect"
    String  basePackage = "com.project.database.model"
}

dialect and driver to use are located on hibernate

Reverse engineering

Once the plugin is declared and database connection defined to get java classes you need only to run this command:

$ gradle hbm2dao

This plugin provides three gradle target:

  • hbm2java
  • hbm2dao
  • hibernate-config

enjoy




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap