Re: [OJB-developers] How to dynamic lazy-load a field or a collection in runtime?
Brought to you by:
thma
From: Thomas M. <tho...@ho...> - 2002-03-11 19:47:57
|
Hi John, John Wang wrote: > As my application needs a high performance design, I am wondering > whether it is possible to modify the classdescriptor in the runtime, to > disable the loading of unneeded fields, and for collections, don't load > the collection object's primary keys at all (the collection may contain > thousands of items), but load only when needed. Can I do it in the runtime? > Yes. The Metadata layer is completely dynamic. There is a method setClassDescriptor(...) in PersistenceBroker that allows to write modified ClassDescriptors to the DescriptorRepository. You may also use CollectionProxies and ReferenceProxies to minimize load overhead during object materialization. Just have a look at the TestCases for this features. Using proxies there is no need to change MetaData at runtime for 1:1, 1:n and n:m associations as they defer materialization of objects to the latest possible point in time (aka "lazy materialization"). To get an impression if OJB will meet your performance needs, there is a special ANT target "performance". Call build[.sh] performance to execute these tests against your target database. The tests perform mass operations 1. using OJB, 2. using native JDBC calls. These tests will give you an impression about the impact OJB has on your applications performance! (In typical Evironments about 10 - 25 % ) The code for the Jdbc based reference test contain sample code that may be helpful if a full dynamic O/R mapping is no option for certain performance critical operations. OJB may still be helpful in such cases as it allows to work cleanly with JDBC connections and PreparedStatements. (just have a look at the test cases) > > > Say that for an user, it has following categoties of info: > > 1. basic info: id, name, > > 2. extended info: home address > > 3. clob field: photo > > 4. collection: a long list of friends > > > > When retrieve a list of users, it only need to retrieve the basic info; > when view a specific user, it needs the extended info; when you want to > photo, you need to clob fields. You certainly don't want to get the > friends until you want to view a specific user, and also no need to > retrieve primary keys of friends collection, too. > > > > Is it possible to do using OJB? sure! There is also another technique that might be useful: ReportQueries. ReportQueries might be used to retrieve a list of basic info. They won't materialize full User objects! Have a look at PersistenceBroker::getReportQueryIteratorByQuery(Query) and the respective TestCases! > > > > Thanks a lot, > > John W > > > |