]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2965 FIX enforce validation query on DataSource
authorDavid Gageot <david@gageot.net>
Wed, 11 Jul 2012 16:10:04 +0000 (18:10 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 11 Jul 2012 16:11:39 +0000 (18:11 +0200)
sonar-application/src/main/assembly/conf/sonar.properties
sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java
sonar-core/src/test/java/org/sonar/core/persistence/H2Database.java
sonar-server/src/main/webapp/WEB-INF/app/models/server.rb

index acdaba0433cee3954b0325cdbac4513190a924d3..e48cda0d6d52396f751f58c2c5e8b01acc26717d 100644 (file)
@@ -45,6 +45,7 @@ sonar.jdbc.password:                       sonar
 # Comment the following line to deactivate the default embedded database.
 sonar.jdbc.url:                            jdbc:h2:tcp://localhost:9092/sonar
 #sonar.jdbc.driverClassName:                org.h2.Driver
+#sonar.jdbc.validationQuery:                values(1)
 
 # directory containing H2 database files. By default it's the /data directory in the sonar installation.
 #sonar.embeddedDatabase.dataDir:
@@ -58,6 +59,7 @@ sonar.jdbc.url:                            jdbc:h2:tcp://localhost:9092/sonar
 
 # Optional properties
 #sonar.jdbc.driverClassName:                com.mysql.jdbc.Driver
+#sonar.jdbc.validationQuery:                select 1
 
 
 #----- Oracle 10g/11g
@@ -71,6 +73,7 @@ sonar.jdbc.url:                            jdbc:h2:tcp://localhost:9092/sonar
 
 # Optional properties
 #sonar.jdbc.driverClassName:                oracle.jdbc.OracleDriver
+#sonar.jdbc.validationQuery:                select 1 from dual
 
 # Uncomment the following property if the Oracle account has permissions to access multiple schemas,
 # for example sonar schemas with different versions. In that case, use the same property during project analysis
@@ -84,6 +87,7 @@ sonar.jdbc.url:                            jdbc:h2:tcp://localhost:9092/sonar
 
 # Optional properties
 #sonar.jdbc.driverClassName:                org.postgresql.Driver
+#sonar.jdbc.validationQuery:                select 1
 
 # Uncomment the following property if the PostgreSQL account has permissions to access multiple schemas,
 # for example sonar schemas with different versions. In that case, use the same property during project analysis
@@ -97,6 +101,7 @@ sonar.jdbc.url:                            jdbc:h2:tcp://localhost:9092/sonar
 
 # Optional properties
 #sonar.jdbc.driverClassName:                net.sourceforge.jtds.jdbc.Driver
+#sonar.jdbc.validationQuery:                select 1  
 
 
 #----- Connection pool settings
index 35a26c4b42b618e017e9dc61814d5d564d9629ec..bb699f82b7bef05608cc858f65100d85561c824a 100644 (file)
@@ -71,7 +71,7 @@ public interface Dialect {
 
   /**
    * Query used to validate the jdbc connection.
-   * 
+   *
    * @since 3.2
    */
   String getValidationQuery();
index 3767121de0dc42ab19a2937c7a23c11f3f2e128e..55db7c2ed942928be05c59faa2cca5a26c069cd4 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.core.persistence;
 
 import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.dbcp.BasicDataSourceFactory;
 import org.hibernate.cfg.Environment;
 import org.sonar.core.persistence.dialect.Dialect;
 import org.sonar.core.persistence.dialect.H2;
@@ -52,13 +53,18 @@ public class H2Database implements Database {
    */
   private void startDatabase() {
     try {
-      datasource = new BasicDataSource();
-      datasource.setDriverClassName("org.h2.Driver");
-      datasource.setUsername("sonar");
-      datasource.setPassword("sonar");
-      datasource.setUrl("jdbc:h2:mem:sonar2");
-      datasource.setMaxActive(2);
-      datasource.setMaxIdle(2);
+      Properties properties = new Properties();
+      properties.put("driverClassName", "org.h2.Driver");
+      properties.put("username", "sonar");
+      properties.put("password", "sonar");
+      // properties.put("url", "jdbc:h2:mem:sonar2;TRACE_LEVEL_SYSTEM_OUT=2");
+      properties.put("url", "jdbc:h2:mem:sonar2");
+
+      // limit to 2 because of Hibernate and MyBatis
+      properties.put("maxActive", "2");
+      properties.put("maxIdle", "2");
+      datasource = (BasicDataSource) BasicDataSourceFactory.createDataSource(properties);
+
     } catch (Exception e) {
       throw new IllegalStateException("Fail to start H2", e);
     }
index d2e50aafbac992b00c160571cf34e6a08c2785c8..7541819bee4c45fb2628b64078b364f8ebf419c5 100644 (file)
@@ -68,6 +68,7 @@ class Server
     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)') {"#{Java::OrgSonarServerUi::JRubyFacade.getInstance().getDatabase().getDialect().getId()} (#{Java::OrgSonarServerUi::JRubyFacade.getInstance().getDatabase().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)}
     add_property(sonar_info, 'Automatic User Creation') {sonar_property(org.sonar.api.CoreProperties.CORE_AUTHENTICATOR_CREATE_USERS)}