diff options
9 files changed, 186 insertions, 44 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java index b91f7fe2d1..5b981ba8e8 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java @@ -726,5 +726,25 @@ public class ServerCDOView extends AbstractCDOView implements org.eclipse.emf.cd { throw new UnsupportedOperationException(); } + + public boolean isSticky() + { + return false; + } + + public CDOBranchPoint getCommittedSinceLastRefresh(CDOID id) + { + throw new UnsupportedOperationException(); + } + + public void setCommittedSinceLastRefresh(CDOID id, CDOBranchPoint branchPoint) + { + throw new UnsupportedOperationException(); + } + + public void clearCommittedSinceLastRefresh() + { + throw new UnsupportedOperationException(); + } } } diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java index 7bb544b7a2..82e67b40d5 100644 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java @@ -99,6 +99,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_325866_Test; import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_326518_Test; import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_326743_Test; import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_328790_Test; +import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_330052_Test; import org.eclipse.emf.cdo.tests.config.impl.ConfigTest; import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite; @@ -268,6 +269,7 @@ public abstract class AllConfigs extends ConfigTestSuite testClasses.add(Bugzilla_326518_Test.class); testClasses.add(Bugzilla_326743_Test.class); testClasses.add(Bugzilla_328790_Test.class); + testClasses.add(Bugzilla_330052_Test.class); // TODO testClasses.add(NonCDOResourceTest.class); // TODO testClasses.add(GeneratedEcoreTest.class); diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_330052_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_330052_Test.java new file mode 100644 index 0000000000..e38110b0c2 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_330052_Test.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Egidijus Vaisnora - initial API and implementation + * Caspar De Groot - maintenance + */ +package org.eclipse.emf.cdo.tests.bugzilla; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.tests.AbstractCDOTest; +import org.eclipse.emf.cdo.tests.model1.Address; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.util.CommitException; +import org.eclipse.emf.cdo.view.CDOView; + +import org.junit.Assert; + +/** + * Bug 330052 - Breakage related to sticky views + * + * @author Egidijus Vaisnora, Caspar De Groot + */ +public class Bugzilla_330052_Test extends AbstractCDOTest +{ + /** + * Tests whether another view in the same session can retrieve the newly committed object + */ + public void test_otherView() throws CommitException + { + CDOSession session = openSession(); + session.options().setPassiveUpdateEnabled(false); + CDOTransaction tx = session.openTransaction(); + CDOView view = session.openView(); + + CDOResource resource = tx.createResource("test"); + Address address = getModel1Factory().createAddress(); + resource.getContents().add(address); + tx.commit(); + + CDOObject object = view.getObject(CDOUtil.getCDOObject(address).cdoID()); + Assert.assertNotNull(object); + session.close(); + } + + /** + * Tests whether an audit view in the same session fetches the correct historical version + */ + public void test_auditView() throws CommitException + { + CDOSession session = openSession(); + session.options().setPassiveUpdateEnabled(false); + CDOTransaction transaction = session.openTransaction(); + + CDOResource resource = transaction.createResource("test"); + Address address = getModel1Factory().createAddress(); + final String testName1 = "name1"; + address.setName(testName1); + resource.getContents().add(address); + long commitTime = transaction.commit().getTimeStamp(); + + final String testName2 = "name2"; + address.setName(testName2); + transaction.commit(); + + CDOView view = session.openView(commitTime); + Address historicalAddress = (Address)view.getObject(CDOUtil.getCDOObject(address).cdoID()); + + Assert.assertEquals(testName1, historicalAddress.getName()); + + session.close(); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java index 3e8ad24822..d639e6a36a 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java @@ -182,6 +182,12 @@ public abstract class CDOSessionImpl extends Container<CDOView> implements Inter private Set<InternalCDOView> views = new HashSet<InternalCDOView>(); /** + * A map to track for every object that was committed since this session's last refresh, onto what CDOBranchPoint it + * was committed. (Used only for sticky transactions, see bug 290032 - Sticky views.) + */ + private Map<CDOID, CDOBranchPoint> committedSinceLastRefresh = new HashMap<CDOID, CDOBranchPoint>(); + + /** * Fixes threading problems between a committing thread and the Net4j thread that delivers incoming commit * notifications. The same applies to lock requests and invalidations */ @@ -1138,6 +1144,32 @@ public abstract class CDOSessionImpl extends Container<CDOView> implements Inter return MessageFormat.format("CDOSession[{0}, {1}]", name, sessionID); //$NON-NLS-1$ } + public CDOBranchPoint getCommittedSinceLastRefresh(CDOID id) + { + if (isSticky()) + { + return committedSinceLastRefresh.get(id); + } + + return null; + } + + public void setCommittedSinceLastRefresh(CDOID id, CDOBranchPoint branchPoint) + { + if (isSticky()) + { + committedSinceLastRefresh.put(id, branchPoint); + } + } + + public void clearCommittedSinceLastRefresh() + { + if (isSticky()) + { + committedSinceLastRefresh.clear(); + } + } + protected ResourceSet createResourceSet() { return new ResourceSetImpl(); @@ -1260,6 +1292,11 @@ public abstract class CDOSessionImpl extends Container<CDOView> implements Inter return invalidationRunnerActive.get(); } + public boolean isSticky() + { + return !options().isPassiveUpdateEnabled() && getRepositoryInfo().isSupportingAudits(); + } + /** * @author Eike Stepper * @since 2.0 diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java index 2caec60f57..cd18832108 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java @@ -215,12 +215,6 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa private Set<EObject> committables; /** - * A map to track for every object that was committed since this TX's last refresh, onto what CDOBranchPoint it was - * committed. (Used only for sticky transactions, see bug 290032 - Sticky views.) - */ - private Map<CDOID, CDOBranchPoint> committedSinceLastRefresh = new HashMap<CDOID, CDOBranchPoint>(); - - /** * A map to hold a clean (i.e. unmodified) revision for objects that have been modified or detached. */ private Map<InternalCDOObject, InternalCDORevision> cleanRevisions = new HashMap<InternalCDOObject, InternalCDORevision>(); @@ -2004,23 +1998,6 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa super.doDeactivate(); } - @Override - protected CDOBranchPoint getBranchPointForID(CDOID id) - { - if (isSticky()) - { - CDOBranchPoint branchPoint = committedSinceLastRefresh.get(id); - if (branchPoint == null) - { - branchPoint = getBranch().getPoint(getSession().getLastUpdateTime()); - } - - return branchPoint; - } - - return this; - } - /** * Bug 298561: This override removes references to remotely detached objects that are present in any DIRTY or NEW * objects. @@ -2048,9 +2025,10 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa } // Bug 290032 - Sticky views - if (isSticky()) + InternalCDOSession session = getSession(); + if (session.isSticky()) { - committedSinceLastRefresh.clear(); + session.clearCommittedSinceLastRefresh(); } return super.invalidate(lastUpdateTime, allChangedObjects, allDetachedObjects, deltas, revisionDeltas, @@ -2369,23 +2347,23 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa session.invalidate(commitInfo, transaction); // Bug 290032 - Sticky views - if (isSticky()) + if (session.isSticky()) { CDOBranchPoint commitBranchPoint = CDOBranchUtil.copyBranchPoint(result); for (CDOObject object : getNewObjects().values()) // Note: keyset() does not work because ID mappings are // not applied there! { - committedSinceLastRefresh.put(object.cdoID(), commitBranchPoint); + session.setCommittedSinceLastRefresh(object.cdoID(), commitBranchPoint); } for (CDOID id : getDirtyObjects().keySet()) { - committedSinceLastRefresh.put(id, commitBranchPoint); + session.setCommittedSinceLastRefresh(id, commitBranchPoint); } for (CDOID id : getDetachedObjects().keySet()) { - committedSinceLastRefresh.put(id, commitBranchPoint); + session.setCommittedSinceLastRefresh(id, commitBranchPoint); } } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java index 9522bb8dc1..810c02fb53 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java @@ -302,14 +302,6 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi return stateLock; } - public boolean isSticky() - { - InternalCDOSession session = getSession(); - boolean passiveUpdate = session.options().isPassiveUpdateEnabled(); - boolean supportingAudits = session.getRepositoryInfo().isSupportingAudits(); - return !passiveUpdate && supportingAudits; - } - public boolean isDirty() { return false; diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java index a14c0b9d06..2f28752879 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java @@ -316,9 +316,26 @@ public class CDOViewImpl extends AbstractCDOView protected CDOBranchPoint getBranchPointForID(CDOID id) { - if (isSticky()) + // If this view's timestamp is something other than UNSPECIFIED_DATE, + // then this is an 'audit' view, and so this timestamp must always be + // used without any concern for possible sticky-view behavior + // + CDOBranchPoint branchPoint = getBranchPoint(); + if (branchPoint.getTimeStamp() != CDOBranchPoint.UNSPECIFIED_DATE) { - return getBranch().getPoint(session.getLastUpdateTime()); + return branchPoint; + } + + InternalCDOSession session = getSession(); + if (session.isSticky()) + { + branchPoint = session.getCommittedSinceLastRefresh(id); + if (branchPoint == null) + { + branchPoint = getBranch().getPoint(session.getLastUpdateTime()); + } + + return branchPoint; } return this; diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOSession.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOSession.java index 7559dd6b03..32ae2787e0 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOSession.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOSession.java @@ -12,6 +12,7 @@ package org.eclipse.emf.spi.cdo; import org.eclipse.emf.cdo.common.CDOCommonRepository; import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.common.model.lob.CDOLobStore; @@ -179,4 +180,24 @@ public interface InternalCDOSession extends CDOSession, PackageProcessor, Packag */ public void processRefreshSessionResult(RefreshSessionResult result, CDOBranch branch, List<InternalCDOView> branchViews, Map<CDOBranch, Map<CDOID, InternalCDORevision>> viewedRevisions); + + /** + * @since 4.0 + */ + public boolean isSticky(); + + /** + * @since 4.0 + */ + public CDOBranchPoint getCommittedSinceLastRefresh(CDOID id); + + /** + * @since 4.0 + */ + public void setCommittedSinceLastRefresh(CDOID id, CDOBranchPoint branchPoint); + + /** + * @since 4.0 + */ + public void clearCommittedSinceLastRefresh(); } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOView.java index 6ef5345701..cc39150764 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOView.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOView.java @@ -55,11 +55,6 @@ public interface InternalCDOView extends CDOView, CDOIDProvider, ILifecycle public CDOStore getStore(); - /** - * @since 4.0 - */ - public boolean isSticky(); - public InternalCDOTransaction toTransaction(); public void attachResource(CDOResourceImpl resource); |