this is precisely what i was hoping for. Is there a reason why we couldn't do something like this?
Brandon Goodin Phase Web and Multimedia P (406) 862-2245 F (406) 862-0354 [EMAIL PROTECTED] http://www.phase.ws > -----Original Message----- > From: Max Rydahl Andersen [mailto:[EMAIL PROTECTED]] > Sent: Monday, September 02, 2002 1:56 AM > To: OJB Users List > Subject: Re: SELECT statements and OJB > > > > > I am extremely new to OJB. But something I was wondering > > > regarding using the > > > PB API is whether or not you can select the particular field > > > (attribute) you > > > want returned. For example, i have a sql statement like such > > > SELECT ID, > > > FIRSTNAME, LASTNAME FROM PEOPLE WHERE ID=2. The PEOPLE table actually > > > contains the following fields: ID, FIRSTNAME, LASTNAME, ADDRESS, CITY, > > > STATE, ZIP, NOTES. In OJB PB it seems that all i can do is > > > the equivalent of > > > SELECT * FROM PEOPLE WHERE... I don't want to select all (*) > > > the fields > > > everytime. In the afformentioned sql statement i want to just > > > produce a list > > > of People objects that have only the id, firstname and > > > lastname variables > > > populated. Am i missing something > > > > Yes! > > > > 1. OJB does *not* perform "select * from", for queries! > > If you look up objects of class x OJB will read the class-descriptor for > > class x and determine all necessary columns to materialize an x > instance. > > The performed select contains all those columns. > > > > If you want to limit the number of columns you can modify the > > class-descriptor for class X do get a reduced number of columns. > > Idea: It would be great if one did not need to modify the class-descriptor > as this will influence code > that needs to have the "full" person :) > > How about letting one at runtime state that: "yes, i want to load > a class X, > but hey - I only have THESE FIELDS in THIS STATEMENT to give you > - the rest > you should just 'forget'" > > e.g. (pseudo-code) > q = new Query("SELECT ID, FIRSTNAME, LASTNAME FROM PEOPLE WHERE ID=2"); > q.setWantedClass(Person.class); > q.limitToField(new String[] = {"ID", "FIRSTNAME", "LASTNAME"}); > > Now when using the query q, the objects returned are true Persons, but the > fields NOT listed in limitToField are simply not filled in. > > One might introduce a variable on such "partial" objects that state which > fields are not available or simply just stating "this is not a complete > object" - This variable should be stated in the repository.xml file. > > Just the fact that one can write a sql statement that is used for creating > objects from instead of always loading them from the stated table > is a great > force (in my opinion) > > Just a thought... > > /max > > > 2. OJB does have a ReportQuery concept. ReportQueries do not generate > > collections of fully materialized entity objects, but a Simple tabular > > representation of resultsets. > > > > You can use PersistenceBroker.getReportQueryIteratorbyQuery(q) > do iterate > > over a query resultset. > > You can also combine ReportQueries with QueryBySql Queries to perform > > arbitrary freeform SQL. > > > > > > > or is this just not > > > possible apart from > > > using a sql statement call from the PB API's QuerBySQL (if > > > that would even > > > work cuz i haven't tested it). If i can't be selective about > > > the data that > > > populates my People object then I will produce a lot of > > > unecessary data > > > collection and population from the database to my objects. > > > Especially if the > > > NOTES field can contain 250k of data (an exaggeration of > > > course but the > > > point is there). The thing that attracted me to OJB was how > > > easy it is to > > > code to a database with OO patterns. I hope the solution > > > isn't something > > > that requires me to write some kind of extra class each time > > > i want to limit > > > what is populated in my People class or require me to create > > > a whole new > > > class to handle just the listing of the basic people info. > > > > This would be a third solution, but as there are two others it's not > > mandatory... > > > > cheers, > > Thomas > > > > > Thanks, > > > Brandon Goodin > > > Phase Web and Multimedia > > > P (406) 862-2245 > > > F (406) 862-0354 > > > [EMAIL PROTECTED] > > > http://www.phase.ws > > > > > > > > > -- > > > To unsubscribe, e-mail: > > > <mailto:[EMAIL PROTECTED]> > > > For additional commands, e-mail: > > > <mailto:[EMAIL PROTECTED]> > > > > > > > -- > > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
