On Nov 23, 2004, at 10:16 PM, Alex Gunawan Wibowo wrote:
> I can use the method "isMandatory()" from
> org.objectstyle.cayenne.map.DbAttribute..
Yep, that's the one.
> the question now is how do i instantiate this DbAttribute.
You don't "instantiate" DbAttribute. The beauty of Cayenne is that
Cayenne runtime provides all the metadata for you, you only need to
find it... Say you have an Artist object with "artistName" Java
property that maps to "ARTIST_NAME" db column. You would go about it
using code like this:
Artist myArtist = ...;
ObjEntity entity =
getDataContext().getEntityResolver().lookupObjEntity(myArtist);
ObjAttribute attribute = (ObjAttribute)
entity.getAttribute("artistName");
boolean isMandatory = attribute.getDbAttribute().isMandatory();
Also don't overlook built-in Cayenne validation (see
http://objectstyle.org/cayenne/userguide/dataobjects/validation.html).
So maybe it will be enough to simply handle ValidationException when
you save your objects to DB, instead of trying to handle each field
manually?
Andrus
> I have this snipplet from the web..
> -------------------------------------
> Iterator it = ent.getAttributes().iterator();
> ....
> DbAttribute at = (DbAttribute) it.next();
> --------------------------------------
> Not too sure about this, but I guess that
> "getAttributes()" is a method from class
> org.objectstyle.cayenne.map.Entity.
>
> THis is what I think:
> I have to instantiate this Entity class,
> and call it's "setDataMap()" method.
> --> I think setDataMap is setting which XML data
> mapping file.
>
> Now the problem is, how do i get the DataMapping
> file??
> Is it stored somewhere?
> If it has to be read manually everytime, that will
> really really slow down the whole system (parsing XML
> files)...
>
>
> Sorry if this is a bit messy...
> But I hope you get the overall picture..
>
>
> Best regards,
>
>
> Alex.
>
>
> --- Alex Gunawan Wibowo <netzone_tec..ahoo.com>
> wrote:
>
>> Hello,
>>
>> Does anyone know if Cayenne can check if a
>> particular
>> field in a table is required to be filled (i.e. NOT
>> NULL)?
>>
>> I'm developing an application with Struts, and I
>> want
>> this behaviour to check if a particular field has
>> been
>> provided by the user.
>> I can manually code this behaviour by reading a
>> property file.. but that is a bit dirty i would say.
>> (i.e. a change in the database schema would require
>> a
>> change in the property file, etc etc).
>>
>> Thank you very much for the help!
>>
>>
>> Best regards,
>>
>> Alex Wibowo
>>
>> =====
>> Alex Wibowo
>> ~ Second is a failure ~
>> The University of Melbourne
>> Department of Computer Science and Software
>> Engineering
>> Website - http://www.cs.mu.oz.au/~agwibowo
>> Team Wasabi -
>> http://www.cs.mu.oz.au/SE-projects/s440gh
>> ==============================================
>>
>>
>>
>> __________________________________
>> Do you Yahoo!?
>> All your favorites on one personal page – Try My
>> Yahoo!
>> http://my.yahoo.com
>>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Meet the all-new My Yahoo! - Try it today!
> http://my.yahoo.com
>
>
>
This archive was generated by hypermail 2.0.0 : Tue Nov 23 2004 - 23:30:29 EST