Re: Getting repository information

Armin Waibel <[email protected]> Wed, 08 Aug 2007 01:43:20 +0200
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hi Lasse,

Lambrecht, Lasse (Allianz Deutschland AG) wrote:
> Hello everybody,
> 
> I'm trying to get some of the information stored in the repository
> files (of my o/r mapping). So far I tried something like this to get
> the "translation" from the Java name of an attribute to the DB2
> column name - which works fine:
> 
> DescriptorRepository lRepository =
> ojbBrokerRef.getDescriptorRepository(); try { ClassDescriptor lClass
> = lRepository.getDescriptorFor(persistenteKlasse); FieldDescriptor
> lField = lClass.getFieldDescriptorByName(feldname); lResult =
> lField.getColumnName(); } catch (ClassNotPersistenceCapableException
> e) { .... }
> 
> Now two questions: a) is there a way to do the opposite? I have a DB2
> table/column name and want to get the Java name. Sure, I can iterate
> through all ClassDescriptors, but that seems not the perfect solution
> (my repository-XML is close to 1 MB). 

Sorry, OJB doesn't provide such specific "reverse"-methods! If this 
happens more then a few times and performance is significant, I 
recommend to map table-name/ClassDescriptor once on startup of the 
application (if different repository profiles are used you have to take 
care of this too - 
http://db.apache.org/ojb/docu/guides/metadata.html#Object+metadata+profiles).


> b) how can I find a field, if I
> don't know, in which ClassDescriptor the field is located? I only
> have a field name in some rare situations. The fieldname is unique.
> The only way I see is to, again, iterate through all 
> ClassDescriptors.

yep! Or again map this by your own on startup of the application.

I would recommend to write a simple test to check the time period for 
CLD-iteration and then decide which way to go.

regards,
Armin

> 
> Regards Lasse Lambrecht
> 
> _____
> 
> 
> Allianz Deutschland AG Vorsitzender des Aufsichtsrats: Michael
> Diekmann. Vorstand: Dr. Gerhard Rupprecht, Vorsitzender; Hansjörg
> Cramer, Dr. Karl-Hermann Lowe, Dr. Christof Mascher, Thomas Pleines,
> Dr. Ulrich Rumm, Ulrich Schumacher, Dr. Maximilian Zimmerer. Für
> Umsatzsteuerzwecke: USt-ID-Nr.: DE 814 580 981 ;
> Versicherungsbeiträge sind umsatzsteuerfrei. Sitz der Gesellschaft:
> München Registergericht: München HRB 158878
> 
>