Andrus,
> Also just found this on GitHub [1]. Not sure how legit it is. But posting our
> own "canonical" SpringBoot example is probably a good idea.
On the subject of 'working examples', I could not agree more.
Cayenne 4 is an excellent framework, and there are some excellent working
examples. However, there are also some framework-collaboration concepts that
could be more easily communicated with more detailed working examples and
recommended “best practices”.
I had to spend hours trying out a lot of non-working code fragments, and
out-dated version examples. The two that provided insight were Ken Anderson’s
"Lovely…. I guess the list doesn’t support attachments…
CayenneService.java” (August 13, 2019 email),
and solution-1 from stackoverflow
https://stackoverflow.com/questions/46713728/using-cayenneruntime-in-webapplication-without-web-xml/46718149#46718149
My legacy Cayenne code (based on the at-the-time - version 3 - highly
recommended "BaseContext.getThreadObjectContext()”) - recently upgraded to
Cayenne-4, as best as I can tell, only works strategically with the
stackoverflow example (above). I would not have been able to get an effective
demo of this working without these two working examples, (i.e. just based on
reference docs).
Comments:
1. These two working examples very quickly contrasted DI-Service vs
ServletFilter strategies.
2. Working examples illustrate complex collaboration scenarios much more
effectively.
Succinctly:
working examples - version-aware - effective collaboration demonstrations
Hope this helps,
Joe
> On Aug 13, 2019, at 1:25 PM, Andrus Adamchik <[email protected]> wrote:
>
>> Cayenne is pretty generic as far as integrations go - it should work well
>> and easily with any framework.
>
> Yep.
>
>>> Has anyone done this before? Are there any suggestions on what I should
>>> be certain to do or avoid? Should I just spin up the standard Cayenne web
>>> filter? Are there other choices?
>
>
> It's been 3 years since I tried SpringBoot, so I don't remember all the
> classes involved. But at the high level the approach should be the same as
> with Bootique:
>
> 1. Bind ServerRuntime as an injectable *singleton*
> 2. Figure out how to scope ObjectContexts based on the app specifics.
>
> I'd actually avoid CayenneFilter. It is too servlet-specific and favors
> session scope for the context. My typical pattern for #2 is creating a simple
> custom service like this:
>
> public interface ICayenneService {
> ObjectContext sharedContext();
> ObjectContext newContext();
> }
>
> It provides user-friendly API around ServerRuntime, and you inject it
> everywhere you need a context. You'd use "sharedContext" for reads, and
> "newContext" for writes.
>
> Also just found this on GitHub [1]. Not sure how legit it is. But posting our
> own "canonical" SpringBoot example is probably a good idea.
>
> Andrus
>
> [1] https://github.com/Softmotions/spring-boot-starter-cayenne
>
>> On Aug 13, 2019, at 7:56 PM, John Huss <[email protected]> wrote:
>>
>> Cayenne is pretty generic as far as integrations go - it should work well
>> and easily with any framework. Just create your ServerRuntime and define a
>> way to retrieve it (using ServletContext.setAttribute is typical). Then
>> you'll want to bind the runtime to each request that comes in, which is all
>> that CayenneFilter does. If CayenneFilter has worked for you, then just use
>> that. CayenneFilter is very minimal so you copy it and customize it if
>> needed.
>>
>> On Tue, Aug 13, 2019 at 11:29 AM Tony Giaccone <[email protected]> wrote:
>>
>>> I want to look into using Cayenne with SpringBoot. I was able to get a
>>> basic cayenne stack up and running by implementing a ContextListener and
>>> on the create event starting up a Cayenne Runtime. I was using an in
>>> memory database and I had problems getting the ;create=true working. My
>>> hack was to set the strategy on the DataNode after the runtime after it
>>> was spun up.
>>>
>>> Has anyone done this before? Are there any suggestions on what I should
>>> be certain to do or avoid? Should I just spin up the standard Cayenne web
>>> filter? Are there other choices?
>>>
>>> Thanks for any help you can provide.
>>>
>>>
>>> Tony
>>>
>