aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-06-18 00:25:11 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-06-18 11:52:18 +0200
commit9fb4133b607bb0a47376df86db11262375c8d9f4 (patch)
treec2438abab8febdbd824ffdd298dab126a4ee484a
parent021bf45623b748e70f20d956e86d595191241786 (diff)
downloadsonarqube-9fb4133b607bb0a47376df86db11262375c8d9f4.tar.gz
sonarqube-9fb4133b607bb0a47376df86db11262375c8d9f4.zip
Drop Hibernate from server
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel3.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/DatabaseSessionFilter.java48
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java14
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/notification/NotificationServiceTest.java19
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/web.xml8
-rw-r--r--sonar-batch/pom.xml22
-rw-r--r--sonar-core/pom.xml10
-rw-r--r--sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionProvider.java31
-rw-r--r--sonar-core/src/main/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactory.java56
12 files changed, 54 insertions, 190 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java b/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java
index 8ab6ab4c626..f83ce0045f3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java
@@ -40,7 +40,6 @@ import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.jpa.session.DatabaseSessionFactory;
import org.sonar.server.db.DbClient;
@Properties({
@@ -67,7 +66,6 @@ public class NotificationService implements Startable {
private final long delayInSeconds;
private final long delayBeforeReportingStatusInSeconds;
- private final DatabaseSessionFactory databaseSessionFactory;
private final DefaultNotificationManager manager;
private final List<NotificationDispatcher> dispatchers;
private final DbClient dbClient;
@@ -76,8 +74,7 @@ public class NotificationService implements Startable {
private boolean stopping = false;
public NotificationService(Settings settings, DefaultNotificationManager manager, DbClient dbClient,
- DatabaseSessionFactory databaseSessionFactory, NotificationDispatcher[] dispatchers) {
- this.databaseSessionFactory = databaseSessionFactory;
+ NotificationDispatcher[] dispatchers) {
this.delayInSeconds = settings.getLong(PROPERTY_DELAY);
this.delayBeforeReportingStatusInSeconds = settings.getLong(PROPERTY_DELAY_BEFORE_REPORTING_STATUS);
this.manager = manager;
@@ -88,9 +85,8 @@ public class NotificationService implements Startable {
/**
* Default constructor when no dispatchers.
*/
- public NotificationService(Settings settings, DefaultNotificationManager manager, DbClient dbClient,
- DatabaseSessionFactory databaseSessionFactory) {
- this(settings, manager, dbClient, databaseSessionFactory, new NotificationDispatcher[0]);
+ public NotificationService(Settings settings, DefaultNotificationManager manager, DbClient dbClient) {
+ this(settings, manager, dbClient, new NotificationDispatcher[0]);
}
@Override
@@ -103,10 +99,6 @@ public class NotificationService implements Startable {
processQueue();
} catch (Exception e) {
LOG.error("Error in NotificationService", e);
- } finally {
- // Free Hibernate session
- // See https://jira.sonarsource.com/browse/SONAR-6566
- databaseSessionFactory.clear();
}
}
}, 0, delayInSeconds, TimeUnit.SECONDS);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel3.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel3.java
index 7df65744ac5..5cef42bf4f4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel3.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel3.java
@@ -21,9 +21,6 @@ package org.sonar.server.platform.platformlevel;
import org.sonar.api.utils.UriReader;
import org.sonar.core.util.DefaultHttpDownloader;
-import org.sonar.jpa.session.DatabaseSessionProvider;
-import org.sonar.jpa.session.DefaultDatabaseConnector;
-import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
import org.sonar.server.platform.PersistentSettings;
import org.sonar.server.platform.ServerIdGenerator;
import org.sonar.server.startup.ServerMetadataPersister;
@@ -37,9 +34,6 @@ public class PlatformLevel3 extends PlatformLevel {
protected void configureLevel() {
add(
PersistentSettings.class,
- DefaultDatabaseConnector.class,
- ThreadLocalDatabaseSessionFactory.class,
- new DatabaseSessionProvider(),
ServerMetadataPersister.class,
DefaultHttpDownloader.class,
UriReader.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java
index ac863cb139a..3cb81131d81 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java
@@ -19,8 +19,6 @@
*/
package org.sonar.server.platform.platformlevel;
-import org.sonar.jpa.session.DefaultDatabaseConnector;
-import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
import org.sonar.server.platform.ws.MigrateDbSystemAction;
import org.sonar.server.platform.ws.StatusAction;
import org.sonar.server.platform.ws.SystemWs;
@@ -35,10 +33,6 @@ public class PlatformLevelSafeMode extends PlatformLevel {
@Override
protected void configureLevel() {
add(
- // DB access required by DatabaseSessionFilter wired into ROR
- DefaultDatabaseConnector.class,
- ThreadLocalDatabaseSessionFactory.class,
-
// Server WS
StatusAction.class,
MigrateDbSystemAction.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
index b4166e004e5..f1d7315580e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.platformlevel;
-import org.sonar.jpa.session.DatabaseSessionFactory;
import org.sonar.server.computation.ReportQueueCleaner;
import org.sonar.server.issue.filter.RegisterIssueFilters;
import org.sonar.server.platform.ServerLifecycleNotifier;
@@ -85,13 +84,4 @@ public class PlatformLevelStartup extends PlatformLevel {
return this;
}
-
- @Override
- public PlatformLevel stop() {
- super.stop();
-
- getComponentByType(DatabaseSessionFactory.class).clear();
-
- return this;
- }
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/DatabaseSessionFilter.java b/server/sonar-server/src/main/java/org/sonar/server/user/DatabaseSessionFilter.java
deleted file mode 100644
index b8a3c31e65a..00000000000
--- a/server/sonar-server/src/main/java/org/sonar/server/user/DatabaseSessionFilter.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.user;
-
-import org.sonar.jpa.session.DatabaseSessionFactory;
-import org.sonar.server.platform.Platform;
-
-import javax.servlet.*;
-import java.io.IOException;
-
-public class DatabaseSessionFilter implements Filter {
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- // nothing to do
- }
-
- @Override
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
- chain.doFilter(request, response);
-
- DatabaseSessionFactory sessionFactory = Platform.component(DatabaseSessionFactory.class);
- if (sessionFactory != null) {
- sessionFactory.clear();
- }
- }
-
- @Override
- public void destroy() {
- // nothing to do
- }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java
index abb6f2381f7..15205263036 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java
@@ -21,6 +21,11 @@ package org.sonar.server.notification;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
+import java.io.InvalidClassException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
@@ -31,13 +36,6 @@ import org.sonar.api.notifications.NotificationChannel;
import org.sonar.core.notification.db.NotificationQueueDao;
import org.sonar.core.notification.db.NotificationQueueDto;
import org.sonar.core.properties.PropertiesDao;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.io.InvalidClassException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
@@ -49,7 +47,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-public class DefaultNotificationManagerTest extends AbstractDbUnitTestCase {
+public class DefaultNotificationManagerTest {
private DefaultNotificationManager manager;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationServiceTest.java
index 515c4279864..214f062eebd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationServiceTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationServiceTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.notification;
import com.google.common.collect.Sets;
+import java.util.Arrays;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -27,13 +28,19 @@ import org.sonar.api.config.Settings;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.core.properties.PropertiesDao;
-import org.sonar.jpa.session.DatabaseSessionFactory;
import org.sonar.server.db.DbClient;
-import java.util.Arrays;
-
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.same;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class NotificationServiceTest {
private static String CREATOR_SIMON = "simon";
@@ -65,7 +72,7 @@ public class NotificationServiceTest {
Settings settings = new Settings().setProperty("sonar.notifications.delay", 1L);
service = new NotificationService(settings, manager,
- dbClient, mock(DatabaseSessionFactory.class),
+ dbClient,
new NotificationDispatcher[] {commentOnIssueAssignedToMe, commentOnIssueCreatedByMe, qualityGateChange});
}
@@ -202,7 +209,7 @@ public class NotificationServiceTest {
public void getDispatchers_empty() {
Settings settings = new Settings().setProperty("sonar.notifications.delay", 1L);
- service = new NotificationService(settings, manager, dbClient, mock(DatabaseSessionFactory.class));
+ service = new NotificationService(settings, manager, dbClient);
assertThat(service.getDispatchers()).hasSize(0);
}
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/web.xml b/server/sonar-web/src/main/webapp/WEB-INF/web.xml
index bcc5d20daca..f1cf10fcfc0 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/web.xml
+++ b/server/sonar-web/src/main/webapp/WEB-INF/web.xml
@@ -36,10 +36,6 @@
<filter-class>org.sonar.server.platform.MasterServletFilter</filter-class>
</filter>
<filter>
- <filter-name>DatabaseSessionFilter</filter-name>
- <filter-class>org.sonar.server.user.DatabaseSessionFilter</filter-class>
- </filter>
- <filter>
<filter-name>UserSessionFilter</filter-name>
<filter-class>org.sonar.server.user.UserSessionFilter</filter-class>
</filter>
@@ -66,10 +62,6 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
- <filter-name>DatabaseSessionFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <filter-mapping>
<filter-name>UserSessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
diff --git a/sonar-batch/pom.xml b/sonar-batch/pom.xml
index 5396ebe1448..c1b2b197c32 100644
--- a/sonar-batch/pom.xml
+++ b/sonar-batch/pom.xml
@@ -107,6 +107,28 @@
<artifactId>freemarker</artifactId>
</dependency>
+ <!-- hibernate -->
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-commons-annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>geronimo-spec</groupId>
+ <artifactId>geronimo-spec-jta</artifactId>
+ </dependency>
+
<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
diff --git a/sonar-core/pom.xml b/sonar-core/pom.xml
index 069d94c38ff..73d735b8a6b 100644
--- a/sonar-core/pom.xml
+++ b/sonar-core/pom.xml
@@ -61,22 +61,32 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
+ <!-- provided only by batch -->
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
+ <!-- provided only by batch -->
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
+ <!-- provided only by batch -->
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
+ <!-- provided only by batch -->
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>geronimo-spec</groupId>
<artifactId>geronimo-spec-jta</artifactId>
+ <!-- provided only by batch -->
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionProvider.java b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionProvider.java
deleted file mode 100644
index 06e17361c00..00000000000
--- a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionProvider.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.jpa.session;
-
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.database.DatabaseSession;
-
-public class DatabaseSessionProvider extends ProviderAdapter {
-
- public DatabaseSession provide(DatabaseSessionFactory factory) {
- return factory.getSession();
- }
-
-}
diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactory.java b/sonar-core/src/main/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactory.java
deleted file mode 100644
index 661598b37cd..00000000000
--- a/sonar-core/src/main/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactory.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.jpa.session;
-
-import org.sonar.api.database.DatabaseSession;
-
-public class ThreadLocalDatabaseSessionFactory implements DatabaseSessionFactory {
-
- private final ThreadLocal<JpaDatabaseSession> threadSession = new ThreadLocal<>();
- private final DatabaseConnector connector;
-
- public ThreadLocalDatabaseSessionFactory(DatabaseConnector connector) {
- this.connector = connector;
- }
-
- @Override
- public DatabaseSession getSession() {
- JpaDatabaseSession session = threadSession.get();
- if (session == null) {
- session = new JpaDatabaseSession(connector);
- session.start();
- threadSession.set(session);
- }
- return session;
- }
-
- @Override
- public void clear() {
- JpaDatabaseSession session = threadSession.get();
- if (session != null) {
- session.stop();
- }
- threadSession.set(null);
- }
-
- public void stop() {
- clear();
- }
-}