*/
package org.sonar.core.persistence;
+import org.picocontainer.Startable;
import org.sonar.core.persistence.dialect.Dialect;
import javax.sql.DataSource;
/**
* @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.
*/
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;
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);
}
}
- public final DefaultDatabase stop() {
+ @Override
+ public void stop() {
if (datasource != null) {
try {
datasource.close();
throw new IllegalStateException("Fail to stop JDBC connection pool", e);
}
}
- return this;
}
public final Dialect getDialect() {
}
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;
}
}
this.createSchema = createSchema;
}
- public H2Database start() {
+ @Override
+ public void start() {
startDatabase();
if (createSchema) {
createSchema();
}
- return this;
}
private void startDatabase() {
}
}
- public H2Database stop() {
+ @Override
+ public void stop() {
try {
datasource.close();
} catch (SQLException e) {
// Ignore error
}
- return this;
}
public DataSource getDataSource() {