cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: inject DataSourceFactory
Date Mon, 18 Aug 2014 14:25:06 GMT
Hi Tore,

Wrap it in a Module, and use bind .. toInstance:

Module m = new Module() {
   @Override
   public void configure(Binder binder) {
      binder.bind(DataSourceFactory.class).toInstance(myFactory);
   }
}

runtime = new ServerRuntime(“cayenne-mydomain.xml”, m);

Or if you are not averse to using nightly builds, use ServerRuntimeBuilder from 3.2 master,
that has “dataSource(DataSource ds)” method to set the DataSource explicitly [1].

Cheers,
Andrus

[1] https://github.com/apache/cayenne/blob/master/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java

On Aug 18, 2014, at 5:15 PM, Tore Halset <halset@pvv.ntnu.no> wrote:

> Hello.
> 
> How should I inject a custom DataSourceFactory? I have tried this, but it still try to
use the DataSourceFactory in the model. This is going to have multiple ServerRuntimes - one
for each database.
> 
> runtime = new ServerRuntime(“cayenne-mydomain.xml");
>        runtime.getInjector().injectMembers(new DataSourceFactory() {
>            @Override
>            public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws
Exception {
>                return mything.getDataSource();
>            }
>        });
> 
> Regards,
> Tore Halset.


Mime
View raw message