Skip to content

Commit

Permalink
added some adapter config parameter for the jdbc connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mkristian committed Feb 23, 2010
1 parent 9f6f87f commit 16a1dc2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion eventlog.rb
@@ -1,7 +1,7 @@
require 'rubygems'
require 'lib/dm-hibernate-adapter.rb'

DataMapper.setup(:default, :adapter => "hibernate")
DataMapper.setup(:default, :adapter => "hibernate", :dialect => "H2", :username => "sa", :url => "jdbc:h2:jibernate")

class Event
include DataMapper::Resource
Expand Down
32 changes: 26 additions & 6 deletions lib/dm-hibernate-adapter.rb
Expand Up @@ -18,18 +18,38 @@ module Adapters

class HibernateAdapter < AbstractAdapter

# TODO maybe more drivers
DRIVERS = {
:H2 => "org.h2.Driver",
:HSQL => "org.hsqldb.jdbcDriver",
:Derby => "org.apache.derby.jdbc.EmbeddedDriver",
:MySQL5 => "com.mysql.jdbc.Driver",
:MySQL5InnoDB => "com.mysql.jdbc.Driver",
:MySQL => "com.mysql.jdbc.Driver",
:MySQLInnoDB => "com.mysql.jdbc.Driver",
:MySQLMyISAM => "com.mysql.jdbc.Driver",
:PostgreSQL => "org.postgresql.Driver",
}

DataMapper::Model.append_inclusions Hibernate::Model

def initialize(name, options = {})
dialect = options.delete(:dialect)
username = options.delete(:username)
password = options.delete(:password)
url = options.delete(:url)
url += "jdbc:" unless url =~ /^jdbc:/
driver = options.delete(:driver) || DRIVERS[dialect.to_sym]
pool_size = options.delete(:pool_size) || "1"
super
Hibernate.dialect = Hibernate::Dialects::H2
Hibernate.dialect = Hibernate::Dialects.const_get(dialect.to_s)
Hibernate.current_session_context_class = "thread"

Hibernate.connection_driver_class = "org.h2.Driver"
Hibernate.connection_url = "jdbc:h2:jibernate"
Hibernate.connection_username = "sa"
Hibernate.connection_password = ""
Hibernate.connection_pool_size = "1"
Hibernate.connection_driver_class = driver.to_s
Hibernate.connection_url = url.to_s # "jdbc:h2:jibernate"
Hibernate.connection_username = username.to_s # "sa"
Hibernate.connection_password = password.to_s # ""
Hibernate.connection_pool_size = pool_size.to_s
Hibernate.properties["hbm2ddl.auto"] = "update"
Hibernate.properties["format_sql"] = "false"
Hibernate.properties["show_sql"] = "true"
Expand Down
2 changes: 1 addition & 1 deletion spec/dm-hibernate-adapter_spec.rb
Expand Up @@ -8,7 +8,7 @@

describe DataMapper::Adapters::HibernateAdapter do
before :all do
@adapter = DataMapper.setup(:default, :adapter => "hibernate")
@adapter = DataMapper.setup(:default, :adapter => "hibernate", :dialect => "H2", :username => "sa", :url => "jdbc:h2:jibernate" )
end

it_should_behave_like 'An Adapter'
Expand Down

0 comments on commit 16a1dc2

Please sign in to comment.