`
sillycat
  • 浏览: 2567351 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Grails(21)GORM Configuration and MYSQL Logging

 
阅读更多

Grails(21)GORM Configuration and MYSQL Logging

1. Mysql Logging
First of all, login in MYSQL
mysql> show variables like "%general_log%";
+------------------+----------------------------------------+

| Variable_name    | Value                                  | +------------------+----------------------------------------+ |

general_log      | OFF                                    | |

general_log_file | /usr/local/mysql/data/sparkworker1.log |

This show variables command will show us if the Logging is On in MySQL Configuration.

Then we can turn it On
mysql>set global general_log = true;

After that, our grails application will connect to Mysql and execute the command. We can see all the SQL statement in the file
>sudo tail -f /usr/local/mysql/data/sparkworker1.log

The content will be something like this>
select campaign0_.id as id14_, campaign0_.version as version14_, campaign0_.announcement_delivery_details_delay as announce3_14_, campaign0_.announcement_delivery_details_delivery_type as announce4_14_, campaign0_.announcement_delivery_details_target_delivery as announce5_14_, campaign0_.tenant_id as tenant6_14_, campaign0_.campaign_name as campaign7_14_, campaign0_.campaign_type as campaign8_14_, campaign0_.created_by_id as created9_14_, campaign0_.date_created as date10_14_, campaign0_.description as descrip11_14_, campaign0_.enabled as enabled14_, campaign0_.end_date as end13_14_, campaign0_.last_updated as last14_14_, campaign0_.message_location as message15_14_, campaign0_.modified_by_id as modified16_14_, campaign0_.notification_message as notific17_14_, campaign0_.notification_title as notific18_14_, campaign0_.promotion_duration as promotion19_14_, campaign0_.promotion_expiration_date as promotion20_14_, campaign0_.promotion_message as promotion21_14_, campaign0_.promotion_message_type as promotion22_14_, campaign0_.promotion_title as promotion23_14_, campaign0_.start_date as start24_14_, campaign0_.announcement_schedule_id as announc26_14_, campaign0_.throttle_interval as throttle27_14_, campaign0_.class as class14_ from campaign campaign0_ inner join campaign_beacons beacons1_ on campaign0_.id=beacons1_.campaign_id inner join beacon_region beaconregi2_ on beacons1_.beacon_id=beaconregi2_.id inner join geo_fence beaconregi2_1_ on beaconregi2_.id=beaconregi2_1_.id where beaconregi2_.id=3 and campaign0_.enabled=1 and campaign0_.tenant_id=1 and campaign0_.campaign_type='STORE_CHECKIN' and campaign0_.start_date<='2014-05-21 18:55:16' and campaign0_.end_date>='2014-05-21 18:55:16'

2. GORM Configuration Changes
Set<Beacon> beacons = []
static hasMany = [beacons:Beacon]

static mapping = {
     beacons(lazy: false, joinTable: [name:’campagin_beacons’, key: ‘campaign_id’, column: ‘beacon_id’])
}

So the relation_table1_table2 table name will be campaign_beacons, and the 2 columns in that table should be
campagin_id and beacon_id.


References:
http://stackoverflow.com/questions/2568507/how-to-log-sql-statements-in-grails

http://grails.org/doc/1.3.7/guide/5.%20Object%20Relational%20Mapping%20(GORM).html#5.2.1.3%20Many-to-many

分享到:
评论

相关推荐

    Grails Persistence with GORM and GSQL

    Grails Persistence with GORM and GSQL

    使用GORM构建Spring Boot应用程序 Grails指南_ Grails框架.pdf

    在本教程中,我们将探讨如何使用GORM(Grails Object-Relational Mapping)构建Spring Boot应用程序。GORM是Grails框架的核心部分,它为开发者提供了简单、强大的数据持久化功能,支持Hibernate和MongoDB等数据库。...

    grails-datastore-gorm-plugin-support-2.0.4.RELEASE.zip

    《Grails Datastore GORM Plugin Support 2.0.4.RELEASE:开源项目的代码生成与Android MVC模式解析》 在IT行业中,开发高效且可维护的软件系统是至关重要的。Grails Datastore GORM Plugin Support 2.0.4.RELEASE...

    Grails GORM查询.pdf

    Grails框架中的GORM(Groovy Object Relational Mapping)是利用Groovy语言的优势来简化数据库操作的一套对象关系映射技术。GORM支持多种查询方式,提供了类似于Hibernate的查询能力,并且由于Groovy语言的动态特性...

    grails-datastore-gorm-tck-1.0.9.RELEASE.zip

    标题 "grails-datastore-gorm-tck-1.0.9.RELEASE.zip" 提供的信息表明,这是一个与Grails框架相关的数据存储(Datastore)和GORM(Grails Object Relational Mapping)测试兼容性工具包(Test Compatibility Kit,...

    grails 连接mysql

    这个例子实现了用grails 连接mysql 数据库,并且把内容显示出来,可以增删除改,下载这个例子后大家要把jdk tomcat grails环境搭好,然后用grails run-app来执行,也可以用其它的开发工具,本人用的是netbeans

    Grails Grails Grails

    2. **GORM(Grails Object Relational Mapping)**: GORM 是Grails的ORM框架,提供了与数据库交互的能力,支持关系型数据库,如MySQL、PostgreSQL等。它提供了CRUD操作,以及事务管理和动态查询。 3. **插件系统**...

    groovy and grails ppt

    Grails则是一个基于Groovy构建的全栈框架,遵循“Don't Repeat Yourself”(DRY)原则和“Convention over Configuration”(CoC)理念,大大简化了开发流程。Grails内置了ORM层,基于Hibernate,使得对象关系映射变...

    Grails帮助文档

    Grails是一个全栈框架,它整合了Spring、Hibernate、Groovy on Grails(GORM)等成熟的技术,提供了MVC(模型-视图-控制器)架构,使得开发人员能够快速构建动态、数据库驱动的Web应用。 ### 2. Groovy语言 Groovy...

    Grails权威指南 Grails权威指南

    GORM支持多种数据库,如MySQL、PostgreSQL等。 4. **Grails命令行工具**:提供了一系列的命令,如`generate-all`用于自动生成控制器、视图和模型类,极大地提高了开发效率。 5. **Grails插件系统**:Grails拥有...

    grails增删改查(初学者必备)

    - Grails的GORM(Grails Object Relational Mapping)框架会自动创建与Domain类对应的数据库表。运行`grails dbm-gorm-diff`命令生成数据库更改脚本,然后用`grails dbm-update`或`dbm-changelog-sync`命令将这些...

    grails-2.4.4.zip

    GORM 提供了对数据库的操作接口,使得开发者可以通过面向对象的方式操作数据,减少了与SQL的直接交互,支持关系型数据库如MySQL、PostgreSQL等。 5. **Grails插件系统** Grails 的强大之处在于其丰富的插件库,如...

    grails使用freemarker.rar

    Grails以其插件系统、GORM(Grails Object Relational Mapping)和Groovy语言的简洁性而受到开发者的欢迎。使用Grails,开发者可以快速构建复杂的应用程序,而FreeMarker的集成进一步增强了其视图层的表现力。 ...

    grails中文文档

    3. **GORM 数据库访问**:Grails 的 GORM(Grailed Object Relational Mapping)提供了一个简单易用的 ORM 解决方案,用于与数据库交互。通过注解和动态方法,你可以轻松操作数据。 4. **Grails 控制器**:学习如何...

    the definitive guide to grails 2

    GORM支持多种数据库,包括MySQL、PostgreSQL和Oracle等,使得开发者可以专注于业务逻辑,而无需关心底层的数据库细节。 #### Services(服务) 在Grails中,服务(Services)是用来封装业务逻辑的组件。它们可以在...

Global site tag (gtag.js) - Google Analytics