cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <johnth...@gmail.com>
Subject Re: Batch iteration
Date Sat, 15 Oct 2016 21:34:39 GMT
I would use a peer context.

You can create a peer context like this if you runtime has been bound to
the current thread using
CayenneRuntime.bindThreadInjector(runtime.getInjector())

public static ObjectContext newObjectContext() {
ObjectContextFactory factory = CayenneRuntime.getThreadInjector
().getInstance(ObjectContextFactory.class);
return (factory != null) ? factory.createContext() : null;
}



On Sat, Oct 15, 2016 at 2:37 PM Mark Wardle <mark@wardle.org> wrote:

> Sorry… meant to say using Cayenne M4.0.M3…
>
> Mark
>
> > On 15 Oct 2016, at 20:29, Mark Wardle <mark@wardle.org> wrote:
> >
> > I’m using ResultBatchIterator like this:
> >
> > Consumer<T> forEach = ...
> > try (ResultBatchIterator<T> iterator = query.batchIterator(context,
> batchSize)) {
> >                       for(List<T> batch : iterator) {
> >                               for (T c : batch) {
> >                                       forEach.accept(c);
> >                               }
> >                       }
> >               }
> >
> > but I also want to do some processing, inserting rows, editing objects
> etc. I see lots of SQL in my logs, but the transaction doesn’t get
> committed until the batch iterator completes, whether I use
> context.commitChanges() or context.performGenericQuery() on some custom SQL
> created using SQLTemplate.
> >
> > Is there a way of committing the transaction earlier, or should I use a
> peer object context? Is there an easy of getting a new peer editing context
> given a single object context or do I need to inject a ServerRuntime here?
> >
> > Thank you,
> >
> > Mark
> >
> >
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message