[CDO] revisions or versions list. [message #765150] |
Tue, 13 December 2011 09:13  |
Eclipse User |
|
|
|
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 #1059374 is a reply to message #1059373] |
Fri, 17 May 2013 13:52   |
Eclipse User |
|
|
|
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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.27055 seconds