]> source.dussan.org Git - sonarqube.git/commitdiff
Database implements Startable
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 11 Feb 2014 21:49:37 +0000 (22:49 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 11 Feb 2014 21:49:37 +0000 (22:49 +0100)
sonar-core/src/main/java/org/sonar/core/persistence/Database.java
sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java
sonar-core/src/main/java/org/sonar/core/persistence/profiling/PersistenceProfiling.java
sonar-core/src/test/java/org/sonar/core/persistence/H2Database.java

index e2a9f75d118f68014dcda67f49109ba62847e3c2..b83dcaea6f9ca47bb387ac4076fe7d8d9eee86b9 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.core.persistence;
 
+import org.picocontainer.Startable;
 import org.sonar.core.persistence.dialect.Dialect;
 
 import javax.sql.DataSource;
@@ -27,11 +28,7 @@ import java.util.Properties;
 /**
  * @since 2.12
  */
-public interface Database {
-  Database start();
-
-  Database stop();
-
+public interface Database extends Startable {
   /**
    * Returns the configured datasource. Null as long as start() is not executed.
    */
index bec9bf8aafa115ce32ddc87732de69bcf710f4cf..a4785642dccfa35dd68a8ef8dc7ac330001ec79d 100644 (file)
@@ -25,6 +25,7 @@ import org.apache.commons.dbcp.BasicDataSourceFactory;
 import org.apache.commons.dbutils.DbUtils;
 import org.apache.commons.lang.StringUtils;
 import org.hibernate.cfg.Environment;
+import org.picocontainer.Startable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.config.Settings;
@@ -67,13 +68,13 @@ public class DefaultDatabase implements Database {
     this.settings = settings;
   }
 
-  public final DefaultDatabase start() {
+  @Override
+  public void start() {
     try {
       initSettings();
       initDatasource();
       checkConnection();
       doAfterStart();
-      return this;
 
     } catch (Exception e) {
       throw new IllegalStateException("Fail to connect to database", e);
@@ -139,7 +140,8 @@ public class DefaultDatabase implements Database {
     }
   }
 
-  public final DefaultDatabase stop() {
+  @Override
+  public void stop() {
     if (datasource != null) {
       try {
         datasource.close();
@@ -147,7 +149,6 @@ public class DefaultDatabase implements Database {
         throw new IllegalStateException("Fail to stop JDBC connection pool", e);
       }
     }
-    return this;
   }
 
   public final Dialect getDialect() {
index 335e7025ef4bd21cd406ba63be432f994ec76b9a..35faac5b3e90a953ed911147caa36e23c6fcca9b 100644 (file)
@@ -33,11 +33,10 @@ public final class PersistenceProfiling {
   }
 
   public static BasicDataSource addProfilingIfNeeded(BasicDataSource datasource, Settings settings) {
-    Profiling.Level profilingLevel = Profiling.Level.fromConfigString(settings.getString(Profiling.CONFIG_PROFILING_LEVEL));
-    if (profilingLevel == Profiling.Level.FULL) {
+    Profiling.Level level = Profiling.Level.fromConfigString(settings.getString(Profiling.CONFIG_PROFILING_LEVEL));
+    if (level == Profiling.Level.FULL) {
       return new ProfilingDataSource(datasource);
-    } else {
-      return datasource;
     }
+    return datasource;
   }
 }
index 774249bbe1f06e8dfc12a2e7c89e504f72bb69c5..a2216af69b03a87cf4a8a2aaf589d3c42d68e966 100644 (file)
@@ -50,12 +50,12 @@ public class H2Database implements Database {
     this.createSchema = createSchema;
   }
 
-  public H2Database start() {
+  @Override
+  public void start() {
     startDatabase();
     if (createSchema) {
       createSchema();
     }
-    return this;
   }
 
   private void startDatabase() {
@@ -96,13 +96,13 @@ public class H2Database implements Database {
     }
   }
 
-  public H2Database stop() {
+  @Override
+  public void stop() {
     try {
       datasource.close();
     } catch (SQLException e) {
       // Ignore error
     }
-    return this;
   }
 
   public DataSource getDataSource() {