Skip to content

Commit

Permalink
lets try to fix #execute_update
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Gega (pietia) committed Sep 30, 2011
1 parent 7d150db commit 79e1987
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/dm-hibernate-adapter.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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>
Expand Down

13 comments on commit 79e1987

@douglasrodrigo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@douglasrodrigo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pietia
Copy link
Collaborator

@pietia pietia commented on 79e1987 Sep 30, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@pietia
Copy link
Collaborator

@pietia pietia commented on 79e1987 Sep 30, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@douglasrodrigo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, Hibernate doWork will help us.

@pietia
Copy link
Collaborator

@pietia pietia commented on 79e1987 Sep 30, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pietia
Copy link
Collaborator

@pietia pietia commented on 79e1987 Sep 30, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tomorrow...

@douglasrodrigo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@pietia
Copy link
Collaborator

@pietia pietia commented on 79e1987 Sep 30, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@douglasrodrigo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do something like that:

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

@pietia
Copy link
Collaborator

@pietia pietia commented on 79e1987 Sep 30, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@douglasrodrigo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@douglasrodrigo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll commit a implementation.

Please sign in to comment.