Skip to content

Commit 3ffddc4

Browse files
committed
Upgraded objectify to get the new Monotonic helper. Change.id is now generated by Monotonic, so that each change has an id one greater than the last change made. This was necessary because Date() didn't offer enough precision to distinguish changes, and also because there are potentially skews in the clocks between various servers, so a time stamp can't be relied upon to always be sequential. The client now uses Change.id instead of Change.date to key the ModeVersions.timeMachineMap which should hopefully fix a bug which I think is related to the Change.date being the same for two different Changes.
1 parent dc1d5ee commit 3ffddc4

File tree

12 files changed

+170
-124
lines changed

12 files changed

+170
-124
lines changed

.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
66
<classpathentry kind="lib" path="war/WEB-INF/lib/lucene-snowball-3.0.2.jar"/>
77
<classpathentry kind="lib" path="war/WEB-INF/lib/lucene-core-3.0.2.jar"/>
8-
<classpathentry kind="lib" path="war/WEB-INF/lib/objectify-2.2.2.jar"/>
98
<classpathentry kind="lib" path="war/WEB-INF/lib/gwtquery-1.0.0-SNAPSHOT.jar"/>
9+
<classpathentry kind="lib" path="war/WEB-INF/lib/objectify-2.2.3.jar"/>
1010
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER/App Engine (2)"/>
1111
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER/GWT (2)"/>
1212
<classpathentry kind="output" path="war/WEB-INF/classes"/>

src/org/argmap/client/ArgMap.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import com.google.gwt.user.client.ui.TabLayoutPanel;
2222
import com.google.gwt.user.client.ui.Widget;
2323

24+
/*
25+
* when a root proposition is first added, program suggest using it instead (as a link) of itself!
26+
*/
2427
/*
2528
* simple linking (create two root nodes, one linking to other's child) causes versions mode problems: link
2629
* change is not showing up, and the delete change that preceeds the link change causes an exception.

src/org/argmap/client/Change.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public enum ChangeType {
106106
public int argPropIndex = -1;
107107
public boolean argPro;
108108

109+
/*
110+
* don't use this method; use ArgMapServiceImpl.getNewChange() instead.
111+
*/
109112
public Change() {
110113

111114
}
@@ -171,10 +174,6 @@ public boolean isAddition() {
171174
return false;
172175
}
173176

174-
public Change(ChangeType changeType) {
175-
this.changeType = changeType;
176-
}
177-
178177
@Override
179178
public String toString() {
180179
return "id:" + id + "; changeType:" + changeType + "; argID:" + argID

src/org/argmap/client/ModeVersions.java

Lines changed: 89 additions & 68 deletions
Large diffs are not rendered by default.

src/org/argmap/client/ViewArgVer.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.ArrayList;
44
import java.util.Collection;
5-
import java.util.Date;
65
import java.util.HashMap;
76
import java.util.List;
87
import java.util.Map;
@@ -12,15 +11,7 @@
1211
public class ViewArgVer extends ViewArg implements ViewNodeVer {
1312
public List<ViewChange> viewChanges = new ArrayList<ViewChange>();
1413
public Map<Long, ViewNodeVer> deletedViews = new HashMap<Long, ViewNodeVer>();
15-
public Date closedDate;
16-
17-
public Date getClosedDate() {
18-
return closedDate;
19-
}
20-
21-
public void setClosedDate(Date closedDate) {
22-
this.closedDate = closedDate;
23-
}
14+
public Long changeIDOnClose;
2415

2516
public ViewArgVer() {
2617
super();
@@ -130,4 +121,15 @@ public NodeChanges chooseNodeChanges(NodeChangesMaps changesMaps) {
130121
public void clearDeletedViews() {
131122
deletedViews.clear();
132123
}
124+
125+
@Override
126+
public Long getChangeIDOnClose() {
127+
return changeIDOnClose;
128+
}
129+
130+
@Override
131+
public void setChangeIDOnClose(Long changeIDOnClose) {
132+
this.changeIDOnClose = changeIDOnClose;
133+
134+
}
133135
}

src/org/argmap/client/ViewDummyVer.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.argmap.client;
22

33
import java.util.Collection;
4-
import java.util.Date;
54
import java.util.List;
65

76
import org.argmap.client.ArgMapService.NodeChangesMaps;
@@ -39,18 +38,6 @@ public ViewNodeVer getChildViewNode(int i) {
3938
return null;
4039
}
4140

42-
@Override
43-
public Date getClosedDate() {
44-
assert false;
45-
return null;
46-
}
47-
48-
@Override
49-
public void setClosedDate(Date closedDate) {
50-
assert false;
51-
52-
}
53-
5441
@Override
5542
public boolean isOpen() {
5643
assert false;
@@ -177,4 +164,15 @@ public void haveFocus() {
177164
public void setTextAreaCursorPosition(int index) {
178165
assert false;
179166
}
167+
168+
@Override
169+
public Long getChangeIDOnClose() {
170+
assert false;
171+
return null;
172+
}
173+
174+
@Override
175+
public void setChangeIDOnClose(Long changeIDOnClose) {
176+
assert false;
177+
}
180178
}

src/org/argmap/client/ViewNodeVer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.argmap.client;
22

33
import java.util.Collection;
4-
import java.util.Date;
54
import java.util.Iterator;
65
import java.util.List;
76

@@ -36,9 +35,9 @@ public interface ViewNodeVer {
3635

3736
public Long getNodeID();
3837

39-
public Date getClosedDate();
38+
public Long getChangeIDOnClose();
4039

41-
public void setClosedDate(Date closedDate);
40+
public void setChangeIDOnClose(Long changeIDOnClose);
4241

4342
public boolean isOpen();
4443

src/org/argmap/client/ViewPropVer.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.ArrayList;
44
import java.util.Collection;
5-
import java.util.Date;
65
import java.util.HashMap;
76
import java.util.List;
87
import java.util.Map;
@@ -13,15 +12,7 @@ public class ViewPropVer extends ViewProp implements ViewNodeVer {
1312
public List<ViewChange> viewChanges = new ArrayList<ViewChange>();
1413

1514
public Map<Long, ViewNodeVer> deletedViews = new HashMap<Long, ViewNodeVer>();
16-
public Date closedDate;
17-
18-
public Date getClosedDate() {
19-
return closedDate;
20-
}
21-
22-
public void setClosedDate(Date closedDate) {
23-
this.closedDate = closedDate;
24-
}
15+
public Long changeIDOnClose;
2516

2617
public ViewPropVer(Proposition proposition) {
2718
super(proposition);
@@ -142,4 +133,14 @@ public NodeChanges chooseNodeChanges(NodeChangesMaps changesMaps) {
142133
public void clearDeletedViews() {
143134
deletedViews.clear();
144135
}
136+
137+
@Override
138+
public Long getChangeIDOnClose() {
139+
return changeIDOnClose;
140+
}
141+
142+
@Override
143+
public void setChangeIDOnClose(Long changeIDOnClose) {
144+
this.changeIDOnClose = changeIDOnClose;
145+
}
145146
}

src/org/argmap/server/ArgMapServiceImpl.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.googlecode.objectify.Objectify;
4040
import com.googlecode.objectify.ObjectifyService;
4141
import com.googlecode.objectify.Query;
42+
import com.googlecode.objectify.helper.Monotonic;
4243

4344
public class ArgMapServiceImpl extends RemoteServiceServlet implements
4445
ArgMapService {
@@ -172,7 +173,7 @@ public Proposition addProp(Long parentArgID, int position, String content) {
172173
putNode(newProposition);
173174
}
174175

175-
Change change = new Change(ChangeType.PROP_ADDITION);
176+
Change change = getNewChange(ChangeType.PROP_ADDITION);
176177
change.propID = newProposition.id;
177178
change.argID = parentArgID;
178179
// TODO this line not needed any longer as we aren't doing forward
@@ -198,7 +199,7 @@ public void linkProposition(Long parentArgID, int position,
198199
putNode(argument);
199200
proposition.linkCount++;
200201
putNode(proposition);
201-
Change change = new Change(ChangeType.PROP_LINK);
202+
Change change = getNewChange(ChangeType.PROP_LINK);
202203
change.argID = parentArgID;
203204
change.propID = proposition.id;
204205
// TODO this line not needed any longer as we aren't doing forward
@@ -231,9 +232,9 @@ public void deleteProp(Long propID) throws ServiceException {
231232
}
232233
Change change;
233234
if (prop.root) {
234-
change = new Change(ChangeType.ROOT_PROP_DELETION);
235+
change = getNewChange(ChangeType.ROOT_PROP_DELETION);
235236
} else {
236-
change = new Change(ChangeType.PROP_DELETION);
237+
change = getNewChange(ChangeType.PROP_DELETION);
237238
}
238239
change.propID = prop.id;
239240
change.oldContent = prop.content;
@@ -307,7 +308,7 @@ public void unlinkProp(Long parentArgID, Long propositionID)
307308
proposition.linkCount--;
308309
putNode(proposition);
309310

310-
Change change = new Change(ChangeType.PROP_UNLINK);
311+
Change change = getNewChange(ChangeType.PROP_UNLINK);
311312
change.argID = parentArgID;
312313
change.propID = proposition.id;
313314
change.argPropIndex = propIndex;
@@ -325,7 +326,7 @@ public void updateProp(Long propID, String content) throws ServiceException {
325326
content = content.trim();
326327
logln("propID:" + propID + "; content:" + content);
327328

328-
Change change = new Change(ChangeType.PROP_MODIFICATION);
329+
Change change = getNewChange(ChangeType.PROP_MODIFICATION);
329330
Lock lock = Lock.getNodeLock(propID);
330331
try {
331332
lock.lock();
@@ -373,7 +374,7 @@ public void deleteArg(Long argID) throws ServiceException {
373374

374375
Proposition parentProp = propQuery.get();
375376

376-
Change argDeletionChange = new Change(ChangeType.ARG_DELETION);
377+
Change argDeletionChange = getNewChange(ChangeType.ARG_DELETION);
377378
argDeletionChange.propID = parentProp.id;
378379
argDeletionChange.argID = argument.id;
379380
argDeletionChange.argPro = argument.pro;
@@ -429,7 +430,7 @@ public Argument addArg(Long parentPropID, boolean pro) {
429430
timer.lap("\\\\");
430431
putNode(parentProp);
431432
timer.lap(";;;;");
432-
Change change = new Change(ChangeType.ARG_ADDITION);
433+
Change change = getNewChange(ChangeType.ARG_ADDITION);
433434
change.argID = newArg.id;
434435
change.propID = parentPropID;
435436
// TODO this line not needed any longer as we aren't doing forward
@@ -450,7 +451,7 @@ public void updateArg(Long argID, String content) throws ServiceException {
450451
Lock lock = Lock.getNodeLock(argID);
451452
try {
452453
lock.lock();
453-
Change change = new Change(ChangeType.ARG_MODIFICATION);
454+
Change change = getNewChange(ChangeType.ARG_MODIFICATION);
454455
Argument arg = ofy.get(Argument.class, argID);
455456
if (arg.content != null && arg.content.trim().equals(content)) {
456457
throw new ServiceException(
@@ -498,6 +499,23 @@ public HttpServletRequest getHttpServletRequest() {
498499
return getThreadLocalRequest();
499500
}
500501

502+
/*
503+
* this sets a new Change's id; it's here (instead of in the Change class
504+
* where it belongs) because it references a class not on the client and
505+
* Changes are sent to the client.
506+
*/
507+
public Change getNewChange() {
508+
Change change = new Change();
509+
change.id = Monotonic.next(ofy, Change.class, "id");
510+
return change;
511+
}
512+
513+
public Change getNewChange(ChangeType changeType) {
514+
Change change = getNewChange();
515+
change.changeType = changeType;
516+
return change;
517+
}
518+
501519
@Override
502520
public NodeChangesMaps getChanges(ArrayList<Long> propIDs,
503521
ArrayList<Long> argIDs) {
@@ -876,7 +894,7 @@ public PartialTrees replaceWithLinkAndGet(Long parentArgID,
876894

877895
/* only delete a proposition that is used in 1 or fewer arguments. */
878896
if (query.count() == 0) {
879-
Change change = new Change(ChangeType.PROP_DELETION);
897+
Change change = getNewChange(ChangeType.PROP_DELETION);
880898
change.propID = removeProp.id;
881899
change.oldContent = removeProp.content;
882900
change.propLinkCount = removeProp.linkCount;
@@ -890,7 +908,7 @@ public PartialTrees replaceWithLinkAndGet(Long parentArgID,
890908
* adding the link before deleting...]
891909
*/
892910
else if (query.count() == 1) {
893-
Change change = new Change(ChangeType.PROP_DELETION);
911+
Change change = getNewChange(ChangeType.PROP_DELETION);
894912
change.propID = removeProp.id;
895913
change.oldContent = removeProp.content;
896914
change.propLinkCount = removeProp.linkCount;
@@ -909,7 +927,7 @@ else if (query.count() == 1) {
909927
* argument where it is empty.
910928
*/
911929
else if (query.count() > 1) {
912-
Change change = new Change(ChangeType.PROP_UNLINK);
930+
Change change = getNewChange(ChangeType.PROP_UNLINK);
913931
change.argID = parentArgID;
914932
change.propID = removePropID;
915933
change.argPropIndex = index;
@@ -923,7 +941,7 @@ else if (query.count() > 1) {
923941
saveVersionInfo(change);
924942
}
925943

926-
Change change = new Change(ChangeType.PROP_LINK);
944+
Change change = getNewChange(ChangeType.PROP_LINK);
927945
change.argID = parentArgID;
928946
change.propID = linkPropID;
929947

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
<!-- Indices written at Mon, 20 Dec 2010 23:22:38 UTC -->
1+
<!-- Indices written at Tue, 21 Dec 2010 17:42:35 UTC -->
22

33
<datastore-indexes>
44

5-
<!-- Used 1 time in query history -->
5+
<!-- Used 4 times in query history -->
66
<datastore-index kind="Proposition" ancestor="false" source="auto">
77
<property name="root" direction="asc"/>
88
<property name="created" direction="desc"/>
99
</datastore-index>
1010

11+
<!-- Used 1 time in query history -->
12+
<datastore-index kind="Change" ancestor="false" source="auto">
13+
<property name="__key__" direction="desc"/>
14+
</datastore-index>
15+
1116
</datastore-indexes>

0 commit comments

Comments
 (0)