Revision: 3933
Author: [email protected]
Date: Fri Aug 27 15:12:47 2010
Log: Removed sketch threading from the network conflict resolver, as flush
is always called on the foreground thread anyway. Removed the tree map from
the architect swing project, as it didn't add any functionality, and had a
tendency to get out of synch.
http://code.google.com/p/power-architect/source/detail?r=3933
Modified:
/trunk/src/main/java/ca/sqlpower/architect/enterprise/NetworkConflictResolver.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/NetworkConflictResolver.java
Fri Aug 27 09:04:16 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/NetworkConflictResolver.java
Fri Aug 27 15:12:47 2010
@@ -185,7 +185,7 @@
if (session.getStatusInformation() != null) {
monitor =
session.getStatusInformation().createProgressMonitor();
monitor.setJobSize(messageBuffer.length() + 2);
- monitor.setMessage("Writing " + messageBuffer.length() + "
changes to the server.");
+ monitor.setMessage("Saving");
monitor.setProgress(0);
final MonitorableImpl finalMonitor = monitor;
new Thread(new Runnable() {
@@ -199,7 +199,6 @@
}
if (finalMonitor.isCancelled() ||
finalMonitor.isFinished()) break;
finalMonitor.incrementProgress();
- finalMonitor.setMessage("Saving");
}
finalMonitor.setMessage("Completing server
update.");
}
@@ -252,7 +251,10 @@
}
// Try to rollback our changes
try {
- session.getWorkspace().rollback("Hello this is a
rollback");
+
SPSessionPersister.undoForSession(session.getWorkspace(),
+ new
LinkedList<PersistedSPObject>(outboundObjectsToAdd.values()),
+ outboundPropertiesToChange,
+ new
LinkedList<RemovedObjectEntry>(outboundObjectsToRemove.values()),
converter);
} catch (Exception e) {
throw new RuntimeException("Reflush failed on
rollback", e);
}
@@ -276,41 +278,35 @@
// Try to create inboundPersistedLists for comparison with
the outbound. These will be used
// for special case collision detection.
fillInboundPersistedLists(json);
-
- session.runInForeground(new Runnable() {
-
- @Override
- public void run() {
- // Try to apply update
- decodeMessage(new JSONTokener(json), newRev);
- // We need an additional step here for checking
for special case conflicts
- List<ConflictMessage> conflicts =
detectConflicts();
- if (conflicts.size() == 0) {
- // Try to return the persisted objects to
their state pre-update.
- try {
-
SPSessionPersister.redoForSession(session.getWorkspace(),
- new
LinkedList<PersistedSPObject>(outboundObjectsToAdd.values()),
- outboundPropertiesToChange,
- new
LinkedList<RemovedObjectEntry>(outboundObjectsToRemove.values()),
converter);
- // We want to re-send our changes, but
only if we were able to restore them
- flush(true);
- } catch (Exception ex) {
- throw new RuntimeException("Reflush failed
on rollforward", ex);
- }
- } else {
- String message = "";
- message += "Your changes have been discarded
due to a conflict between you and another user: \n";
- for (int i = 0; i < MAX_CONFLICTS_TO_DISPLAY
&& i < conflicts.size(); i++) {
- message += conflicts.get(i).getMessage()
+ "\n";
- }
- session.createUserPrompter(message,
- UserPromptType.MESSAGE,
- UserPromptOptions.OK,
- UserPromptResponse.OK,
- "OK", "OK").promptUser("");
- }
- }
- });
+
+ // Try to apply update
+ decodeMessage(new JSONTokener(json), newRev);
+ // We need an additional step here for checking for
special case conflicts
+ List<ConflictMessage> conflicts = detectConflicts();
+ if (conflicts.size() == 0) {
+ // Try to return the persisted objects to their state
pre-update.
+ try {
+
SPSessionPersister.redoForSession(session.getWorkspace(),
+ new
LinkedList<PersistedSPObject>(outboundObjectsToAdd.values()),
+ outboundPropertiesToChange,
+ new
LinkedList<RemovedObjectEntry>(outboundObjectsToRemove.values()),
converter);
+ // We want to re-send our changes, but only if we
were able to restore them
+ flush(true);
+ } catch (Exception ex) {
+ throw new RuntimeException("Reflush failed on
rollforward", ex);
+ }
+ } else {
+ String message = "";
+ message += "Your changes have been discarded due to a
conflict between you and another user: \n";
+ for (int i = 0; i < MAX_CONFLICTS_TO_DISPLAY && i <
conflicts.size(); i++) {
+ message += conflicts.get(i).getMessage() + "\n";
+ }
+ session.createUserPrompter(message,
+ UserPromptType.MESSAGE,
+ UserPromptOptions.OK,
+ UserPromptResponse.OK,
+ "OK", "OK").promptUser("");
+ }
}
} finally {
if (monitor != null) {
@@ -443,7 +439,7 @@
try {
if (currentRevision < newRevision) {
List<UpdateListener> updateListenersCopy = new
ArrayList<UpdateListener>(updateListeners);
- for (UpdateListener listener : updateListenersCopy) {
+ for (UpdateListener listener : updateListeners) {
listener.preUpdatePerformed(NetworkConflictResolver.this);
}
// Now we can apply the update ...
@@ -860,7 +856,7 @@
return (String) p.getNewValue();
}
}
- throw new IllegalArgumentException("Given persisted object has no
corresponding name property!");
+ throw new IllegalArgumentException("Persisted Object with UUID " +
o.getUUID() + " has no name property");
}
/**
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
Thu Aug 5 12:09:29 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
Fri Aug 27 15:12:47 2010
@@ -19,7 +19,6 @@
package ca.sqlpower.architect.swingui;
-import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -40,10 +39,7 @@
import ca.sqlpower.architect.profile.ProfileManager;
import ca.sqlpower.enterprise.client.Group;
import ca.sqlpower.enterprise.client.User;
-import ca.sqlpower.object.AbstractSPListener;
import ca.sqlpower.object.MappedSPTree;
-import ca.sqlpower.object.SPChildEvent;
-import ca.sqlpower.object.SPListener;
import ca.sqlpower.object.SPObject;
import ca.sqlpower.object.annotation.Accessor;
import ca.sqlpower.object.annotation.Constructor;
@@ -52,11 +48,11 @@
import ca.sqlpower.object.annotation.NonProperty;
import ca.sqlpower.object.annotation.Transient;
import ca.sqlpower.object.annotation.ConstructorParameter.ParameterType;
-import ca.sqlpower.sqlobject.SQLObject;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectRoot;
import ca.sqlpower.sqlobject.UserDefinedSQLType;
import ca.sqlpower.util.RunnableDispatcher;
+import ca.sqlpower.util.SQLPowerUtils;
import ca.sqlpower.util.WorkspaceContainer;
/**
@@ -83,71 +79,6 @@
CriticManager.class, KettleSettings.class, User.class,
Group.class,
BusinessDefinition.class,
FormulaMetricCalculation.class)));
- /**
- * A hash map mapping all the descendants of this project.
- * It must be kept up to date by listening to all its descendant nodes
- * for child added and child removed events.
- */
- private final HashMap<String, SPObject> projectMap;
-
- /**
- * The listener used to keep the projectMap up to date.
- */
- private final SPListener projectMapListener = new AbstractSPListener()
{
- public void childAdded(SPChildEvent e) {
- populateTreeMap(e.getChild());
- }
-
- public void childRemoved(SPChildEvent e) {
- unpopulateTreeMap(e.getChild());
- }
-
- public void propertyChanged(PropertyChangeEvent e) {
- if (e.getPropertyName().toUpperCase().equals("UUID")) {
- projectMap.put((String) e.getNewValue(),
projectMap.remove(e.getOldValue()));
- }
- }
-
- private void populateTreeMap(SPObject addedChild) {
- if (projectMap.put(addedChild.getUUID(), addedChild) != null) {
- throw new IllegalStateException("Object added under
project with same UUID! Adding " + addedChild);
- }
- addedChild.addSPListener(this);
- //Be careful here. If calling getChildren adds children to the
object this
- //listener will get called twice, once because the listener is
now on the parent
- //and again for the loop.
- if (addedChild instanceof SQLObject) {
- for (SPObject o : ((SQLObject)
addedChild).getChildrenWithoutPopulating()) {
- populateTreeMap(o);
- }
- } else {
- for (SPObject o : addedChild.getChildren()) {
- populateTreeMap(o);
- }
- }
- }
-
- private void unpopulateTreeMap(SPObject removedChild) {
- if (projectMap.remove(removedChild.getUUID()) != removedChild)
{
- throw new IllegalStateException("Inconsistent project
map: " +
- "removed child's entry in map was either null, or
different object.");
- }
- removedChild.removeSPListener(this);
-
- //Removing a listener should not cause a SQLObject to populate
but we need to
- //remove the listener from all descendants and clear the map .
- if (removedChild instanceof SQLObject) {
- for (SPObject o : ((SQLObject)
removedChild).getChildrenWithoutPopulating()) {
- unpopulateTreeMap(o);
- }
- } else {
- for (SPObject o : removedChild.getChildren()) {
- unpopulateTreeMap(o);
- }
- }
- }
- };
-
private PlayPenContentPane playPenContentPane;
/**
@@ -180,10 +111,8 @@
kettleSettings.setParent(this);
setName("Architect Project");
- projectMap = new HashMap<String, SPObject>();
criticManager = new CriticManager();
criticManager.setParent(this);
- projectMapListener.childAdded(new SPChildEvent(this, null, this,
0, null));
}
/**
@@ -208,8 +137,6 @@
criticManager.setParent(this);
setName("Architect Project");
- projectMap = new HashMap<String, SPObject>();
- projectMapListener.childAdded(new SPChildEvent(this, null, this,
0, null));
}
@Override
@@ -367,7 +294,7 @@
@NonBound
public SPObject getObjectInTree(String uuid) {
- return projectMap.get(uuid);
+ return SQLPowerUtils.findByUuid(this, uuid, SPObject.class);
}
/**
@@ -377,7 +304,7 @@
*/
@NonBound
public <T extends SPObject> T getObjectInTree(String uuid, Class<T>
expectedType) {
- return expectedType.cast(getObjectInTree(uuid));
+ return SQLPowerUtils.findByUuid(this, uuid, expectedType);
}
@NonProperty