Permalink
Browse files

lets try to fix #execute_update

  • Loading branch information...
1 parent 7d150db commit 79e19875428fef7281f251e72219bfb82cfcdcb7 @pietia pietia committed Sep 30, 2011
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/dm-hibernate-adapter.rb
@@ -28,6 +28,9 @@ module Adapters
java_import org.hibernate.criterion.Restrictions # ie. Restriction.eq
java_import org.hibernate.criterion.Order # ie. Order.asc
+ java_import java.sql.Connection
+ java_import java.sql.SQLException
+ java_import java.sql.Statement
class HibernateAdapter < AbstractAdapter
@@ -196,10 +199,15 @@ def delete(resources)
# extension to the adapter API
def execute_update(sql)
- raise "NYI"
- # unit_of_work do |session|
- # session.do_work(UpdateWork.new(sql))
- # end
+ unit_of_work do |session|
+ con = session.connection
+ st = con.create_statement
+ begin
+ st.execute_update(sql)
+ ensure
+ st.close
+ end
+ end
end
# <dm-transactions>

13 comments on commit 79e1987

Collaborator

douglasrodrigo replied Sep 30, 2011

Pietia be careful using session.connection directly, in a connection pool environment the session will return a new connection, consider to use a createSQLQuery instead.

Collaborator

douglasrodrigo replied Sep 30, 2011

ops sorry Pietia, update are supported only in HQL, but I don't know if will be possible generate a HQL with the sql received.

Collaborator

pietia replied Sep 30, 2011

good catch

Collaborator

douglasrodrigo replied Sep 30, 2011

yep, Hibernate doWork will help us.

Collaborator

pietia replied Sep 30, 2011

Collaborator

pietia replied Sep 30, 2011

tomorrow...

Collaborator

douglasrodrigo replied Sep 30, 2011

Pietia we can consider to create UpdateWork in Ruby and avoid a jar dependency inside of Jibernate. What do you think?

Collaborator

pietia replied Sep 30, 2011

Collaborator

douglasrodrigo replied Sep 30, 2011

we can do something like that:

session.do_work do |connection|
connection.createStatement()
...
end

Collaborator

pietia replied Sep 30, 2011

but what about pooling ? AFAIR Hibernate doesn't support something like: getCurrentConnection

Collaborator

douglasrodrigo replied Sep 30, 2011

JRuby will create a Work interface implementation in Runtime and call 'execute' method passing a connection, the implementation of 'execute' method will be the Ruby code block.
Take look in Closure Conversion:
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby

Collaborator

douglasrodrigo replied Sep 30, 2011

I'll commit a implementation.

Please sign in to comment.