Twofer: MySQL and java.lang.Boolean? WO Class like NSValueTransformer?
Twofer: MySQL and java.lang.Boolean? WO Class like NSValueTransformer?
- Subject: Twofer: MySQL and java.lang.Boolean? WO Class like NSValueTransformer?
- From: Rams <email@hidden>
- Date: Tue, 24 Aug 2004 21:32:21 -0400
Hi all,
I'm having a bit of trouble using booleans with MySQL 4.0.17 and WO
5.2.3. I'm wondering if anyone else has come up with a solution. I
have searched the archives and read every (33) post containing
substring "MySQL Boolean".
I am using the JCAuthentication.framework with my D2JC app, therefore
my server class contains the following code.
/*
public Boolean isAdministrator() {
Number n = (Number)storedValueForKey("isAdministrator");
return (n.intValue()==0)?Boolean.FALSE:Boolean.TRUE;
}
*/
public Boolean isAdministrator() {
return (Boolean)storedValueForKey("isAdministrator");
}
public void setIsAdministrator(Boolean value) {
int i = value.booleanValue() ? 1 : 0;
Integer dbValue = new Integer(i);
takeStoredValueForKey(dbValue, "isAdministrator");
}
The commented code is what I would *think* should be appropriate, but
instead it breaks the interface. A query on the Entity gives empty
results if that code is used, even querying with empty fields to find
every Entity. [Logically, I would expect to get a class cast exception
in isAdministrator() since I don't see how I can cast a Number to a
Boolean. I chalk it up to WebObjects magic since I have the attribute
marked as a double with a value type 'c' in EOModeler...] However, the
problem is reversed if I attempt to use takeStoredValueForKey with a
boolean value. In that instance, I cannot save any changes related to
that Entity. This leaves me with the code above. It works well
enough, but the interface displays and demands 1's and 0's. In order
to search I would like to use something familiar to users (a checkbox),
instead of insisting they remember '1 means true, 0 means false'.
What are the rest of you doing? I know MySQL is fairly ubiquitous and
Booleans are a fact of life, so someone must be doing something with
the two, no?
I also wouldn't mind knowing how to catch the query widget's value
before turning it into a fetch spec and adjusting things with a little
code. Although this would only partially solve my previous problem, I
would also like to search Entities by age in years. At the moment, I
am stuck with date ranges on a EORangeTextFieldController for my Date
of Birth attribute. I have yet to find anything like a
NSValueTransformer in the WebObjects API. I thought I'd hit the
jackpot with validate<key>, but unfortunately it is not called in the
case of queries... I've added a client side property key age() and a
method for deriving age from DOB, but it does not work for queries. I
tried sticking the same method in the server side class, no luck. Even
if it did work, I think converting age to a date and then doing a fetch
would be a lot less resource intensive than fetching lots of objects
and filtering through them with business logic. How do I catch/coerce
the value before the fetch spec is built?
Sorry for such a long message! Any help is, as always, greatly
appreciated :-)
--
Learn how to cryptographically sign your mail in Panther
http://www.joar.com/certificates/
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.