You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Aleksey Maslov <Al...@Lab49.com> on 2011/03/14 18:06:17 UTC

How to add custom code to avro generated Java objects?

Hi,

Is there a way to specify inter dependencies between object methods in IDL?
For example, if object tracks 2 symmetrical properties that have perfect
-1/+1 correlation; when one is updated, the other needs to be updated (in
opposite direction in case of -1 corr); Ex:

record CredtiCardStatement {
double balance;
double payed;
}

so paying 100 units should decrease the balance by 100 units; 

any way to specify such dependencies in the IDL? 
Or if I add this code to the generated Java file, is there a way to merge
future re-generations of the record from IDL -> avro protocol -> java, not
override it;

I am trying to smarten-up my java representations of avro data objects i get
from generating from IDL but how can i preserve my changes, as i modify the
IDL and re-generate the java object definitions?

Thank you,
Aleksey


--
View this message in context: http://apache-avro.679487.n3.nabble.com/How-to-add-custom-code-to-avro-generated-Java-objects-tp2676654p2676654.html
Sent from the Avro - Users mailing list archive at Nabble.com.

Re: How to add custom code to avro generated Java objects?

Posted by Alex Maslov <al...@lab49.com>.
Yes, it does.

Thank you.

----- Original Message -----
From: Doug Cutting [mailto:cutting@apache.org]
Sent: Monday, March 14, 2011 02:45 PM
To: user@avro.apache.org <us...@avro.apache.org>
Subject: Re: How to add custom code to avro generated Java objects?

The best practice is not to modify the generated classes directly, but
rather to author classes that wrap instances of generated classes,
adding methods that enforce such constraints to those.  The wrapper
classes can then also maintain back-compatible APIs.  Does that make sense?

Doug

On 03/14/2011 10:06 AM, Aleksey Maslov wrote:
> Hi,
>
> Is there a way to specify inter dependencies between object methods in IDL?
> For example, if object tracks 2 symmetrical properties that have perfect
> -1/+1 correlation; when one is updated, the other needs to be updated (in
> opposite direction in case of -1 corr); Ex:
>
> record CredtiCardStatement {
> double balance;
> double payed;
> }
>
> so paying 100 units should decrease the balance by 100 units;
>
> any way to specify such dependencies in the IDL?
> Or if I add this code to the generated Java file, is there a way to merge
> future re-generations of the record from IDL -> avro protocol -> java, not
> override it;
>
> I am trying to smarten-up my java representations of avro data objects i get
> from generating from IDL but how can i preserve my changes, as i modify the
> IDL and re-generate the java object definitions?
>
> Thank you,
> Aleksey
>
>
> --
> View this message in context: http://apache-avro.679487.n3.nabble.com/How-to-add-custom-code-to-avro-generated-Java-objects-tp2676654p2676654.html
> Sent from the Avro - Users mailing list archive at Nabble.com.

This email and any attachments may contain information which is confidential and/or privileged. The information is intended exclusively for the addressee and the views expressed may not be official policy, but the personal views of the originator. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents is prohibited. If you have received this email and any file transmitted with it in error, please notify the sender by telephone or return email immediately and delete the material from your computer. Internet communications are not secure and Lab49 is not responsible for their abuse by third parties, nor for any alteration or corruption in transmission, nor for any damage or loss caused by any virus or other defect. Lab49 accepts no liability or responsibility arising out of or in any way connected to this email.

Re: How to add custom code to avro generated Java objects?

Posted by Doug Cutting <cu...@apache.org>.
The best practice is not to modify the generated classes directly, but
rather to author classes that wrap instances of generated classes,
adding methods that enforce such constraints to those.  The wrapper
classes can then also maintain back-compatible APIs.  Does that make sense?

Doug

On 03/14/2011 10:06 AM, Aleksey Maslov wrote:
> Hi,
> 
> Is there a way to specify inter dependencies between object methods in IDL?
> For example, if object tracks 2 symmetrical properties that have perfect
> -1/+1 correlation; when one is updated, the other needs to be updated (in
> opposite direction in case of -1 corr); Ex:
> 
> record CredtiCardStatement {
> double balance;
> double payed;
> }
> 
> so paying 100 units should decrease the balance by 100 units; 
> 
> any way to specify such dependencies in the IDL? 
> Or if I add this code to the generated Java file, is there a way to merge
> future re-generations of the record from IDL -> avro protocol -> java, not
> override it;
> 
> I am trying to smarten-up my java representations of avro data objects i get
> from generating from IDL but how can i preserve my changes, as i modify the
> IDL and re-generate the java object definitions?
> 
> Thank you,
> Aleksey
> 
> 
> --
> View this message in context: http://apache-avro.679487.n3.nabble.com/How-to-add-custom-code-to-avro-generated-Java-objects-tp2676654p2676654.html
> Sent from the Avro - Users mailing list archive at Nabble.com.