On Tue, Jul 29, 2003 at 04:58:10PM +1000, Brian Wallis wrote:
> 
> This may be just an ignorant CMP question, but...
> 
> Can I define a mapping (in the jaws type-mappings for a database) so that I 
> can use a user defined class. In this instance I'm interested in a simple 
> Enum class.
> 
> In my CMP bean definition I want the persistent attribute to be of type 
> my.package.MyEnum and the mapping to the database to be (for example) 
> NUMBER(1) or STRING as appropriate to my app.
> 
> To do this I would need to supply the conversion code to convert from MyEnum 
> to an appropriate JDBC type to store in NUMBER(1). The advantage I get is 
> that I can encapsulate the range checking or string matching for the enum 
> type in my class rather than have an interface to the CMP Bean that allows 
> the storing of any int or string that will fit the DB type.
> 
> I haven't managed to find out if this is possible and if so where this might 
> be documented. 
> 

I'm not sure if this is the solution you're looking for - you could
simply wrap the cmp-method with a custom getter/setter method in the bean:

/**
 * This defines a CMP field.
 * Used by the container to persist the bean, but not a part of
 * the business interface of the bean.
 * @ejb.persistence column-name="enum_value" jdbc-type="INT"
 */
 public abstract int getEnumValue();

/**
 * This an accessor in the business interface.
 * @ejb.interface-method
 */
 public Enum getEnum(){
   Enum enum = new Enum(getEnumValue());
   return enum;
 }

 (and the same for the setter).

 //Anders

-- 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. Anders Engstr�m         [EMAIL PROTECTED]
. http://www.gnejs.net    PGP-Key: ED010E7F
. [Your mind is like an umbrella. It doesn't work unless you open it.]  

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to