Class: Rubernate::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/rubernate/connection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, *classes) ⇒ Connection

Returns a new instance of Connection.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubernate/connection.rb', line 10

def initialize(connection,*classes)

  import org.hibernate.Session
  import org.hibernate.SessionFactory
  import org.hibernate.Transaction
  import org.hibernate.cfg.AnnotationConfiguration
  import org.hibernate.ejb.Ejb3Configuration


  self.configuration = Ejb3Configuration.new
  
  self.configuration.set_property "hibernate.dialect",connection[:dialect]
  self.configuration.set_property "hibernate.connection.url", connection[:url]
  self.configuration.set_property "hibernate.connection.driver_class", connection[:driver]
  self.configuration.set_property "hibernate.connection.user", "root"
  self.configuration.set_property "hibernate.connection.password", ""
  self.configuration.set_property "javax.persistence.provider ","org.hibernate.ejb.HibernatePersistence"
  self.configuration.set_property "hibernate.hbm2ddl.auto", connection[:auto_ddl]
  self.configuration.set_property "hibernate.connection.provider_class","org.hibernate.connection.DriverManagerConnectionProvider"
  classes.each do |clazz|
    clazz.each do |c1|
      configuration.addAnnotatedClass c1
    end
  end

end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



7
8
9
# File 'lib/rubernate/connection.rb', line 7

def configuration
  @configuration
end

#connecionObject

Returns the value of attribute connecion.



7
8
9
# File 'lib/rubernate/connection.rb', line 7

def connecion
  @connecion
end

#factoryObject

Returns the value of attribute factory.



7
8
9
# File 'lib/rubernate/connection.rb', line 7

def factory
  @factory
end

Class Method Details

.entity_managerObject



42
43
44
# File 'lib/rubernate/connection.rb', line 42

def self.entity_manager
  @@factory.createEntityManager
end

Instance Method Details

#entity_manager_factoryObject



38
39
40
# File 'lib/rubernate/connection.rb', line 38

def entity_manager_factory
  @@factory = configuration.buildEntityManagerFactory
end