2009年4月7日火曜日

[grails]upgraded the plugin for grails to execute native query

I created and upgraded the grails plugin named native-query(Version 0.2) to execute native query statement like ORACLE's query hint, mysql match-against statement on the grails framework.

Installation Steps
  1. download zip file named grails-native-query-0.2.zip via http://groups.google.com/group/taapps-sourcecode-libraries/web/grails-native-query-0.2.zip
  2. installing plugin into the grails application
    grails install-plugin grails-native-query-0.2.zip
How to use
  • use DomainObject.executeJdbcQuery method injected into the Domain Class
    • Description
      This executeJdbcQuery method is static method injected into the Domain Class object.
    • Return Value
      This method returns the List object and each objects stored into the List are Domain Objects of the fetched rows.
    • Arguments
      1. Required String type, where, order by, match against clauses(No need to enter the "select * from " statement)
      2. Optional String type, select option like the "SQL_CALC_FOUND_ROWS(mysql)" or hint text(ORACLE)
      3. List object or Map object stored the bind values
    • Example
      Following examples are using the Domain Class named "Test", this is a test domain class.
      • use the standard select statement
        def result=Test.executeJdbcQueryMap("where id=160")
      • use positonal parameter
        def result=Test.executeJdbcQueryMap("where id=?",[160])
      • use named map parameter
        def result=Test.executeJdbcQueryMap("where id=:id",[id:160])
      • use the positonal parameter wit
        def result=Test.executeJdbcQueryMap("where id=?","SQL_CALC_FOUND_ROWS",[160])
      • use the List object as the member of the positional parameters
        def result=Test.executeJdbcQueryMap("where id in (?)","SQL_CALC_FOUND_ROWS",[[160,161,162,163,164]])

  • use NativeQueryUtil.executeJdbcQueryMap method to execute free sql statement(not need to be related to the Domain Class)
    • Return Value
      This method returns the List object and each objects stored into the List are Map object stored the fetched column name and the value, map key is column name
    • Arguments
      1. String type, Select statement
      2. List object or Map object stored the bind values
    • Example
      • use the standard select statement
        def result=NativeQueryUtil.executeJdbcQueryMap("select * from test where id=103")
      • use positional map
        def result=NativeQueryUtil.executeJdbcQueryMap("select * from test where id=?",[103])
      • use namedmap parameter
        def result=NativeQueryUtil.executeJdbcQueryMap("select * from test where id=:id",[id:103])
      • use the List object as the member of the positional parameters
        def result=NativeQueryUtil.executeJdbcQueryMap("select * from test where id in (?)",[[103.104,105,106]])
  • use the NativeQueryUtil.executeNativeQuery method(execute sql statement via Hibernate's createQuery method)
    • Description
      This method executes the select statement via Hibernate's session.createQuery method.
    • Return Value
      Domain Object or List object stored the domain objects of the fetched rows.
    • Arguments
      1. String Type, select statement
      2. Map type, mapping the table name and domain class
      3. List object or Map object stored the bind values
    • Example
      • def result=NativeQueryUtil.executeNativeQuery("select /* query */ tbl.* from test tbl where id=?",[tbl:Test],[101])


0 件のコメント: