Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] revisions or versions list.
[CDO] revisions or versions list. [message #765150] Tue, 13 December 2011 14:13 Go to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hello,

After shifting through various forum posts, Eike often advises to use view.setTimeStamp(ts); to get a CDOView which, can then be use to view.getObject(CDOID); and get an historical revision.
In order to so, one would need to know which timestamp to use right?

So far I am doing this, but it seems rather clumsy (counting back the versions duh..) Is there a better way ?


	public Iterator<CDORevision> cdoRevisions(CDOObject cdoObject) {
		
		List<CDORevision> revisions = Lists.newArrayList();
		
		CDORevision cdoRevision = cdoObject.cdoRevision();
		// get the previous.
		for (int version = cdoRevision.getVersion(); version > 0; version--) {

			CDOBranchVersion branchVersion = cdoRevision.getBranch()
					.getVersion(version);

			CDORevision revision = cdoObject
					.cdoView()
					.getSession()
					.getRevisionManager()
					.getRevisionByVersion(cdoObject.cdoID(), branchVersion, 0,
							true);
			
			revisions.add(revision);

			System.out.println("Revision= " + revision + " @ "
					+ new Date(revision.getTimeStamp()));

			CDORevisionDelta delta = revision.compare(cdoRevision);
			this.cdoPrintDelta(delta);
		}
		return revisions.iterator();
	}

Re: [CDO] revisions or versions list. [message #1059373 is a reply to message #765150] Fri, 17 May 2013 17:43 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
I hope this is what you're asking, but this is how I have successfully gotten a specific version:

First get the object, then CDOUtil.getRevisionByVersion() to get the specific version, the get that versions timestamp, set it in the view and get by id. I've confirmed this gets the revision of the object that I request.

CDOObject latest = transaction.getObject(cdoID);
CDORevision specificRev = CDOUtil.getRevisionByVersion(latest, version);
CDOID revId = specificRev.getID();
transaction.setTimeStamp(mapRev.getTimeStamp());
CDOObject chosen = getObjectById(revId);

I would *assume* that setting the timestamp on the view will permanently set the view at this revision until the transaction is closed, which is ok if this is all you're going to do with the transaction. I don't know this for sure though as I haven't tested it. I'm about to ask this question to the forum in fact.

[Updated on: Fri, 17 May 2013 17:45]

Report message to a moderator

Re: [CDO] revisions or versions list. [message #1059374 is a reply to message #1059373] Fri, 17 May 2013 17:52 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 17.05.2013 19:43, schrieb Warwick Burrows:
> This is how I have successfully gotten a specific version:
>
> First get the object, then CDOUtil.getRevisionByVersion() to get the specific version, the get that versions
> timestamp, set it in the view and get by id. I've confirmed this gets the revision of the object that I request.
>
> CDOObject latest = transaction.getObject(cdoID);
> CDORevision specificRev = CDOUtil.getRevisionByVersion(latest, version);
> CDOID revId = specificRev.getID();
Here revID is identical to cdoID.

> transaction.setTimeStamp(mapRev.getTimeStamp());
Not sure what mapRev is, but setTimeStamp() delegates to setBranchPoint(), which is overridden in CDOTransactionImpl:

@Override
public synchronized boolean setBranchPoint(CDOBranchPoint branchPoint)
{
if (branchPoint.getTimeStamp() != UNSPECIFIED_DATE)
{
throw new IllegalArgumentException("Changing the target time is not supported by transactions");
}

if (isDirty() && !getBranch().equals(branchPoint.getBranch()))
{
throw new IllegalStateException("Changing the target branch is impossible while transaction is dirty");
}

return super.setBranchPoint(branchPoint);
}

I.e. you can't change the timestamp (of a transaction) to anything but UNSPECIFIED_DATE, or in wother words, you can't
modify the past.

> CDOObject chosen = getObjectById(revId);
What exactly does getObjectById() do and how?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


>
> I would *assume* that setting the timestamp on the view will permanently set the view at this revision until the
> transaction is closed, which is ok if this is all you're going to do with the transaction. I don't know this for sure
> though as I haven't tested it. I'm about to ask this question to the forum in fact.


Re: [CDO] revisions or versions list. [message #1059393 is a reply to message #1059374] Fri, 17 May 2013 21:44 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Hi Eike,

Thanks for confirming that the cdo ids are the same, regardless of the version. It makes sense.

Here is an amended code snippet with fixes for the things you pointed out. In fact the code works I just didn't generalize it up enough before pasting it here:

CDOObject latest = view.getObject(cdoID);
CDORevision specificRev = CDOUtil.getRevisionByVersion(latest, version);
view.setTimeStamp(specificRev.getTimeStamp());
CDOObject chosen = view.getObject(cdoID);

Thanks,
Warwick
Re: [CDO] revisions or versions list. [message #1059396 is a reply to message #1059393] Fri, 17 May 2013 21:55 Go to previous message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Oh and thanks for referring to CDOBranchPoint.UNSPECIFIED_DATE because my next question to the forum was to ask how I reset the view back to looking at the latest state of the object.
Previous Topic:Change EMF properties and refresh Property View
Next Topic:Xcore and contains of referenced model
Goto Forum:
  


Current Time: Fri Mar 29 08:26:04 GMT 2024

Powered by FUDForum. Page generated in 0.03347 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top