From 2a387b3eb1c18708800e5c546cee98dd68d513c7 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 26 Feb 2016 20:36:12 +0100 Subject: [PATCH] SONAR-7330 Remove DAOv2 base classes --- .../java/org/sonar/server/db/BaseDao.java | 358 ----------- .../org/sonar/server/db/DeprecatedDao.java | 87 --- .../platformlevel/PlatformLevel1.java | 2 - .../org/sonar/server/search/BaseIndex.java | 592 ------------------ .../sonar/server/search/BaseNormalizer.java | 65 -- .../search/DbSynchronizationHandler.java | 53 -- .../java/org/sonar/server/search/Index.java | 54 -- .../org/sonar/server/search/IndexClient.java | 52 -- .../org/sonar/server/search/IndexQueue.java | 149 ----- .../org/sonar/server/search/IndexStat.java | 44 -- .../org/sonar/server/search/QueryContext.java | 3 +- .../java/org/sonar/server/search/Result.java | 22 - .../sonar/server/search/action/DeleteKey.java | 54 -- .../search/action/DeleteNestedItem.java | 66 -- .../server/search/action/IndexAction.java | 69 -- .../sonar/server/search/action/InsertDto.java | 63 -- .../server/search/action/RefreshIndex.java | 44 -- .../sonar/server/search/action/UpsertDto.java | 56 -- .../search/action/UpsertNestedItem.java | 66 -- .../server/search/action/package-info.java | 23 - .../server/component/ComponentFinderTest.java | 2 +- .../java/org/sonar/server/db/BaseDaoTest.java | 123 ---- .../org/sonar/server/db/fake/FakeDao.java | 43 -- .../org/sonar/server/db/fake/FakeDto.java | 47 -- .../org/sonar/server/db/fake/FakeMapper.java | 36 -- .../ws/DuplicationsParserTest.java | 2 +- .../issue/IssueCommentServiceMediumTest.java | 3 - .../measure/custom/ws/CreateActionTest.java | 2 +- .../measure/custom/ws/DeleteActionTest.java | 2 +- .../measure/custom/ws/MetricsActionTest.java | 2 +- .../measure/custom/ws/UpdateActionTest.java | 2 +- .../measure/ws/ComponentActionTest.java | 2 +- .../measure/ws/ComponentTreeActionTest.java | 2 +- .../server/metric/ws/CreateActionTest.java | 2 +- .../server/metric/ws/DeleteActionTest.java | 2 +- .../server/metric/ws/SearchActionTest.java | 2 +- .../server/metric/ws/UpdateActionTest.java | 2 +- .../permission/ws/RemoveGroupActionTest.java | 2 +- .../SearchProjectPermissionsActionTest.java | 2 +- .../ws/TemplateUsersActionTest.java | 2 +- .../ws/template/ApplyTemplateActionTest.java | 2 - .../template/SearchTemplatesActionTest.java | 2 +- .../project/ws/BulkDeleteActionTest.java | 2 +- .../server/project/ws/DeleteActionTest.java | 2 +- .../qualityprofile/ws/ExportActionTest.java | 3 +- .../qualityprofile/ws/SearchActionTest.java | 4 +- .../sonar/server/search/BaseIndexTest.java | 146 ----- .../server/search/action/DeleteKeyTest.java | 71 --- .../search/action/RefreshIndexTest.java | 72 --- .../server/user/ws/SearchActionTest.java | 2 +- .../server/usertoken/ws/RevokeActionTest.java | 2 +- .../server/usertoken/ws/SearchActionTest.java | 2 +- .../org/sonar/core/persistence/MyBatis.java | 5 +- .../main/java/org/sonar/db/BatchSession.java | 16 +- .../src/main/java/org/sonar/db/DbSession.java | 27 +- .../src/main/java/org/sonar/db/MyBatis.java | 9 +- .../sonar/db/deprecated/ClusterAction.java | 28 - .../org/sonar/db/deprecated/NullQueue.java | 30 - .../org/sonar/db/deprecated/WorkQueue.java | 29 - .../java/org/sonar/db/BatchSessionTest.java | 22 +- .../test/java/org/sonar/db/MyBatisTest.java | 7 +- .../src/test/java/org/sonar/db/TestDb.java | 3 +- .../sonar/db/component/ComponentDaoTest.java | 2 +- .../ComponentDaoWithDuplicatedKeysTest.java | 2 +- .../sonar/db/component/SnapshotDaoTest.java | 11 +- .../db/duplication/DuplicationDaoTest.java | 2 +- .../org/sonar/db/measure/MeasureDaoTest.java | 4 +- .../db/measure/MeasureFilterDaoTest.java | 2 +- .../MeasureFilterFavouriteDaoTest.java | 2 +- .../GroupWithPermissionDaoTest.java | 2 +- .../permission/PermissionTemplateDaoTest.java | 2 +- .../java/org/sonar/db/user/GroupDaoTest.java | 4 +- .../java/org/sonar/db/user/UserDaoTest.java | 2 +- 73 files changed, 59 insertions(+), 2666 deletions(-) delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/db/DeprecatedDao.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/BaseNormalizer.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/DbSynchronizationHandler.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/Index.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/IndexClient.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/IndexStat.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteKey.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteNestedItem.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshIndex.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertDto.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertNestedItem.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/search/action/package-info.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/db/BaseDaoTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeDao.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeDto.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeMapper.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/search/action/DeleteKeyTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/search/action/RefreshIndexTest.java delete mode 100644 sonar-db/src/main/java/org/sonar/db/deprecated/ClusterAction.java delete mode 100644 sonar-db/src/main/java/org/sonar/db/deprecated/NullQueue.java delete mode 100644 sonar-db/src/main/java/org/sonar/db/deprecated/WorkQueue.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java b/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java deleted file mode 100644 index 1def17d25dc..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java +++ /dev/null @@ -1,358 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import java.io.Serializable; -import java.sql.Timestamp; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Map; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.apache.ibatis.session.ResultContext; -import org.sonar.api.utils.System2; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.db.Dao; -import org.sonar.db.DbSession; -import org.sonar.db.Dto; -import org.sonar.server.exceptions.NotFoundException; -import org.sonar.server.search.DbSynchronizationHandler; -import org.sonar.server.search.IndexDefinition; -import org.sonar.server.search.action.DeleteKey; -import org.sonar.server.search.action.DeleteNestedItem; -import org.sonar.server.search.action.InsertDto; -import org.sonar.server.search.action.RefreshIndex; -import org.sonar.server.search.action.UpsertDto; -import org.sonar.server.search.action.UpsertNestedItem; - -import static com.google.common.collect.Maps.newHashMap; - -/** - * naming convention for DAO - * ========================= - *

- * The DAO manages a Business Domain for a set of DTO. There is a Main DTO (i.e. RuleDto) - * that has a few nested/child DTOs. The DAO supports nested DTOs for 1-to-1 and 1-to-many - * relations. Many-to-many relations are handled by their own DAO classes (i.e. ActiveRuleDao) - *

- * Main DTO - * ------------------------- - *

- * * GET Methods - * - returns a single DTO - * - DTO is fully loaded (no field will return null) - * - returns null (and not empty) - * - examples: - * - RuleDto = ruleDao.getNullableByKey(dto.getKey()); - *

- * * FIND Methods - * - returns a List of DTO. - * - Returns an empty list id no match - * - method name is FULLY-NOMINATIVE - * - examples: - * - List rules findByQualityProfile(QualityProfile qprofile) - * - List rules findByQualityProfile(QualityProfileKey qprofileKey) - * - List rules findByQualityProfileAndCreatedAfter(QualityProfileKey qprofileKey, Date date) - *

- * * CRUD Methods - * - insert(DTO) - * - udpate(DTO) - * - delete(DTO) - *

- * Nested DTO - * ------------------------- - *

- * Some DAO implementations also manage nested DTO. RuleTag for example is managed by the RuleDao class - * Nested DTO are accessible following a similar convention for the Main DTO: - *

- * * GET Methods - * - returns a single DTO - * - DTO is fully loaded (no field will return null) - * - returns null (and not empty) - * - prefixed with DTO type - * - examples: - * - RuleTagDto = ruleDao.getTagByKey(tagDto.getKey()); - *

- * * FIND Methods - * - returns a List of DTO. - * - Returns an empty list id no match - * - method name is FULLY-NOMINATIVE - * - prefixed with DTO type - * - examples: - * - List tags findRuleTagByRuleKey(RuleKey key) - * - List tags findRuleTagByRepositoryAndLanguage(RepositoryKey key, String language) - *

- * * CRUD Methods are slightly different because they REQUIRE the main DTO to be valid - * - Nested dto methods MUST have the Main DTO or it's key as param - * - add - * - remove - * - update - * - examples: - * - RuleTagDto tag add(RuleTagDto tag, RuleKey key) - * - RuleParamDto param add(RuleParamDto param, RuleDto rule) - * - * @param iBatis Mapper class - * @param Produced DTO class from this dao - * @param DTO Key class - */ -public abstract class BaseDao, KEY extends Serializable> implements DeprecatedDao, Dao { - - private static final Logger LOGGER = Loggers.get(BaseDao.class); - - protected IndexDefinition indexDefinition; - private Class mapperClass; - private System2 system2; - - protected boolean hasIndex() { - return indexDefinition != null; - } - - protected BaseDao(@Nullable IndexDefinition indexDefinition, Class mapperClass, System2 system2) { - this.mapperClass = mapperClass; - this.indexDefinition = indexDefinition; - this.system2 = system2; - } - - public String getIndexType() { - return indexDefinition != null ? this.indexDefinition.getIndexType() : null; - } - - protected MAPPER mapper(DbSession session) { - return session.getMapper(mapperClass); - } - - @Override - @CheckForNull - public DTO getNullableByKey(DbSession session, KEY key) { - return doGetNullableByKey(session, key); - } - - @Override - public DTO getByKey(DbSession session, KEY key) { - DTO value = doGetNullableByKey(session, key); - if (value == null) { - throw new NotFoundException(String.format("Key '%s' not found", key)); - } - return value; - } - - @Override - public DTO update(DbSession session, DTO item) { - Date now = new Date(system2.now()); - update(session, item, now); - return item; - } - - @Override - public DTO update(DbSession session, DTO item, DTO... others) { - update(session, Lists.asList(item, others)); - return item; - } - - @Override - public Collection update(DbSession session, Collection items) { - Date now = new Date(system2.now()); - for (DTO item : items) { - update(session, item, now); - } - return items; - } - - private void update(DbSession session, DTO item, Date now) { - try { - item.setUpdatedAt(now); - doUpdate(session, item); - if (hasIndex()) { - session.enqueue(new UpsertDto<>(getIndexType(), item)); - } - } catch (Exception e) { - throw new IllegalStateException("Fail to update item in db: " + item, e); - } - } - - @Override - public DTO insert(DbSession session, DTO item) { - insert(session, item, new Date(system2.now())); - return item; - } - - @Override - public Collection insert(DbSession session, Collection items) { - Date now = new Date(system2.now()); - for (DTO item : items) { - insert(session, item, now); - } - return items; - } - - @Override - public DTO insert(DbSession session, DTO item, DTO... others) { - insert(session, Lists.asList(item, others)); - return item; - } - - private void insert(DbSession session, DTO item, Date now) { - if (item.getCreatedAt() == null) { - item.setCreatedAt(now); - } - item.setUpdatedAt(now); - try { - doInsert(session, item); - if (hasIndex()) { - session.enqueue(new UpsertDto<>(getIndexType(), item)); - } - } catch (Exception e) { - throw new IllegalStateException("Fail to insert item in db: " + item, e); - } - } - - @Override - public void delete(DbSession session, DTO item) { - deleteByKey(session, item.getKey()); - } - - @Override - public void delete(DbSession session, DTO item, DTO... others) { - delete(session, Lists.asList(item, others)); - } - - @Override - public void delete(DbSession session, Collection items) { - for (DTO item : items) { - delete(session, item); - } - } - - @Override - public void deleteByKey(DbSession session, KEY key) { - Preconditions.checkNotNull(key, "Missing key"); - try { - doDeleteByKey(session, key); - if (hasIndex()) { - session.enqueue(new DeleteKey<>(getIndexType(), key)); - } - } catch (Exception e) { - throw new IllegalStateException("Fail to delete item from db: " + key, e); - } - } - - protected final void enqueueUpdate(Object nestedItem, KEY key, DbSession session) { - if (hasIndex()) { - session.enqueue(new UpsertNestedItem<>( - this.getIndexType(), key, nestedItem)); - } - } - - public void enqueueDelete(Object nestedItem, KEY key, DbSession session) { - if (hasIndex()) { - session.enqueue(new DeleteNestedItem<>( - this.getIndexType(), key, nestedItem)); - session.commit(); - } - } - - public void enqueueInsert(Object nestedItem, KEY key, DbSession session) { - if (hasIndex()) { - this.enqueueUpdate(nestedItem, key, session); - } - } - - // Synchronization methods - - protected DbSynchronizationHandler getSynchronizationResultHandler(final DbSession session, Map params) { - return new DbSynchronizationHandler(session, params) { - private int count = 0; - - @Override - public void handleResult(ResultContext resultContext) { - DTO dto = (DTO) resultContext.getResultObject(); - // session.enqueue(new UpsertDto(getIndexType(), dto, false)); - getSession().enqueue(new InsertDto<>(getIndexType(), dto, false)); - count++; - if (count % 100000 == 0) { - LOGGER.info("Synchronized {} {}", count, getIndexType()); - } - } - - @Override - public void enqueueCollected() { - // Do nothing in this case - } - }; - } - - protected Map getSynchronizationParams(@Nullable Date date, Map params) { - Map finalParams = newHashMap(); - if (date != null) { - finalParams.put("date", new Timestamp(date.getTime())); - } - return finalParams; - } - - @Override - public void synchronizeAfter(final DbSession session) { - this.synchronizeAfter(session, null, Collections.emptyMap()); - } - - @Override - public void synchronizeAfter(final DbSession session, @Nullable Date date) { - this.synchronizeAfter(session, date, Collections.emptyMap()); - } - - @Override - public void synchronizeAfter(final DbSession session, @Nullable Date date, Map params) { - DbSynchronizationHandler handler = getSynchronizationResultHandler(session, params); - session.select(getSynchronizeStatementFQN(), getSynchronizationParams(date, params), handler); - handler.enqueueCollected(); - session.enqueue(new RefreshIndex(this.getIndexType())); - session.commit(); - } - - private String getSynchronizeStatementFQN() { - return mapperClass.getName() + "." + this.getSynchronizationStatementName(); - } - - @CheckForNull - protected abstract DTO doGetNullableByKey(DbSession session, KEY key); - - protected String getSynchronizationStatementName() { - return "selectAfterDate"; - } - - protected DTO doInsert(DbSession session, DTO item) { - throw notImplemented(this); - } - - protected DTO doUpdate(DbSession session, DTO item) { - throw notImplemented(this); - } - - protected void doDeleteByKey(DbSession session, KEY key) { - throw notImplemented(this); - } - - private static RuntimeException notImplemented(BaseDao baseDao) { - throw new IllegalStateException("Not implemented yet for class [" + baseDao.getClass().getSimpleName() + "]"); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/DeprecatedDao.java b/server/sonar-server/src/main/java/org/sonar/server/db/DeprecatedDao.java deleted file mode 100644 index d4d6265b57a..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/db/DeprecatedDao.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Date; -import java.util.Map; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.sonar.db.DbSession; -import org.sonar.db.Dto; - -public interface DeprecatedDao, KEY extends Serializable> { - - /** - * Get a DTO by its key. Return null if the key does not exist. - */ - @CheckForNull - DTO getNullableByKey(DbSession session, KEY key); - - /** - * Get a DTO by its key. - * - * @throws org.sonar.server.exceptions.NotFoundException if the key does not exist - */ - DTO getByKey(DbSession session, KEY key); - - /** - * Update a table row. DTO id must be set. The field updatedAt - * is changed by this method. - */ - DTO update(DbSession session, DTO dto); - - /** - * Update one or more table rows. Note that the returned DTO is only - * the first updated one. - */ - DTO update(DbSession session, DTO dto, DTO... others); - - Collection update(DbSession session, Collection dtos); - - DTO insert(DbSession session, DTO dto); - - /** - * Insert one or more database rows. Note - * that the returned DTO is only the first inserted one. - */ - DTO insert(DbSession session, DTO dto, DTO... others); - - Collection insert(DbSession session, Collection dtos); - - void delete(DbSession session, DTO dto); - - /** - * Delete one or more table rows. - */ - void delete(DbSession session, DTO dto, DTO... others); - - void delete(DbSession session, Collection dtos); - - void deleteByKey(DbSession session, KEY key); - - void synchronizeAfter(final DbSession session); - - void synchronizeAfter(DbSession session, @Nullable Date date); - - void synchronizeAfter(DbSession session, @Nullable Date date, Map params); - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index c4cf1b9e5b0..39491d3e6b0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -46,7 +46,6 @@ import org.sonar.server.qualityprofile.index.ActiveRuleIndex; import org.sonar.server.ruby.PlatformRackBridge; import org.sonar.server.rule.index.RuleIndex; import org.sonar.server.search.EsSearchModule; -import org.sonar.server.search.IndexQueue; import org.sonar.server.user.ThreadLocalUserSession; public class PlatformLevel1 extends PlatformLevel { @@ -76,7 +75,6 @@ public class PlatformLevel1 extends PlatformLevel { // must instantiate deprecated class in 5.2 and only this one (and not its replacement) // to avoid having two SqlSessionFactory instances org.sonar.core.persistence.MyBatis.class, - IndexQueue.class, DatabaseServerCompatibility.class, DatabaseVersion.class, PurgeProfiler.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java deleted file mode 100644 index 18a569eea15..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java +++ /dev/null @@ -1,592 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; -import java.io.Serializable; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Queue; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; -import org.elasticsearch.action.count.CountRequestBuilder; -import org.elasticsearch.action.count.CountResponse; -import org.elasticsearch.action.get.GetRequestBuilder; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetItemResponse; -import org.elasticsearch.action.get.MultiGetRequest; -import org.elasticsearch.action.get.MultiGetRequestBuilder; -import org.elasticsearch.action.get.MultiGetResponse; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchScrollRequestBuilder; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.index.query.BoolFilterBuilder; -import org.elasticsearch.index.query.FilterBuilder; -import org.elasticsearch.index.query.FilterBuilders; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.aggregations.Aggregation; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.Aggregations; -import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; -import org.elasticsearch.search.aggregations.bucket.terms.Terms; -import org.elasticsearch.search.aggregations.metrics.max.Max; -import org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount; -import org.elasticsearch.search.fetch.source.FetchSourceContext; -import org.joda.time.DateTime; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.db.Dto; -import org.sonar.server.exceptions.NotFoundException; - -/** - * @deprecated replaced by {@link org.sonar.server.es.BaseIndex} - */ -@Deprecated -public abstract class BaseIndex, KEY extends Serializable> - implements Index { - - private static final Logger LOG = Loggers.get(BaseIndex.class); - - public static final int SCROLL_TIME_IN_MINUTES = 3; - - private final SearchClient client; - private final BaseNormalizer normalizer; - private final IndexDefinition indexDefinition; - - protected BaseIndex(IndexDefinition indexDefinition, BaseNormalizer normalizer, SearchClient client) { - this.normalizer = normalizer; - this.client = client; - this.indexDefinition = indexDefinition; - } - - @Override - public BaseNormalizer getNormalizer() { - return normalizer; - } - - @Override - public final String getIndexName() { - return this.indexDefinition.getIndexName(); - } - - @Override - public final String getIndexType() { - return this.indexDefinition.getIndexType(); - } - - /* Component Methods */ - - @Override - public void start() { - /* Setup the index if necessary */ - initializeIndex(); - } - - @Override - public void stop() { - // nothing to do - } - - public SearchClient getClient() { - return client; - } - - // Scrolling within the index - @Override - public Iterator scroll(final String scrollId) { - return new Iterator() { - - private final Queue hits = new ArrayDeque<>(); - - @Override - public boolean hasNext() { - if (hits.isEmpty()) { - SearchScrollRequestBuilder esRequest = client.prepareSearchScroll(scrollId) - .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)); - Collections.addAll(hits, esRequest.get().getHits().getHits()); - } - return !hits.isEmpty(); - } - - @Override - public DOMAIN next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - return toDoc(hits.poll().getSource()); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Cannot remove item from scroll"); - } - }; - } - - /* Cluster And ES Stats/Client methods */ - - protected void initializeIndex() { - String index = this.getIndexName(); - - IndicesExistsResponse indexExistsResponse = client.prepareIndicesExist(index).get(); - try { - - if (!indexExistsResponse.isExists()) { - LOG.debug("Setup of {} for type {}", this.getIndexName(), this.getIndexType()); - client.prepareCreate(index) - .setSettings(getIndexSettings()) - .get(); - } - - LOG.debug("Update of index {} for type {}", this.getIndexName(), this.getIndexType()); - client.preparePutMapping(index) - .setType(getIndexType()) - .setIgnoreConflicts(true) - .setSource(mapDomain()) - .get(); - - } catch (Exception e) { - throw new IllegalStateException("Invalid configuration for index " + this.getIndexName(), e); - } - } - - @Override - public IndexStat getIndexStat() { - CountRequestBuilder countRequest = client.prepareCount(this.getIndexName()) - .setTypes(this.getIndexType()) - .setQuery(QueryBuilders.matchAllQuery()); - CountResponse response = countRequest.get(); - return new IndexStat(getLastSynchronization(), response.getCount()); - } - - /* Synchronization methods */ - - @Override - @CheckForNull - public Date getLastSynchronization() { - return getLastSynchronization(Collections.emptyMap()); - } - - @Override - @CheckForNull - public Date getLastSynchronization(Map params) { - SearchRequestBuilder request = client.prepareSearch(this.getIndexName()) - .setTypes(this.getIndexType()) - .setQuery(QueryBuilders.filteredQuery( - QueryBuilders.matchAllQuery(), - getLastSynchronizationBuilder(params) - )) - .setSize(0) - .addAggregation(AggregationBuilders.max("latest") - .field(BaseNormalizer.UPDATED_AT_FIELD)); - - SearchResponse response = request.get(); - - Max max = response.getAggregations().get("latest"); - if (max.getValue() > 0) { - Date date = new DateTime((long) max.getValue()).toDate(); - LOG.debug("Index {}:{} has last update of {}", this.getIndexName(), this.getIndexType(), date); - return date; - } else { - LOG.debug("Index {}:{} has no last update date", this.getIndexName(), this.getIndexType()); - return null; - } - } - - protected FilterBuilder getLastSynchronizationBuilder(Map params) { - return FilterBuilders.matchAllFilter(); - } - - /* Index management methods */ - - protected abstract String getKeyValue(KEY key); - - public final Settings getIndexSettings() { - ImmutableSettings.Builder settings = this.getBaseIndexSettings(); - - // In case there is a replication factor set by the index, - // it is removed since we're using global cluster state - // see https://jira.sonarsource.com/browse/SONAR-5687 - settings.remove("index.number_of_replicas"); - - return settings.build(); - } - - protected abstract Map mapProperties(); - - protected abstract Map mapKey(); - - protected Map mapDomain() { - Map mapping = new HashMap<>(); - mapping.put("dynamic", false); - mapping.put("_all", ImmutableMap.of("enabled", false)); - if (mapKey() != null) { - mapping.put("_id", mapKey()); - } - mapping.put("properties", mapProperties()); - LOG.debug("Index Mapping {}", mapping.get("properties")); - return mapping; - } - - protected Map mapField(IndexField field) { - return mapField(field, true); - } - - protected Map mapField(IndexField field, boolean allowRecursive) { - if (field.type() == IndexField.Type.TEXT) { - return mapTextField(field, allowRecursive); - } else if (field.type() == IndexField.Type.STRING) { - return mapStringField(field, allowRecursive); - } else if (field.type() == IndexField.Type.BOOLEAN) { - return mapBooleanField(); - } else if (field.type() == IndexField.Type.OBJECT) { - return mapNestedField(field); - } else if (field.type() == IndexField.Type.DATE) { - return mapDateField(); - } else if (field.type() == IndexField.Type.DOUBLE) { - return mapDoubleField(); - } else { - throw new IllegalStateException("Mapping does not exist for type: " + field.type()); - } - } - - protected Map mapDoubleField() { - return ImmutableMap.of("type", "double"); - } - - protected Map mapBooleanField() { - return ImmutableMap.of("type", "boolean"); - } - - protected Map mapNestedField(IndexField field) { - Map mapping = new HashMap<>(); - mapping.put("type", "nested"); - mapping.put("dynamic", "true"); - Map mappings = new HashMap<>(); - for (IndexField nestedField : field.nestedFields()) { - if (nestedField != null) { - mappings.put(nestedField.field(), mapField(nestedField)); - } - } - mapping.put("properties", mappings); - return mapping; - } - - protected Map mapDateField() { - return ImmutableMap.of( - "type", "date", - "format", "date_time"); - } - - protected boolean needMultiField(IndexField field) { - return (field.type() == IndexField.Type.TEXT - || field.type() == IndexField.Type.STRING) - && (field.isSortable() || field.isSearchable()); - } - - protected Map mapGramsField() { - return ImmutableMap.of( - "type", "string", - "index", "analyzed", - "index_analyzer", "index_grams", - "search_analyzer", "search_grams"); - } - - protected Map mapWordsField() { - return ImmutableMap.of( - "type", "string", - "index", "analyzed", - "index_analyzer", "index_words", - "search_analyzer", "search_words"); - } - - protected Map mapMultiField(IndexField field) { - Map mapping = new HashMap<>(); - if (field.isSortable()) { - mapping.put(IndexField.SORT_SUFFIX, ImmutableMap.of( - "type", "string", - "index", "analyzed", - "analyzer", "sortable")); - } - if (field.isSearchable()) { - if (field.type() != IndexField.Type.TEXT) { - mapping.put(IndexField.SEARCH_PARTIAL_SUFFIX, mapGramsField()); - } - mapping.put(IndexField.SEARCH_WORDS_SUFFIX, mapWordsField()); - } - mapping.put(field.field(), mapField(field, false)); - return mapping; - } - - protected Map mapStringField(IndexField field, boolean allowRecursive) { - Map mapping = new HashMap<>(); - // check if the field needs to be MultiField - if (allowRecursive && needMultiField(field)) { - mapping.put("type", "multi_field"); - mapping.put("fields", mapMultiField(field)); - } else { - mapping.put("type", "string"); - mapping.put("index", "analyzed"); - mapping.put("index_analyzer", "keyword"); - mapping.put("search_analyzer", "whitespace"); - } - return mapping; - } - - protected Map mapTextField(IndexField field, boolean allowRecursive) { - Map mapping = new HashMap<>(); - // check if the field needs to be MultiField - if (allowRecursive && needMultiField(field)) { - mapping.put("type", "multi_field"); - mapping.put("fields", mapMultiField(field)); - } else { - mapping.put("type", "string"); - mapping.put("index", "analyzed"); - mapping.put("index_analyzer", "keyword"); - mapping.put("search_analyzer", "whitespace"); - } - return mapping; - } - - /* Base CRUD methods */ - - protected abstract DOMAIN toDoc(Map fields); - - public DOMAIN getByKey(KEY key) { - DOMAIN value = getNullableByKey(key); - if (value == null) { - throw new NotFoundException(String.format("Key '%s' not found", key)); - } - return value; - } - - @CheckForNull - @Override - public DOMAIN getNullableByKey(KEY key) { - GetRequestBuilder request = client.prepareGet() - .setType(this.getIndexType()) - .setIndex(this.getIndexName()) - .setId(this.getKeyValue(key)) - .setFetchSource(true) - .setRouting(this.getKeyValue(key)); - - GetResponse response = request.get(); - - if (response.isExists()) { - return toDoc(response.getSource()); - } - return null; - } - - public List getByKeys(Collection keys) { - if (keys.isEmpty()) { - return Collections.emptyList(); - } - List results = new ArrayList<>(); - MultiGetRequestBuilder request = client.prepareMultiGet() - .setPreference("_local"); - for (KEY key : keys) { - request.add(new MultiGetRequest - .Item(getIndexName(), getIndexType(), getKeyValue(key)) - .routing(getKeyValue(key)) - .fetchSourceContext(FetchSourceContext.FETCH_SOURCE)); - } - - MultiGetResponse response = request.get(); - if (response.getResponses() != null) { - for (MultiGetItemResponse item : response.getResponses()) { - Map source = item.getResponse().getSource(); - if (source != null) { - results.add(toDoc(source)); - } - } - } - return results; - } - - public Collection getByKeys(KEY... keys) { - return getByKeys(ImmutableSet.copyOf(keys)); - } - - /* ES QueryHelper Methods */ - - protected BoolFilterBuilder addTermFilter(BoolFilterBuilder filter, String field, @Nullable Collection values) { - if (values != null && !values.isEmpty()) { - BoolFilterBuilder valuesFilter = FilterBuilders.boolFilter(); - for (String value : values) { - FilterBuilder valueFilter = FilterBuilders.termFilter(field, value); - valuesFilter.should(valueFilter); - } - filter.must(valuesFilter); - } - return filter; - } - - protected BoolFilterBuilder addTermFilter(BoolFilterBuilder filter, String field, @Nullable String value) { - if (value != null && !value.isEmpty()) { - filter.must(FilterBuilders.termFilter(field, value)); - } - return filter; - } - - public Long countAll() { - return client.prepareCount(this.getIndexName()) - .setTypes(this.getIndexType()) - .get().getCount(); - } - - public Map countByField(IndexField indexField, FilterBuilder filter) { - Map counts = new HashMap<>(); - - SearchRequestBuilder request = client.prepareSearch(this.getIndexName()) - .setTypes(this.getIndexType()) - .setQuery(QueryBuilders.filteredQuery( - QueryBuilders.matchAllQuery(), - filter)) - .setSize(0) - .addAggregation(AggregationBuilders - .terms(indexField.field()) - .field(indexField.field()) - .order(Terms.Order.count(false)) - .size(Integer.MAX_VALUE) - .minDocCount(0)); - - SearchResponse response = request.get(); - - Terms values = - response.getAggregations().get(indexField.field()); - - for (Terms.Bucket value : values.getBuckets()) { - counts.put(value.getKey(), value.getDocCount()); - } - return counts; - } - - public Map countByField(IndexField indexField) { - return countByField(indexField, FilterBuilders.matchAllFilter()); - } - - // Response helpers - protected Multimap processAggregations(Aggregations aggregations) { - Multimap stats = ArrayListMultimap.create(); - if (aggregations != null) { - for (Aggregation aggregation : aggregations.asList()) { - if (aggregation instanceof StringTerms) { - for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) { - FacetValue facetValue = new FacetValue(value.getKey(), value.getDocCount()); - stats.put(aggregation.getName(), facetValue); - } - } else if (aggregation instanceof InternalValueCount) { - InternalValueCount count = (InternalValueCount) aggregation; - FacetValue facetValue = new FacetValue(count.getName(), count.getValue()); - stats.put(count.getName(), facetValue); - } - } - } - return stats; - } - - private ImmutableSettings.Builder getBaseIndexSettings() { - return ImmutableSettings.builder() - - .put("index.number_of_replicas", 0) - .put("index.number_of_shards", 1) - - // Disallow dynamic mapping (too expensive) - .put("index.mapper.dynamic", false) - - // Sortable text analyzer - .put("index.analysis.analyzer.sortable.type", "custom") - .put("index.analysis.analyzer.sortable.tokenizer", "keyword") - .putArray("index.analysis.analyzer.sortable.filter", "trim", "lowercase") - - // Edge NGram index-analyzer - .put("index.analysis.analyzer.index_grams.type", "custom") - .put("index.analysis.analyzer.index_grams.tokenizer", "whitespace") - .putArray("index.analysis.analyzer.index_grams.filter", "trim", "lowercase", "gram_filter") - - // Edge NGram search-analyzer - .put("index.analysis.analyzer.search_grams.type", "custom") - .put("index.analysis.analyzer.search_grams.tokenizer", "whitespace") - .putArray("index.analysis.analyzer.search_grams.filter", "trim", "lowercase") - - // Word index-analyzer - .put("index.analysis.analyzer.index_words.type", "custom") - .put("index.analysis.analyzer.index_words.tokenizer", "standard") - .putArray("index.analysis.analyzer.index_words.filter", - "standard", "word_filter", "lowercase", "stop", "asciifolding", "porter_stem") - - // Word search-analyzer - .put("index.analysis.analyzer.search_words.type", "custom") - .put("index.analysis.analyzer.search_words.tokenizer", "standard") - .putArray("index.analysis.analyzer.search_words.filter", - "standard", "lowercase", "stop", "asciifolding", "porter_stem") - - // Edge NGram filter - .put("index.analysis.filter.gram_filter.type", "edgeNGram") - .put("index.analysis.filter.gram_filter.min_gram", 2) - .put("index.analysis.filter.gram_filter.max_gram", 15) - .putArray("index.analysis.filter.gram_filter.token_chars", "letter", "digit", "punctuation", "symbol") - - // Word filter - .put("index.analysis.filter.word_filter.type", "word_delimiter") - .put("index.analysis.filter.word_filter.generate_word_parts", true) - .put("index.analysis.filter.word_filter.catenate_words", true) - .put("index.analysis.filter.word_filter.catenate_numbers", true) - .put("index.analysis.filter.word_filter.catenate_all", true) - .put("index.analysis.filter.word_filter.split_on_case_change", true) - .put("index.analysis.filter.word_filter.preserve_original", true) - .put("index.analysis.filter.word_filter.split_on_numerics", true) - .put("index.analysis.filter.word_filter.stem_english_possessive", true) - - // Path Analyzer - .put("index.analysis.analyzer.path_analyzer.type", "custom") - .put("index.analysis.analyzer.path_analyzer.tokenizer", "path_hierarchy") - - // UUID Module analyzer - .put("index.analysis.tokenizer.dot_tokenizer.type", "pattern") - .put("index.analysis.tokenizer.dot_tokenizer.pattern", "\\.") - .put("index.analysis.analyzer.uuid_analyzer.type", "custom") - .putArray("index.analysis.analyzer.uuid_analyzer.filter", "trim", "lowercase") - .put("index.analysis.analyzer.uuid_analyzer.tokenizer", "dot_tokenizer"); - - } - - protected StickyFacetBuilder stickyFacetBuilder(QueryBuilder query, Map filters) { - return new StickyFacetBuilder(query, filters); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/BaseNormalizer.java b/server/sonar-server/src/main/java/org/sonar/server/search/BaseNormalizer.java deleted file mode 100644 index 55f03c2cb68..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/BaseNormalizer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.elasticsearch.action.update.UpdateRequest; -import org.sonar.db.DbClient; -import org.sonar.db.Dto; - -public abstract class BaseNormalizer, KEY extends Serializable> { - - public static final String UPDATED_AT_FIELD = "updatedAt"; - - protected final DbClient db; - - protected BaseNormalizer(DbClient db) { - this.db = db; - } - - protected Map getUpsertFor(Set fields, Map update) { - Map upsert = new HashMap<>(update); - for (IndexField field : fields) { - if (!upsert.containsKey(field.field())) { - if (field.type().equals(IndexField.Type.OBJECT)) { - upsert.put(field.field(), new ArrayList()); - } else { - upsert.put(field.field(), null); - } - } - } - return upsert; - } - - public List deleteNested(Object object, KEY key) { - throw new IllegalStateException("Nested Delete not implemented in current normalizer!"); - } - - public List normalizeNested(Object object, KEY key) { - throw new IllegalStateException("Nested Normalize not implemented in current normalizer!"); - } - - public abstract List normalize(DTO dto); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/DbSynchronizationHandler.java b/server/sonar-server/src/main/java/org/sonar/server/search/DbSynchronizationHandler.java deleted file mode 100644 index 2d98b274fec..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/DbSynchronizationHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search; - -import org.apache.ibatis.session.ResultContext; -import org.apache.ibatis.session.ResultHandler; -import org.sonar.db.DbSession; - -import javax.annotation.CheckForNull; - -import java.util.Map; - -public abstract class DbSynchronizationHandler implements ResultHandler { - - private final DbSession session; - private final Map params; - - protected DbSynchronizationHandler(DbSession session, Map params) { - this.session = session; - this.params = params; - } - - @Override - public abstract void handleResult(ResultContext context); - - @CheckForNull - public abstract void enqueueCollected(); - - public final DbSession getSession() { - return session; - } - - public final Map getParams() { - return params; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/Index.java b/server/sonar-server/src/main/java/org/sonar/server/search/Index.java deleted file mode 100644 index 249947fb8d2..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/Index.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search; - -import org.picocontainer.Startable; -import org.sonar.api.server.ServerSide; -import org.sonar.db.Dto; - -import javax.annotation.CheckForNull; - -import java.io.Serializable; -import java.util.Date; -import java.util.Iterator; -import java.util.Map; - -@ServerSide -public interface Index, KEY extends Serializable> extends Startable { - - @CheckForNull - DOMAIN getNullableByKey(KEY key); - - String getIndexType(); - - String getIndexName(); - - @CheckForNull - Date getLastSynchronization(); - - @CheckForNull - Date getLastSynchronization(Map params); - - IndexStat getIndexStat(); - - Iterator scroll(String scrollId); - - BaseNormalizer getNormalizer(); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/IndexClient.java b/server/sonar-server/src/main/java/org/sonar/server/search/IndexClient.java deleted file mode 100644 index 469043c09b3..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/IndexClient.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search; - -import org.sonar.api.server.ServerSide; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -/** - * Facade for all Elasticsearch indices - */ -@ServerSide -public class IndexClient { - - private final Map, Index> indexComponents; - - public IndexClient(Index... indexComponents) { - - this.indexComponents = new HashMap<>(); - - for (Index indexComponent : indexComponents) { - this.indexComponents.put(indexComponent.getClass(), indexComponent); - } - } - - public K get(Class clazz) { - return (K) this.indexComponents.get(clazz); - } - - public Collection> allIndices() { - return indexComponents.values(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java b/server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java deleted file mode 100644 index 7bf849b693b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search; - -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder; -import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; -import org.elasticsearch.action.bulk.BulkRequestBuilder; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.action.delete.DeleteRequest; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.update.UpdateRequest; -import org.sonar.api.server.ServerSide; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.db.deprecated.WorkQueue; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.server.search.action.IndexAction; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -@ServerSide -public class IndexQueue implements WorkQueue> { - - private final SearchClient searchClient; - private final ComponentContainer container; - - private static final Logger LOGGER = Loggers.get(IndexQueue.class); - - private static final Integer CONCURRENT_NORMALIZATION_FACTOR = 1; - - public IndexQueue(SearchClient searchClient, ComponentContainer container) { - this.searchClient = searchClient; - this.container = container; - } - - @Override - public void enqueue(List> actions) { - if (actions.isEmpty()) { - return; - } - boolean refreshRequired = false; - - Map indexes = getIndexMap(); - Set indices = new HashSet<>(); - for (IndexAction action : actions) { - Index index = indexes.get(action.getIndexType()); - action.setIndex(index); - if (action.needsRefresh()) { - refreshRequired = true; - indices.add(index.getIndexName()); - } - } - - BulkRequestBuilder bulkRequestBuilder = searchClient.prepareBulk(); - - processActionsIntoQueries(bulkRequestBuilder, actions); - - if (bulkRequestBuilder.numberOfActions() > 0) { - // execute the request - BulkResponse response = bulkRequestBuilder.setRefresh(false).get(); - - if (refreshRequired) { - this.refreshRequiredIndex(indices); - } - - if (response.hasFailures()) { - throw new IllegalStateException("Errors while indexing stack: " + response.buildFailureMessage()); - } - } - } - - private void refreshRequiredIndex(Set indices) { - if (!indices.isEmpty()) { - RefreshRequestBuilder refreshRequest = searchClient.prepareRefresh(indices.toArray(new String[indices.size()])) - .setForce(false); - - RefreshResponse refreshResponse = refreshRequest.get(); - - if (refreshResponse.getFailedShards() > 0) { - LOGGER.warn("{} Shard(s) did not refresh", refreshResponse.getFailedShards()); - } - } - } - - private void processActionsIntoQueries(BulkRequestBuilder bulkRequestBuilder, List> actions) { - try { - boolean hasInlineRefreshRequest = false; - ExecutorService executorService = Executors.newFixedThreadPool(CONCURRENT_NORMALIZATION_FACTOR); - // invokeAll() blocks until ALL tasks submitted to executor complete - List>> requests = (List) executorService.invokeAll(actions, 20, TimeUnit.MINUTES); - for (Future> updates : requests) { - for (ActionRequest update : updates.get()) { - - if (IndexRequest.class.isAssignableFrom(update.getClass())) { - bulkRequestBuilder.add((IndexRequest) update); - } else if (UpdateRequest.class.isAssignableFrom(update.getClass())) { - bulkRequestBuilder.add((UpdateRequest) update); - } else if (DeleteRequest.class.isAssignableFrom(update.getClass())) { - bulkRequestBuilder.add((DeleteRequest) update); - } else if (RefreshRequest.class.isAssignableFrom(update.getClass())) { - hasInlineRefreshRequest = true; - } else { - throw new IllegalStateException("Un-managed request type: " + update.getClass()); - } - } - } - executorService.shutdown(); - bulkRequestBuilder.setRefresh(hasInlineRefreshRequest); - } catch (Exception e) { - LOGGER.error("Could not execute normalization for stack", e); - throw new IllegalStateException("Could not execute normalization for stack", e); - } - } - - private Map getIndexMap() { - Map indexes = new HashMap<>(); - for (Index index : container.getComponentsByType(Index.class)) { - indexes.put(index.getIndexType(), index); - } - return indexes; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/IndexStat.java b/server/sonar-server/src/main/java/org/sonar/server/search/IndexStat.java deleted file mode 100644 index 0ebff21d8d7..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/IndexStat.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import java.util.Date; - -public class IndexStat { - - private final Date lastUpdate; - private final long documentCount; - - public IndexStat(@Nullable Date lastUpdate, long documentCount) { - this.lastUpdate = lastUpdate; - this.documentCount = documentCount; - } - - @CheckForNull - public Date getLastUpdate() { - return lastUpdate; - } - - public long getDocumentCount() { - return documentCount; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/QueryContext.java b/server/sonar-server/src/main/java/org/sonar/server/search/QueryContext.java index b1bdc38cb39..6dada64ab4b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/QueryContext.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/QueryContext.java @@ -39,7 +39,6 @@ public class QueryContext { public static final int DEFAULT_OFFSET = 0; public static final int DEFAULT_LIMIT = 10; public static final int MAX_LIMIT = 500; - public static final boolean DEFAULT_FACET = false; private int offset = DEFAULT_OFFSET; private int limit = DEFAULT_LIMIT; @@ -56,7 +55,7 @@ public class QueryContext { } /** - * Whether or not the search returns facets for the domain. Defaults to {@link #DEFAULT_FACET} + * Whether or not the search returns facets for the domain. */ public boolean isFacet() { return !facets.isEmpty(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/Result.java b/server/sonar-server/src/main/java/org/sonar/server/search/Result.java index 408eacaef99..4e1ccb72ce7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/Result.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/Result.java @@ -19,46 +19,24 @@ */ package org.sonar.server.search; -import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.Map; import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.search.SearchHit; public class Result { private final List hits; private final Facets facets; private final long total; - private final String scrollId; - private final BaseIndex index; public Result(SearchResponse response) { - this(null, response); - } - - public Result(@Nullable BaseIndex index, SearchResponse response) { - this.index = index; - this.scrollId = response.getScrollId(); this.facets = new Facets(response); this.total = (int) response.getHits().totalHits(); this.hits = new ArrayList<>(); - if (index != null) { - for (SearchHit hit : response.getHits()) { - this.hits.add(index.toDoc(hit.getSource())); - } - } - } - - public Iterator scroll() { - Preconditions.checkState(scrollId != null, "Result is not scrollable. Please use QueryOptions.setScroll()"); - return index.scroll(scrollId); } public List getHits() { diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteKey.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteKey.java deleted file mode 100644 index 64f75c0438b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteKey.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.action; - -import org.elasticsearch.action.delete.DeleteRequest; -import org.elasticsearch.client.Requests; -import org.sonar.server.search.Index; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -public class DeleteKey extends IndexAction { - - private final K key; - - public DeleteKey(String indexType, K key) { - super(indexType); - this.key = key; - } - - @Override - public String getKey() { - return key.toString(); - } - - @Override - public List doCall(Index index) { - List requests = new ArrayList<>(); - requests.add(Requests.deleteRequest(index.getIndexName()) - .id(getKey()) - .type(indexType) - .refresh(needsRefresh())); - return requests; - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteNestedItem.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteNestedItem.java deleted file mode 100644 index 3f955a31801..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteNestedItem.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.action; - -import org.elasticsearch.action.update.UpdateRequest; -import org.sonar.server.search.Index; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -public class DeleteNestedItem extends IndexAction { - - private final K key; - private final Object item; - private final Object[] items; - - public DeleteNestedItem(String indexType, K key, Object item, Object... items) { - super(indexType); - this.key = key; - this.item = item; - this.items = items; - } - - @Override - public String getKey() { - return this.key.toString(); - } - - @Override - public List doCall(Index index) { - List updates = new ArrayList<>(); - updates.addAll(deleteItem(index, item, key)); - for (Object otherItem : items) { - updates.addAll(deleteItem(index, otherItem, key)); - } - return updates; - } - - private List deleteItem(Index index, Object item, K key) { - List updates = index.getNormalizer().deleteNested(item, key); - for (UpdateRequest update : updates) { - update.index(index.getIndexName()) - .type(index.getIndexType()) - .refresh(needsRefresh()); - } - return updates; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java deleted file mode 100644 index 6ae9ab1e16f..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.action; - -import org.elasticsearch.action.ActionRequest; -import org.sonar.db.deprecated.ClusterAction; -import org.sonar.server.search.Index; - -import java.util.List; - -public abstract class IndexAction implements ClusterAction> { - - public static final String MISSING_INDEX_EXCEPTION = "Cannot execute request on null index"; - - protected final String indexType; - private final boolean requiresRefresh; - private Index index; - - protected IndexAction(String indexType) { - this(indexType, true); - } - - protected IndexAction(String indexType, boolean requiresRefresh) { - this.indexType = indexType; - this.requiresRefresh = requiresRefresh; - } - - public abstract String getKey(); - - public String getIndexType() { - return indexType; - } - - public IndexAction setIndex(Index index) { - this.index = index; - return this; - } - - @Override - public final List call() throws IllegalStateException { - if (index == null) { - throw new IllegalStateException(MISSING_INDEX_EXCEPTION); - } - return doCall(index); - } - - public abstract List doCall(Index index); - - public boolean needsRefresh() { - return this.requiresRefresh; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java deleted file mode 100644 index 9c3cf2c65b6..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.action; - -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.update.UpdateRequest; -import org.sonar.db.Dto; -import org.sonar.server.search.Index; - -import java.util.ArrayList; -import java.util.List; - -public class InsertDto extends IndexAction { - - private final DTO dto; - - public InsertDto(String indexType, DTO dto, boolean requiresRefresh) { - super(indexType, requiresRefresh); - this.dto = dto; - } - - @Override - public String getKey() { - return dto.getKey().toString(); - } - - @Override - public List doCall(Index index) { - List inserts = new ArrayList<>(); - List updates = index.getNormalizer().normalize(dto); - for (UpdateRequest update : updates) { - if (update.doc() != null) { - inserts.add(update.upsertRequest() - .index(index.getIndexName()) - .type(index.getIndexType()) - .id(update.id()) - .routing(update.routing())); - } else { - inserts.add(update - .index(index.getIndexName()) - .type(index.getIndexType())); - } - } - return inserts; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshIndex.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshIndex.java deleted file mode 100644 index 069a2e65c08..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshIndex.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.action; - -import com.google.common.collect.ImmutableList; -import java.util.List; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; -import org.sonar.server.search.Index; - -public class RefreshIndex extends IndexAction { - - public RefreshIndex(String indexType) { - super(indexType); - } - - @Override - public String getKey() { - throw new IllegalStateException("Refresh Action has no key"); - } - - @Override - public List doCall(Index index) { - return ImmutableList.of( - new RefreshRequest() - .indices(index.getIndexName())); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertDto.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertDto.java deleted file mode 100644 index e00e7853b59..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertDto.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.action; - -import org.elasticsearch.action.update.UpdateRequest; -import org.sonar.db.Dto; -import org.sonar.server.search.Index; - -import java.util.List; - -public class UpsertDto extends IndexAction { - - private final DTO dto; - - public UpsertDto(String indexType, DTO dto) { - this(indexType, dto, true); - } - - public UpsertDto(String indexType, DTO dto, boolean requiresRefresh) { - super(indexType, requiresRefresh); - this.dto = dto; - } - - @Override - public String getKey() { - return dto.getKey().toString(); - } - - @Override - public List doCall(Index index) { - List updates = index.getNormalizer().normalize(dto); - for (UpdateRequest update : updates) { - update.index(index.getIndexName()) - .type(index.getIndexType()) - .refresh(needsRefresh()); - } - return updates; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertNestedItem.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertNestedItem.java deleted file mode 100644 index 16199418354..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertNestedItem.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.action; - -import org.elasticsearch.action.update.UpdateRequest; -import org.sonar.server.search.Index; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -public class UpsertNestedItem extends IndexAction { - - private final K key; - private final Object item; - private final Object[] items; - - public UpsertNestedItem(String indexType, K key, Object item, Object... items) { - super(indexType); - this.key = key; - this.item = item; - this.items = items; - } - - @Override - public String getKey() { - return key.toString(); - } - - @Override - public List doCall(Index index) { - List updates = new ArrayList<>(); - updates.addAll(normalizeItem(index, item, key)); - for (Object otherItem : items) { - updates.addAll(normalizeItem(index, otherItem, key)); - } - return updates; - } - - private List normalizeItem(Index index, Object item, K key) { - List updates = index.getNormalizer().normalizeNested(item, key); - for (UpdateRequest update : updates) { - update.index(index.getIndexName()) - .type(index.getIndexType()) - .refresh(needsRefresh()); - } - return updates; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/package-info.java deleted file mode 100644 index 15de66f3736..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.search.action; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java index 0fee457bb37..f2f21566f44 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java @@ -44,7 +44,7 @@ public class ComponentFinderTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); ComponentDbTester componentDb = new ComponentDbTester(db); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); ComponentFinder underTest = new ComponentFinder(db.getDbClient()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/BaseDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/BaseDaoTest.java deleted file mode 100644 index afe02c09c0f..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/db/BaseDaoTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db; - -import java.util.Date; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.sonar.api.utils.System2; -import org.sonar.core.util.Uuids; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; -import org.sonar.db.MyBatis; -import org.sonar.server.db.fake.FakeDao; -import org.sonar.server.db.fake.FakeDto; -import org.sonar.server.db.fake.FakeMapper; -import org.sonar.test.DbTests; - -import static org.assertj.core.api.Assertions.assertThat; - -@Category(DbTests.class) -public class BaseDaoTest { - - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, BaseDaoTest.class, "schema.sql"); - - private static final String DTO_ALIAS = "fake"; - - private FakeDao dao; - private DbSession session; - - @Before - public void setupBatis() { - MyBatis batis = db.myBatis(); - batis.getSessionFactory().getConfiguration().getTypeAliasRegistry().registerAlias(DTO_ALIAS, FakeDto.class); - batis.getSessionFactory().getConfiguration().addMapper(FakeMapper.class); - } - - @Before - public void before() { - this.session = db.myBatis().openSession(false); - this.dao = new FakeDao(System2.INSTANCE); - } - - @After - public void after() { - this.session.close(); - db.executeUpdateSql("TRUNCATE TABLE fake"); - } - - @Test - public void has_fake_mapper() { - FakeMapper mapper = db.myBatis().getSessionFactory() - .getConfiguration().getMapper(FakeMapper.class, session); - assertThat(mapper).isNotNull(); - } - - @Test - public void can_insert_and_select_by_key() { - long t0 = System.currentTimeMillis() - 1000; - - String key = Uuids.create(); - FakeDto myDto = new FakeDto() - .setKey(key); - dao.insert(session, myDto); - - session.commit(); - assertThat(myDto.getId()).isGreaterThan(0); - - long t1 = System.currentTimeMillis() + 1000; - - FakeDto dto = dao.getByKey(session, key); - assertThat(dto).isNotNull(); - - assertThat(dto.getUpdatedAt().getTime()).isGreaterThan(t0); - assertThat(dto.getCreatedAt().getTime()).isLessThan(t1); - } - - @Test - public void does_enqueue_on_insert() { - FakeDto myDto = new FakeDto() - .setKey(Uuids.create()); - dao.insert(session, myDto); - session.commit(); - assertThat(session.getActionCount()).isEqualTo(1); - } - - @Test - public void synchronize_to_es_after_date() { - long t0 = System.currentTimeMillis() - 1000; - - String key = Uuids.create(); - FakeDto myDto = new FakeDto() - .setKey(key); - dao.insert(session, myDto); - - session.commit(); - assertThat(session.getActionCount()).isEqualTo(1); - - dao.synchronizeAfter(session, new Date(t0)); - // Synchronize adds an implicit action to the queue before finishing. - assertThat(session.getActionCount()).isEqualTo(3); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeDao.java b/server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeDao.java deleted file mode 100644 index 836e2dc4b51..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeDao.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.fake; - -import org.sonar.api.utils.System2; -import org.sonar.db.DbSession; -import org.sonar.server.db.BaseDao; -import org.sonar.server.search.IndexDefinition; - -public class FakeDao extends BaseDao { - - public FakeDao(System2 system2) { - super(IndexDefinition.createFor("test", "fake"), FakeMapper.class, system2); - } - - @Override - protected FakeDto doInsert(DbSession session, FakeDto item) { - mapper(session).insert(item); - return item; - } - - @Override - protected FakeDto doGetNullableByKey(DbSession session, String key) { - return mapper(session).selectByKey(key); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeDto.java b/server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeDto.java deleted file mode 100644 index fdc12294100..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeDto.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.fake; - -import org.sonar.db.Dto; - -public class FakeDto extends Dto { - - private long id; - private String key; - - @Override - public String getKey() { - return key; - } - - public long getId() { - return id; - } - - public FakeDto setId(long id) { - this.id = id; - return this; - } - - public FakeDto setKey(String key) { - this.key = key; - return this; - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeMapper.java b/server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeMapper.java deleted file mode 100644 index bce954cb9f8..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/db/fake/FakeMapper.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.fake; - -import org.apache.ibatis.annotations.Param; - -import javax.annotation.Nullable; - -import java.sql.Timestamp; -import java.util.List; - -public interface FakeMapper { - - void insert(FakeDto dto); - - FakeDto selectByKey(@Param("key") String key); - - List selectAfterDate(@Nullable @Param("date") Timestamp date); -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java index d57d8be339a..73f08478e43 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java @@ -49,7 +49,7 @@ public class DuplicationsParserTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); ComponentDao componentDao = db.getDbClient().componentDao(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java index 7188ae8b0d0..2c2bb42992e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java @@ -48,7 +48,6 @@ import org.sonar.db.rule.RuleTesting; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionUpdater; -import org.sonar.server.search.IndexClient; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; @@ -63,7 +62,6 @@ public class IssueCommentServiceMediumTest { public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester); DbClient db; - IndexClient indexClient; DbSession session; IssueCommentService service; @@ -75,7 +73,6 @@ public class IssueCommentServiceMediumTest { public void setUp() { tester.clearDbAndIndexes(); db = tester.get(DbClient.class); - indexClient = tester.get(IndexClient.class); session = db.openSession(false); service = tester.get(IssueCommentService.class); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java index a6e23b7f262..6a1b8390c65 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java @@ -88,7 +88,7 @@ public class CreateActionTest { DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsTester ws; diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java index bf1cf7b0486..6cd5248f53e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java @@ -55,7 +55,7 @@ public class DeleteActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsTester ws; diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java index bd4ff5cb2ef..eff72fcae4d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java @@ -67,7 +67,7 @@ public class MetricsActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsTester ws; ComponentDto defaultProject; diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java index 79cf52fbf44..e29422b08ac 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java @@ -72,7 +72,7 @@ public class UpdateActionTest { @ClassRule public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings())); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); System2 system = mock(System2.class); WsTester ws; diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java index 3854eca6678..ce70587be12 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java @@ -75,7 +75,7 @@ public class ComponentActionTest { public DbTester db = DbTester.create(System2.INSTANCE); ComponentDbTester componentDb = new ComponentDbTester(db); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsActionTester ws = new WsActionTester(new ComponentAction(dbClient, new ComponentFinder(dbClient), userSession)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index 2f6af91b770..fddd838e358 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -91,7 +91,7 @@ public class ComponentTreeActionTest { public DbTester db = DbTester.create(System2.INSTANCE); ComponentDbTester componentDb = new ComponentDbTester(db); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsActionTester ws = new WsActionTester( new ComponentTreeAction( diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java index 98af5a29009..b7372d6a3c6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java @@ -65,7 +65,7 @@ public class CreateActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsTester ws; diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java index 7fe950ebc36..629206bff29 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java @@ -56,7 +56,7 @@ public class DeleteActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); MetricDao metricDao; WsTester ws; diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java index 22dcb3e62d1..59a4bc9a3ce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java @@ -43,7 +43,7 @@ public class SearchActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsTester ws; @Before diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java index f278e8d5876..705f66d8e97 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java @@ -65,7 +65,7 @@ public class UpdateActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsTester ws; diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java index e6db1e9699f..96686f92d8e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java @@ -71,7 +71,7 @@ public class RemoveGroupActionTest { ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV"); private PermissionUpdater permissionUpdater; private ArgumentCaptor permissionChangeCaptor = ArgumentCaptor.forClass(PermissionChange.class); - private DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); @Before public void setUp() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java index 6da5415d360..8d451aeae79 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java @@ -77,7 +77,7 @@ public class SearchProjectPermissionsActionTest { WsActionTester ws; I18nRule i18n = new I18nRule(); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); ResourceTypesRule resourceTypes = new ResourceTypesRule(); SearchProjectPermissionsDataLoader dataLoader; diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/TemplateUsersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/TemplateUsersActionTest.java index fffe754702b..b6b8ac62fc7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/TemplateUsersActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/TemplateUsersActionTest.java @@ -71,7 +71,7 @@ public class TemplateUsersActionTest { public DbTester db = DbTester.create(System2.INSTANCE); ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV"); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsActionTester ws; TemplateUsersAction underTest; diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java index 7e376e8f051..89e66222946 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java @@ -53,7 +53,6 @@ import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.issue.index.IssueAuthorizationIndexer; -import org.sonar.server.permission.PermissionFinder; import org.sonar.server.permission.PermissionService; import org.sonar.server.permission.ws.PermissionDependenciesFinder; import org.sonar.server.tester.UserSessionRule; @@ -107,7 +106,6 @@ public class ApplyTemplateActionTest { dbSession = db.getSession(); PermissionRepository repository = new PermissionRepository(dbClient, new Settings()); - PermissionFinder permissionFinder = new PermissionFinder(dbClient); ComponentFinder componentFinder = new ComponentFinder(dbClient); PermissionService permissionService = new PermissionService(dbClient, repository, issueAuthorizationIndexer, userSession, componentFinder); PermissionDependenciesFinder permissionDependenciesFinder = new PermissionDependenciesFinder(dbClient, componentFinder, new UserGroupFinder(dbClient), resourceTypes); diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java index 0bad77f9b99..3a2a52733d2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java @@ -72,7 +72,7 @@ public class SearchTemplatesActionTest { WsActionTester ws; I18nRule i18n = new I18nRule(); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); ResourceTypes resourceTypes = mock(ResourceTypes.class); SearchTemplatesDataLoader dataLoader; diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java index 394408c8fe6..f60fa055b0e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java @@ -86,7 +86,7 @@ public class BulkDeleteActionTest { WsTester ws; DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); ResourceType resourceType; @Before diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java index d36cae4fe8f..16b166639ce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java @@ -88,7 +88,7 @@ public class DeleteActionTest { DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); ResourceType resourceType; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java index 8a47805ad47..5d56c0ed40f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java @@ -65,7 +65,7 @@ public class ExportActionTest { DbClient dbClient = db.getDbClient(); - DbSession session = db.getSession(); + final DbSession session = db.getSession(); QualityProfileDao qualityProfileDao = dbClient.qualityProfileDao(); @@ -75,7 +75,6 @@ public class ExportActionTest { @Before public void before() { - session = dbClient.openSession(false); backuper = mock(QProfileBackuper.class); db.truncateTables(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java index d3488edd3b9..bd709310be9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java @@ -66,8 +66,8 @@ public class SearchActionTest { // TODO remove mock private QProfileLoader profileLoader = mock(QProfileLoader.class); - private DbClient dbClient = db.getDbClient(); - private DbSession dbSession = db.getSession(); + final DbClient dbClient = db.getDbClient(); + final DbSession dbSession = db.getSession(); private QualityProfileDao qualityProfileDao = dbClient.qualityProfileDao(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java deleted file mode 100644 index 5a50c6f5fc8..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search; - -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.config.Settings; -import org.sonar.process.ProcessProperties; -import org.sonar.server.es.EsServerHolder; - -import java.io.Serializable; -import java.util.Collections; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - -public class BaseIndexTest { - - @ClassRule - public static TemporaryFolder temp = new TemporaryFolder(); - - SearchClient searchClient; - - @Before - public void setup() { - EsServerHolder holder = EsServerHolder.get(); - Settings settings = new Settings(); - settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, false); - settings.setProperty(ProcessProperties.CLUSTER_NAME, holder.getClusterName()); - settings.setProperty(ProcessProperties.CLUSTER_NODE_NAME, holder.getNodeName()); - settings.setProperty(ProcessProperties.SEARCH_PORT, String.valueOf(holder.getPort())); - settings.setProperty(ProcessProperties.SEARCH_HOST, String.valueOf(holder.getHostName())); - searchClient = new SearchClient(settings); - searchClient.start(); - } - - @After - public void tearDown() { - if (searchClient != null) { - searchClient.stop(); - } - } - - @Test - public void can_load() { - BaseIndex index = getIndex(searchClient); - assertThat(index).isNotNull(); - } - - @Test - public void creates_domain_index() { - BaseIndex index = getIndex(this.searchClient); - - IndicesExistsResponse indexExistsResponse = index.getClient().nativeClient().admin().indices() - .prepareExists(IndexDefinition.TEST.getIndexName()).execute().actionGet(); - - assertThat(indexExistsResponse.isExists()).isTrue(); - } - - @Test - public void settings_has_no_replication_factor() { - BaseIndex index = getIndex(this.searchClient); - - // base case, there are no replication factors. - assertThat(index.getIndexSettings().get("index.number_of_replicas")).isNull(); - - // replication factor removed from settings when set in index - BaseIndex newIndex = new BaseIndex( - IndexDefinition.TEST, - null, searchClient) { - - @Override - protected String getKeyValue(Serializable key) { - return null; - } - - @Override - protected Map mapProperties() { - return Collections.emptyMap(); - } - - @Override - protected Map mapKey() { - return Collections.emptyMap(); - } - - @Override - public Object toDoc(Map fields) { - return null; - } - }; - newIndex.start(); - - assertThat(index.getIndexSettings().get("index.number_of_replicas")).isNull(); - - } - - private BaseIndex getIndex(final SearchClient searchClient) { - BaseIndex index = new BaseIndex( - IndexDefinition.TEST, - null, searchClient) { - @Override - protected String getKeyValue(Serializable key) { - return null; - } - - @Override - protected Map mapProperties() { - return Collections.emptyMap(); - } - - @Override - protected Map mapKey() { - return Collections.emptyMap(); - } - - @Override - public Object toDoc(Map fields) { - return null; - } - }; - index.start(); - return index; - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/action/DeleteKeyTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/action/DeleteKeyTest.java deleted file mode 100644 index 8b391569da2..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/search/action/DeleteKeyTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.action; - -import org.elasticsearch.action.delete.DeleteRequest; -import org.junit.Before; -import org.junit.Test; -import org.sonar.server.search.Index; -import org.sonar.server.search.IndexDefinition; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class DeleteKeyTest { - - IndexDefinition TEST_INDEX = IndexDefinition.createFor("TEST", "TESTING"); - - Index index; - - @Before - public void setUp() { - index = mock(Index.class); - when(index.getIndexName()).thenReturn(TEST_INDEX.getIndexName()); - } - - @Test - public void get_delete_request() { - String key = "test_key"; - DeleteKey deleteAction = new DeleteKey<>(TEST_INDEX.getIndexType(), key); - - try { - deleteAction.call(); - fail(); - } catch (Exception e) { - assertThat(e.getMessage()).isEqualTo(IndexAction.MISSING_INDEX_EXCEPTION); - } - - // Insert Index for action - deleteAction.setIndex(index); - - List requests = deleteAction.call(); - assertThat(requests).hasSize(1); - - DeleteRequest request = requests.get(0); - assertThat(request.type()).isEqualTo(TEST_INDEX.getIndexType()); - assertThat(request.index()).isEqualTo(TEST_INDEX.getIndexName()); - assertThat(request.id()).isEqualTo(key); - assertThat(request.refresh()).isTrue(); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/action/RefreshIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/action/RefreshIndexTest.java deleted file mode 100644 index 205ecc94eea..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/search/action/RefreshIndexTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.action; - -import java.util.List; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; -import org.junit.Before; -import org.junit.Test; -import org.sonar.server.search.Index; -import org.sonar.server.search.IndexDefinition; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class RefreshIndexTest { - IndexDefinition TEST_INDEX = IndexDefinition.createFor("TEST", "TESTING"); - - Index index; - - @Before - public void setUp() { - index = mock(Index.class); - when(index.getIndexName()).thenReturn(TEST_INDEX.getIndexName()); - } - - @Test - public void get_delete_request() { - RefreshIndex refreshAction = new RefreshIndex(TEST_INDEX.getIndexType()); - - try { - refreshAction.call(); - fail(); - } catch (Exception e) { - assertThat(e.getMessage()).isEqualTo(IndexAction.MISSING_INDEX_EXCEPTION); - } - - try { - refreshAction.getKey(); - fail(); - } catch (Exception e) { - assertThat(e.getMessage()).isEqualTo("Refresh Action has no key"); - } - - // Insert Index for action - refreshAction.setIndex(index); - - List requests = refreshAction.call(); - assertThat(requests).hasSize(1); - - RefreshRequest request = requests.get(0); - assertThat(request.indices()).containsOnly(TEST_INDEX.getIndexName()); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java index 8800583aebf..aba79a5f0a6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java @@ -61,7 +61,7 @@ public class SearchActionTest { public DbTester db = DbTester.create(System2.INSTANCE); UserDbTester userDb = new UserDbTester(db); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsTester ws; UserIndex index; diff --git a/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/RevokeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/RevokeActionTest.java index 05744c22d32..a2c5d12d22a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/RevokeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/RevokeActionTest.java @@ -51,7 +51,7 @@ public class RevokeActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); @Rule public UserSessionRule userSession = UserSessionRule.standalone(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java index 82a9918e60b..0dadb0b5755 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java @@ -62,7 +62,7 @@ public class SearchActionTest { public DbTester db = DbTester.create(System2.INSTANCE); UserDbTester userDb = new UserDbTester(db); DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); WsActionTester ws = new WsActionTester(new SearchAction(dbClient, userSession)); diff --git a/sonar-db/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-db/src/main/java/org/sonar/core/persistence/MyBatis.java index 5d66a44b676..c72e0e5ec7e 100644 --- a/sonar-db/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-db/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -20,7 +20,6 @@ package org.sonar.core.persistence; import org.sonar.db.Database; -import org.sonar.db.deprecated.WorkQueue; /** * Kept for backward compatibility of plugins/libs (like sonar-license) that are directly calling classes from the core @@ -30,8 +29,8 @@ import org.sonar.db.deprecated.WorkQueue; @Deprecated public class MyBatis extends org.sonar.db.MyBatis { - public MyBatis(Database database, WorkQueue queue) { - super(database, queue); + public MyBatis(Database database) { + super(database); } } diff --git a/sonar-db/src/main/java/org/sonar/db/BatchSession.java b/sonar-db/src/main/java/org/sonar/db/BatchSession.java index 93cc0540b58..9e98d66e622 100644 --- a/sonar-db/src/main/java/org/sonar/db/BatchSession.java +++ b/sonar-db/src/main/java/org/sonar/db/BatchSession.java @@ -29,8 +29,6 @@ import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; -import org.sonar.db.deprecated.ClusterAction; -import org.sonar.db.deprecated.WorkQueue; public class BatchSession extends DbSession { @@ -39,21 +37,15 @@ public class BatchSession extends DbSession { private final int batchSize; private int count = 0; - public BatchSession(WorkQueue queue, SqlSession session) { - this(queue, session, MAX_BATCH_SIZE); + public BatchSession(SqlSession session) { + this(session, MAX_BATCH_SIZE); } - BatchSession(WorkQueue queue, SqlSession session, int batchSize) { - super(queue, session); + BatchSession(SqlSession session, int batchSize) { + super(session); this.batchSize = batchSize; } - @Override - public void enqueue(ClusterAction action) { - increment(); - super.enqueue(action); - } - @Override public void select(String statement, Object parameter, ResultHandler handler) { reset(); diff --git a/sonar-db/src/main/java/org/sonar/db/DbSession.java b/sonar-db/src/main/java/org/sonar/db/DbSession.java index 08e2b4ba04d..845dc679c64 100644 --- a/sonar-db/src/main/java/org/sonar/db/DbSession.java +++ b/sonar-db/src/main/java/org/sonar/db/DbSession.java @@ -20,7 +20,6 @@ package org.sonar.db; import java.sql.Connection; -import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.ibatis.executor.BatchResult; @@ -28,49 +27,25 @@ import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; -import org.sonar.db.deprecated.ClusterAction; -import org.sonar.db.deprecated.WorkQueue; public class DbSession implements SqlSession { - private List actions; - private SqlSession session; private int actionCount; - public DbSession(WorkQueue queue, SqlSession session) { + public DbSession(SqlSession session) { this.actionCount = 0; this.session = session; - this.actions = new ArrayList<>(); - } - - /** - * @deprecated since 5.5, not used anymore - */ - @Deprecated - public void enqueue(ClusterAction action) { - actionCount++; - this.actions.add(action); - } - - /** - * @deprecated since 5.5, not used anymore - */ - @Deprecated - public int getActionCount() { - return actionCount; } @Override public void commit() { session.commit(); - actions.clear(); } @Override public void commit(boolean force) { session.commit(force); - actions.clear(); } /** diff --git a/sonar-db/src/main/java/org/sonar/db/MyBatis.java b/sonar-db/src/main/java/org/sonar/db/MyBatis.java index 5076f23dc21..b7517208fc8 100644 --- a/sonar-db/src/main/java/org/sonar/db/MyBatis.java +++ b/sonar-db/src/main/java/org/sonar/db/MyBatis.java @@ -57,7 +57,6 @@ import org.sonar.db.dashboard.WidgetMapper; import org.sonar.db.dashboard.WidgetPropertyDto; import org.sonar.db.dashboard.WidgetPropertyMapper; import org.sonar.db.debt.RequirementMigrationDto; -import org.sonar.db.deprecated.WorkQueue; import org.sonar.db.duplication.DuplicationMapper; import org.sonar.db.duplication.DuplicationUnitDto; import org.sonar.db.event.EventDto; @@ -139,11 +138,9 @@ public class MyBatis { private final Database database; private SqlSessionFactory sessionFactory; - private WorkQueue queue; - public MyBatis(Database database, WorkQueue queue) { + public MyBatis(Database database) { this.database = database; - this.queue = queue; } // FIXME should be visible only to DAOs -> to be moved to AbstractDao @@ -265,10 +262,10 @@ public class MyBatis { public DbSession openSession(boolean batch) { if (batch) { SqlSession session = sessionFactory.openSession(ExecutorType.BATCH); - return new BatchSession(queue, session); + return new BatchSession(session); } SqlSession session = sessionFactory.openSession(ExecutorType.REUSE); - return new DbSession(queue, session); + return new DbSession(session); } /** diff --git a/sonar-db/src/main/java/org/sonar/db/deprecated/ClusterAction.java b/sonar-db/src/main/java/org/sonar/db/deprecated/ClusterAction.java deleted file mode 100644 index 55512295d6e..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/deprecated/ClusterAction.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.deprecated; - -import java.util.concurrent.Callable; - -public interface ClusterAction extends Callable { - - @Override - K call() throws Exception; -} diff --git a/sonar-db/src/main/java/org/sonar/db/deprecated/NullQueue.java b/sonar-db/src/main/java/org/sonar/db/deprecated/NullQueue.java deleted file mode 100644 index 9fa09f9c0cb..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/deprecated/NullQueue.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.deprecated; - -import java.util.List; - -public class NullQueue implements WorkQueue { - - @Override - public void enqueue(List actions) { - // do nothing - } -} diff --git a/sonar-db/src/main/java/org/sonar/db/deprecated/WorkQueue.java b/sonar-db/src/main/java/org/sonar/db/deprecated/WorkQueue.java deleted file mode 100644 index d6466da6d28..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/deprecated/WorkQueue.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.deprecated; - -import java.util.List; -import java.util.concurrent.Callable; - -public interface WorkQueue { - - void enqueue(List actions); - -} diff --git a/sonar-db/src/test/java/org/sonar/db/BatchSessionTest.java b/sonar-db/src/test/java/org/sonar/db/BatchSessionTest.java index e1f02e93ca0..40fe0541f6f 100644 --- a/sonar-db/src/test/java/org/sonar/db/BatchSessionTest.java +++ b/sonar-db/src/test/java/org/sonar/db/BatchSessionTest.java @@ -21,8 +21,6 @@ package org.sonar.db; import org.apache.ibatis.session.SqlSession; import org.junit.Test; -import org.sonar.db.deprecated.ClusterAction; -import org.sonar.db.deprecated.WorkQueue; import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.mock; @@ -34,8 +32,7 @@ public class BatchSessionTest { @Test public void shouldCommitWhenReachingBatchSize() { SqlSession mybatisSession = mock(SqlSession.class); - WorkQueue queue = mock(WorkQueue.class); - BatchSession session = new BatchSession(queue, mybatisSession, 10); + BatchSession session = new BatchSession(mybatisSession, 10); for (int i = 0; i < 9; i++) { session.insert("id" + i); @@ -51,22 +48,14 @@ public class BatchSessionTest { @Test public void shouldCommitWhenReachingBatchSizeWithoutCommits() { SqlSession mybatisSession = mock(SqlSession.class); - WorkQueue queue = mock(WorkQueue.class); - BatchSession session = new BatchSession(queue, mybatisSession, 10); - - ClusterAction action = new ClusterAction() { - @Override - public Object call() throws Exception { - return null; - } - }; + BatchSession session = new BatchSession(mybatisSession, 10); for (int i = 0; i < 9; i++) { - session.enqueue(action); + session.delete("delete something"); verify(mybatisSession, never()).commit(); verify(mybatisSession, never()).commit(anyBoolean()); } - session.enqueue(action); + session.delete("delete something"); verify(mybatisSession).commit(); session.close(); } @@ -74,8 +63,7 @@ public class BatchSessionTest { @Test public void shouldResetCounterAfterCommit() { SqlSession mybatisSession = mock(SqlSession.class); - WorkQueue queue = mock(WorkQueue.class); - BatchSession session = new BatchSession(queue, mybatisSession, 10); + BatchSession session = new BatchSession(mybatisSession, 10); for (int i = 0; i < 35; i++) { session.insert("id" + i); diff --git a/sonar-db/src/test/java/org/sonar/db/MyBatisTest.java b/sonar-db/src/test/java/org/sonar/db/MyBatisTest.java index b3023a4af63..9368138569d 100644 --- a/sonar-db/src/test/java/org/sonar/db/MyBatisTest.java +++ b/sonar-db/src/test/java/org/sonar/db/MyBatisTest.java @@ -25,16 +25,13 @@ import org.hamcrest.core.Is; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.sonar.db.deprecated.WorkQueue; import org.sonar.db.rule.RuleMapper; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; public class MyBatisTest { private static H2Database database; - private WorkQueue queue = mock(WorkQueue.class); @BeforeClass public static void start() { @@ -49,7 +46,7 @@ public class MyBatisTest { @Test public void shouldConfigureMyBatis() { - MyBatis myBatis = new MyBatis(database, queue); + MyBatis myBatis = new MyBatis(database); myBatis.start(); Configuration conf = myBatis.getSessionFactory().getConfiguration(); @@ -60,7 +57,7 @@ public class MyBatisTest { @Test public void shouldOpenBatchSession() { - MyBatis myBatis = new MyBatis(database, queue); + MyBatis myBatis = new MyBatis(database); myBatis.start(); SqlSession session = myBatis.openSession(false); diff --git a/sonar-db/src/test/java/org/sonar/db/TestDb.java b/sonar-db/src/test/java/org/sonar/db/TestDb.java index 8ab3dc5a611..e4d2fd0aa0a 100644 --- a/sonar-db/src/test/java/org/sonar/db/TestDb.java +++ b/sonar-db/src/test/java/org/sonar/db/TestDb.java @@ -40,7 +40,6 @@ import org.junit.AssumptionViolatedException; import org.sonar.api.config.Settings; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; -import org.sonar.db.deprecated.NullQueue; import org.sonar.db.dialect.H2; /** @@ -105,7 +104,7 @@ class TestDb { commands = DatabaseCommands.forDialect(db.getDialect()); tester = new DataSourceDatabaseTester(db.getDataSource(), commands.useLoginAsSchema() ? login : null); - myBatis = new MyBatis(db, new NullQueue()); + myBatis = new MyBatis(db); myBatis.start(); } } diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java index e739cba9096..dd5c13782ca 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -58,7 +58,7 @@ public class ComponentDaoTest { public DbTester db = DbTester.create(System2.INSTANCE); ComponentDbTester componentDb = new ComponentDbTester(db); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); ComponentDao underTest = new ComponentDao(); diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest.java index 10f6c501cd7..122c108ed03 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest.java @@ -44,7 +44,7 @@ public class ComponentDaoWithDuplicatedKeysTest { DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); ComponentDao underTest = new ComponentDao(); diff --git a/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java index e4ee5ac915c..59bbea74db0 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java @@ -29,7 +29,6 @@ import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Scopes; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; -import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.test.DbTests; @@ -51,8 +50,7 @@ public class SnapshotDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); ComponentDbTester componentDb = new ComponentDbTester(db); - DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); SnapshotDao underTest = db.getDbClient().snapshotDao(); @@ -178,7 +176,8 @@ public class SnapshotDaoTest { assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setComponentId(1L).setSort(BY_DATE, DESC)).get(0).getId()).isEqualTo(3L); assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setScope(Scopes.PROJECT).setQualifier(Qualifiers.PACKAGE))).extracting("id").containsOnly(1L); - assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setScope(Scopes.DIRECTORY).setQualifier(Qualifiers.PACKAGE))).extracting("id").containsOnly(2L, 3L, 4L, 5L, 6L); + assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setScope(Scopes.DIRECTORY).setQualifier(Qualifiers.PACKAGE))).extracting("id").containsOnly( + 2L, 3L, 4L, 5L, 6L); assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD"))).hasSize(3); assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("UNKOWN"))).isEmpty(); @@ -227,7 +226,7 @@ public class SnapshotDaoTest { newSnapshotForProject(project).setCreatedAt(5L), newSnapshotForProject(project).setCreatedAt(2L), newSnapshotForProject(project).setCreatedAt(1L) - ); + ); dbSession.commit(); SnapshotDto dto = underTest.selectOldestSnapshot(dbSession, project.getId()); @@ -247,7 +246,7 @@ public class SnapshotDaoTest { db.getSession().commit(); assertThat(dto.getId()).isNotNull(); - db.assertDbUnit(getClass(), "insert-result.xml", new String[]{"id"}, "snapshots"); + db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "snapshots"); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java index c31b3e6938e..b9cd5e367dc 100644 --- a/sonar-db/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java @@ -37,7 +37,7 @@ public class DuplicationDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - DbSession dbSession = db.getSession(); + final DbSession dbSession = db.getSession(); DuplicationDao dao = db.getDbClient().duplicationDao(); diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java index 37c53d4bde0..fa2985530b7 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java @@ -58,8 +58,8 @@ public class MeasureDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private DbClient dbClient = db.getDbClient(); - private DbSession dbSession = db.getSession(); + final DbClient dbClient = db.getDbClient(); + final DbSession dbSession = db.getSession(); MeasureDao underTest = dbClient.measureDao(); diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterDaoTest.java index f9bfd12ba0c..369f2368065 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterDaoTest.java @@ -33,7 +33,7 @@ public class MeasureFilterDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - DbSession session = db.getSession(); + final DbSession session = db.getSession(); MeasureFilterDao underTest = db.getDbClient().measureFilterDao(); diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterFavouriteDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterFavouriteDaoTest.java index 41402810c3a..d2c94c30768 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterFavouriteDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterFavouriteDaoTest.java @@ -33,7 +33,7 @@ public class MeasureFilterFavouriteDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - DbSession session = db.getSession(); + final DbSession session = db.getSession(); MeasureFilterFavouriteDao underTest = db.getDbClient().measureFilterFavouriteDao(); diff --git a/sonar-db/src/test/java/org/sonar/db/permission/GroupWithPermissionDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/GroupWithPermissionDaoTest.java index 778cb24ec5e..ddb3b5b9923 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/GroupWithPermissionDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/GroupWithPermissionDaoTest.java @@ -48,7 +48,7 @@ public class GroupWithPermissionDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - DbSession session = db.getSession(); + final DbSession session = db.getSession(); PermissionDao underTest = new PermissionDao(db.myBatis()); diff --git a/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java index 4853cac312f..a6a2696806b 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java @@ -61,7 +61,7 @@ public class PermissionTemplateDaoTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - DbSession session = db.getSession(); + final DbSession session = db.getSession(); DbClient dbClient = db.getDbClient(); PermissionTemplateDao underTest = new PermissionTemplateDao(db.myBatis(), system); diff --git a/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java index 3fba65b42ef..efd1887a503 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java @@ -25,7 +25,6 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; -import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.test.DbTests; @@ -41,8 +40,7 @@ public class GroupDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - DbSession dbSession = db.getSession(); - DbClient dbClient = db.getDbClient(); + final DbSession dbSession = db.getSession(); System2 system2 = mock(System2.class); GroupDao underTest = new GroupDao(system2); diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java index a090b59b03b..55d413370f2 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java @@ -70,7 +70,7 @@ public class UserDaoTest { DbClient dbClient = db.getDbClient(); UserDao underTest = db.getDbClient().userDao(); - DbSession session = db.getSession(); + final DbSession session = db.getSession(); @Before public void setUp() throws Exception { -- 2.39.5