• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Big Decimal as optimistic lock attribute?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Big Decimal as optimistic lock attribute?


  • Subject: Re: Big Decimal as optimistic lock attribute?
  • From: David Avendasora <email@hidden>
  • Date: Wed, 9 Dec 2009 12:13:00 -0500

I know I have posted this before. I should just create a patch, but here's what I add to the setter in my Velocity EOGenerator _Entity template that will enforce scale on BigDecimal:

public void set${attribute.capitalizedName}($attribute.javaClassName ${attribute.name}) {
#if ($attribute.javaClassName == "java.math.BigDecimal")
		if (${attribute.name} != null) {
			${attribute.name} = ${attribute.name}.setScale(${attribute.scale}, RoundingMode.HALF_UP);
		}
#end

This will force all set values to conform to the scale defined in the EOModel, which should be set to match the DB.

Dave

On Dec 9, 2009, at 12:01 PM, Jon Nolan wrote:

> Kieran Kelleher wrote:
>> Am I dreaming in thinking that I saw a discussion at some time in the past that there is some flaw with using BigDecimals as reliable* optimistic locking attributes? ..... or was that just NSTimestamps and float/double type values? .....
> Kieran,
>
> I seem to remember some trouble with this in the past involving precision but, like you, I don't remember if it extended to BigDecimal.  Doesn't seem like it should given what that class is all about.
> I've given up on struggling with various locking attribute types and have gone with locking on primary key and an int/long called serialNumber.  Then I have something like this in the eo class.
>
>   public void willInsert() {
>       super.willInsert();
>       setSerialNumber(0);
>   }
>     public void willUpdate() {
>       super.willUpdate();
>       setSerialNumber(serialNumber().intValue() + 1);
>   }
>
> I have zero failures with this approach and perhaps just as importantly zero headaches.  The only (slight) negative is a bit of DB bloat.
>
> Jon
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
>

David Avendasora
Senior Software Engineer
K12, Inc.

*****
WebObjects Documentation Wiki : http://wiki.objectstyle.org/confluence/display/WO/
*****
WebObjects API: http://developer.apple.com/legacy/mac/library/documentation/MacOSXServer/Reference/WO54_Reference/index.html
*****

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Big Decimal as optimistic lock attribute? (From: Kieran Kelleher <email@hidden>)
 >Re: Big Decimal as optimistic lock attribute? (From: Jon Nolan <email@hidden>)

  • Prev by Date: Re: Big Decimal as optimistic lock attribute?
  • Next by Date: Re: Big Decimal as optimistic lock attribute?
  • Previous by thread: Re: Big Decimal as optimistic lock attribute?
  • Next by thread: Re: Big Decimal as optimistic lock attribute?
  • Index(es):
    • Date
    • Thread