diff options
10 files changed, 42 insertions, 13 deletions
diff --git a/sonar-application/src/main/assembly/conf/sonar.properties b/sonar-application/src/main/assembly/conf/sonar.properties index 23823ae59ec..d03383e0020 100644 --- a/sonar-application/src/main/assembly/conf/sonar.properties +++ b/sonar-application/src/main/assembly/conf/sonar.properties @@ -102,12 +102,11 @@ sonar.jdbc.timeBetweenEvictionRunsMillis: 30000 #----- JDBC Datasource bounded to JNDI # When sonar webapp is deployed into a JEE server, the JDBC datasource can be configured into the JEE server and registered into JNDI. # In such a case Sonar uses this datasource to connect to database. -# If you activate this feature, then the properties starting with "sonar.jdbc." can be commented, EXCEPT "sonar.jdbc.driverClassName". +# If you activate this feature, then the properties starting with "sonar.jdbc." can be commented, except "sonar.jdbc.dialect". # The JDBC driver must still be deployed into the directory /extensions/jdbc-driver. #sonar.jdbc.jndiName: jdbc/sonar -# If you don't use the default JDBC drivers, as listed above, then you have to explicitly set the dialect to use. -# Values are : mysql, derby, oracle, postgresql +# Values are : mysql, mssql, derby, oracle, postgresql #sonar.jdbc.dialect= diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/Derby.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/Derby.java index 7f17ac50a67..b0c0ec5614d 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/Derby.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/Derby.java @@ -35,6 +35,10 @@ public class Derby implements Dialect { return "derby"; } + public String getActiveRecordDialectCode() { + return "derby"; + } + public Class<? extends org.hibernate.dialect.Dialect> getHibernateDialectClass() { return DerbyWithDecimalDialect.class; } diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/Dialect.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/Dialect.java index b2537a36096..0f860ae4e32 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/Dialect.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/Dialect.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource + * Copyright (C) 2009 SonarSource SA * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or @@ -35,6 +35,11 @@ public interface Dialect { Class<? extends org.hibernate.dialect.Dialect> getHibernateDialectClass(); /** + * @return the activerecord dialect to be used + */ + String getActiveRecordDialectCode(); + + /** * Used to autodetect a dialect for a given driver URL * * @param jdbcConnectionURL a jdbc driver url such as jdbc:mysql://localhost:3306/sonar diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/HsqlDb.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/HsqlDb.java index e5ffebe4477..b6bb3a68392 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/HsqlDb.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/HsqlDb.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource + * Copyright (C) 2009 SonarSource SA * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or @@ -31,6 +31,10 @@ public class HsqlDb implements Dialect { return "hsqldb"; } + public String getActiveRecordDialectCode() { + return "hsqldb"; + } + public Class<? extends org.hibernate.dialect.Dialect> getHibernateDialectClass() { return HSQLDialect.class; } diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/MsSql.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/MsSql.java index 764e8a57324..f59c2ee4240 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/MsSql.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/MsSql.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource + * Copyright (C) 2009 SonarSource SA * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or @@ -32,6 +32,10 @@ public class MsSql implements Dialect { return "mssql"; } + public String getActiveRecordDialectCode() { + return "sqlserver"; + } + public Class<? extends org.hibernate.dialect.Dialect> getHibernateDialectClass() { return MsSqlDialect.class; } diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/MySql.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/MySql.java index e062e61aa4f..180dec0b1ee 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/MySql.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/MySql.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource + * Copyright (C) 2009 SonarSource SA * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or @@ -34,6 +34,10 @@ public class MySql implements Dialect { return "mysql"; } + public String getActiveRecordDialectCode() { + return "mysql"; + } + public Class<? extends org.hibernate.dialect.Dialect> getHibernateDialectClass() { return MySqlWithDecimalDialect.class; } diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/Oracle.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/Oracle.java index 221848bb0a7..ebec6753619 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/Oracle.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/Oracle.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource + * Copyright (C) 2009 SonarSource SA * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or @@ -34,6 +34,10 @@ public class Oracle implements Dialect { return "oracle"; } + public String getActiveRecordDialectCode() { + return "oracle"; + } + public Class<? extends org.hibernate.dialect.Dialect> getHibernateDialectClass() { return Oracle10gWithDecimalDialect.class; } diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSql.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSql.java index 65f3436ca33..7d7318e51eb 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSql.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSql.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource + * Copyright (C) 2009 SonarSource SA * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or @@ -33,6 +33,10 @@ public class PostgreSql implements Dialect { return "postgresql"; } + public String getActiveRecordDialectCode() { + return "postgre"; + } + public Class<? extends org.hibernate.dialect.Dialect> getHibernateDialectClass() { return PostgreSQLWithDecimalDialect.class; } diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseConnector.java b/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseConnector.java index 3ba4cbc5d47..ba3e77928fa 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseConnector.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseConnector.java @@ -21,6 +21,7 @@ package org.sonar.jpa.session; import org.apache.commons.configuration.Configuration; import org.apache.commons.lang.StringUtils; +import org.hibernate.cfg.Environment; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.database.DatabaseProperties; @@ -154,7 +155,7 @@ public abstract class AbstractDatabaseConnector implements DatabaseConnector { props.put("hibernate.connection.isolation", Integer.toString(transactionIsolation)); } props.put("hibernate.hbm2ddl.auto", getConfiguration().getString(DatabaseProperties.PROP_HIBERNATE_HBM2DLL, "validate")); - props.put("hibernate.dialect", getDialectClass()); + props.put(Environment.DIALECT, getDialectClass()); props.put("hibernate.generate_statistics", getConfiguration().getBoolean(DatabaseProperties.PROP_HIBERNATE_GENERATE_STATISTICS, false)); props.put("hibernate.show_sql", Boolean.valueOf(LOG_SQL.isInfoEnabled()).toString()); 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 721bd127307..2ce9d7254ca 100644 --- a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb +++ b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb @@ -62,11 +62,11 @@ module ActiveRecord @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') + @config[:dialect] = ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getDialect().getActiveRecordDialectCode() connection # force the connection to load set_native_database_types @@ -81,7 +81,7 @@ end class ActiveRecord::Migration def self.alter_to_big_primary_key(tablename) - dialect = ActiveRecord::Base.configurations[ ENV['RAILS_ENV'] ]["dialect"] + dialect = ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getDialect().getActiveRecordDialectCode() case dialect when "postgre" execute "ALTER TABLE #{tablename} ALTER COLUMN id TYPE bigint" |