import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import org.apache.ibatis.session.ResultContext;
-import org.apache.ibatis.session.ResultHandler;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.DaoComponent;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.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;
// Synchronization methods
- protected ResultHandler getSynchronizationResultHandler(final DbSession session) {
- return new ResultHandler() {
+ protected DbSynchronizationHandler getSynchronizationResultHandler(final DbSession session) {
+ return new DbSynchronizationHandler() {
@Override
public void handleResult(ResultContext resultContext) {
DTO dto = (DTO) resultContext.getResultObject();
session.enqueue(new UpsertDto<DTO>(getIndexType(), dto, true));
}
+
+ @Override
+ public void enqueueCollected() {
+ // Do nothing in this case
+ }
};
}
@Override
public void synchronizeAfter(final DbSession session, Date date) {
try {
- session.select(getSynchronizeStatementFQN(), getSynchronizationParams(date), getSynchronizationResultHandler(session));
+ DbSynchronizationHandler handler = getSynchronizationResultHandler(session);
+ session.select(getSynchronizeStatementFQN(), getSynchronizationParams(date), handler);
+ handler.enqueueCollected();
} catch (Exception e) {
throw new IllegalStateException(e);
}
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import org.apache.ibatis.session.ResultContext;
-import org.apache.ibatis.session.ResultHandler;
import org.sonar.api.security.DefaultGroups;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.core.persistence.DaoComponent;
import org.sonar.core.persistence.DbSession;
import org.sonar.server.db.BaseDao;
+import org.sonar.server.search.DbSynchronizationHandler;
import org.sonar.server.search.IndexDefinition;
import org.sonar.server.search.action.UpsertDto;
}
@Override
- protected ResultHandler getSynchronizationResultHandler(final DbSession session) {
- return new ResultHandler() {
+ protected DbSynchronizationHandler getSynchronizationResultHandler(final DbSession session) {
+ return new DbSynchronizationHandler() {
private final Map<String, IssueAuthorizationDto> authorizationDtoMap = new HashMap<String, IssueAuthorizationDto>();
- private int count = 0;
@Override
public void handleResult(ResultContext context) {
issueAuthorizationDto.addUser(user);
}
authorizationDtoMap.put(project, issueAuthorizationDto);
- count++;
-
- // TODO this sort of breaks the scrollable RS. Should be inline.
- // Check if this is the last
- if (count == context.getResultCount()) {
- for (IssueAuthorizationDto authorization : authorizationDtoMap.values()) {
- session.enqueue(new UpsertDto<IssueAuthorizationDto>(getIndexType(), authorization, true));
- }
+ }
+
+ @Override
+ public void enqueueCollected() {
+ for (IssueAuthorizationDto authorization : authorizationDtoMap.values()) {
+ session.enqueue(new UpsertDto<IssueAuthorizationDto>(getIndexType(), authorization, true));
}
}
};
}
private void synchronizePermissions() {
- // The index synchronizer cannot use an existing session, otherwise it's failing with the error : org.apache.ibatis.executor.ExecutorException: Executor was closed
+ // The synchronisation cannot use an existing session, otherwise it's failing with the error : org.apache.ibatis.executor.ExecutorException: Executor was closed
DbSession session = dbClient.openSession(false);
try {
dbClient.issueAuthorizationDao().synchronizeAfter(session, index.get(IssueAuthorizationIndex.class).getLastSynchronization());
--- /dev/null
+/*
+ * 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;
+
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
+
+import javax.annotation.CheckForNull;
+
+public interface DbSynchronizationHandler extends ResultHandler {
+
+ @Override
+ void handleResult(ResultContext context);
+
+ @CheckForNull
+ void enqueueCollected();
+}