|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Fetch original state of the objectHi,
I want to write attribute change validation rules. I gathered that eclipse link automatically weave change tracker into the jpa entities + it uses AttributeChangeTrackingPolicy (by default), hence keep the clone of the original object. Pre - condition :- Weaving should be enabled. (Please validate my understanding) How can I get the original state of the object. By original state I mean state of object before the update chnages were applied. AttributeChangeListner acl = ( AttributeChangeListner) (((ChanageTracker) xxxx)._persistence_getPropertyChangeListener()) Now how to get the original state of the object??? Regards, Gaurav Malhotra |
|
|
Re: Fetch original state of the objectAttribute change tracking does not keep the original state, only the list of attributes that change. When using weaving attribute change tracking is the default, otherwise it is deferred.
If you use deferred change tracking, then you can get the backupClone from the UnitOfWork, it will have the original values. I think there is an enhancement request for have the ObjectChangeSets contain the old values, feel free to vote for this, or add one if you can't find it. You may also be able to create your own AttributeChangeTrackingPolicy subclass that keeps the old values.
James Sutherland EclipseLink, TopLink Wiki: EclipseLink, TopLink Forums: TopLink, EclipseLink Book: Java Persistence |
|
|
Re: Fetch original state of the objectHi James,
I was on holiday so couldn't look into your reply. Creating MyAttributeChangeListner (extending AttributeChangeListner) I was able to hold onto the old values. Few more questions 1) How can I tell eclipselink to start weaving MyAttributeChangeListner into the jpa entities rather than default AttributeChangeListner. 2) How can I get the new jpa entities from the unit of work (RepeatbleUnitOfWork)? (in insert/update use cases) Reason for above questions I an constructing annotation driven validation framework for eclipselink for my project. My validation are fired from the aspect which can weaved around the crud service and validation parsing info is constructed at deployment time. The validation framework exploits apache common bean validations + valang + spring validation framework + groovy script (or any pluggable script like MVEL) Note :- no proxy is created around the JPA entities. Examples // Spring validators @OhiBusinessRule(name = "Relation Validations", beforeInsUpdValidators = { GenericDynamicFieldsValidator.class, RelationValidator.class }) // valang @OhiBusinessRule(name = "valangRules", rulesBefore = { "dynamicFieldUsage.fieldUsageName : upper(?) = TRUE: 'dynamicFieldUsage.fieldUsageName is not in upper case' : 'errors.dfusFieldUsageName'", "dynamicFieldUsage.inLov : ? = TRUE : 'Indication lov is not True' : 'errors.indInLov'" }, valangFunctions = { Upper.class }) // groovy @OhiBusinessRule(name = "groovyRules", rulesBefore = { "relation.name != null: 'relation name cannot be null' : 'errors.relation.name'}) Regards, Gaurav Malhotra Oracle
|
|
|
Re: Fetch original state of the objectHi Gaurav,
The best way to enable your MyAttributeChangeListner is to write a subclass of org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy and enable it on your descriptors either through a SessionCustomizer or a DescriptorCustomizer. You should be able to simply override the setChangeListener(Object clone, UnitOfWorkImpl uow, ClassDescriptor descriptor) method and maybe the setAggregateChangeListener(Object parent, Object aggregate, UnitOfWorkImpl uow, ClassDescriptor descriptor, String mappingAttribute) method depending on what you want to track. The UnitOfWork tracks new objects in a number of lists. Try taking a look at the newObjectsCloneToOriginal list. -Tom Gaurav Malhotra wrote: > Hi James, > > I was on holiday so couldn't look into your reply. > > Creating MyAttributeChangeListner (extending AttributeChangeListner) I > was able to hold onto the old values. > Few more questions > > 1) How can I tell eclipselink to start weaving MyAttributeChangeListner > into the jpa entities rather than default AttributeChangeListner. > > 2) How can I get the new jpa entities from the unit of work > (RepeatbleUnitOfWork)? (in insert/update use cases) > > Reason for above questions > I an constructing annotation driven validation framework for eclipselink > for my project. My validation are fired from the aspect which can weaved > around the crud service and validation parsing info is constructed at > deployment time. The validation framework exploits apache common bean > validations + valang + spring validation framework + groovy script (or any > pluggable script like MVEL) > Note :- no proxy is created around the JPA entities. > Examples > // Spring validators > @OhiBusinessRule(name = "Relation Validations", beforeInsUpdValidators = { > GenericDynamicFieldsValidator.class, RelationValidator.class }) > > // valang > @OhiBusinessRule(name = "valangRules", > rulesBefore = { "dynamicFieldUsage.fieldUsageName : > upper(?) = TRUE: 'dynamicFieldUsage.fieldUsageName is not in upper case' : > 'errors.dfusFieldUsageName'", > "dynamicFieldUsage.inLov : ? = TRUE : > 'Indication lov is not True' : 'errors.indInLov'" }, > valangFunctions = { Upper.class }) > > // groovy > @OhiBusinessRule(name = "groovyRules", > rulesBefore = { "relation.name != null: 'relation name > cannot be null' : 'errors.relation.name'}) > > > > > Regards, > Gaurav Malhotra > Oracle > > > Gaurav Malhotra wrote: >> Hi, >> >> I want to write attribute change validation rules. I gathered that >> eclipse link automatically weave change tracker into the jpa entities + it >> uses AttributeChangeTrackingPolicy (by default), hence keep the clone of >> the original object. >> Pre - condition :- Weaving should be enabled. >> (Please validate my understanding) >> >> How can I get the original state of the object. By original state I mean >> state of object before the update chnages were applied. >> >> AttributeChangeListner acl = ( AttributeChangeListner) >> (((ChanageTracker) xxxx)._persistence_getPropertyChangeListener()) >> >> Now how to get the original state of the object??? >> >> Regards, >> Gaurav Malhotra >> > eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
| Free embeddable forum powered by Nabble | Forum Help |