You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by levan Dvalishvili <ad...@amostudio.com> on 2006/05/29 19:20:53 UTC
Enum Type
Hi All!
I am need to this mailing ,a s a fact this is my first question here ..
I am working on a project and would like to use ENUM as an attribute on my
bean like this :
------------------ SAMPLE CODE ------------------------
public class Shipment implements Serializable{
enum ShipmentStatus{notShipped("Not Shiped"),
onTheWay("on the way"),
arrived("Arrived");
private String value;
ShipmentStatus(String newValue) {
value = newValue;
}
ShipmentStatus() {
value="NOT SPECIFIED";
}
String getShipmentStatus() { return value; }
}
private ShipmentStatus Status;
private Date departureDate;
private ShipmentStatus Status;
private Date ArivalDate;
etc .....
}
---------------------- END OF SAMPLE CODE --------------------------------
I am working into IBATIS as I go ..., and would like to ask if this way will
work with the mapping? Do I have to write a custom type handler?
I also have ac corresponding enum on database side (DB is mySQL) Has
anything like that been done yet? Is this a right way of doing it or should
I just forget about ENUM and just use string?
Best regards
And thanks for creating such a great product
Levan.
Re: Enum Type
Posted by Nathan Maves <Na...@Sun.COM>.
Levan,
As a first time poster let me inform you on a great source of
information. Below is the archive of this alias. Please search
there before posting new questions.
http://www.mail-archive.com/user-java@ibatis.apache.org/
To answer your post...
Yes, This is fully supported in ibatis. You will need to create a
CTH(custom type handler). There is a wiki post about this.
http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I
+use+a+Custom+Type+Handler+with+complex+property+or+Type+Safe
+Enumeration
On a side note I would not suggest naming you enums like that. Other
people might get them confused with a method name. I would suggest
FULL CAPS for enum names. Just a good convention :)
Nathan
On May 29, 2006, at 11:20 AM, levan Dvalishvili wrote:
> Hi All!
> I am need to this mailing ,a s a fact this is my first question
> here ..
>
> I am working on a project and would like to use ENUM as an
> attribute on my
> bean like this :
>
> ------------------ SAMPLE CODE ------------------------
> public class Shipment implements Serializable{
> enum ShipmentStatus{notShipped("Not Shiped"),
> onTheWay("on the way"),
> arrived("Arrived");
>
> private String value;
>
> ShipmentStatus(String newValue) {
> value = newValue;
> }
>
>
> ShipmentStatus() {
> value="NOT SPECIFIED";
> }
> String getShipmentStatus() { return value; }
> }
>
> private ShipmentStatus Status;
> private Date departureDate;
> private ShipmentStatus Status;
> private Date ArivalDate;
> etc .....
> }
> ---------------------- END OF SAMPLE CODE
> --------------------------------
>
> I am working into IBATIS as I go ..., and would like to ask if this
> way will
> work with the mapping? Do I have to write a custom type handler?
> I also have ac corresponding enum on database side (DB is mySQL) Has
> anything like that been done yet? Is this a right way of doing it
> or should
> I just forget about ENUM and just use string?
> Best regards
> And thanks for creating such a great product
> Levan.
>
>
>