get rid of the transaction... why are you doing a broker.close() before
you starting iterating? Not sure what you are trying to do.
getIteratorByQuery() is a lazy version of getCollectionByQuery(). If
does a count when creating the iterator and a select on each
iter.next().
your code should look more like this:
broker = PersistenceBrokerFactory.defaultPersistenceBroker();
Query query = 'whatever your query is';
Iterator iter = broker.getIteratorByQuery(query);
while (iter.hasNext()) {
Person person = (Person) iter.next()
...
}
broker.close();
On Thu, 2003-10-30 at 08:00, [EMAIL PROTECTED] wrote:
> Hello,
>
> I have a question/problem about the function getIteratorByQuery():
>
> Here is a code:
>
> ****code****
> Iterator iter = null;
> try {
> broker = PersistenceBrokerFactory.defaultPersistenceBroker();
> broker.beginTransaction();
> iter = broker.getIteratorByQuery(query);
> broker.commitTransaction();
> } catch (PersistenceBrokerException t) {
> broker.abortTransaction();
> t.printStackTrace();
> } finally {
> broker.close();
> }
>
> while (iter.hasNext()) {
> Person person = (Person) iter.next();
> ....
> some code
> ....
> }
> ****code****
>
> I have noticed that the Iterator object called iter isn't available after the broker
> is closed (no iteration in the "while" statement).
> Why?
>
> My idea is to use a broker only when I need one and close it just after the use.
> What is the solution?
> But could I write the code as below?
>
> ****code****
> try {
> broker = PersistenceBrokerFactory.defaultPersistenceBroker();
> broker.beginTransaction();
> Iterator iter = broker.getIteratorByQuery(query);
> while (iter.hasNext()) {
> Person person = (Person) iter.next();
> ....
> some code
> ....
> }
> broker.commitTransaction();
> } catch (PersistenceBrokerException t) {
> broker.abortTransaction();
> t.printStackTrace();
> } finally {
> broker.close();
> }
> ****code****
>
> Thanks for any help
> Sylvain
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]