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 | |
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')
4 files changed, 47 insertions, 35 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index d0544c03692..5c680ab91bc 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -46,11 +46,19 @@ import org.sonar.server.rules.ProfilesConsole; import org.sonar.server.rules.RulesConsole; import org.sonar.updatecenter.common.Version; +import java.sql.Connection; +import java.sql.SQLException; import java.util.Collection; import java.util.List; import java.util.Set; -public final class JRubyFacade implements ServerComponent { +public final class JRubyFacade { + + private static final JRubyFacade SINGLETON = new JRubyFacade(); + + public static JRubyFacade getInstance() { + return SINGLETON; + } public FilterResult executeFilter(Filter filter) { return getContainer().getComponent(FilterExecutor.class).execute(filter); @@ -253,6 +261,10 @@ public final class JRubyFacade implements ServerComponent { return getContainer().getComponent(Configuration.class).getString(key, null); } + public Connection getConnection() throws SQLException { + return getContainer().getComponent(DatabaseConnector.class).getConnection(); + } + public Object getCoreComponentByClassname(String className) { if (className == null) { return null; diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/server.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/server.rb index 04574290983..b9ce7cbe8dc 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/server.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/server.rb @@ -70,7 +70,7 @@ class Server add_property(sonar_info, 'Database Login') {sonar_property('sonar.jdbc.username')} add_property(sonar_info, 'Database Driver') {"#{jdbc_metadata.getDriverName()} #{jdbc_metadata.getDriverVersion()}"} add_property(sonar_info, 'Database Driver Class') {sonar_property('sonar.jdbc.driverClassName')} - add_property(sonar_info, 'Database Dialect (Hibernate/Rails)') {"#{@java_facade.getDialect().getId()} (#{@java_facade.getDialect().getHibernateDialectClass().getName()} / #{@java_facade.getDialect().getActiveRecordDialectCode()})"} + add_property(sonar_info, 'Database Dialect (Hibernate)') {"#{@java_facade.getDialect().getId()} (#{@java_facade.getDialect().getHibernateDialectClass().getName()})"} add_property(sonar_info, 'Database Validation Query') {sonar_property('sonar.jdbc.validationQuery')} add_property(sonar_info, 'Hibernate Default Schema') {sonar_property('sonar.hibernate.default_schema')} add_property(sonar_info, 'External User Authentication') {sonar_property(org.sonar.api.CoreProperties.CORE_AUTHENTICATOR_CLASS)} 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 |