Re: Cayenne And SpringBoot

Emerson Castañeda <[email protected]>
Newsgroups gmane.comp.java.cayenne.user
Message-ID <CALnPV8TBW_5mUxjOELem2HCW70pMQuSxYtFv0iU2UkZ-ibU3TA@mail.gmail.com>
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
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.