diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-04-13 12:59:18 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-04-14 16:57:16 +0200 |
commit | 52381e82419a894011d765f072807ca64719a33f (patch) | |
tree | b14866d070dc6a5cb6ea086dacf3a3840be34354 /sonar-server/src/main/webapp/WEB-INF/config | |
parent | 8b5731af59ca25207b5da796ff74f92c868a4ac7 (diff) | |
download | sonarqube-52381e82419a894011d765f072807ca64719a33f.tar.gz sonarqube-52381e82419a894011d765f072807ca64719a33f.zip |
SONAR-2100 ruby on rails webapp : do not load JDBC datasource from JNDI in ruby on rails
Diffstat (limited to 'sonar-server/src/main/webapp/WEB-INF/config')
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/config/database.yml | 14 | ||||
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/config/environment.rb | 52 |
2 files changed, 33 insertions, 33 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/config/database.yml b/sonar-server/src/main/webapp/WEB-INF/config/database.yml index fe6f5b75f1e..4dd0ad9ca87 100644 --- a/sonar-server/src/main/webapp/WEB-INF/config/database.yml +++ b/sonar-server/src/main/webapp/WEB-INF/config/database.yml @@ -1,16 +1,6 @@ -<% java = Java::OrgSonarServerUi::JRubyFacade.new %> +# JDBC configured is loaded from Sonar development: adapter: jdbc - jndi: <%= java.getConfigurationValue("sonar.jdbc.jndiName") || 'jdbc/sonar' %> - pool: 10 - timeout: 5000 - dialect: <%= java.getDialect().getActiveRecordDialectCode() %> - driver: none production: - adapter: jdbc - jndi: <%= java.getConfigurationValue("sonar.jdbc.jndiName") || 'jdbc/sonar' %> - pool: 10 - timeout: 5000 - dialect: <%= java.getDialect().getActiveRecordDialectCode() %> - driver: none
\ No newline at end of file + adapter: jdbc
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb index 632d8516cf2..721bd127307 100644 --- a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb +++ b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb @@ -1,11 +1,5 @@ -# Be sure to restart your server when you modify this file - -# Uncomment below to force Rails into production mode when -# you don't control web/app server and can't set it the proper way -# ENV['RAILS_ENV'] ||= 'production' - # Specifies gem version of Rails to use when vendor/rails is not present -RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION +#RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') @@ -21,19 +15,6 @@ Rails::Initializer.run do |config| # you must remove the Active Record framework. config.frameworks -= [ :action_mailer ] - # Specify gems that this application depends on. - # They can then be installed with "rake gems:install" on new installations. - # You have to specify the :lib option for libraries, where the Gem name (sqlite3-ruby) differs from the file itself (sqlite3) - # config.gem "bj" - # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" - # config.gem "sqlite3-ruby", :lib => "sqlite3" - # config.gem "aws-s3", :lib => "aws/s3" - - # Only load the plugins named here, in the order given. By default, all plugins - # in vendor/plugins are loaded in alphabetical order. - # :all can be used as a placeholder for all plugins not explicitly named - # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - # Add additional load paths for your own custom dirs # config.load_paths += %W( #{RAILS_ROOT}/extras ) @@ -68,8 +49,37 @@ Rails::Initializer.run do |config| # config.active_record.observers = :cacher, :garbage_collector, :forum_observer end -class ActiveRecord::Migration +module ActiveRecord + module ConnectionAdapters + + # Patch to delegate configuration of JDBC datasource to Sonar. + # See vendor/gems/activerecord-jdbc-adapter/lib/active_record/connection_adapters/jdbc_adapter.rb + class JdbcConnection + def initialize(config) + @config = config.symbolize_keys! + @config[:retry_count] ||= 5 + @config[:connection_alive_sql] ||= ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.jdbc.validationQuery') + + @jndi_connection = true # used in JndiConnectionPoolCallbacks to close this initial connection + + @connection_factory = JdbcConnectionFactory.impl do + ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConnection() + end + @config[:driver] = ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.jdbc.driverClassName') + + connection # force the connection to load + set_native_database_types + @stmts = {} + rescue Exception => e + raise "Fail to connect to database: #{e}" + end + end + end +end + + +class ActiveRecord::Migration def self.alter_to_big_primary_key(tablename) dialect = ActiveRecord::Base.configurations[ ENV['RAILS_ENV'] ]["dialect"] case dialect |