Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2007-06-14 17:20:27 -0400
committerrelves2007-06-14 17:20:27 -0400
commit024a0c4e4a82ce7ad5ee39a2a6e40e38667cb696 (patch)
tree44e169f73f3797995129213c411a96e02cbf2f94 /org.eclipse.mylyn.tasks.core
parentfe5d2f52d079fdd2e099f8956b3bbad7fab1191b (diff)
downloadorg.eclipse.mylyn.tasks-024a0c4e4a82ce7ad5ee39a2a6e40e38667cb696.tar.gz
org.eclipse.mylyn.tasks-024a0c4e4a82ce7ad5ee39a2a6e40e38667cb696.tar.xz
org.eclipse.mylyn.tasks-024a0c4e4a82ce7ad5ee39a2a6e40e38667cb696.zip
NEW - bug 191575: [api] optimize query synchronization
https://bugs.eclipse.org/bugs/show_bug.cgi?id=191575
Diffstat (limited to 'org.eclipse.mylyn.tasks.core')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/LocalRepositoryConnector.java12
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java24
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractTask.java11
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java12
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskCollector.java22
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskFactory.java2
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/QueryHitCollector.java107
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java26
8 files changed, 106 insertions, 110 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/LocalRepositoryConnector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/LocalRepositoryConnector.java
index 331555779..1790c6a89 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/LocalRepositoryConnector.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/LocalRepositoryConnector.java
@@ -11,7 +11,7 @@
package org.eclipse.mylyn.internal.tasks.core;
-import java.util.Collections;
+
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
@@ -21,8 +21,8 @@ import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery;
import org.eclipse.mylyn.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.IAttachmentHandler;
+import org.eclipse.mylyn.tasks.core.ITaskCollector;
import org.eclipse.mylyn.tasks.core.ITaskDataHandler;
-import org.eclipse.mylyn.tasks.core.QueryHitCollector;
import org.eclipse.mylyn.tasks.core.RepositoryTaskData;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -63,9 +63,9 @@ public class LocalRepositoryConnector extends AbstractRepositoryConnector {
}
@Override
- public Set<AbstractTask> getChangedSinceLastSync(TaskRepository repository,
- Set<AbstractTask> tasks, IProgressMonitor monitor) throws CoreException {
- return Collections.emptySet();
+ public boolean markStaleTasks(TaskRepository repository,
+ Set<AbstractTask> tasks, IProgressMonitor monitor) {
+ return false;
}
@Override
@@ -104,7 +104,7 @@ public class LocalRepositoryConnector extends AbstractRepositoryConnector {
@Override
public IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository, IProgressMonitor monitor,
- QueryHitCollector resultCollector, boolean forced) {
+ ITaskCollector resultCollector) {
// ignore
return null;
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
index 8eca91e4a..fad1df265 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
@@ -171,7 +171,7 @@ public abstract class AbstractRepositoryConnector {
* IQueryHitCollector that collects the hits found
*/
public abstract IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository,
- IProgressMonitor monitor, QueryHitCollector resultCollector, boolean forced);
+ IProgressMonitor monitor, ITaskCollector resultCollector);
/**
* The connector's summary i.e. "JIRA (supports 3.3.1 and later)"
@@ -250,18 +250,23 @@ public abstract class AbstractRepositoryConnector {
}
/**
- * Of <code>tasks</code> provided, return all that have changed since last
- * synchronization of <code>repository</code>
+ * Of <code>tasks</code> provided, return all that have changed since last synchronization of
+ * <code>repository</code>.
*
- * All errors should be thrown as <code>CoreException</code> for the
- * framework to handle, since background synchronizations fail silently when
- * disconnected.
+ * Tasks that need to be synchronized (i.e. task data updated) should be passed to
+ * <code>collector.accept(Task)</code> method, or if repository connector can update task data, it can use
+ * <code>collector.accept(RepositoryTaskData)</code> call.
*
- * TODO: Add progress monitor as parameter
+ * All errors should be thrown as <code>CoreException</code> for the framework to handle, since background
+ * synchronizations fail silently when disconnected.
+ * @param tasks TODO
+ *
+ * @return null if there was no tasks changed in the repository, otherwise collection of updated tasks (within
+ * <code>tasks</code> collection), so empty collection means that there are some other tasks changed
*
* @throws CoreException
*/
- public abstract Set<AbstractTask> getChangedSinceLastSync(TaskRepository repository,
+ public abstract boolean markStaleTasks(TaskRepository repository,
Set<AbstractTask> tasks, IProgressMonitor monitor) throws CoreException;
/**
@@ -392,7 +397,7 @@ public abstract class AbstractRepositoryConnector {
* synchronization timestamp. Override to return actual timestamp from
* repository.
*/
- public String getLastSyncTimestamp(TaskRepository repository, Set<AbstractTask> changedTasks) {
+ public String getSynchronizationTimestamp(TaskRepository repository, Set<AbstractTask> changedTasks) {
Date mostRecent = new Date(0);
String mostRecentTimeStamp = repository.getSyncTimeStamp();
for (AbstractTask task : changedTasks) {
@@ -432,4 +437,5 @@ public abstract class AbstractRepositoryConnector {
this.taskDataManager = taskDataManager;
}
+
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractTask.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractTask.java
index e1dfb29a7..ab8a3b448 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractTask.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractTask.java
@@ -66,6 +66,8 @@ public abstract class AbstractTask extends AbstractTaskContainer {
// transient
private IStatus errorStatus = null;
+
+ private boolean stale = false;
public enum RepositoryTaskSyncState {
OUTGOING, SYNCHRONIZED, INCOMING, CONFLICT
@@ -446,4 +448,13 @@ public abstract class AbstractTask extends AbstractTaskContainer {
public void setDueDate(Date date) {
this.dueDate = date;
}
+
+ public boolean isStale() {
+ return stale;
+ }
+
+ public void setStale(boolean stale) {
+ this.stale = stale;
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java
index 8f38aed49..a2995d956 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java
@@ -126,6 +126,8 @@ public class DelegatingTaskExternalizer implements ITaskListExternalizer {
public static final String KEY_SYNC_STATE = "offlineSyncState";
public static final String KEY_OWNER = "Owner";
+
+ public static final String KEY_STALE = "Stale";
private List<ITaskListExternalizer> delegateExternalizers = new ArrayList<ITaskListExternalizer>();
@@ -204,6 +206,11 @@ public class DelegatingTaskExternalizer implements ITaskListExternalizer {
} else {
node.setAttribute(KEY_REMINDED, VAL_FALSE);
}
+ if (task.isStale()) {
+ node.setAttribute(KEY_STALE, VAL_TRUE);
+ } else {
+ node.setAttribute(KEY_STALE, VAL_FALSE);
+ }
if (task instanceof AbstractTask) {
AbstractTask abstractTask = (AbstractTask) task;
@@ -483,6 +490,11 @@ public class DelegatingTaskExternalizer implements ITaskListExternalizer {
} else {
task.setReminded(false);
}
+ if (element.hasAttribute(KEY_STALE) && element.getAttribute(KEY_STALE).compareTo(VAL_TRUE) == 0) {
+ task.setStale(true);
+ } else {
+ task.setStale(false);
+ }
if (task instanceof AbstractTask) {
AbstractTask abstractTask = (AbstractTask) task;
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskCollector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskCollector.java
new file mode 100644
index 000000000..2aad2db65
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskCollector.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 University Of British Columbia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * University Of British Columbia - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.core;
+
+import org.eclipse.core.runtime.CoreException;
+
+public interface ITaskCollector {
+
+ void accept(AbstractTask task);
+
+ void accept(RepositoryTaskData taskData) throws CoreException;
+
+}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskFactory.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskFactory.java
index 834e0947e..68583a7ad 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskFactory.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskFactory.java
@@ -23,6 +23,6 @@ public interface ITaskFactory {
* @param forced -
* user requested synchronization
*/
- public abstract AbstractTask createTask(RepositoryTaskData taskData, boolean synchData, boolean forced, IProgressMonitor monitor) throws CoreException;
+ public abstract AbstractTask createTask(RepositoryTaskData taskData, IProgressMonitor monitor) throws CoreException;
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/QueryHitCollector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/QueryHitCollector.java
index b68a980b8..310e337c3 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/QueryHitCollector.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/QueryHitCollector.java
@@ -10,131 +10,64 @@
*******************************************************************************/
package org.eclipse.mylyn.tasks.core;
-import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
/**
* Collects QueryHits resulting from repository search
*
* @author Shawn Minto
* @author Rob Elves (generalized from bugzilla)
+ * @author Steffen Pingel
*/
-public class QueryHitCollector {
+public class QueryHitCollector implements ITaskCollector {
public static final int MAX_HITS = 5000;
public static final String MAX_HITS_REACHED = "Max allowed number of hits returned exceeded. Some hits may not be displayed. Please narrow query scope.";
- protected Set<AbstractTask> taskResults = new HashSet<AbstractTask>();
+ private final Set<AbstractTask> taskResults = new HashSet<AbstractTask>();
- /** The progress monitor for the search operation */
- private IProgressMonitor monitor = new NullProgressMonitor();
+ private final TaskList taskList;
- /** The number of matches found */
- private int matchCount;
-
- /** The string to display to the user while querying */
- private static final String STARTING = "querying the server";
-
- /** The string to display to the user when we have 1 match */
- private static final String MATCH = "1 match";
-
- /** The string to display to the user when we have multiple or no matches */
- private static final String MATCHES = "{0} matches";
-
- /** The string to display to the user when the query is done */
- private static final String DONE = "done";
-
- protected TaskList taskList;
-
- protected ITaskFactory taskFactory;
+ private final ITaskFactory taskFactory;
public QueryHitCollector(TaskList tasklist, ITaskFactory taskFactory) {
this.taskList = tasklist;
this.taskFactory = taskFactory;
}
- public void aboutToStart(int startMatchCount) throws CoreException {
- taskResults.clear();
- matchCount = startMatchCount;
- monitor.setTaskName(STARTING);
- }
-
public void accept(AbstractTask task) {
-
- if (!getProgressMonitor().isCanceled()) {
- getProgressMonitor().subTask(getFormattedMatchesString(matchCount));
- getProgressMonitor().worked(1);
+ if (task == null) {
+ throw new IllegalArgumentException();
}
-
- if (task == null)
- return;
-
- AbstractTask hitTask = taskList.getTask(task.getHandleIdentifier());
- if (hitTask == null) {
- hitTask = task;
- // task is new, add to tasklist
- taskList.addTask(hitTask);
+
+ AbstractTask existingTask = taskList.getTask(task.getHandleIdentifier());
+ if (existingTask == null) {
+ task.setStale(true);
+ } else {
+ // preserve meta attributes of existing task
+ task.setLastSyncDateStamp(existingTask.getLastSyncDateStamp());
+ task.setStale(existingTask.isStale());
}
- taskResults.add((AbstractTask) hitTask);
- matchCount++;
+
+ taskResults.add((AbstractTask) task);
}
public void accept(RepositoryTaskData taskData) throws CoreException {
- if (taskData == null)
- return;
-
- if (!getProgressMonitor().isCanceled()) {
- getProgressMonitor().subTask(getFormattedMatchesString(matchCount));
- getProgressMonitor().worked(1);
+ if (taskData == null) {
+ throw new IllegalArgumentException();
}
- AbstractTask task = taskFactory.createTask(taskData, true, false, new SubProgressMonitor(monitor, 1));
+ AbstractTask task = taskFactory.createTask(taskData, new NullProgressMonitor());
taskResults.add(task);
- matchCount++;
- }
-
- public void done() {
- if (monitor != null && !monitor.isCanceled()) {
- // if the operation is cancelled, finish with the data that we
- // already have
- String matchesString = getFormattedMatchesString(matchCount);
- monitor.setTaskName(MessageFormat.format(DONE, new Object[] { matchesString }));
- monitor.done();
- }
-
- // Cut no longer used references because the collector might be re-used
- monitor = null;
- }
-
- protected String getFormattedMatchesString(int count) {
- if (count == 1) {
- return MATCH;
- }
- Object[] messageFormatArgs = { new Integer(count) };
- return MessageFormat.format(MATCHES, messageFormatArgs);
- }
-
- public IProgressMonitor getProgressMonitor() {
- return monitor;
- }
-
- public void setProgressMonitor(IProgressMonitor monitor) {
- this.monitor = monitor;
}
public Set<AbstractTask> getTaskHits() {
return taskResults;
}
- public void clear() {
- taskResults.clear();
- }
-
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
index 70c727789..7d81e8de3 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
@@ -294,8 +294,23 @@ public class TaskRepository {
@Override
public boolean equals(Object object) {
- if (object instanceof TaskRepository && getUrl() != null) {
- return getUrl().equals(((TaskRepository) object).getUrl());
+ if (object instanceof TaskRepository) {
+ TaskRepository repository = (TaskRepository) object;
+ if (getUrl() == null) {
+ if (repository.getUrl() != null) {
+ return false;
+ }
+ } else {
+ if(!getUrl().equals(repository.getUrl())) {
+ return false;
+ }
+ }
+ if (getKind() == null) {
+ return repository.getKind() == null;
+ } else {
+ return getKind().equals(repository.getKind());
+ }
+
} else {
return super.equals(object);
}
@@ -303,11 +318,8 @@ public class TaskRepository {
@Override
public int hashCode() {
- if (getUrl() != null) {
- return getUrl().hashCode();
- } else {
- return super.hashCode();
- }
+ int res = getUrl()==null ? 1 : getUrl().hashCode();
+ return res * 31 + (getKind()==null ? 1 : getKind().hashCode());
}
@Override

Back to the top