1. Detecting Conflicts in Put()
WORK IN PROGRESS
+------------+--------------+--------------+---------------+--------------+------------------+ | LUID | Comparison With Existing Data | No Existing Data | + +--------------+--------------+---------------+--------------+ + | | *Newer* | *Older* | *Equal* | *Unknown* | | +------------+--------------+--------------+---------------+--------------+------------------+ | Known | Put (1) | Conflict (2) | Skip (3) | Conflict (4) | Put (5) | +------------+--------------+--------------+---------------+--------------+------------------+ | Unknown | Conflict (2) | Conflict (2) | Skip (3) | Conflict (4) | Put (5) | +------------+--------------+--------------+---------------+--------------+------------------+
Pseudo-code
1 def put(self, data, overwrite, LUID=None):
2 DataProvider.TwoWay.put(self, data, overwrite, LUID)
3 if overwrite and LUID:
4 LUID = self._replace_data(LUID, data)
5 else:
6 if LUID and self._data_exists(LUID):
7 oldData = self._get_data(LUID)
8 comp = data.compare(oldData)
9 #Possibility 1: If LUID != None (i.e this is a modification/update of a
10 #previous sync, and we are newer, the go ahead an put the data
11 if LUID != None and comp == conduit.datatypes.COMPARISON_NEWER:
12 LUID = self._replace_data(LUID, data)
13 #Possibility 3: We are the same, so return either rid
14 elif comp == conduit.datatypes.COMPARISON_EQUAL:
15 return oldData.get_rid()
16 #Possibility 2, 4: All that remains are conflicts
17 else:
18 raise Exceptions.SynchronizeConflictError(comp, data, oldData)
19 else:
20 #Possibility 5:
21 LUID = self._put_data(data)
22
23 #now return the rid
24 if not LUID:
25 raise Exceptions.SyncronizeError("Error putting/updating data")
26 else:
27 return self._get_data(LUID).get_rid()