Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Fetch original state of the object

Hi 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




Back to the top