3939import com .googlecode .objectify .Objectify ;
4040import com .googlecode .objectify .ObjectifyService ;
4141import com .googlecode .objectify .Query ;
42+ import com .googlecode .objectify .helper .Monotonic ;
4243
4344public 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
0 commit comments