Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Logging Commits with a Repository handler
[CDO] Logging Commits with a Repository handler [message #1701947] Fri, 17 July 2015 04:17 Go to next message
Eclipse UserFriend
Hi,

I am using the latest mars version of CDO to build a server. This
server has a Repository Handler (repository.addHandler(handler);) that
logs changes committed to the repository.

Change logs look similar to output that the
org.eclipse.emf.cdo.common.commit.handler.TextCommitInfoLog produces.


For example here a Person is added to a Location:

2015-07-16 22:49:50,104, [net4j-Thread-3] Commit
com.verticon.cdo.server.provider, INFO,
com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[,
<1 addition, 1 change>, CommitData[newObjects=1, changedObjects=1,
detachedObjects=0]]]
+ Person@_2FsM0Cw2EeWbAoAY83zZjw:0v1
name = Mikey
tag = null
alternateId = null
comments = null
description = null
parent = null
longitude = null
events = []
latitude = null
altitude = null
altitudeMode = null
children = []
type = null
* Location@_PO1bkCtzEeWN-IAY83zZjw:0v6 uri=_PO1bkCtzEeWN-IAY83zZjw
children = CDOFeatureDelta[children, ADD,
value=_2FsM0Cw2EeWbAoAY83zZjw, index=1]


And here the same person's name was changed from Mikey to Mikey Mouse:

2015-07-16 23:01:41,923, [net4j-Thread-4] Commit
com.verticon.cdo.server.provider, INFO,
com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[,
<1 change>, CommitData[newObjects=0, changedObjects=1, detachedObjects=0]]]
* Person@_2FsM0Cw2EeWbAoAY83zZjw:0v1 uri=_2FsM0Cw2EeWbAoAY83zZjw
name = CDOFeatureDelta[name, SET, value=Mikey Mouse,
oldValue=UNSPECIFIED]


Questions:

1. Since we can have more than one resource open on a repo, for all
adds, removes and changes committed I would like to log which resource
on my repository has had the commit. I can get to the CDOURI, but I need
to see the Resource uri. How can I get this from the ITransaction or
the IStoreAccessor.CommitContext that is passed into my handler?


2. In the case commit of a change as in the second example above, why
does a CDOFeatureDelta not show the oldValue but shows
oldValue=UNSPECIFIED? I would expect the second log message above to
have the output:

CDOFeatureDelta[name, SET, value=Mikey Mouse, oldValue=Mikey]

Anyway to get the old value?


thanks for any help on this,
John
Re: [CDO] Logging Commits with a Repository handler [message #1701952 is a reply to message #1701947] Fri, 17 July 2015 05:41 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6447
Registered: July 2009
Senior Member
Hi John,

There are two ways:

1) The fast and low-level way is to work only with the CDORevisions that are on the server. In contrast to EObjects you
cannot directly navigate references of CDORevisions because they're represented as CDOIDs. So you need a
CDORevisionProvider to map the CDOIDs of target objects to their respective CDORevisions.

1.1) If you want to navigate through already committed data you could use "new
ManagedRevisionProvider(IRepository.getRevisionManager(), commitInfo)". The commitInfo determines the CDOBranchPoint,
which is always equal to IRepository.getBranchManager().getMainBranch().getHead() unless your repository uses auditing
or branching.

1.2) If you want to navigate over uncommitted data a good candidate is "new
CDOChangeSetDataRevisionProvider(IRepository.getRevisionManager(), commitInfo)". Here the commitInfo not only specifies
the CDOBranchPoint but also provides the needed CDOChangeSetData to compute the post-commit state on the fly.

These two methods will also be handy if you're only interested in resource paths:

CDORevisionUtil.getResourceNodePath(CDOID, CDORevisionProvider)
CDORevisionUtil.getResourceNodePath(CDORevision, CDORevisionProvider)

2) The more convenient but slightly heavier way is to open a ServerCDOView with one of the following methods:

CDOServerUtil.openView(ISession, CDOBranchPoint, CDORevisionProvider)
CDOServerUtil.openView(ISession, CDOBranchPoint)
CDOServerUtil.openView(IView)
CDOServerUtil.openView(CommitContext)

The returned CDOView provides you with simple read access to a navigable EObject graph similar to the client side.

Cheers
/Eike

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



Am 17.07.2015 um 06:17 schrieb John E. Conlon:
> Hi,
>
> I am using the latest mars version of CDO to build a server. This server has a Repository Handler
> (repository.addHandler(handler);) that logs changes committed to the repository.
>
> Change logs look similar to output that the org.eclipse.emf.cdo.common.commit.handler.TextCommitInfoLog produces.
>
>
> For example here a Person is added to a Location:
>
> 2015-07-16 22:49:50,104, [net4j-Thread-3] Commit com.verticon.cdo.server.provider, INFO,
> com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[, <1 addition, 1 change>,
> CommitData[newObjects=1, changedObjects=1, detachedObjects=0]]]
> + Person@_2FsM0Cw2EeWbAoAY83zZjw:0v1
> name = Mikey
> tag = null
> alternateId = null
> comments = null
> description = null
> parent = null
> longitude = null
> events = []
> latitude = null
> altitude = null
> altitudeMode = null
> children = []
> type = null
> * Location@_PO1bkCtzEeWN-IAY83zZjw:0v6 uri=_PO1bkCtzEeWN-IAY83zZjw
> children = CDOFeatureDelta[children, ADD, value=_2FsM0Cw2EeWbAoAY83zZjw, index=1]
>
>
> And here the same person's name was changed from Mikey to Mikey Mouse:
>
> 2015-07-16 23:01:41,923, [net4j-Thread-4] Commit com.verticon.cdo.server.provider, INFO,
> com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[, <1 change>, CommitData[newObjects=0,
> changedObjects=1, detachedObjects=0]]]
> * Person@_2FsM0Cw2EeWbAoAY83zZjw:0v1 uri=_2FsM0Cw2EeWbAoAY83zZjw
> name = CDOFeatureDelta[name, SET, value=Mikey Mouse, oldValue=UNSPECIFIED]
>
>
> Questions:
>
> 1. Since we can have more than one resource open on a repo, for all adds, removes and changes committed I would like
> to log which resource on my repository has had the commit. I can get to the CDOURI, but I need to see the Resource
> uri. How can I get this from the ITransaction or the IStoreAccessor.CommitContext that is passed into my handler?
>
>
> 2. In the case commit of a change as in the second example above, why does a CDOFeatureDelta not show the oldValue but
> shows oldValue=UNSPECIFIED? I would expect the second log message above to have the output:
>
> CDOFeatureDelta[name, SET, value=Mikey Mouse, oldValue=Mikey]
>
> Anyway to get the old value?
>
>
> thanks for any help on this,
> John


Re: [CDO] Logging Commits with a Repository handler [message #1702044 is a reply to message #1701952] Fri, 17 July 2015 20:30 Go to previous messageGo to next message
Eclipse UserFriend
Hi Eike,

Thanks that was very helpful.


> These two methods will also be handy if you're only interested in
> resource paths:
>
> CDORevisionUtil.getResourceNodePath(CDOID, CDORevisionProvider)
> CDORevisionUtil.getResourceNodePath(CDORevision, CDORevisionProvider)
>
I used both of these to retrieve the nodes information for my log
entries. (I also see that Transaction is also a CDORevisionProvider.)

For Adds:
String path = CDORevisionUtil.getResourceNodePath(cdoRevision, transaction);
buffer.append(MessageFormat.format(
" + {0} resource={1}{2}", cdoRevision,
transaction.getRepository().getName(), path)).append('\n');

For Changes:
CDOID id = delta.getID();
CDORevision cdoRevision = transaction.getRevision(id);
String path = CDORevisionUtil.getResourceNodePath(id, transaction);
buffer.append(MessageFormat.format(
" * {0} resource={1}{2}", cdoRevision,
transaction.getRepository().getName(), path)).append('\n');



Which outputs logs like:
2015-07-17 14:57:49,942, [net4j-Thread-4] Commit
com.verticon.cdo.server.provider, INFO,
com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[,
<1 addition, 1 change>, CommitData[newObjects=1, changedObjects=1,
detachedObjects=0]]]
+ PersonType@_GGEM0Cy-EeWbAoAY83zZjw:0v1 resource=repo1/resource1
nameLabel = null
tagLabel = null
alternateIdLabel = null
commentsLabel = null
descriptionLabel = null
longitudeLabel = null
latitudeLabel = null
altitudeLabel = null
altitudeModeLabel = null
name = null
childrenTypes = []
lastNameLabel = null
* Admin@_iCAXQBaZEeWMkYoAJwAAAA:0v9 resource=repo1/resource1
categories = CDOFeatureDelta[categories, ADD,
value=_GGEM0Cy-EeWbAoAY83zZjw, index=4]


Only minor issue I now have is with deletes. Here are two log messages.
The first is before the commit and the second is after:

2015-07-17 14:56:30,096, [net4j-Thread-3] Commit
com.verticon.cdo.server.provider, DEBUG,
com.verticon.cdo.server.provider.CommitHandler, Before Commit
CommitInfo[, <1 change, 1 removal>, CommitData[newObjects=0,
changedObjects=1, detachedObjects=1]]]
* Admin@_iCAXQBaZEeWMkYoAJwAAAA:0v7 resource=repo1/resource1
categories = CDOFeatureDelta[categories, REMOVE, value=UNKNOWN,
index=4]
- ItemType@_9hIUQCsxEeWUeIAY83zZjw:0v3 resource=repo1/resource1

2015-07-17 14:56:30,148, [net4j-Thread-3] Commit
com.verticon.cdo.server.provider, INFO,
com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[,
<1 change, 1 removal>, CommitData[newObjects=0, changedObjects=1,
detachedObjects=1]]]
* Admin@_iCAXQBaZEeWMkYoAJwAAAA:0v8 resource=repo1/resource1
categories = CDOFeatureDelta[categories, REMOVE, value=UNKNOWN,
index=4]
- null

Note the last line in the second log message - CDORevision is null after
the commit.


Here is the code that generates them:

if (afterCommit) {
CDORevision cdoRevision = transaction.getRevision(id);
buffer.append(" - ").append(cdoRevision).append('\n');

} else {
CDORevision cdoRevision = transaction.getRevision(id);
String path = CDORevisionUtil.getResourceNodePath(id, transaction);
buffer.append(MessageFormat.format(
" - {0} resource={1}{2}", cdoRevision,
transaction.getRepository().getName(), path)).append('\n');
}

I have to treat the before and after condition differently because I
cant get a nodePath after the commit either. As shown above the
cdoRevision from the transaction (CDORevisionProvider) also is null
after the commit.

Yes, I know I just deleted the node. But is there a way to get Revision
and nodePath 'After the Commit' of a detached object?


best regards,
John


On 07/17/2015 12:41 AM, Eike Stepper wrote:
> Hi John,
>
> There are two ways:
>
> 1) The fast and low-level way is to work only with the CDORevisions that
> are on the server. In contrast to EObjects you cannot directly navigate
> references of CDORevisions because they're represented as CDOIDs. So you
> need a CDORevisionProvider to map the CDOIDs of target objects to their
> respective CDORevisions.
>
> 1.1) If you want to navigate through already committed data you could
> use "new ManagedRevisionProvider(IRepository.getRevisionManager(),
> commitInfo)". The commitInfo determines the CDOBranchPoint, which is
> always equal to IRepository.getBranchManager().getMainBranch().getHead()
> unless your repository uses auditing or branching.
>
> 1.2) If you want to navigate over uncommitted data a good candidate is
> "new CDOChangeSetDataRevisionProvider(IRepository.getRevisionManager(),
> commitInfo)". Here the commitInfo not only specifies the CDOBranchPoint
> but also provides the needed CDOChangeSetData to compute the post-commit
> state on the fly.
>
> These two methods will also be handy if you're only interested in
> resource paths:
>
> CDORevisionUtil.getResourceNodePath(CDOID, CDORevisionProvider)
> CDORevisionUtil.getResourceNodePath(CDORevision, CDORevisionProvider)
>
> 2) The more convenient but slightly heavier way is to open a
> ServerCDOView with one of the following methods:
>
> CDOServerUtil.openView(ISession, CDOBranchPoint, CDORevisionProvider)
> CDOServerUtil.openView(ISession, CDOBranchPoint)
> CDOServerUtil.openView(IView)
> CDOServerUtil.openView(CommitContext)
>
> The returned CDOView provides you with simple read access to a navigable
> EObject graph similar to the client side.
>
> Cheers
> /Eike
>
> ----
> http://www.esc-net.de
> http://thegordian.blogspot.com
> http://twitter.com/eikestepper
>
>
>
> Am 17.07.2015 um 06:17 schrieb John E. Conlon:
>> Hi,
>>
>> I am using the latest mars version of CDO to build a server. This
>> server has a Repository Handler (repository.addHandler(handler);) that
>> logs changes committed to the repository.
>>
>> Change logs look similar to output that the
>> org.eclipse.emf.cdo.common.commit.handler.TextCommitInfoLog produces.
>>
>>
>> For example here a Person is added to a Location:
>>
>> 2015-07-16 22:49:50,104, [net4j-Thread-3] Commit
>> com.verticon.cdo.server.provider, INFO,
>> com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[,
>> <1 addition, 1 change>, CommitData[newObjects=1, changedObjects=1,
>> detachedObjects=0]]]
>> + Person@_2FsM0Cw2EeWbAoAY83zZjw:0v1
>> name = Mikey
>> tag = null
>> alternateId = null
>> comments = null
>> description = null
>> parent = null
>> longitude = null
>> events = []
>> latitude = null
>> altitude = null
>> altitudeMode = null
>> children = []
>> type = null
>> * Location@_PO1bkCtzEeWN-IAY83zZjw:0v6 uri=_PO1bkCtzEeWN-IAY83zZjw
>> children = CDOFeatureDelta[children, ADD,
>> value=_2FsM0Cw2EeWbAoAY83zZjw, index=1]
>>
>>
>> And here the same person's name was changed from Mikey to Mikey Mouse:
>>
>> 2015-07-16 23:01:41,923, [net4j-Thread-4] Commit
>> com.verticon.cdo.server.provider, INFO,
>> com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[,
>> <1 change>, CommitData[newObjects=0, changedObjects=1,
>> detachedObjects=0]]]
>> * Person@_2FsM0Cw2EeWbAoAY83zZjw:0v1 uri=_2FsM0Cw2EeWbAoAY83zZjw
>> name = CDOFeatureDelta[name, SET, value=Mikey Mouse,
>> oldValue=UNSPECIFIED]
>>
>>
>> Questions:
>>
>> 1. Since we can have more than one resource open on a repo, for all
>> adds, removes and changes committed I would like to log which resource
>> on my repository has had the commit. I can get to the CDOURI, but I
>> need to see the Resource uri. How can I get this from the
>> ITransaction or the IStoreAccessor.CommitContext that is passed into
>> my handler?
>>
>>
>> 2. In the case commit of a change as in the second example above, why
>> does a CDOFeatureDelta not show the oldValue but shows
>> oldValue=UNSPECIFIED? I would expect the second log message above to
>> have the output:
>>
>> CDOFeatureDelta[name, SET, value=Mikey Mouse, oldValue=Mikey]
>>
>> Anyway to get the old value?
>>
>>
>> thanks for any help on this,
>> John
>
Re: [CDO] Logging Commits with a Repository handler [message #1702055 is a reply to message #1702044] Sat, 18 July 2015 06:21 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6447
Registered: July 2009
Senior Member
Am 17.07.2015 um 22:30 schrieb John E. Conlon:
> [...]
>
>
> Only minor issue I now have is with deletes. Here are two log messages. The first is before the commit and the second
> is after:
>
> 2015-07-17 14:56:30,096, [net4j-Thread-3] Commit com.verticon.cdo.server.provider, DEBUG,
> com.verticon.cdo.server.provider.CommitHandler, Before Commit CommitInfo[, <1 change, 1 removal>,
> CommitData[newObjects=0, changedObjects=1, detachedObjects=1]]]
> * Admin@_iCAXQBaZEeWMkYoAJwAAAA:0v7 resource=repo1/resource1
> categories = CDOFeatureDelta[categories, REMOVE, value=UNKNOWN, index=4]
> - ItemType@_9hIUQCsxEeWUeIAY83zZjw:0v3 resource=repo1/resource1
>
> 2015-07-17 14:56:30,148, [net4j-Thread-3] Commit com.verticon.cdo.server.provider, INFO,
> com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[, <1 change, 1 removal>, CommitData[newObjects=0,
> changedObjects=1, detachedObjects=1]]]
> * Admin@_iCAXQBaZEeWMkYoAJwAAAA:0v8 resource=repo1/resource1
> categories = CDOFeatureDelta[categories, REMOVE, value=UNKNOWN, index=4]
> - null
>
> Note the last line in the second log message - CDORevision is null after the commit.
>
>
> Here is the code that generates them:
>
> if (afterCommit) {
How do you determine afterCommit? Via IRepository.WriteAccessHandler.handleTransactionBeforeCommitting() ?

> CDORevision cdoRevision = transaction.getRevision(id);
> buffer.append(" - ").append(cdoRevision).append('\n');
>
> } else {
> CDORevision cdoRevision = transaction.getRevision(id);
> String path = CDORevisionUtil.getResourceNodePath(id, transaction);
> buffer.append(MessageFormat.format(
> " - {0} resource={1}{2}", cdoRevision,
> transaction.getRepository().getName(), path)).append('\n');
> }
>
> I have to treat the before and after condition differently because I cant get a nodePath after the commit either. As
> shown above the cdoRevision from the transaction (CDORevisionProvider) also is null after the commit.
>
> Yes, I know I just deleted the node. But is there a way to get Revision and nodePath 'After the Commit' of a detached
> object?
I think your handleTransactionBeforeCommitting() should remember all values that you'll need in
handleTransactionAfterCommitted() and can't compute there (anymore).

Cheers
/Eike

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


Re: [CDO] Logging Commits with a Repository handler [message #1702081 is a reply to message #1702055] Sun, 19 July 2015 03:59 Go to previous message
Eclipse UserFriend
On 07/18/2015 01:21 AM, Eike Stepper wrote:
> Am 17.07.2015 um 22:30 schrieb John E. Conlon:
>> [...]
>>
>>
>> Only minor issue I now have is with deletes. Here are two log
>> messages. The first is before the commit and the second is after:
>>
>> 2015-07-17 14:56:30,096, [net4j-Thread-3] Commit
>> com.verticon.cdo.server.provider, DEBUG,
>> com.verticon.cdo.server.provider.CommitHandler, Before Commit
>> CommitInfo[, <1 change, 1 removal>, CommitData[newObjects=0,
>> changedObjects=1, detachedObjects=1]]]
>> * Admin@_iCAXQBaZEeWMkYoAJwAAAA:0v7 resource=repo1/resource1
>> categories = CDOFeatureDelta[categories, REMOVE, value=UNKNOWN,
>> index=4]
>> - ItemType@_9hIUQCsxEeWUeIAY83zZjw:0v3 resource=repo1/resource1
>>
>> 2015-07-17 14:56:30,148, [net4j-Thread-3] Commit
>> com.verticon.cdo.server.provider, INFO,
>> com.verticon.cdo.server.provider.CommitHandler, Committed CommitInfo[,
>> <1 change, 1 removal>, CommitData[newObjects=0, changedObjects=1,
>> detachedObjects=1]]]
>> * Admin@_iCAXQBaZEeWMkYoAJwAAAA:0v8 resource=repo1/resource1
>> categories = CDOFeatureDelta[categories, REMOVE, value=UNKNOWN,
>> index=4]
>> - null
>>
>> Note the last line in the second log message - CDORevision is null
>> after the commit.
>>
>>
>> Here is the code that generates them:
>>
>> if (afterCommit) {
> How do you determine afterCommit? Via
> IRepository.WriteAccessHandler.handleTransactionBeforeCommitting() ?
>

Yes -
handleTransactionBeforeCommitting is set false,
handleTransactionAfterCommitted is set true.

>> CDORevision cdoRevision = transaction.getRevision(id);
>> buffer.append(" - ").append(cdoRevision).append('\n');
>>
>> } else {
>> CDORevision cdoRevision = transaction.getRevision(id);
>> String path = CDORevisionUtil.getResourceNodePath(id, transaction);
>> buffer.append(MessageFormat.format(
>> " - {0} resource={1}{2}", cdoRevision,
>> transaction.getRepository().getName(), path)).append('\n');
>> }
>>
>> I have to treat the before and after condition differently because I
>> cant get a nodePath after the commit either. As shown above the
>> cdoRevision from the transaction (CDORevisionProvider) also is null
>> after the commit.
>>
>> Yes, I know I just deleted the node. But is there a way to get
>> Revision and nodePath 'After the Commit' of a detached object?
> I think your handleTransactionBeforeCommitting() should remember all
> values that you'll need in handleTransactionAfterCommitted() and can't
> compute there (anymore).

I was thinking I could do that, but wanted to see if I missed something
to prevent me keeping state.

Thanks Eike!
Previous Topic:[CDO] lock(long timeout) not timeout-ing...
Next Topic:[CDO] Does CDO support multiple packages having classes of same name.
Goto Forum:
  


Current Time: Thu Oct 24 04:08:28 GMT 2019

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

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

Back to the top