# 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:
# Optional properties
#sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
-#sonar.jdbc.validationQuery: select 1
#----- Oracle 10g/11g
# 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
# 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
# Optional properties
#sonar.jdbc.driverClassName: net.sourceforge.jtds.jdbc.Driver
-#sonar.jdbc.validationQuery: select 1
#----- Connection pool settings
if (StringUtils.isNotBlank(initStatement)) {
datasource.setConnectionInitSqls(Arrays.asList(initStatement));
}
+
+ datasource.setValidationQuery(dialect.getValidationQuery());
}
public final DefaultDatabase stop() {
* @since 2.14
*/
String getFalseSqlValue();
+
+ /**
+ * Query used to validate the jdbc connection.
+ *
+ * @since 3.2
+ */
+ String getValidationQuery();
}
public String getFalseSqlValue() {
return "false";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1";
+ }
}
public String getFalseSqlValue() {
return "0";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1";
+ }
}
public String getFalseSqlValue() {
return "false";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1";
+ }
}
public String getFalseSqlValue() {
return "0";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1 FROM DUAL";
+ }
}
public String getFalseSqlValue() {
return "false";
}
+
+ public String getValidationQuery() {
+ return "SELECT 1";
+ }
}
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;
*/
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);
}
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)}