Here’s what I did - but it’s a year + old…
Please note that it also integrates Hikari for connection pools.
With the above done, all you should have to do is:
@Autowired
ICayenneService cayenneService;
Again, I probably can’t answer questions too quickly, but hopefully this helps!
Ken
> On Aug 13, 2019, at 2:16 PM, John Huss <[email protected]> wrote:
>
> You don't want to construct multiple ServerRuntimes, especially not one per
> context. You just need one runtime and you can create many contexts from it.
>
> On Tue, Aug 13, 2019 at 1:09 PM Emerson Castañeda <[email protected]> wrote:
>
>> I got this working using this approach:
>>
>> *dependencies:*
>>
>> //for persistency
>> compile 'org.apache.cayenne:cayenne-server:X.Y'
>> compile 'org.apache.cayenne:cayenne-java8:X.Y'
>> compile 'com.oracle:ojdbc.x.y.b'
>>
>>
>> *application.yml*
>>
>> spring:
>> application:
>> name: app-api
>> evnpath:
>> cayenne_datasource:
>> fpa:
>> username: user
>> password: pwd
>> url: jdbc:oracle:thin:@server.org:1521/DEV.org
>> driver: oracle.jdbc.driver.OracleDriver
>>
>>
>> *Configuration class:*
>>
>> @Component
>> public class DataProviderService {
>> private static final Logger logger =
>> LoggerFactory.getLogger(DataProviderService.class);
>> List<ObjectContext> cayenneContexts = null;
>> @Autowired
>> private MyBeanPropertyReader myBeanPropertyReader;
>>
>> private ObjectContext cayenneContext(String user, String password,String
>> url, String driver) {
>> ServerRuntimeBuilder b = ServerRuntime.builder();
>> b = b.url(url);
>> b = b.jdbcDriver(driver);
>> b = b.user(user);
>> b = b.password(password);
>> b = b.addConfigs("cayenne-ExistentFacultyPortfolio.xml");
>> ServerRuntime cayenneRuntime = b.build();
>> return cayenneRuntime.newContext();
>> }
>>
>>
>> @PostConstruct
>> private void init(){
>> cayenneContexts =
>>
>> Arrays.asList(cayenneContext(myBeanPropertyReader.getUser(),myBeanPropertyReader.getPassword(),
>> myBeanPropertyReader.getUrl(),myBeanPropertyReader.getDriver()));
>>
>> logger.debug("DataProviderService init APPLICATION");
>>
>> cayenneContexts.forEach(
>> oc -> oc.getEntityResolver()
>> .getDataMaps()
>> .forEach(dm -> logger.debug("DATAMAP : "+dm.getName())));
>> }
>>
>> //any other method using the context
>> }
>>
>> *Usage:*
>>
>> @Autowired
>> private DataProviderService dataProviderService;
>>
>>
>> *Note:*
>>
>> datanode and datamap are located in the usual place: src/main/resourcesMy
>>
>> On Tue, Aug 13, 2019 at 12:29 PM 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
>>>
>>