Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 250486 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/emf/cdo/CDOView.java (-11 / +19 lines)
Lines 199-214 Link Here
199
  public void setInvalidationNotificationEnabled(boolean enabled);
199
  public void setInvalidationNotificationEnabled(boolean enabled);
200
200
201
  /**
201
  /**
202
   * Returns the current {@link CDOChangeSubscriptionPolicy change subscription policy}.
202
   * Returns the current {@link CDOAdapterPolicy change subscription policy}.
203
   * 
203
   * 
204
   * @return The current change subscription policy, never <code>null</code>.
204
   * @return The current change subscription policy, never <code>null</code>.
205
   * @see #setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy)
205
   * @see #setChangeSubscriptionPolicy(CDOAdapterPolicy)
206
   * @since 2.0
206
   * @since 2.0
207
   */
207
   */
208
  public CDOChangeSubscriptionPolicy getChangeSubscriptionPolicy();
208
  public CDOAdapterPolicy getChangeSubscriptionPolicy();
209
209
210
  /**
210
  /**
211
   * Specifies the change subscription policy. By default, the value is set to {@link CDOChangeSubscriptionPolicy#NONE}.
211
   * Specifies the change subscription policy. By default, the value is set to {@link CDOAdapterPolicy#NONE}.
212
   * <p>
212
   * <p>
213
   * To activate the policy, you must do the following: <br>
213
   * To activate the policy, you must do the following: <br>
214
   * <code>transaction.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);</code>
214
   * <code>transaction.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);</code>
Lines 219-230 Link Here
219
   * By activating this feature, each object having at least one adapter that matches the current policy will be
219
   * By activating this feature, each object having at least one adapter that matches the current policy will be
220
   * registered with the server and will be notified for each change occurring in the scope of any other transaction.
220
   * registered with the server and will be notified for each change occurring in the scope of any other transaction.
221
   * <p>
221
   * <p>
222
   * {@link CDOChangeSubscriptionPolicy#NONE} - Disabled. <br>
222
   * {@link CDOAdapterPolicy#NONE} - Disabled. <br>
223
   * {@link CDOChangeSubscriptionPolicy#ALL} - Enabled for all adapters used.<br>
223
   * {@link CDOAdapterPolicy#ALL} - Enabled for all adapters used.<br>
224
   * {@link CDOChangeSubscriptionPolicy#ONLY_CDO_ADAPTER} - Enabled only for adapters that implement {@link CDOAdapter}.
224
   * {@link CDOAdapterPolicy#ONLY_CDO_ADAPTER} - Enabled only for adapters that implement {@link CDOAdapter}. <br>
225
   * <br>
225
   * Any other class that implement {@link CDOAdapterPolicy} will enable for whatever rules defined in that class. <br>
226
   * Any other class that implement {@link CDOChangeSubscriptionPolicy} will enable for whatever rules defined in that
227
   * class. <br>
228
   * <p>
226
   * <p>
229
   * If <code>myAdapter</code> in the above example matches the current policy, <code>eObject</code> will be registered
227
   * If <code>myAdapter</code> in the above example matches the current policy, <code>eObject</code> will be registered
230
   * with the server and you will receive all changes from other transaction.
228
   * with the server and you will receive all changes from other transaction.
Lines 239-245 Link Here
239
   * 
237
   * 
240
   * @since 2.0
238
   * @since 2.0
241
   */
239
   */
242
  public void setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy policy);
240
  public void setChangeSubscriptionPolicy(CDOAdapterPolicy policy);
241
242
  /**
243
   * @since 2.0
244
   */
245
  public CDOAdapterPolicy getStrongReferencePolicy();
246
247
  /**
248
   * @since 2.0
249
   */
250
  public void setStrongReferencePolicy(CDOAdapterPolicy policy);
243
251
244
  /**
252
  /**
245
   * @since 2.0
253
   * @since 2.0
(-)src/org/eclipse/emf/cdo/CDOTransactionHandler.java (-1 / +11 lines)
Lines 48-55 Link Here
48
   * Called by a <code>CDOTransaction</code> <b>before</b> it is being committed. The implementor of this method is
48
   * Called by a <code>CDOTransaction</code> <b>before</b> it is being committed. The implementor of this method is
49
   * allowed to throw an unchecked exception that will propagate up to the operation that is about to commit the
49
   * allowed to throw an unchecked exception that will propagate up to the operation that is about to commit the
50
   * transaction.
50
   * transaction.
51
   * 
52
   * @since 2.0
53
   */
54
  public void committingTransaction(CDOTransaction transaction, CDOCommitContext commitContext);
55
56
  /**
57
   * Called by a <code>CDOTransaction</code> <b>after</b> it is being committed. The implementor of this method is
58
   * <b>not</b> allowed to throw an unchecked exception.
59
   * 
60
   * @since 2.0
51
   */
61
   */
52
  public void committingTransaction(CDOTransaction transaction);
62
  public void committedTransaction(CDOTransaction transaction, CDOCommitContext commitContext);
53
63
54
  /**
64
  /**
55
   * Called by a <code>CDOTransaction</code> <b>after</b> it is rolled back. If the implementor of this method throws an
65
   * Called by a <code>CDOTransaction</code> <b>after</b> it is rolled back. If the implementor of this method throws an
(-)src/org/eclipse/emf/cdo/CDOInvalidationNotification.java (-1 / +1 lines)
Lines 25-31 Link Here
25
 * 
25
 * 
26
 * @author Simon McDuff
26
 * @author Simon McDuff
27
 * @see CDOSessionInvalidationEvent
27
 * @see CDOSessionInvalidationEvent
28
 * @see CDOChangeSubscriptionPolicy
28
 * @see CDOAdapterPolicy
29
 * @noimplement This interface is not intended to be implemented by clients.
29
 * @noimplement This interface is not intended to be implemented by clients.
30
 */
30
 */
31
public interface CDOInvalidationNotification extends CDONotification
31
public interface CDOInvalidationNotification extends CDONotification
(-)src/org/eclipse/emf/cdo/CDOSessionInvalidationEvent.java (-1 / +1 lines)
Lines 26-32 Link Here
26
 * 
26
 * 
27
 * @author Eike Stepper
27
 * @author Eike Stepper
28
 * @see CDOInvalidationNotification
28
 * @see CDOInvalidationNotification
29
 * @see CDOChangeSubscriptionPolicy
29
 * @see CDOAdapterPolicy
30
 * @noimplement This interface is not intended to be implemented by clients.
30
 * @noimplement This interface is not intended to be implemented by clients.
31
 */
31
 */
32
public interface CDOSessionInvalidationEvent extends CDOSessionEvent
32
public interface CDOSessionInvalidationEvent extends CDOSessionEvent
(-)src/org/eclipse/emf/cdo/CDOViewInvalidationEvent.java (-1 / +1 lines)
Lines 20-26 Link Here
20
 * 
20
 * 
21
 * @author Simon McDuff
21
 * @author Simon McDuff
22
 * @see CDOInvalidationNotification
22
 * @see CDOInvalidationNotification
23
 * @see CDOChangeSubscriptionPolicy
23
 * @see CDOAdapterPolicy
24
 * @noimplement This interface is not intended to be implemented by clients.
24
 * @noimplement This interface is not intended to be implemented by clients.
25
 * @since 2.0
25
 * @since 2.0
26
 */
26
 */
(-)src/org/eclipse/emf/cdo/CDOChangeSubscriptionPolicy.java (-78 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo;
13
14
import org.eclipse.emf.common.notify.Adapter;
15
import org.eclipse.emf.ecore.EObject;
16
17
/**
18
 * Specifies a change subscription policy.
19
 * <p>
20
 * To activate a policy, you must do the following: <br>
21
 * <code>view.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);</code>
22
 * <p>
23
 * To register an object, you must add an adapter to the object in which you are interested:<br>
24
 * <code>eObject.eAdapters().add(myAdapter);</code>
25
 * <p>
26
 * By activating this feature, each object having at least one adapter that matches the current policy will be
27
 * registered with the server and will be notified for each change occurring in the scope of any other transaction.
28
 * <p>
29
 * {@link CDOChangeSubscriptionPolicy#NONE} - Disabled. <br>
30
 * {@link CDOChangeSubscriptionPolicy#ALL} - Enabled for all adapters used.<br>
31
 * {@link CDOChangeSubscriptionPolicy#ONLY_CDO_ADAPTER} - Enabled only for adapters that implement {@link CDOAdapter}. <br>
32
 * Any other class that implement {@link CDOChangeSubscriptionPolicy} will enable for whatever rules defined in that
33
 * class. <br>
34
 * <p>
35
 * If <code>myAdapter</code> in the above example matches the current policy, <code>eObject</code> will be registered
36
 * with the server and you will receive all changes from other transaction.
37
 * <p>
38
 * When the policy is changed all objects in the cache will automatically be recalculated.
39
 * <p>
40
 * You can subscribe to temporary objects. Even if you cannot receive notifications from other {@link CDOTransaction}
41
 * for these because they are only local to you, at commit time these objects will be registered automatically.
42
 * <p>
43
 * <b>Note:</b> It can be used with <code>CDOSession.setPassiveUpdate(false)</code>. In this case, it will receive
44
 * changes without having the objects changed.
45
 * 
46
 * @author Simon McDuff
47
 * @see CDOSessionInvalidationEvent
48
 * @see CDOInvalidationNotification
49
 * @since 2.0
50
 */
51
public interface CDOChangeSubscriptionPolicy
52
{
53
  public static final CDOChangeSubscriptionPolicy NONE = new CDOChangeSubscriptionPolicy()
54
  {
55
    public boolean shouldSubscribe(EObject eObject, Adapter adapter)
56
    {
57
      return false;
58
    }
59
  };
60
61
  public static final CDOChangeSubscriptionPolicy ONLY_CDO_ADAPTER = new CDOChangeSubscriptionPolicy()
62
  {
63
    public boolean shouldSubscribe(EObject eObject, Adapter adapter)
64
    {
65
      return adapter instanceof CDOAdapter;
66
    }
67
  };
68
69
  public static final CDOChangeSubscriptionPolicy ALL = new CDOChangeSubscriptionPolicy()
70
  {
71
    public boolean shouldSubscribe(EObject eObject, Adapter adapter)
72
    {
73
      return true;
74
    }
75
  };
76
77
  public boolean shouldSubscribe(EObject eObject, Adapter adapter);
78
}
(-)src/org/eclipse/emf/internal/cdo/CDOViewImpl.java (-20 / +166 lines)
Lines 12-18 Link Here
12
 **************************************************************************/
12
 **************************************************************************/
13
package org.eclipse.emf.internal.cdo;
13
package org.eclipse.emf.internal.cdo;
14
14
15
import org.eclipse.emf.cdo.CDOChangeSubscriptionPolicy;
15
import org.eclipse.emf.cdo.CDOAdapterPolicy;
16
import org.eclipse.emf.cdo.CDOFeatureAnalyzer;
16
import org.eclipse.emf.cdo.CDOFeatureAnalyzer;
17
import org.eclipse.emf.cdo.CDONotification;
17
import org.eclipse.emf.cdo.CDONotification;
18
import org.eclipse.emf.cdo.CDOObject;
18
import org.eclipse.emf.cdo.CDOObject;
Lines 64-69 Link Here
64
import org.eclipse.net4j.util.WrappedException;
64
import org.eclipse.net4j.util.WrappedException;
65
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
65
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
66
import org.eclipse.net4j.util.collection.CloseableIterator;
66
import org.eclipse.net4j.util.collection.CloseableIterator;
67
import org.eclipse.net4j.util.collection.HashBag;
67
import org.eclipse.net4j.util.concurrent.RWLockManager;
68
import org.eclipse.net4j.util.concurrent.RWLockManager;
68
import org.eclipse.net4j.util.om.trace.ContextTracer;
69
import org.eclipse.net4j.util.om.trace.ContextTracer;
69
import org.eclipse.net4j.util.ref.ReferenceType;
70
import org.eclipse.net4j.util.ref.ReferenceType;
Lines 124-129 Link Here
124
125
125
  private CDOResourceImpl rootResource;
126
  private CDOResourceImpl rootResource;
126
127
128
  private ChangeSubscriptionManager changeSubscriptionManager = createChangeSubscriptionManager();
129
130
  private ViewAdapterManager adapterPolicyManager = createAdapterManager();
131
132
  private CDOAdapterPolicy changeSubscriptionPolicy = CDOAdapterPolicy.NONE;
133
134
  private CDOAdapterPolicy adapterReferencePolicy = CDOAdapterPolicy.NONE;
135
127
  @ExcludeFromDump
136
  @ExcludeFromDump
128
  private transient CDOID lastLookupID;
137
  private transient CDOID lastLookupID;
129
138
Lines 133-148 Link Here
133
  /**
142
  /**
134
   * @since 2.0
143
   * @since 2.0
135
   */
144
   */
136
  private ChangeSubscriptionManager changeSubscriptionManager = new ChangeSubscriptionManager();
137
138
  /**
139
   * @since 2.0
140
   */
141
  private CDOChangeSubscriptionPolicy changeSubscriptionPolicy = CDOChangeSubscriptionPolicy.NONE;
142
143
  /**
144
   * @since 2.0
145
   */
146
  public CDOViewImpl(InternalCDOSession session, int viewID)
145
  public CDOViewImpl(InternalCDOSession session, int viewID)
147
  {
146
  {
148
    this.session = session;
147
    this.session = session;
Lines 339-345 Link Here
339
  /**
338
  /**
340
   * @since 2.0
339
   * @since 2.0
341
   */
340
   */
342
  public CDOChangeSubscriptionPolicy getChangeSubscriptionPolicy()
341
  public CDOAdapterPolicy getChangeSubscriptionPolicy()
343
  {
342
  {
344
    return changeSubscriptionPolicy;
343
    return changeSubscriptionPolicy;
345
  }
344
  }
Lines 347-357 Link Here
347
  /**
346
  /**
348
   * @since 2.0
347
   * @since 2.0
349
   */
348
   */
350
  public void setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy subscriptionPolicy)
349
  public void setChangeSubscriptionPolicy(CDOAdapterPolicy subscriptionPolicy)
351
  {
350
  {
352
    if (subscriptionPolicy == null)
351
    if (subscriptionPolicy == null)
353
    {
352
    {
354
      subscriptionPolicy = CDOChangeSubscriptionPolicy.NONE;
353
      subscriptionPolicy = CDOAdapterPolicy.NONE;
355
    }
354
    }
356
355
357
    if (changeSubscriptionPolicy != subscriptionPolicy)
356
    if (changeSubscriptionPolicy != subscriptionPolicy)
Lines 364-369 Link Here
364
  /**
363
  /**
365
   * @since 2.0
364
   * @since 2.0
366
   */
365
   */
366
  public CDOAdapterPolicy getStrongReferencePolicy()
367
  {
368
    return adapterReferencePolicy;
369
  }
370
371
  /**
372
   * @since 2.0
373
   */
374
  public void setStrongReferencePolicy(CDOAdapterPolicy adapterPolicy)
375
  {
376
    if (adapterPolicy == null)
377
    {
378
      adapterPolicy = CDOAdapterPolicy.NONE;
379
    }
380
381
    if (adapterReferencePolicy != adapterPolicy)
382
    {
383
      adapterReferencePolicy = adapterPolicy;
384
      adapterPolicyManager.reset();
385
    }
386
  }
387
388
  /**
389
   * @since 2.0
390
   */
367
  public CDORevisionPrefetchingPolicy getRevisionPrefetchingPolicy()
391
  public CDORevisionPrefetchingPolicy getRevisionPrefetchingPolicy()
368
  {
392
  {
369
    return revisionPrefetchingPolicy;
393
    return revisionPrefetchingPolicy;
Lines 1213-1219 Link Here
1213
   */
1237
   */
1214
  public void handleChangeSubscription(Collection<CDORevisionDelta> deltas, Collection<CDOID> detachedObjects)
1238
  public void handleChangeSubscription(Collection<CDORevisionDelta> deltas, Collection<CDOID> detachedObjects)
1215
  {
1239
  {
1216
    if (getChangeSubscriptionPolicy() != CDOChangeSubscriptionPolicy.NONE)
1240
    if (getChangeSubscriptionPolicy() != CDOAdapterPolicy.NONE)
1217
    {
1241
    {
1218
      if (deltas != null)
1242
      if (deltas != null)
1219
      {
1243
      {
Lines 1253-1258 Link Here
1253
  /**
1277
  /**
1254
   * @since 2.0
1278
   * @since 2.0
1255
   */
1279
   */
1280
  protected ChangeSubscriptionManager createChangeSubscriptionManager()
1281
  {
1282
    return new ChangeSubscriptionManager();
1283
  }
1284
1285
  /**
1286
   * @since 2.0
1287
   */
1288
  public ViewAdapterManager getAdapterManager()
1289
  {
1290
    return adapterPolicyManager;
1291
  }
1292
1293
  /**
1294
   * @since 2.0
1295
   */
1296
  protected ViewAdapterManager createAdapterManager()
1297
  {
1298
    return new ViewAdapterManager();
1299
  }
1300
1301
  /**
1302
   * @since 2.0
1303
   */
1304
  public void handleAddAdapter(InternalCDOObject eObject, Adapter adapter)
1305
  {
1306
    if (!FSMUtil.isNew(eObject))
1307
    {
1308
      subscribe(eObject, adapter);
1309
    }
1310
1311
    adapterPolicyManager.attachAdapter(eObject, adapter);
1312
  }
1313
1314
  /**
1315
   * @since 2.0
1316
   */
1317
  public void handleRemoveAdapter(InternalCDOObject eObject, Adapter adapter)
1318
  {
1319
    if (!FSMUtil.isNew(eObject))
1320
    {
1321
      unsubscribe(eObject, adapter);
1322
    }
1323
1324
    adapterPolicyManager.detachAdapter(eObject, adapter);
1325
  }
1326
1327
  /**
1328
   * @since 2.0
1329
   */
1256
  public void subscribe(EObject eObject, Adapter adapter)
1330
  public void subscribe(EObject eObject, Adapter adapter)
1257
  {
1331
  {
1258
    changeSubscriptionManager.subscribe(eObject, adapter);
1332
    changeSubscriptionManager.subscribe(eObject, adapter);
Lines 1492-1497 Link Here
1492
   * @author Simon McDuff
1566
   * @author Simon McDuff
1493
   * @since 2.0
1567
   * @since 2.0
1494
   */
1568
   */
1569
  protected class ViewAdapterManager
1570
  {
1571
    protected Set<CDOObject> objects = new HashBag<CDOObject>();
1572
1573
    public ViewAdapterManager()
1574
    {
1575
    }
1576
1577
    protected synchronized void attachObject(CDOObject object)
1578
    {
1579
      int count = 0;
1580
      for (Adapter adapter : object.eAdapters())
1581
      {
1582
        if (adapterReferencePolicy.isValid(object, adapter))
1583
        {
1584
          count++;
1585
        }
1586
      }
1587
1588
      for (int i = 0; i < count; i++)
1589
      {
1590
        objects.add(object);
1591
      }
1592
    }
1593
1594
    protected synchronized void detachObject(CDOObject object)
1595
    {
1596
      while (objects.remove(object))
1597
      {
1598
        // Do nothing
1599
      }
1600
    }
1601
1602
    protected synchronized void attachAdapter(CDOObject object, Adapter adapter)
1603
    {
1604
      if (getStrongReferencePolicy().isValid(object, adapter))
1605
      {
1606
        objects.add(object);
1607
      }
1608
    }
1609
1610
    protected synchronized void detachAdapter(CDOObject object, Adapter adapter)
1611
    {
1612
      if (getStrongReferencePolicy().isValid(object, adapter))
1613
      {
1614
        objects.add(object);
1615
      }
1616
    }
1617
1618
    public synchronized void reset()
1619
    {
1620
      // Keep the object in memory
1621
      Set<CDOObject> oldObject = objects;
1622
      objects = new HashBag<CDOObject>();
1623
      if (getStrongReferencePolicy() != CDOAdapterPolicy.NONE)
1624
      {
1625
        InternalCDOObject objects[] = getObjectsArray();
1626
        for (int i = 0; i < objects.length; i++)
1627
        {
1628
          InternalCDOObject object = objects[i];
1629
          attachObject(object);
1630
        }
1631
      }
1632
1633
      oldObject.clear();
1634
    }
1635
  };
1636
1637
  /**
1638
   * @author Simon McDuff
1639
   * @since 2.0
1640
   */
1495
  protected class ChangeSubscriptionManager
1641
  protected class ChangeSubscriptionManager
1496
  {
1642
  {
1497
    private Map<CDOID, SubscribeEntry> subscriptions = new HashMap<CDOID, SubscribeEntry>()
1643
    private Map<CDOID, SubscribeEntry> subscriptions = new HashMap<CDOID, SubscribeEntry>()
Lines 1518-1524 Link Here
1518
      {
1664
      {
1519
        subscriptions.clear();
1665
        subscriptions.clear();
1520
        List<CDOID> cdoIDs = new ArrayList<CDOID>();
1666
        List<CDOID> cdoIDs = new ArrayList<CDOID>();
1521
        if (changeSubscriptionPolicy != CDOChangeSubscriptionPolicy.NONE)
1667
        if (changeSubscriptionPolicy != CDOAdapterPolicy.NONE)
1522
        {
1668
        {
1523
          for (InternalCDOObject cdoObject : getObjectsArray())
1669
          for (InternalCDOObject cdoObject : getObjectsArray())
1524
          {
1670
          {
Lines 1605-1611 Link Here
1605
        {
1751
        {
1606
          for (Adapter adapter : object.eAdapters())
1752
          for (Adapter adapter : object.eAdapters())
1607
          {
1753
          {
1608
            if (changeSubscriptionPolicy.shouldSubscribe(object, adapter))
1754
            if (changeSubscriptionPolicy.isValid(object, adapter))
1609
            {
1755
            {
1610
              count++;
1756
              count++;
1611
            }
1757
            }
Lines 1620-1626 Link Here
1620
    {
1766
    {
1621
      synchronized (subscriptions)
1767
      synchronized (subscriptions)
1622
      {
1768
      {
1623
        if (getChangeSubscriptionPolicy().shouldSubscribe(eObject, adapter))
1769
        if (getChangeSubscriptionPolicy().isValid(eObject, adapter))
1624
        {
1770
        {
1625
          InternalCDOObject internalCDOObject = FSMUtil.adapt(eObject, CDOViewImpl.this);
1771
          InternalCDOObject internalCDOObject = FSMUtil.adapt(eObject, CDOViewImpl.this);
1626
          if (internalCDOObject.cdoView() != CDOViewImpl.this)
1772
          if (internalCDOObject.cdoView() != CDOViewImpl.this)
Lines 1648-1654 Link Here
1648
          }
1794
          }
1649
1795
1650
          // Notification need to be enable to send correct value to the server
1796
          // Notification need to be enable to send correct value to the server
1651
          if (getChangeSubscriptionPolicy() != CDOChangeSubscriptionPolicy.NONE)
1797
          if (getChangeSubscriptionPolicy() != CDOAdapterPolicy.NONE)
1652
          {
1798
          {
1653
            request(Collections.singletonList(id), false, true);
1799
            request(Collections.singletonList(id), false, true);
1654
          }
1800
          }
Lines 1666-1672 Link Here
1666
          subscriptions.remove(id);
1812
          subscriptions.remove(id);
1667
1813
1668
          // Notification need to be enable to send correct value to the server
1814
          // Notification need to be enable to send correct value to the server
1669
          if (getChangeSubscriptionPolicy() != CDOChangeSubscriptionPolicy.NONE)
1815
          if (getChangeSubscriptionPolicy() != CDOAdapterPolicy.NONE)
1670
          {
1816
          {
1671
            request(Collections.singletonList(id), false, false);
1817
            request(Collections.singletonList(id), false, false);
1672
          }
1818
          }
(-)src/org/eclipse/emf/internal/cdo/CDOXATransactionCommitContext.java (-3 / +3 lines)
Lines 38-44 Link Here
38
 * @author Simon McDuff
38
 * @author Simon McDuff
39
 * @since 2.0
39
 * @since 2.0
40
 */
40
 */
41
public class CDOXATransactionCommitContext implements Callable<Object>, CDOIDProvider, CDOCommitContext
41
public class CDOXATransactionCommitContext implements Callable<Object>, CDOIDProvider, InternalCDOCommitContext
42
{
42
{
43
  private CDOXATransactionImpl transactionManager;
43
  private CDOXATransactionImpl transactionManager;
44
44
Lines 48-60 Link Here
48
48
49
  private CommitTransactionResult result;
49
  private CommitTransactionResult result;
50
50
51
  private CDOCommitContext delegateCommitContext;
51
  private InternalCDOCommitContext delegateCommitContext;
52
52
53
  private Map<CDOIDExternalTempImpl, InternalCDOTransaction> requestedIDs = new HashMap<CDOIDExternalTempImpl, InternalCDOTransaction>();
53
  private Map<CDOIDExternalTempImpl, InternalCDOTransaction> requestedIDs = new HashMap<CDOIDExternalTempImpl, InternalCDOTransaction>();
54
54
55
  private Map<InternalCDOObject, CDOIDExternalTempImpl> objectToID = new HashMap<InternalCDOObject, CDOIDExternalTempImpl>();
55
  private Map<InternalCDOObject, CDOIDExternalTempImpl> objectToID = new HashMap<InternalCDOObject, CDOIDExternalTempImpl>();
56
56
57
  public CDOXATransactionCommitContext(CDOXATransactionImpl manager, CDOCommitContext commitContext)
57
  public CDOXATransactionCommitContext(CDOXATransactionImpl manager, InternalCDOCommitContext commitContext)
58
  {
58
  {
59
    transactionManager = manager;
59
    transactionManager = manager;
60
    delegateCommitContext = commitContext;
60
    delegateCommitContext = commitContext;
(-)src/org/eclipse/emf/internal/cdo/CDOCommitContext.java (-50 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo;
13
14
import org.eclipse.emf.cdo.CDOObject;
15
import org.eclipse.emf.cdo.common.id.CDOID;
16
import org.eclipse.emf.cdo.common.model.CDOPackage;
17
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
18
import org.eclipse.emf.cdo.eresource.CDOResource;
19
20
import org.eclipse.emf.internal.cdo.protocol.CommitTransactionResult;
21
22
import java.util.List;
23
import java.util.Map;
24
25
/**
26
 * Provides a context for a commit operation.
27
 * 
28
 * @author Simon McDuff
29
 * @since 2.0
30
 */
31
public interface CDOCommitContext
32
{
33
  public InternalCDOTransaction getTransaction();
34
35
  public void preCommit();
36
37
  public void postCommit(CommitTransactionResult result);
38
39
  public List<CDOPackage> getNewPackages();
40
41
  public Map<CDOID, CDOResource> getNewResources();
42
43
  public Map<CDOID, CDOObject> getNewObjects();
44
45
  public Map<CDOID, CDOObject> getDirtyObjects();
46
47
  public Map<CDOID, CDORevisionDelta> getRevisionDeltas();
48
49
  public Map<CDOID, CDOObject> getDetachedObjects();
50
}
(-)src/org/eclipse/emf/internal/cdo/InternalCDOTransaction.java (-1 / +1 lines)
Lines 25-31 Link Here
25
 */
25
 */
26
public interface InternalCDOTransaction extends CDOTransaction, InternalCDOView
26
public interface InternalCDOTransaction extends CDOTransaction, InternalCDOView
27
{
27
{
28
  public CDOCommitContext createCommitContext();
28
  public InternalCDOCommitContext createCommitContext();
29
29
30
  public void handleRollback(CDOSavepoint savepoint);
30
  public void handleRollback(CDOSavepoint savepoint);
31
31
(-)src/org/eclipse/emf/internal/cdo/CDOXATransactionImpl.java (-1 / +1 lines)
Lines 257-263 Link Here
257
257
258
    for (InternalCDOTransaction transaction : transactions)
258
    for (InternalCDOTransaction transaction : transactions)
259
    {
259
    {
260
      CDOCommitContext context = transaction.createCommitContext();
260
      InternalCDOCommitContext context = transaction.createCommitContext();
261
      CDOXATransactionCommitContext xaContext = new CDOXATransactionCommitContext(this, context);
261
      CDOXATransactionCommitContext xaContext = new CDOXATransactionCommitContext(this, context);
262
      xaContext.setState(CDOXAPhase1State.INSTANCE);
262
      xaContext.setState(CDOXAPhase1State.INSTANCE);
263
      activeContext.put(transaction, xaContext);
263
      activeContext.put(transaction, xaContext);
(-)src/org/eclipse/emf/internal/cdo/InternalCDOView.java (+4 lines)
Lines 78-83 Link Here
78
78
79
  public boolean isLocked(CDOObject object, RWLockManager.LockType lockType);
79
  public boolean isLocked(CDOObject object, RWLockManager.LockType lockType);
80
80
81
  public void handleAddAdapter(InternalCDOObject eObject, Adapter adapter);
82
83
  public void handleRemoveAdapter(InternalCDOObject eObject, Adapter adapter);
84
81
  public void subscribe(EObject eObject, Adapter adapter);
85
  public void subscribe(EObject eObject, Adapter adapter);
82
86
83
  public void unsubscribe(EObject eObject, Adapter adapter);
87
  public void unsubscribe(EObject eObject, Adapter adapter);
(-)src/org/eclipse/emf/internal/cdo/CDOSingleTransactionStrategy.java (-1 / +1 lines)
Lines 39-45 Link Here
39
39
40
  public void commit(InternalCDOTransaction transaction, IProgressMonitor progressMonitor) throws Exception
40
  public void commit(InternalCDOTransaction transaction, IProgressMonitor progressMonitor) throws Exception
41
  {
41
  {
42
    CDOCommitContext commitContext = transaction.createCommitContext();
42
    InternalCDOCommitContext commitContext = transaction.createCommitContext();
43
    if (TRACER.isEnabled())
43
    if (TRACER.isEnabled())
44
    {
44
    {
45
      TRACER.format("CDOCommitContext.preCommit");
45
      TRACER.format("CDOCommitContext.preCommit");
(-)src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java (-3 / +50 lines)
Lines 11-19 Link Here
11
 **************************************************************************/
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo;
12
package org.eclipse.emf.internal.cdo;
13
13
14
import org.eclipse.emf.cdo.CDOAdapterPolicy;
15
import org.eclipse.emf.cdo.CDOCommitContext;
14
import org.eclipse.emf.cdo.CDOObject;
16
import org.eclipse.emf.cdo.CDOObject;
15
import org.eclipse.emf.cdo.CDOSavepoint;
17
import org.eclipse.emf.cdo.CDOSavepoint;
16
import org.eclipse.emf.cdo.CDOState;
18
import org.eclipse.emf.cdo.CDOState;
19
import org.eclipse.emf.cdo.CDOTransaction;
17
import org.eclipse.emf.cdo.CDOTransactionConflictEvent;
20
import org.eclipse.emf.cdo.CDOTransactionConflictEvent;
18
import org.eclipse.emf.cdo.CDOTransactionFinishedEvent;
21
import org.eclipse.emf.cdo.CDOTransactionFinishedEvent;
19
import org.eclipse.emf.cdo.CDOTransactionHandler;
22
import org.eclipse.emf.cdo.CDOTransactionHandler;
Lines 457-463 Link Here
457
  /**
460
  /**
458
   * @since 2.0
461
   * @since 2.0
459
   */
462
   */
460
  public CDOCommitContext createCommitContext()
463
  public InternalCDOCommitContext createCommitContext()
461
  {
464
  {
462
    return new CDOCommitContextImpl();
465
    return new CDOCommitContextImpl();
463
  }
466
  }
Lines 1047-1055 Link Here
1047
  }
1050
  }
1048
1051
1049
  /**
1052
  /**
1053
   * @since 2.0
1054
   */
1055
  @Override
1056
  protected ViewAdapterManager createAdapterManager()
1057
  {
1058
    return new TransactionAdapterManager();
1059
  }
1060
1061
  /**
1050
   * @author Simon McDuff
1062
   * @author Simon McDuff
1051
   */
1063
   */
1052
  private class CDOCommitContextImpl implements CDOCommitContext
1064
  private class CDOCommitContextImpl implements InternalCDOCommitContext
1053
  {
1065
  {
1054
    private Map<CDOID, CDOResource> newResources;
1066
    private Map<CDOID, CDOResource> newResources;
1055
1067
Lines 1120-1126 Link Here
1120
1132
1121
        for (CDOTransactionHandler handler : getHandlers())
1133
        for (CDOTransactionHandler handler : getHandlers())
1122
        {
1134
        {
1123
          handler.committingTransaction(getTransaction());
1135
          handler.committingTransaction(getTransaction(), this);
1124
        }
1136
        }
1125
1137
1126
        try
1138
        try
Lines 1192-1197 Link Here
1192
            session.handleCommitNotification(timeStamp, dirtyIDs, detachedIDs, deltasCopy, getTransaction());
1204
            session.handleCommitNotification(timeStamp, dirtyIDs, detachedIDs, deltasCopy, getTransaction());
1193
          }
1205
          }
1194
1206
1207
          for (CDOTransactionHandler handler : getHandlers())
1208
          {
1209
            handler.committedTransaction(getTransaction(), this);
1210
          }
1211
1212
          ((TransactionAdapterManager)getAdapterManager()).committedTransaction(getTransaction(), this);
1213
1195
          cleanUp();
1214
          cleanUp();
1196
          lastCommitTime = timeStamp;
1215
          lastCommitTime = timeStamp;
1197
          Map<CDOIDTemp, CDOID> idMappings = result.getIDMappings();
1216
          Map<CDOIDTemp, CDOID> idMappings = result.getIDMappings();
Lines 1329-1334 Link Here
1329
    }
1348
    }
1330
  }
1349
  }
1331
1350
1351
  private final class TransactionAdapterManager extends ViewAdapterManager
1352
  {
1353
    public TransactionAdapterManager()
1354
    {
1355
    }
1356
1357
    public void committedTransaction(CDOTransaction transaction, CDOCommitContext commitContext)
1358
    {
1359
      if (getStrongReferencePolicy() != CDOAdapterPolicy.NONE)
1360
      {
1361
        for (CDOObject object : commitContext.getNewObjects().values())
1362
        {
1363
          attachObject(object);
1364
        }
1365
1366
        for (CDOObject object : commitContext.getNewResources().values())
1367
        {
1368
          attachObject(object);
1369
        }
1370
1371
        for (CDOObject object : commitContext.getDetachedObjects().values())
1372
        {
1373
          detachObject(object);
1374
        }
1375
      }
1376
    }
1377
  }
1378
1332
  /**
1379
  /**
1333
   * @author Eike Stepper
1380
   * @author Eike Stepper
1334
   */
1381
   */
(-)src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java (-4 / +4 lines)
Lines 535-543 Link Here
535
        protected void didAdd(int index, Adapter newObject)
535
        protected void didAdd(int index, Adapter newObject)
536
        {
536
        {
537
          super.didAdd(index, newObject);
537
          super.didAdd(index, newObject);
538
          if (!FSMUtil.isTransient(CDOObjectImpl.this) && !FSMUtil.isNew(CDOObjectImpl.this))
538
          if (!FSMUtil.isTransient(CDOObjectImpl.this))
539
          {
539
          {
540
            cdoView().subscribe(CDOObjectImpl.this, newObject);
540
            cdoView().handleAddAdapter(CDOObjectImpl.this, newObject);
541
          }
541
          }
542
        }
542
        }
543
543
Lines 545-553 Link Here
545
        protected void didRemove(int index, Adapter oldObject)
545
        protected void didRemove(int index, Adapter oldObject)
546
        {
546
        {
547
          super.didRemove(index, oldObject);
547
          super.didRemove(index, oldObject);
548
          if (!FSMUtil.isTransient(CDOObjectImpl.this) && !FSMUtil.isNew(CDOObjectImpl.this))
548
          if (!FSMUtil.isTransient(CDOObjectImpl.this))
549
          {
549
          {
550
            cdoView().unsubscribe(CDOObjectImpl.this, oldObject);
550
            cdoView().handleRemoveAdapter(CDOObjectImpl.this, oldObject);
551
          }
551
          }
552
        }
552
        }
553
      };
553
      };
(-).settings/.api_filters (-17 / +26 lines)
Lines 18-64 Link Here
18
            </message_arguments>
18
            </message_arguments>
19
        </filter>
19
        </filter>
20
    </resource>
20
    </resource>
21
    <resource path="src/org/eclipse/emf/internal/cdo/CDOXATransactionImpl.java" type="org.eclipse.emf.internal.cdo.CDOXATransactionImpl$CDOXAState">
21
    <resource path="src/org/eclipse/emf/internal/cdo/InternalCDOCommitContext.java" type="org.eclipse.emf.internal.cdo.InternalCDOCommitContext">
22
        <filter id="643846161">
22
        <filter id="643846161">
23
            <message_arguments>
23
            <message_arguments>
24
                <message_argument value="CommitTransactionResult"/>
24
                <message_argument value="CommitTransactionResult"/>
25
                <message_argument value="CDOXAState"/>
25
                <message_argument value="InternalCDOCommitContext"/>
26
                <message_argument value="check_result(CommitTransactionResult)"/>
26
                <message_argument value="postCommit(CommitTransactionResult)"/>
27
            </message_arguments>
27
            </message_arguments>
28
        </filter>
28
        </filter>
29
    </resource>
29
    </resource>
30
    <resource path="src/org/eclipse/emf/internal/cdo/InternalCDOObject.java" type="org.eclipse.emf.internal.cdo.InternalCDOObject">
30
    <resource path="src/org/eclipse/emf/internal/cdo/CDOXATransactionCommitContext.java" type="org.eclipse.emf.internal.cdo.CDOXATransactionCommitContext">
31
        <filter id="1211105284">
31
        <filter id="643846161">
32
            <message_arguments>
32
            <message_arguments>
33
                <message_argument value="cdoInternalCleanup()"/>
33
                <message_argument value="CommitTransactionResult"/>
34
                <message_argument value="CDOXATransactionCommitContext"/>
35
                <message_argument value="setResult(CommitTransactionResult)"/>
34
            </message_arguments>
36
            </message_arguments>
35
        </filter>
37
        </filter>
36
        <filter id="1211105284">
38
        <filter id="643842064">
37
            <message_arguments>
39
            <message_arguments>
38
                <message_argument value="cdoInternalPostLoad(boolean)"/>
40
                <message_argument value="CommitTransactionResult"/>
41
                <message_argument value="CDOXATransactionCommitContext"/>
42
                <message_argument value="getResult()"/>
39
            </message_arguments>
43
            </message_arguments>
40
        </filter>
44
        </filter>
41
    </resource>
42
    <resource path="src/org/eclipse/emf/internal/cdo/CDOXATransactionCommitContext.java" type="org.eclipse.emf.internal.cdo.CDOXATransactionCommitContext">
43
        <filter id="643846161">
45
        <filter id="643846161">
44
            <message_arguments>
46
            <message_arguments>
45
                <message_argument value="CommitTransactionResult"/>
47
                <message_argument value="CommitTransactionResult"/>
46
                <message_argument value="CDOXATransactionCommitContext"/>
48
                <message_argument value="CDOXATransactionCommitContext"/>
47
                <message_argument value="setResult(CommitTransactionResult)"/>
49
                <message_argument value="postCommit(CommitTransactionResult)"/>
48
            </message_arguments>
50
            </message_arguments>
49
        </filter>
51
        </filter>
52
    </resource>
53
    <resource path="src/org/eclipse/emf/internal/cdo/CDOXATransactionImpl.java" type="org.eclipse.emf.internal.cdo.CDOXATransactionImpl$CDOXAState">
50
        <filter id="643846161">
54
        <filter id="643846161">
51
            <message_arguments>
55
            <message_arguments>
52
                <message_argument value="CommitTransactionResult"/>
56
                <message_argument value="CommitTransactionResult"/>
53
                <message_argument value="CDOXATransactionCommitContext"/>
57
                <message_argument value="CDOXAState"/>
54
                <message_argument value="postCommit(CommitTransactionResult)"/>
58
                <message_argument value="check_result(CommitTransactionResult)"/>
55
            </message_arguments>
59
            </message_arguments>
56
        </filter>
60
        </filter>
57
        <filter id="643842064">
61
    </resource>
62
    <resource path="src/org/eclipse/emf/internal/cdo/InternalCDOObject.java" type="org.eclipse.emf.internal.cdo.InternalCDOObject">
63
        <filter id="1211105284">
58
            <message_arguments>
64
            <message_arguments>
59
                <message_argument value="CommitTransactionResult"/>
65
                <message_argument value="cdoInternalCleanup()"/>
60
                <message_argument value="CDOXATransactionCommitContext"/>
66
            </message_arguments>
61
                <message_argument value="getResult()"/>
67
        </filter>
68
        <filter id="1211105284">
69
            <message_arguments>
70
                <message_argument value="cdoInternalPostLoad(boolean)"/>
62
            </message_arguments>
71
            </message_arguments>
63
        </filter>
72
        </filter>
64
    </resource>
73
    </resource>
(-)src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionResult.java (-6 / +5 lines)
Lines 15-21 Link Here
15
import org.eclipse.emf.cdo.common.revision.CDOReferenceAdjuster;
15
import org.eclipse.emf.cdo.common.revision.CDOReferenceAdjuster;
16
import org.eclipse.emf.cdo.internal.common.revision.CDOIDMapper;
16
import org.eclipse.emf.cdo.internal.common.revision.CDOIDMapper;
17
17
18
import org.eclipse.emf.internal.cdo.CDOCommitContext;
18
import org.eclipse.emf.internal.cdo.InternalCDOCommitContext;
19
import org.eclipse.emf.internal.cdo.revision.CDOPostCommitReferenceAdjuster;
19
import org.eclipse.emf.internal.cdo.revision.CDOPostCommitReferenceAdjuster;
20
20
21
import java.util.HashMap;
21
import java.util.HashMap;
Lines 26-32 Link Here
26
 */
26
 */
27
public final class CommitTransactionResult
27
public final class CommitTransactionResult
28
{
28
{
29
30
  private String rollbackMessage;
29
  private String rollbackMessage;
31
30
32
  private long timeStamp;
31
  private long timeStamp;
Lines 35-49 Link Here
35
34
36
  private CDOReferenceAdjuster referenceAdjuster;
35
  private CDOReferenceAdjuster referenceAdjuster;
37
36
38
  private CDOCommitContext commitContext;
37
  private InternalCDOCommitContext commitContext;
39
38
40
  public CommitTransactionResult(CDOCommitContext commitContext, String rollbackMessage)
39
  public CommitTransactionResult(InternalCDOCommitContext commitContext, String rollbackMessage)
41
  {
40
  {
42
    this.rollbackMessage = rollbackMessage;
41
    this.rollbackMessage = rollbackMessage;
43
    this.commitContext = commitContext;
42
    this.commitContext = commitContext;
44
  }
43
  }
45
44
46
  public CommitTransactionResult(CDOCommitContext commitContext, long timeStamp)
45
  public CommitTransactionResult(InternalCDOCommitContext commitContext, long timeStamp)
47
  {
46
  {
48
    this.timeStamp = timeStamp;
47
    this.timeStamp = timeStamp;
49
    this.commitContext = commitContext;
48
    this.commitContext = commitContext;
Lines 65-71 Link Here
65
    this.referenceAdjuster = referenceAdjuster;
64
    this.referenceAdjuster = referenceAdjuster;
66
  }
65
  }
67
66
68
  public CDOCommitContext getCommitContext()
67
  public InternalCDOCommitContext getCommitContext()
69
  {
68
  {
70
    return commitContext;
69
    return commitContext;
71
  }
70
  }
(-)src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java (-5 / +5 lines)
Lines 37-43 Link Here
37
import org.eclipse.emf.cdo.internal.common.CDODataOutputImpl;
37
import org.eclipse.emf.cdo.internal.common.CDODataOutputImpl;
38
import org.eclipse.emf.cdo.spi.common.InternalCDOPackage;
38
import org.eclipse.emf.cdo.spi.common.InternalCDOPackage;
39
39
40
import org.eclipse.emf.internal.cdo.CDOCommitContext;
40
import org.eclipse.emf.internal.cdo.InternalCDOCommitContext;
41
import org.eclipse.emf.internal.cdo.InternalCDOSession;
41
import org.eclipse.emf.internal.cdo.InternalCDOSession;
42
import org.eclipse.emf.internal.cdo.bundle.OM;
42
import org.eclipse.emf.internal.cdo.bundle.OM;
43
import org.eclipse.emf.internal.cdo.revision.CDOListWithElementProxiesImpl;
43
import org.eclipse.emf.internal.cdo.revision.CDOListWithElementProxiesImpl;
Lines 61-80 Link Here
61
  private static final ContextTracer PROTOCOL_TRACER = new ContextTracer(OM.DEBUG_PROTOCOL,
61
  private static final ContextTracer PROTOCOL_TRACER = new ContextTracer(OM.DEBUG_PROTOCOL,
62
      CommitTransactionRequest.class);
62
      CommitTransactionRequest.class);
63
63
64
  protected CDOCommitContext commitContext;
64
  protected InternalCDOCommitContext commitContext;
65
65
66
  public CommitTransactionRequest(CDOClientProtocol protocol, CDOCommitContext commitContext)
66
  public CommitTransactionRequest(CDOClientProtocol protocol, InternalCDOCommitContext commitContext)
67
  {
67
  {
68
    this(protocol, CDOProtocolConstants.SIGNAL_COMMIT_TRANSACTION, commitContext);
68
    this(protocol, CDOProtocolConstants.SIGNAL_COMMIT_TRANSACTION, commitContext);
69
  }
69
  }
70
70
71
  public CommitTransactionRequest(CDOClientProtocol protocol, short signalID, CDOCommitContext commitContext)
71
  public CommitTransactionRequest(CDOClientProtocol protocol, short signalID, InternalCDOCommitContext commitContext)
72
  {
72
  {
73
    super(protocol, signalID);
73
    super(protocol, signalID);
74
    this.commitContext = commitContext;
74
    this.commitContext = commitContext;
75
  }
75
  }
76
76
77
  protected CDOCommitContext getCommitContext()
77
  protected InternalCDOCommitContext getCommitContext()
78
  {
78
  {
79
    return commitContext;
79
    return commitContext;
80
  }
80
  }
(-)src/org/eclipse/emf/cdo/util/CDODefaultTransactionHandler.java (-6 / +15 lines)
Lines 10-15 Link Here
10
 **************************************************************************/
10
 **************************************************************************/
11
package org.eclipse.emf.cdo.util;
11
package org.eclipse.emf.cdo.util;
12
12
13
import org.eclipse.emf.cdo.CDOCommitContext;
13
import org.eclipse.emf.cdo.CDOObject;
14
import org.eclipse.emf.cdo.CDOObject;
14
import org.eclipse.emf.cdo.CDOTransaction;
15
import org.eclipse.emf.cdo.CDOTransaction;
15
import org.eclipse.emf.cdo.CDOTransactionHandler;
16
import org.eclipse.emf.cdo.CDOTransactionHandler;
Lines 25-31 Link Here
25
  {
26
  {
26
  }
27
  }
27
28
28
  /**
29
  /*
29
   * This implementation does nothing. Clients may override to provide specialized behaviour.
30
   * This implementation does nothing. Clients may override to provide specialized behaviour.
30
   */
31
   */
31
  public void attachingObject(CDOTransaction transaction, CDOObject object)
32
  public void attachingObject(CDOTransaction transaction, CDOObject object)
Lines 33-39 Link Here
33
    // Do nothing
34
    // Do nothing
34
  }
35
  }
35
36
36
  /**
37
  /*
37
   * This implementation does nothing. Clients may override to provide specialized behaviour.
38
   * This implementation does nothing. Clients may override to provide specialized behaviour.
38
   */
39
   */
39
  public void detachingObject(CDOTransaction transaction, CDOObject object)
40
  public void detachingObject(CDOTransaction transaction, CDOObject object)
Lines 41-47 Link Here
41
    // Do nothing
42
    // Do nothing
42
  }
43
  }
43
44
44
  /**
45
  /*
45
   * This implementation does nothing. Clients may override to provide specialized behaviour.
46
   * This implementation does nothing. Clients may override to provide specialized behaviour.
46
   */
47
   */
47
  public void modifyingObject(CDOTransaction transaction, CDOObject object, CDOFeatureDelta featureChange)
48
  public void modifyingObject(CDOTransaction transaction, CDOObject object, CDOFeatureDelta featureChange)
Lines 49-67 Link Here
49
    // Do nothing
50
    // Do nothing
50
  }
51
  }
51
52
52
  /**
53
  /*
53
   * This implementation does nothing. Clients may override to provide specialized behaviour.
54
   * This implementation does nothing. Clients may override to provide specialized behaviour.
54
   */
55
   */
55
  public void committingTransaction(CDOTransaction transaction)
56
  public void committingTransaction(CDOTransaction transaction, CDOCommitContext commitContext)
56
  {
57
  {
57
    // Do nothing
58
    // Do nothing
58
  }
59
  }
59
60
60
  /**
61
  /*
61
   * This implementation does nothing. Clients may override to provide specialized behaviour.
62
   * This implementation does nothing. Clients may override to provide specialized behaviour.
62
   */
63
   */
63
  public void rolledBackTransaction(CDOTransaction transaction)
64
  public void rolledBackTransaction(CDOTransaction transaction)
64
  {
65
  {
65
    // Do nothing
66
    // Do nothing
66
  }
67
  }
68
69
  /*
70
   * This implementation does nothing. Clients may override to provide specialized behaviour.
71
   */
72
  public void committedTransaction(CDOTransaction transaction, CDOCommitContext commitContext)
73
  {
74
    // Do nothing
75
  }
67
}
76
}
(-)src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java (-1 / +6 lines)
Lines 11-16 Link Here
11
 **************************************************************************/
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo.util;
12
package org.eclipse.emf.internal.cdo.util;
13
13
14
import org.eclipse.emf.cdo.CDOCommitContext;
14
import org.eclipse.emf.cdo.CDOObject;
15
import org.eclipse.emf.cdo.CDOObject;
15
import org.eclipse.emf.cdo.CDOSession;
16
import org.eclipse.emf.cdo.CDOSession;
16
import org.eclipse.emf.cdo.CDOTransaction;
17
import org.eclipse.emf.cdo.CDOTransaction;
Lines 368-374 Link Here
368
    {
369
    {
369
    }
370
    }
370
371
371
    public void committingTransaction(CDOTransaction transaction)
372
    public void committingTransaction(CDOTransaction transaction, CDOCommitContext commitContext)
372
    {
373
    {
373
    }
374
    }
374
375
Lines 379-384 Link Here
379
    public void detachingObject(CDOTransaction transaction, CDOObject object)
380
    public void detachingObject(CDOTransaction transaction, CDOObject object)
380
    {
381
    {
381
    }
382
    }
383
384
    public void committedTransaction(CDOTransaction transaction, CDOCommitContext commitContext)
385
    {
386
    }
382
  }
387
  }
383
388
384
  /**
389
  /**
(-)src/org/eclipse/emf/internal/cdo/InternalCDOCommitContext.java (+31 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo;
13
14
import org.eclipse.emf.cdo.CDOCommitContext;
15
16
import org.eclipse.emf.internal.cdo.protocol.CommitTransactionResult;
17
18
/**
19
 * Provides a context for a commit operation.
20
 * 
21
 * @author Simon McDuff
22
 * @since 2.0
23
 */
24
public interface InternalCDOCommitContext extends CDOCommitContext
25
{
26
  public InternalCDOTransaction getTransaction();
27
28
  public void preCommit();
29
30
  public void postCommit(CommitTransactionResult result);
31
}
(-)src/org/eclipse/emf/cdo/CDOAdapterPolicy.java (+77 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo;
13
14
import org.eclipse.emf.common.notify.Adapter;
15
import org.eclipse.emf.ecore.EObject;
16
17
/**
18
 * Specifies an adapter policy.
19
 * <p>
20
 * To activate a policy, you must do the following: <br>
21
 * <code>view.setChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);</code>
22
 * <p>
23
 * To register an object, you must add an adapter to the object in which you are interested:<br>
24
 * <code>eObject.eAdapters().add(myAdapter);</code>
25
 * <p>
26
 * By activating this feature, each object having at least one adapter that matches the current policy will be
27
 * registered with the server and will be notified for each change occurring in the scope of any other transaction.
28
 * <p>
29
 * {@link CDOAdapterPolicy#NONE} - Disabled. <br>
30
 * {@link CDOAdapterPolicy#ALL} - Enabled for all adapters used.<br>
31
 * {@link CDOAdapterPolicy#ONLY_CDO_ADAPTER} - Enabled only for adapters that implement {@link CDOAdapter}. <br>
32
 * Any other class that implement {@link CDOAdapterPolicy} will enable for whatever rules defined in that class. <br>
33
 * <p>
34
 * If <code>myAdapter</code> in the above example matches the current policy, <code>eObject</code> will be registered
35
 * with the server and you will receive all changes from other transaction.
36
 * <p>
37
 * When the policy is changed all objects in the cache will automatically be recalculated.
38
 * <p>
39
 * You can subscribe to temporary objects. Even if you cannot receive notifications from other {@link CDOTransaction}
40
 * for these because they are only local to you, at commit time these objects will be registered automatically.
41
 * <p>
42
 * <b>Note:</b> It can be used with <code>CDOSession.setPassiveUpdate(false)</code>. In this case, it will receive
43
 * changes without having the objects changed.
44
 * 
45
 * @author Simon McDuff
46
 * @see CDOSessionInvalidationEvent
47
 * @see CDOInvalidationNotification
48
 * @since 2.0
49
 */
50
public interface CDOAdapterPolicy
51
{
52
  public static final CDOAdapterPolicy NONE = new CDOAdapterPolicy()
53
  {
54
    public boolean isValid(EObject eObject, Adapter adapter)
55
    {
56
      return false;
57
    }
58
  };
59
60
  public static final CDOAdapterPolicy ONLY_CDO_ADAPTER = new CDOAdapterPolicy()
61
  {
62
    public boolean isValid(EObject eObject, Adapter adapter)
63
    {
64
      return adapter instanceof CDOAdapter;
65
    }
66
  };
67
68
  public static final CDOAdapterPolicy ALL = new CDOAdapterPolicy()
69
  {
70
    public boolean isValid(EObject eObject, Adapter adapter)
71
    {
72
      return true;
73
    }
74
  };
75
76
  public boolean isValid(EObject eObject, Adapter adapter);
77
}
(-)src/org/eclipse/emf/cdo/CDOCommitContext.java (+43 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo;
13
14
import org.eclipse.emf.cdo.common.id.CDOID;
15
import org.eclipse.emf.cdo.common.model.CDOPackage;
16
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
17
import org.eclipse.emf.cdo.eresource.CDOResource;
18
19
import java.util.List;
20
import java.util.Map;
21
22
/**
23
 * Provides a context for a commit operation.
24
 * 
25
 * @author Simon McDuff
26
 * @since 2.0
27
 */
28
public interface CDOCommitContext
29
{
30
  public CDOTransaction getTransaction();
31
32
  public List<CDOPackage> getNewPackages();
33
34
  public Map<CDOID, CDOResource> getNewResources();
35
36
  public Map<CDOID, CDOObject> getNewObjects();
37
38
  public Map<CDOID, CDOObject> getDirtyObjects();
39
40
  public Map<CDOID, CDORevisionDelta> getRevisionDeltas();
41
42
  public Map<CDOID, CDOObject> getDetachedObjects();
43
}
(-)src/org/eclipse/emf/cdo/tests/TransactionHandlerTest.java (-1 / +6 lines)
Lines 11-16 Link Here
11
 **************************************************************************/
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.tests;
12
package org.eclipse.emf.cdo.tests;
13
13
14
import org.eclipse.emf.cdo.CDOCommitContext;
14
import org.eclipse.emf.cdo.CDOObject;
15
import org.eclipse.emf.cdo.CDOObject;
15
import org.eclipse.emf.cdo.CDOSession;
16
import org.eclipse.emf.cdo.CDOSession;
16
import org.eclipse.emf.cdo.CDOTransaction;
17
import org.eclipse.emf.cdo.CDOTransaction;
Lines 377-383 Link Here
377
      listOfAddingObject.add(object);
378
      listOfAddingObject.add(object);
378
    }
379
    }
379
380
380
    public void committingTransaction(CDOTransaction transaction)
381
    public void committingTransaction(CDOTransaction transaction, CDOCommitContext commitContext)
381
    {
382
    {
382
      numberOfCommit++;
383
      numberOfCommit++;
383
    }
384
    }
Lines 396-400 Link Here
396
    {
397
    {
397
      numberOfRollback++;
398
      numberOfRollback++;
398
    }
399
    }
400
401
    public void committedTransaction(CDOTransaction transaction, CDOCommitContext commitContext)
402
    {
403
    }
399
  }
404
  }
400
}
405
}
(-)src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java (+1 lines)
Lines 79-84 Link Here
79
    testClasses.add(RepositoryTest.class);
79
    testClasses.add(RepositoryTest.class);
80
    testClasses.add(LockingManagerTest.class);
80
    testClasses.add(LockingManagerTest.class);
81
    testClasses.add(MultiValuedOfAttributeTest.class);
81
    testClasses.add(MultiValuedOfAttributeTest.class);
82
    testClasses.add(AdapterManagerTest.class);
82
83
83
    // Specific for MEMStore
84
    // Specific for MEMStore
84
    testClasses.add(MEMStoreQueryTest.class);
85
    testClasses.add(MEMStoreQueryTest.class);
(-)src/org/eclipse/emf/cdo/tests/ChangeSubscriptionTest.java (-25 / +23 lines)
Lines 10-16 Link Here
10
 **************************************************************************/
10
 **************************************************************************/
11
package org.eclipse.emf.cdo.tests;
11
package org.eclipse.emf.cdo.tests;
12
12
13
import org.eclipse.emf.cdo.CDOChangeSubscriptionPolicy;
13
import org.eclipse.emf.cdo.CDOAdapterPolicy;
14
import org.eclipse.emf.cdo.CDODeltaNotification;
14
import org.eclipse.emf.cdo.CDODeltaNotification;
15
import org.eclipse.emf.cdo.CDOSession;
15
import org.eclipse.emf.cdo.CDOSession;
16
import org.eclipse.emf.cdo.CDOTransaction;
16
import org.eclipse.emf.cdo.CDOTransaction;
Lines 39-53 Link Here
39
{
39
{
40
  public void testSameSession() throws Exception
40
  public void testSameSession() throws Exception
41
  {
41
  {
42
    testSameSession(CDOChangeSubscriptionPolicy.ALL);
42
    testSameSession(CDOAdapterPolicy.ALL);
43
  }
43
  }
44
44
45
  public void testSameSession_disable() throws Exception
45
  public void testSameSession_disable() throws Exception
46
  {
46
  {
47
    testSameSession(CDOChangeSubscriptionPolicy.NONE);
47
    testSameSession(CDOAdapterPolicy.NONE);
48
  }
48
  }
49
49
50
  public void testSameSession(final CDOChangeSubscriptionPolicy enabled) throws Exception
50
  public void testSameSession(final CDOAdapterPolicy enabled) throws Exception
51
  {
51
  {
52
    msg("Opening session");
52
    msg("Opening session");
53
    final CDOSession session = openModel1Session();
53
    final CDOSession session = openModel1Session();
Lines 103-118 Link Here
103
      @Override
103
      @Override
104
      protected boolean successful()
104
      protected boolean successful()
105
      {
105
      {
106
        return enabled == CDOChangeSubscriptionPolicy.ALL && adapter.getNotifications().size() == 1
106
        return enabled == CDOAdapterPolicy.ALL && adapter.getNotifications().size() == 1
107
            || enabled == CDOChangeSubscriptionPolicy.NONE && adapter.getNotifications().size() == 0;
107
            || enabled == CDOAdapterPolicy.NONE && adapter.getNotifications().size() == 0;
108
      }
108
      }
109
    }.timedOut();
109
    }.timedOut();
110
110
111
    assertEquals(false, timedOut);
111
    assertEquals(false, timedOut);
112
112
113
    // Switching policy to the other
113
    // Switching policy to the other
114
    final CDOChangeSubscriptionPolicy enabled2 = enabled == CDOChangeSubscriptionPolicy.ALL ? CDOChangeSubscriptionPolicy.NONE
114
    final CDOAdapterPolicy enabled2 = enabled == CDOAdapterPolicy.ALL ? CDOAdapterPolicy.NONE : CDOAdapterPolicy.ALL;
115
        : CDOChangeSubscriptionPolicy.ALL;
116
115
117
    transaction.setChangeSubscriptionPolicy(enabled2);
116
    transaction.setChangeSubscriptionPolicy(enabled2);
118
117
Lines 132-139 Link Here
132
      @Override
131
      @Override
133
      protected boolean successful()
132
      protected boolean successful()
134
      {
133
      {
135
        return enabled2 == CDOChangeSubscriptionPolicy.ALL && adapter.getNotifications().size() == 1
134
        return enabled2 == CDOAdapterPolicy.ALL && adapter.getNotifications().size() == 1
136
            || enabled2 == CDOChangeSubscriptionPolicy.NONE && adapter.getNotifications().size() == 0;
135
            || enabled2 == CDOAdapterPolicy.NONE && adapter.getNotifications().size() == 0;
137
      }
136
      }
138
    }.timedOut();
137
    }.timedOut();
139
138
Lines 142-157 Link Here
142
141
143
  public void testSeparateSession() throws Exception
142
  public void testSeparateSession() throws Exception
144
  {
143
  {
145
    testSeparateSession(CDOChangeSubscriptionPolicy.ALL);
144
    testSeparateSession(CDOAdapterPolicy.ALL);
146
145
147
  }
146
  }
148
147
149
  public void testSeparateSession_disable() throws Exception
148
  public void testSeparateSession_disable() throws Exception
150
  {
149
  {
151
    testSeparateSession(CDOChangeSubscriptionPolicy.NONE);
150
    testSeparateSession(CDOAdapterPolicy.NONE);
152
  }
151
  }
153
152
154
  public void testSeparateSession(final CDOChangeSubscriptionPolicy enabled) throws Exception
153
  public void testSeparateSession(final CDOAdapterPolicy enabled) throws Exception
155
  {
154
  {
156
    msg("Opening session");
155
    msg("Opening session");
157
    final CDOSession session = openModel1Session();
156
    final CDOSession session = openModel1Session();
Lines 209-224 Link Here
209
      @Override
208
      @Override
210
      protected boolean successful()
209
      protected boolean successful()
211
      {
210
      {
212
        return enabled == CDOChangeSubscriptionPolicy.ALL && adapter.getNotifications().size() == 1
211
        return enabled == CDOAdapterPolicy.ALL && adapter.getNotifications().size() == 1
213
            || enabled == CDOChangeSubscriptionPolicy.NONE && adapter.getNotifications().size() == 0;
212
            || enabled == CDOAdapterPolicy.NONE && adapter.getNotifications().size() == 0;
214
      }
213
      }
215
    }.timedOut();
214
    }.timedOut();
216
215
217
    assertEquals(false, timedOut);
216
    assertEquals(false, timedOut);
218
217
219
    // Switching policy to the other
218
    // Switching policy to the other
220
    final CDOChangeSubscriptionPolicy enabled2 = enabled == CDOChangeSubscriptionPolicy.ALL ? CDOChangeSubscriptionPolicy.NONE
219
    final CDOAdapterPolicy enabled2 = enabled == CDOAdapterPolicy.ALL ? CDOAdapterPolicy.NONE : CDOAdapterPolicy.ALL;
221
        : CDOChangeSubscriptionPolicy.ALL;
222
220
223
    transaction.setChangeSubscriptionPolicy(enabled2);
221
    transaction.setChangeSubscriptionPolicy(enabled2);
224
222
Lines 238-245 Link Here
238
      @Override
236
      @Override
239
      protected boolean successful()
237
      protected boolean successful()
240
      {
238
      {
241
        return enabled2 == CDOChangeSubscriptionPolicy.ALL && adapter.getNotifications().size() == 1
239
        return enabled2 == CDOAdapterPolicy.ALL && adapter.getNotifications().size() == 1
242
            || enabled2 == CDOChangeSubscriptionPolicy.NONE && adapter.getNotifications().size() == 0;
240
            || enabled2 == CDOAdapterPolicy.NONE && adapter.getNotifications().size() == 0;
243
      }
241
      }
244
    }.timedOut();
242
    }.timedOut();
245
243
Lines 268-274 Link Here
268
266
269
    msg("Opening transaction");
267
    msg("Opening transaction");
270
    final CDOTransaction transaction = session.openTransaction();
268
    final CDOTransaction transaction = session.openTransaction();
271
    transaction.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);
269
    transaction.setChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
272
    msg("Creating resource");
270
    msg("Creating resource");
273
    final CDOResource resourceA = transaction.createResource("/test1");
271
    final CDOResource resourceA = transaction.createResource("/test1");
274
272
Lines 289-295 Link Here
289
    session2.setPassiveUpdateEnabled(false);
287
    session2.setPassiveUpdateEnabled(false);
290
288
291
    final CDOTransaction transaction2 = session2.openTransaction();
289
    final CDOTransaction transaction2 = session2.openTransaction();
292
    transaction.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);
290
    transaction.setChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
293
291
294
    final Category category1B = (Category)transaction2.getObject(CDOUtil.getCDOObject(category1A).cdoID(), true);
292
    final Category category1B = (Category)transaction2.getObject(CDOUtil.getCDOObject(category1A).cdoID(), true);
295
293
Lines 390-396 Link Here
390
    assertEquals(false, timedOut);
388
    assertEquals(false, timedOut);
391
389
392
    // Switching policy to the other
390
    // Switching policy to the other
393
    transaction.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);
391
    transaction.setChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
394
392
395
    adapter.getNotifications().clear();
393
    adapter.getNotifications().clear();
396
394
Lines 439-445 Link Here
439
    msg("Opening transaction");
437
    msg("Opening transaction");
440
    final CDOTransaction transaction = session.openTransaction();
438
    final CDOTransaction transaction = session.openTransaction();
441
439
442
    transaction.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);
440
    transaction.setChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
443
441
444
    msg("Creating resource");
442
    msg("Creating resource");
445
    final CDOResource resourceA = transaction.createResource("/test1");
443
    final CDOResource resourceA = transaction.createResource("/test1");
Lines 570-576 Link Here
570
  /**
568
  /**
571
   * @author Simon McDuff
569
   * @author Simon McDuff
572
   */
570
   */
573
  private class CDOIDFilterChangeSubscriptionPolicy implements CDOChangeSubscriptionPolicy
571
  private class CDOIDFilterChangeSubscriptionPolicy implements CDOAdapterPolicy
574
  {
572
  {
575
    private Set<CDOID> cdoIDs = new HashSet<CDOID>();
573
    private Set<CDOID> cdoIDs = new HashSet<CDOID>();
576
574
Lines 578-584 Link Here
578
    {
576
    {
579
    }
577
    }
580
578
581
    public boolean shouldSubscribe(EObject eObject, Adapter object)
579
    public boolean isValid(EObject eObject, Adapter object)
582
    {
580
    {
583
      return cdoIDs.contains(((InternalCDOObject)eObject).cdoID());
581
      return cdoIDs.contains(((InternalCDOObject)eObject).cdoID());
584
    }
582
    }
(-)src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_251087_Test.java (-4 / +4 lines)
Lines 12-18 Link Here
12
12
13
package org.eclipse.emf.cdo.tests.bugzilla;
13
package org.eclipse.emf.cdo.tests.bugzilla;
14
14
15
import org.eclipse.emf.cdo.CDOChangeSubscriptionPolicy;
15
import org.eclipse.emf.cdo.CDOAdapterPolicy;
16
import org.eclipse.emf.cdo.CDOSession;
16
import org.eclipse.emf.cdo.CDOSession;
17
import org.eclipse.emf.cdo.CDOTransaction;
17
import org.eclipse.emf.cdo.CDOTransaction;
18
import org.eclipse.emf.cdo.common.id.CDOID;
18
import org.eclipse.emf.cdo.common.id.CDOID;
Lines 45-51 Link Here
45
    CDOTransaction transaction1 = session.openTransaction();
45
    CDOTransaction transaction1 = session.openTransaction();
46
46
47
    transaction1.setInvalidationNotificationEnabled(true);
47
    transaction1.setInvalidationNotificationEnabled(true);
48
    transaction1.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);
48
    transaction1.setChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
49
49
50
    String resourcePath = "/test1";
50
    String resourcePath = "/test1";
51
    CDOResource res = transaction1.createResource(resourcePath);
51
    CDOResource res = transaction1.createResource(resourcePath);
Lines 71-77 Link Here
71
    CDOTransaction transaction1 = sessionA.openTransaction();
71
    CDOTransaction transaction1 = sessionA.openTransaction();
72
72
73
    transaction1.setInvalidationNotificationEnabled(true);
73
    transaction1.setInvalidationNotificationEnabled(true);
74
    transaction1.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);
74
    transaction1.setChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
75
75
76
    String resourcePath = "/test1";
76
    String resourcePath = "/test1";
77
    CDOResource res = transaction1.createResource(resourcePath);
77
    CDOResource res = transaction1.createResource(resourcePath);
Lines 83-89 Link Here
83
    CDOID companyID = CDOUtil.getCDOObject(obj2).cdoID();
83
    CDOID companyID = CDOUtil.getCDOObject(obj2).cdoID();
84
    Company companyB = (Company)transB1.getObject(companyID);
84
    Company companyB = (Company)transB1.getObject(companyID);
85
    sessionB.setPassiveUpdateEnabled(false);
85
    sessionB.setPassiveUpdateEnabled(false);
86
    transB1.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);
86
    transB1.setChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
87
    final TestAdapter testAdapter = new TestAdapter();
87
    final TestAdapter testAdapter = new TestAdapter();
88
    companyB.eAdapters().add(testAdapter);
88
    companyB.eAdapters().add(testAdapter);
89
    assertEquals(true, ((InternalCDOTransaction)transB1).hasSubscription(companyID));
89
    assertEquals(true, ((InternalCDOTransaction)transB1).hasSubscription(companyID));
(-)src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_254489_Test.java (-2 / +2 lines)
Lines 11-17 Link Here
11
11
12
package org.eclipse.emf.cdo.tests.bugzilla;
12
package org.eclipse.emf.cdo.tests.bugzilla;
13
13
14
import org.eclipse.emf.cdo.CDOChangeSubscriptionPolicy;
14
import org.eclipse.emf.cdo.CDOAdapterPolicy;
15
import org.eclipse.emf.cdo.CDOSession;
15
import org.eclipse.emf.cdo.CDOSession;
16
import org.eclipse.emf.cdo.CDOTransaction;
16
import org.eclipse.emf.cdo.CDOTransaction;
17
import org.eclipse.emf.cdo.eresource.CDOResource;
17
import org.eclipse.emf.cdo.eresource.CDOResource;
Lines 55-61 Link Here
55
55
56
    transaction1.commit();
56
    transaction1.commit();
57
57
58
    transaction2.setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy.ALL);
58
    transaction2.setChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
59
    CDOResource res2 = transaction2.getResource("/res1");
59
    CDOResource res2 = transaction2.getResource("/res1");
60
    Company companyA2 = (Company)res2.getContents().get(0);
60
    Company companyA2 = (Company)res2.getContents().get(0);
61
    final TestAdapter companyA2Adapter = new TestAdapter();
61
    final TestAdapter companyA2Adapter = new TestAdapter();
(-)src/org/eclipse/emf/cdo/tests/AdapterManagerTest.java (+261 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 **************************************************************************/
11
package org.eclipse.emf.cdo.tests;
12
13
import org.eclipse.emf.cdo.CDOAdapterPolicy;
14
import org.eclipse.emf.cdo.CDOSession;
15
import org.eclipse.emf.cdo.CDOTransaction;
16
import org.eclipse.emf.cdo.common.id.CDOID;
17
import org.eclipse.emf.cdo.tests.model1.Company;
18
import org.eclipse.emf.cdo.util.CDOUtil;
19
20
import org.eclipse.emf.common.notify.Adapter;
21
import org.eclipse.emf.common.notify.Notification;
22
import org.eclipse.emf.common.notify.Notifier;
23
24
import java.lang.ref.WeakReference;
25
import java.util.ArrayList;
26
import java.util.List;
27
28
/**
29
 * @author Simon McDuff
30
 */
31
public class AdapterManagerTest extends AbstractCDOTest
32
{
33
  public void testAdapterPolicy_NONE() throws Exception
34
  {
35
    msg("Opening session");
36
    final CDOSession session = openModel1Session();
37
38
    session.setPassiveUpdateEnabled(false);
39
40
    // ************************************************************* //
41
42
    msg("Creating company");
43
    Company companyA = getModel1Factory().createCompany();
44
    TestAdapter testAdapter = new TestAdapter();
45
    msg("Opening transaction");
46
    CDOTransaction transaction = session.openTransaction();
47
48
    transaction.createResource("/resA").getContents().add(companyA);
49
50
    msg("Committing");
51
    transaction.commit();
52
53
    CDOID id = CDOUtil.getCDOObject(companyA).cdoID();
54
    companyA.eAdapters().add(testAdapter);
55
    companyA = null;
56
57
    System.gc();
58
59
    assertEquals(false, transaction.isObjectRegistered(id));
60
    companyA = (Company)transaction.getObject(id);
61
    assertEquals(0, testAdapter.getNotifications().size());
62
    companyA.setCity("Ottawa");
63
    assertEquals(0, testAdapter.getNotifications().size());
64
  }
65
66
  public void testAdapterPolicy_ALL() throws Exception
67
  {
68
    msg("Opening session");
69
    final CDOSession session = openModel1Session();
70
71
    session.setPassiveUpdateEnabled(false);
72
73
    // ************************************************************* //
74
75
    msg("Creating company");
76
    Company companyA = getModel1Factory().createCompany();
77
    TestAdapter testAdapter = new TestAdapter();
78
    msg("Opening transaction");
79
    CDOTransaction transaction = session.openTransaction();
80
81
    transaction.setStrongReferencePolicy(CDOAdapterPolicy.ALL);
82
83
    transaction.createResource("/resA").getContents().add(companyA);
84
85
    msg("Committing");
86
    transaction.commit();
87
    CDOID id = CDOUtil.getCDOObject(companyA).cdoID();
88
    companyA.eAdapters().add(testAdapter);
89
    companyA = null;
90
91
    testAdapter.getNotifications().clear();
92
    System.gc();
93
94
    assertEquals(true, transaction.isObjectRegistered(id));
95
    companyA = (Company)transaction.getObject(id);
96
97
    assertEquals(0, testAdapter.getNotifications().size());
98
    companyA.setCity("Ottawa");
99
    assertEquals(1, testAdapter.getNotifications().size());
100
  }
101
102
  public void testAdapterPolicy_AttachObject() throws Exception
103
  {
104
    msg("Opening session");
105
    final CDOSession session = openModel1Session();
106
107
    session.setPassiveUpdateEnabled(false);
108
109
    // ************************************************************* //
110
111
    msg("Creating company");
112
    Company companyA = getModel1Factory().createCompany();
113
    TestAdapter testAdapter = new TestAdapter();
114
115
    companyA.eAdapters().add(testAdapter);
116
117
    msg("Opening transaction");
118
    CDOTransaction transaction = session.openTransaction();
119
120
    transaction.setStrongReferencePolicy(CDOAdapterPolicy.ALL);
121
122
    transaction.createResource("/resA").getContents().add(companyA);
123
124
    msg("Committing");
125
    transaction.commit();
126
    CDOID id = CDOUtil.getCDOObject(companyA).cdoID();
127
128
    companyA = null;
129
130
    testAdapter.getNotifications().clear();
131
    System.gc();
132
133
    assertEquals(true, transaction.isObjectRegistered(id));
134
    companyA = (Company)transaction.getObject(id);
135
136
    assertEquals(0, testAdapter.getNotifications().size());
137
    companyA.setCity("Ottawa");
138
    assertEquals(1, testAdapter.getNotifications().size());
139
  }
140
141
  public void testAdapterPolicy_DetachObject() throws Exception
142
  {
143
    msg("Opening session");
144
    final CDOSession session = openModel1Session();
145
146
    session.setPassiveUpdateEnabled(false);
147
148
    // ************************************************************* //
149
150
    msg("Creating company");
151
    Company companyA = getModel1Factory().createCompany();
152
    WeakReference<Company> weakCompanyA = new WeakReference<Company>(companyA);
153
154
    TestAdapter testAdapter = new TestAdapter();
155
156
    companyA.eAdapters().add(testAdapter);
157
158
    msg("Opening transaction");
159
    CDOTransaction transaction = session.openTransaction();
160
161
    transaction.setStrongReferencePolicy(CDOAdapterPolicy.ALL);
162
163
    transaction.createResource("/resA").getContents().add(companyA);
164
165
    msg("Committing");
166
    transaction.commit();
167
    CDOID id = CDOUtil.getCDOObject(companyA).cdoID();
168
    companyA = null;
169
170
    testAdapter.getNotifications().clear();
171
    System.gc();
172
173
    assertEquals(true, transaction.isObjectRegistered(id));
174
    Company companyB = (Company)transaction.getObject(id);
175
    assertEquals(companyB, weakCompanyA.get());
176
    companyB.setCity("Ottawa");
177
    transaction.getResource("/resA").getContents().remove(0);
178
    transaction.commit();
179
    companyB = null;
180
181
    testAdapter.getNotifications().clear();
182
    System.gc();
183
184
    assertTrue(weakCompanyA.get() == null);
185
  }
186
187
  public void testAdapterPolicy_ChangePolicy() throws Exception
188
  {
189
    msg("Opening session");
190
    final CDOSession session = openModel1Session();
191
192
    session.setPassiveUpdateEnabled(false);
193
194
    // ************************************************************* //
195
196
    msg("Creating company");
197
    Company companyA = getModel1Factory().createCompany();
198
199
    TestAdapter testAdapter = new TestAdapter();
200
    companyA.eAdapters().add(testAdapter);
201
202
    msg("Opening transaction");
203
    CDOTransaction transaction = session.openTransaction();
204
205
    transaction.createResource("/resA").getContents().add(companyA);
206
207
    msg("Committing");
208
    transaction.commit();
209
    CDOID id = CDOUtil.getCDOObject(companyA).cdoID();
210
    transaction.setStrongReferencePolicy(CDOAdapterPolicy.ALL);
211
    companyA = null;
212
213
    testAdapter.getNotifications().clear();
214
    System.gc();
215
216
    assertEquals(true, transaction.isObjectRegistered(id));
217
    transaction.setStrongReferencePolicy(CDOAdapterPolicy.NONE);
218
219
    System.gc();
220
221
    assertEquals(false, transaction.isObjectRegistered(id));
222
  }
223
224
  /**
225
   * @author Simon McDuff
226
   */
227
  private static class TestAdapter implements Adapter
228
  {
229
    private List<Notification> notifications = new ArrayList<Notification>();
230
231
    public TestAdapter()
232
    {
233
    }
234
235
    public Notifier getTarget()
236
    {
237
      return null;
238
    }
239
240
    public List<Notification> getNotifications()
241
    {
242
      return notifications;
243
    }
244
245
    public boolean isAdapterForType(Object type)
246
    {
247
      return false;
248
    }
249
250
    public void notifyChanged(Notification notification)
251
    {
252
      notifications.add(notification);
253
    }
254
255
    public void setTarget(Notifier newTarget)
256
    {
257
258
    }
259
  }
260
261
}

Return to bug 250486