• 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: Booleans
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Booleans


  • Subject: Re: Booleans
  • From: Jonathan Rochkind <email@hidden>
  • Date: Thu, 11 Mar 2004 12:38:10 -0600

What I recommend is giving up on EOF giving you boolean values. It's just too broken, sometimes in especially mysterious ways. (See also http://www.wodev.com/cgi-bin/WebObjects/WODev.woa/wa/Main?wikiPage=Weird52EOFBug)

But you can still get booleanValues yourself. You just need to do it yourself. Here's what I've taken to doing, to minimize any convenience.

1) Provide your attribute in the EOModel just as you have, called "isShipped". But make it not a class property. Nor should it have the lock marker next to it. It can still be used for db fetches.

2) Provide another attribute to the same column, but call it, let's say "shipped_integer". (Avoid the "is" on the front, because then I think EOF will (undocumentedly) try to convert to boolean for you, because of "is"! We want to avoid that here). [Don't worry about the fact that we have two attributes pointing to the same column---the fact that one is not used for locking and is not a class property means that EOF pretty much ignores it---although it can still be used to generate SQL, conveniently!].

3) There should not be "shipped_integer" and "setShipped_integer" cover methods in your .java class. Instead, provide your own manual cover methods with the name you really want, and with boolean conversion built in. (It's up to you whether to use capital-B Boolean, which is really three valued (null, false, or true), or use a primitive 'boolean' which can not be false. Write the conversion however you want, to map from Number to B/boolean, and back. this is just an example)
public boolean isShipped() {
Number n = storedValueForKey("shipped_integer");
if ( n == null || n.intValue() == 0)
return false;
else
return true;
}
public boolean setIsShipped(boolean b) {
Integer integerValue;
if ( b )
integerValue = new Integer(1);
else
integerValue = new Integer(0);
takeStoredValueForKey( integerValue, "shipped_integer");
}



Once you've set up your model/entity like this, essentially doing the boolean conversion by hand, all your existing code should just work. You can still create db-qualifiers on "isShipped", you've got that attribute in your model. Your Java code can still access the methods isShipped/setIsShipped, because you've defined them, and done the boolean conversion yourself manually. EOF does not know what's going on, as far as it knows, there's just a simple numeric attribute called "shipped_integer", and EOF isn't going to try and do any boolean conversion. Becuase, when EOF does try to do the boolean conversion, it seems to fail in sometimes spectacularly mysterious ways.


So that's what I've taken to doing. A bit of a pain in the set-up, but once you've gotten it set up, it works well.

--Jonathan

At 6:54 PM +0100 3/11/04, David Griffith wrote:
Hi Chuck,

Thanks for the link, had a look.  Have actually read all of that on the list
already which is fine.  The 'c' value type I have just added recently to see
if it helped, it didn't.  I'm going to remove it again.

The truth is, I have used the first method described in that article, as
listed below, and it DOES NOT WORK.  I am using custom classes by the way
(as generated by EOModeler) - would that have any impact?  I have not
modified the custom class methods for this attribute.  Basically, I don't
want to go and change all the columns that are boolean to use a numeric
format unless there is no other choice.

I can use a fetchSpec with the following bindings for example:

(fetch spec bindings):
isShipped = $isShipped


And pass it the bindings in code: bindings.addObject(Boolean.TRUE, "isShipped");

And it will return exactly the correct records.

However, if I use a relationship traversal with an array filter to try and
locate the one I want, I get no results as the value of:

someEntity.isShipped()

ALWAYS returns false, no matter what, even though it is true in the
database.

Anyone else any suggestions before I go ripping my model apart and
recreating tables????  (which have DATA!)

Regards,
Dave.

 Try removing the value type.  I think that c is incorrect for this
 usage.
 See also
> http://wodev.spearway.com/cgi-bin/WebObjects/WODev.woa/wa/Main?
wikiPage=BooleanModeling
>
 Chuck


 On Mar 10, 2004, at 8:57 PM, David Griffith wrote:

 HI all,

 I have en EOPrototype set up in my EOModel like this:

 Name: boolean
 Value Class:  java.lang.Boolean
 Factory Method:  valueOf
 Conversion Method:  toString
 Init Arguament: NSString

 And I have just added 'c' as the value type.

 The value stored in the database as a result is 'true' or 'false' and
 it is
 getting stored ok.

 However, anytime I reference the value in code, like:

 orderStatus.oscIsShipped()

 I ALWAYS get false.  No matter what.  Even though it is true in the
 database.

 It's got to be something small, can someone tell me why?  It's
 driving
 me
 crazy.

 Regards,
 Dave.
 _______________________________________________
 webobjects-dev mailing list | email@hidden
 Help/Unsubscribe/Archives:
 http://www.lists.apple.com/mailman/listinfo/webobjects-dev
 Do not post admin requests to the list. They will be ignored.
 _______________________________________________
 webobjects-dev mailing list | email@hidden
 Help/Unsubscribe/Archives:
 http://www.lists.apple.com/mailman/listinfo/webobjects-dev
 Do not post admin requests to the list. They will be ignored.
 _______________________________________________
 webobjects-dev mailing list | email@hidden
 Help/Unsubscribe/Archives:
 http://www.lists.apple.com/mailman/listinfo/webobjects-dev
 Do not post admin requests to the list. They will be ignored.
 _______________________________________________
 webobjects-dev mailing list | email@hidden
 Help/Unsubscribe/Archives:
 http://www.lists.apple.com/mailman/listinfo/webobjects-dev
 Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Booleans (From: David Griffith <email@hidden>)

  • Prev by Date: Re: Booleans [SOLVED]
  • Next by Date: Re: DbEdit again
  • Previous by thread: Re: Comparing Dates & Timestamps
  • Next by thread: Re: Grrr! awakeFromInsertion - discovery
  • Index(es):
    • Date
    • Thread