Re: Internal Data Type for BOOL
Re: Internal Data Type for BOOL
- Subject: Re: Internal Data Type for BOOL
- From: Pierre Frisch <email@hidden>
- Date: Tue, 3 Jun 2003 21:00:07 -0700
There is a much easier solution using custom attributes You can get EOF
to map directly from a String to a Boolean. Have a look at:
http://wodev.spearway.com/cgi-bin/WebObjects/WODev.woa/wa/
Main?wikiPage=BooleanModeling
Here is how I do it. I define the column as a Character Varying of 5 so
that I can store "true" or "false". In EOModeler I define the Internal
Data Type as custom the class as java.lang.Boolean, the factory method
as valueOf and the Conversion method as toString and the init argument
as NSString?. This works well even if it waste a little space in the
database.
To make it easier to use you should define it as a prototype.
Woks with all databases, it does not rely on any implementation from
the PlugIn and no accessor method to write. Works with EOGenerator too.
Pierre
On Tuesday, June 3, 2003, at 06:57 PM, Art Isbell wrote:
Different databases handle boolean datatypes in different ways, some
more seamlessly than others. But all databases handle integer
datatypes seamlessly, so making booleans integers should work across
all databases.
After struggling somewhat with boolean data, I finally decided to
adopt someone's suggestion on how to store booleans as integers.
Basically, model booleans as integers in your eomodel. Name the
boolean attribute with something like an "Int" suffix - e.g.,
isActiveInt. EOModeler's generated Java class file will contain
isActiveInt() and setIsActiveInt() accessors. Add 2 more accessors
that you will actually use in your WO apps including in WO component
bindings:
public boolean isActive() {
Number isActive = isActiveInt();
return ((isActive != null) && (isActive.intValue() == 1));
}
public void setIsActive(boolean aFlag) {
setIsActiveInt(new Integer(aFlag ? 1 : 0));
}
Aloha,
Art
_______________________________________________
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.