Grails

Allow lists as named parameters on Domain.executeUpdate

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1.1
  • Fix Version/s: 1.2-M4
  • Component/s: Persistence, Plugins
  • Labels:
    None

Description

Add enhancement for something like:

def selectedList = [1, 2, 3]
Book.executeUpdate("delete Book b where b.id in ( :list )", list: selectedList)

This might be accomplished by changing:

HibernatePluginSupport.groovy
metaClass.static.executeUpdate = {String query, Map argMap ->
    template.execute(  { session ->
            Query queryObject = session.createQuery(query)
            SessionFactoryUtils.applyTransactionTimeout(queryObject, template.sessionFactory);
            for (entry in argMap) {
>              entry.value instanceof List ? queryObject.setParameterList(entry.key, entry.value) :
>                      queryObject.setParameter(entry.key, entry.value)
            }
            queryObject.executeUpdate()
          } as HibernateCallback
         , true);
}

Activity

Hide
Burt Beckwith added a comment -

I submitted a pull request with an ExecuteUpdatePersistentMethod class (analogous to ExecuteQueryPersistentMethod).

Show
Burt Beckwith added a comment - I submitted a pull request with an ExecuteUpdatePersistentMethod class (analogous to ExecuteQueryPersistentMethod).
Hide
Graeme Rocher added a comment -

Thanks Burt

Show
Graeme Rocher added a comment - Thanks Burt

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: