summaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-11 13:48:59 +0200
committerDavid Gageot <david@gageot.net>2012-07-11 17:38:40 +0200
commitcd2d985404cbe202d55f4024c3aa64bf1f186839 (patch)
treead65aafe0370c57e6e277586cee25ba4f082034f /sonar-core
parent713a024a1cc38874b5fb709ede64c13a4f21ec53 (diff)
downloadsonarqube-cd2d985404cbe202d55f4024c3aa64bf1f186839.tar.gz
sonarqube-cd2d985404cbe202d55f4024c3aa64bf1f186839.zip
SONAR-2965 enforce validation query on DataSource
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java7
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/H2.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/MsSql.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/PostgreSql.java4
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/H2Database.java20
8 files changed, 36 insertions, 13 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java b/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java
index cf3b54f99f0..8e4b7f4625a 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java
@@ -124,6 +124,8 @@ public class DefaultDatabase implements Database {
if (StringUtils.isNotBlank(initStatement)) {
datasource.setConnectionInitSqls(Arrays.asList(initStatement));
}
+
+ datasource.setValidationQuery(dialect.getValidationQuery());
}
public final DefaultDatabase stop() {
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java
index 03f368620d6..35a26c4b42b 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java
@@ -68,4 +68,11 @@ public interface Dialect {
* @since 2.14
*/
String getFalseSqlValue();
+
+ /**
+ * Query used to validate the jdbc connection.
+ *
+ * @since 3.2
+ */
+ String getValidationQuery();
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/H2.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/H2.java
index 00879be648b..fd761f82d24 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/H2.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/H2.java
@@ -64,4 +64,8 @@ public class H2 implements Dialect {
public String getFalseSqlValue() {
return "false";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1";
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MsSql.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MsSql.java
index 14589780d83..0b0e944f489 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MsSql.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MsSql.java
@@ -85,5 +85,9 @@ public class MsSql implements Dialect {
public String getFalseSqlValue() {
return "0";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1";
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java
index 0f718bdb710..94f8dc8cf1a 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java
@@ -77,4 +77,8 @@ public class MySql implements Dialect {
public String getFalseSqlValue() {
return "false";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1";
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java
index 6adbb43e521..a9f235a23e8 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java
@@ -84,4 +84,8 @@ public class Oracle implements Dialect {
public String getFalseSqlValue() {
return "0";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1 FROM DUAL";
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/PostgreSql.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/PostgreSql.java
index 8c1b29cc3c5..07d5ddd48ed 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/PostgreSql.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/PostgreSql.java
@@ -81,4 +81,8 @@ public class PostgreSql implements Dialect {
public String getFalseSqlValue() {
return "false";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1";
+ }
}
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/H2Database.java b/sonar-core/src/test/java/org/sonar/core/persistence/H2Database.java
index 55db7c2ed94..3767121de0d 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/H2Database.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/H2Database.java
@@ -20,7 +20,6 @@
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;
@@ -53,18 +52,13 @@ public class H2Database implements Database {
*/
private void startDatabase() {
try {
- 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);
-
+ 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);
} catch (Exception e) {
throw new IllegalStateException("Fail to start H2", e);
}