Installation Steps
- 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
- installing plugin into the grails application
grails install-plugin grails-native-query-0.2.zip
- 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
- Required String type, where, order by, match against clauses(No need to enter the "select * from " statement)
- Optional String type, select option like the "SQL_CALC_FOUND_ROWS(mysql)" or hint text(ORACLE)
- List object or Map object stored the bind values
- Required String type, where, order by, match against clauses(No need to enter the "select * from " statement)
- 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 the standard select statement
- Description
- 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
- String type, Select statement
- List object or Map object stored the bind values
- String type, Select statement
- 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 standard select statement
- Return Value
- 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
- String Type, select statement
- Map type, mapping the table name and domain class
- 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])
- def result=NativeQueryUtil.executeNativeQuery("select /* query */ tbl.* from test tbl where id=?",[tbl:Test],[101])
- Description
0 件のコメント:
コメントを投稿