aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@sonarsource.com>2014-09-23 13:49:15 +0200
committerStephane Gamard <stephane.gamard@sonarsource.com>2014-09-23 13:58:17 +0200
commit22a4eaeb820f50d4aac63c8b98030e41525a3809 (patch)
tree4837e6738b9532fe7b2b282f61dc00fd7fb6b038
parent5f97303009f20fdf47d70f9ba3edaa0337ac16a5 (diff)
downloadsonarqube-22a4eaeb820f50d4aac63c8b98030e41525a3809.tar.gz
sonarqube-22a4eaeb820f50d4aac63c8b98030e41525a3809.zip
SONAR-5531 - Optimized Synchronizer (no upsert)
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java72
1 files changed, 72 insertions, 0 deletions
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
new file mode 100644
index 00000000000..107d04326a6
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java
@@ -0,0 +1,72 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.search.action;
+
+import org.elasticsearch.action.ActionRequest;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.sonar.core.persistence.Dto;
+import org.sonar.server.search.Index;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class InsertDto<DTO extends Dto> extends IndexAction<ActionRequest> {
+
+ private final DTO dto;
+
+ public InsertDto(String indexType, DTO dto) {
+ this(indexType, dto, true);
+ }
+
+ public InsertDto(String indexType, DTO dto, boolean requiresRefresh) {
+ super(indexType, requiresRefresh);
+ this.dto = dto;
+ }
+
+ @Override
+ public String getKey() {
+ return dto.getKey().toString();
+ }
+
+ @Override
+ public Class getPayloadClass() {
+ return dto.getClass();
+ }
+
+ @Override
+ public List<ActionRequest> doCall(Index index) throws Exception {
+ List<ActionRequest> inserts = new ArrayList<ActionRequest>();
+ List<UpdateRequest> 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;
+ }
+}