|
Lines 25-30
Link Here
|
| 25 |
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; |
25 |
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; |
| 26 |
import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta; |
26 |
import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta; |
| 27 |
import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta; |
27 |
import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta; |
|
|
28 |
import org.eclipse.emf.cdo.spi.common.revision.InternalCDOFeatureDelta.WithIndex; |
| 28 |
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; |
29 |
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; |
| 29 |
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager; |
30 |
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager; |
| 30 |
import org.eclipse.emf.cdo.view.CDOView; |
31 |
import org.eclipse.emf.cdo.view.CDOView; |
|
Lines 34-39
Link Here
|
| 34 |
import org.eclipse.emf.ecore.EcorePackage; |
35 |
import org.eclipse.emf.ecore.EcorePackage; |
| 35 |
import org.eclipse.emf.ecore.InternalEObject; |
36 |
import org.eclipse.emf.ecore.InternalEObject; |
| 36 |
|
37 |
|
|
|
38 |
import java.util.ArrayList; |
| 39 |
import java.util.List; |
| 37 |
import java.util.Set; |
40 |
import java.util.Set; |
| 38 |
|
41 |
|
| 39 |
/** |
42 |
/** |
|
Lines 42-47
Link Here
|
| 42 |
*/ |
45 |
*/ |
| 43 |
public class CDONotificationBuilder implements CDOFeatureDeltaVisitor |
46 |
public class CDONotificationBuilder implements CDOFeatureDeltaVisitor |
| 44 |
{ |
47 |
{ |
|
|
48 |
|
| 49 |
public class IndexData |
| 50 |
{ |
| 51 |
|
| 52 |
public int size; |
| 53 |
|
| 54 |
} |
| 55 |
|
| 45 |
private CDOView view; |
56 |
private CDOView view; |
| 46 |
|
57 |
|
| 47 |
private InternalEObject object; |
58 |
private InternalEObject object; |
|
Lines 126-138
Link Here
|
| 126 |
oldValue = view.getObject(id, false); |
137 |
oldValue = view.getObject(id, false); |
| 127 |
if (oldValue == null) |
138 |
if (oldValue == null) |
| 128 |
{ |
139 |
{ |
| 129 |
for (CDOObject detachedObject : detachedObjects) |
140 |
CDOObject cdoObject = findDetachedObjectsByCDOId(id); |
|
|
141 |
if (cdoObject != null) |
| 130 |
{ |
142 |
{ |
| 131 |
if (detachedObject.cdoID().equals(id)) |
143 |
oldValue = cdoObject; |
| 132 |
{ |
|
|
| 133 |
oldValue = detachedObject; |
| 134 |
break; |
| 135 |
} |
| 136 |
} |
144 |
} |
| 137 |
} |
145 |
} |
| 138 |
} |
146 |
} |
|
Lines 143-171
Link Here
|
| 143 |
public void visit(CDOSetFeatureDelta delta) |
151 |
public void visit(CDOSetFeatureDelta delta) |
| 144 |
{ |
152 |
{ |
| 145 |
EStructuralFeature feature = delta.getFeature(); |
153 |
EStructuralFeature feature = delta.getFeature(); |
| 146 |
add(new CDODeltaNotificationImpl(object, NotificationImpl.SET, getEFeatureID(feature), getOldValue(feature), delta |
154 |
|
| 147 |
.getValue())); |
155 |
Object oldValue = getOldValue(feature); |
|
|
156 |
|
| 157 |
if (oldValue instanceof CDOID) |
| 158 |
{ |
| 159 |
CDOID oldValueId = (CDOID)oldValue; |
| 160 |
CDOObject cdoObject = findDetachedObjectsByCDOId(oldValueId); |
| 161 |
if (cdoObject != null) |
| 162 |
{ |
| 163 |
oldValue = cdoObject; |
| 164 |
} |
| 165 |
} |
| 166 |
add(new CDODeltaNotificationImpl(object, NotificationImpl.SET, getEFeatureID(feature), oldValue, delta.getValue())); |
| 148 |
} |
167 |
} |
| 149 |
|
168 |
|
| 150 |
public void visit(CDOUnsetFeatureDelta delta) |
169 |
public void visit(CDOUnsetFeatureDelta delta) |
| 151 |
{ |
170 |
{ |
| 152 |
EStructuralFeature feature = delta.getFeature(); |
171 |
EStructuralFeature feature = delta.getFeature(); |
| 153 |
add(new CDODeltaNotificationImpl(object, NotificationImpl.UNSET, getEFeatureID(feature), getOldValue(feature), null)); |
172 |
|
|
|
173 |
Object oldValue = getOldValue(feature); |
| 174 |
|
| 175 |
if (oldValue instanceof CDOID) |
| 176 |
{ |
| 177 |
CDOID oldValueId = (CDOID)oldValue; |
| 178 |
CDOObject cdoObject = findDetachedObjectsByCDOId(oldValueId); |
| 179 |
if (cdoObject != null) |
| 180 |
{ |
| 181 |
oldValue = cdoObject; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
add(new CDODeltaNotificationImpl(object, NotificationImpl.UNSET, getEFeatureID(feature), oldValue, null)); |
| 154 |
} |
186 |
} |
| 155 |
|
187 |
|
| 156 |
public void visit(CDOListFeatureDelta deltas) |
188 |
public void visit(CDOListFeatureDelta deltas) |
| 157 |
{ |
189 |
{ |
|
|
190 |
|
| 191 |
patchIndices(deltas); |
| 192 |
|
| 158 |
for (CDOFeatureDelta delta : deltas.getListChanges()) |
193 |
for (CDOFeatureDelta delta : deltas.getListChanges()) |
| 159 |
{ |
194 |
{ |
| 160 |
delta.accept(this); |
195 |
delta.accept(this); |
| 161 |
} |
196 |
} |
| 162 |
} |
197 |
} |
| 163 |
|
198 |
|
|
|
199 |
private void patchIndices(CDOListFeatureDelta deltas) |
| 200 |
{ |
| 201 |
List<CDOFeatureDelta> rest = new ArrayList<CDOFeatureDelta>(); |
| 202 |
rest.addAll(deltas.getListChanges()); |
| 203 |
for (CDOFeatureDelta delta : deltas.getListChanges()) |
| 204 |
{ |
| 205 |
rest.remove(delta); |
| 206 |
if (delta instanceof CDOAddFeatureDelta) |
| 207 |
{ |
| 208 |
CDOAddFeatureDelta addDelta = (CDOAddFeatureDelta)delta; |
| 209 |
for (CDOFeatureDelta cdoFeatureDelta : rest) |
| 210 |
{ |
| 211 |
if (cdoFeatureDelta instanceof CDOClearFeatureDelta) |
| 212 |
{ |
| 213 |
break; |
| 214 |
} |
| 215 |
|
| 216 |
if (cdoFeatureDelta instanceof WithIndex) |
| 217 |
{ |
| 218 |
WithIndex withIndex = (WithIndex)cdoFeatureDelta; |
| 219 |
withIndex.adjustAfterRemoval(addDelta.getIndex()); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
} |
| 224 |
else if (delta instanceof CDORemoveFeatureDelta) |
| 225 |
{ |
| 226 |
CDORemoveFeatureDelta removeDelta = (CDORemoveFeatureDelta)delta; |
| 227 |
for (CDOFeatureDelta cdoFeatureDelta : rest) |
| 228 |
{ |
| 229 |
if (cdoFeatureDelta instanceof CDOClearFeatureDelta) |
| 230 |
{ |
| 231 |
break; |
| 232 |
} |
| 233 |
if (cdoFeatureDelta instanceof WithIndex) |
| 234 |
{ |
| 235 |
WithIndex withIndex = (WithIndex)cdoFeatureDelta; |
| 236 |
withIndex.adjustAfterAddition(removeDelta.getIndex()); |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
else if (delta instanceof CDOClearFeatureDelta) |
| 241 |
{ |
| 242 |
// Nothing to do :-) |
| 243 |
|
| 244 |
} |
| 245 |
else if (delta instanceof CDOMoveFeatureDelta) |
| 246 |
{ |
| 247 |
CDOMoveFeatureDelta moveDelta = (CDOMoveFeatureDelta)delta; |
| 248 |
|
| 249 |
for (CDOFeatureDelta cdoFeatureDelta : rest) |
| 250 |
{ |
| 251 |
|
| 252 |
if (cdoFeatureDelta instanceof CDOClearFeatureDelta) |
| 253 |
{ |
| 254 |
break; |
| 255 |
} |
| 256 |
|
| 257 |
if (cdoFeatureDelta instanceof WithIndex) |
| 258 |
{ |
| 259 |
WithIndex withIndex = (WithIndex)cdoFeatureDelta; |
| 260 |
withIndex.adjustAfterAddition(moveDelta.getOldPosition()); |
| 261 |
withIndex.adjustAfterRemoval(moveDelta.getNewPosition()); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
} |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 164 |
public void visit(CDOClearFeatureDelta delta) |
269 |
public void visit(CDOClearFeatureDelta delta) |
| 165 |
{ |
270 |
{ |
|
|
271 |
|
| 166 |
EStructuralFeature feature = delta.getFeature(); |
272 |
EStructuralFeature feature = delta.getFeature(); |
| 167 |
add(new CDODeltaNotificationImpl(object, NotificationImpl.REMOVE_MANY, getEFeatureID(feature), |
273 |
Object oldValue = getOldValue(feature); |
| 168 |
getOldValue(feature), null)); |
274 |
if (oldValue instanceof List<?>) |
|
|
275 |
{ |
| 276 |
List<?> idList = (List<?>)oldValue; |
| 277 |
if (!idList.isEmpty() && idList.get(0) instanceof CDOID) |
| 278 |
{ |
| 279 |
List<CDOObject> oldValueObjects = new ArrayList<CDOObject>(idList.size()); |
| 280 |
List<CDOID> cdoIdList = (List<CDOID>)idList; |
| 281 |
for (CDOID cdoId : cdoIdList) |
| 282 |
{ |
| 283 |
CDOObject oldObject = findDetachedObjectsByCDOId(cdoId); |
| 284 |
if (oldObject != null) |
| 285 |
{ |
| 286 |
oldValueObjects.add(oldObject); |
| 287 |
} |
| 288 |
} |
| 289 |
oldValue = oldValueObjects; |
| 290 |
} |
| 291 |
|
| 292 |
} |
| 293 |
|
| 294 |
add(new CDODeltaNotificationImpl(object, NotificationImpl.REMOVE_MANY, getEFeatureID(feature), oldValue, null)); |
| 295 |
} |
| 296 |
|
| 297 |
private CDOObject findDetachedObjectsByCDOId(CDOID cdoid) |
| 298 |
{ |
| 299 |
if (detachedObjects != null) |
| 300 |
{ |
| 301 |
for (CDOObject cdoObject : detachedObjects) |
| 302 |
{ |
| 303 |
if (cdoObject.cdoID().equals(cdoid)) |
| 304 |
{ |
| 305 |
return cdoObject; |
| 306 |
} |
| 307 |
} |
| 308 |
} |
| 309 |
return null; |
| 169 |
} |
310 |
} |
| 170 |
|
311 |
|
| 171 |
public void visit(CDOContainerFeatureDelta delta) |
312 |
public void visit(CDOContainerFeatureDelta delta) |
|
Lines 174-179
Link Here
|
| 174 |
if (oldRevision != null) |
315 |
if (oldRevision != null) |
| 175 |
{ |
316 |
{ |
| 176 |
oldValue = oldRevision.getContainerID(); |
317 |
oldValue = oldRevision.getContainerID(); |
|
|
318 |
|
| 319 |
if (oldValue instanceof CDOID) |
| 320 |
{ |
| 321 |
CDOID oldValueId = (CDOID)oldValue; |
| 322 |
CDOObject cdoObject = findDetachedObjectsByCDOId(oldValueId); |
| 323 |
if (cdoObject != null) |
| 324 |
{ |
| 325 |
oldValue = cdoObject; |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 177 |
} |
329 |
} |
| 178 |
|
330 |
|
| 179 |
add(new CDODeltaNotificationImpl(object, NotificationImpl.SET, EcorePackage.eINSTANCE.eContainmentFeature(), |
331 |
add(new CDODeltaNotificationImpl(object, NotificationImpl.SET, EcorePackage.eINSTANCE.eContainmentFeature(), |