> I'm also not able to access the ServerRuntime instance from my custom
> DataSourceFactory

While you can't access ServerRuntime, you can inject anything inside it into 
your factory just by declaring and annotating it it ("anything" == interfaces 
declared in ServerModule). E.g.:

public class MyDSF implement DataSourceFactory {

   @Inject
   private DbAdapter adapter;

   public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws 
Exception { .. }
}

> i'm trying to implement a custom DataSourceFactory class. While this is
> dead easy of course i'm struggling a bit on how to get my configuration
> parameters into the instance of my class.

While there are other ways to do it, here is a very simple one - create an 
instance of DataSourceFactory yourself inside the module, with all the 
parameters and pass it to Cayenne DI after that:

public MyM implements Module {

    private String[] stuff;

    public MyM(String… stuff) {
        this.stuff = stuff;
    }

    public void configure(Binder binder) {
  
       DataSourceFactory dsf = new MyOtherDSF(stuff);
       binder.bind(DataSourceFactory.class).toInstance(dsf);
    }
}

BTW the above is even compatible with @Inject - Cayenne will inject objects 
into fields annotated with @Inject like in the previous example.

Andrus


On Feb 28, 2013, at 1:00 PM, Daniel Scheibe <[email protected]> wrote:

> Guys,
> 
> i'm trying to implement a custom DataSourceFactory class. While this is
> dead easy of course i'm struggling a bit on how to get my configuration
> parameters into the instance of my class.
> 
> I want to have some custom user properties (external data source
> configuration, custom data source pool, etc.) injected into my custom
> DataSourceFactory but since the object instace is created by the
> ServerRuntime on startup i have practically no way of getting that done, or
> am i missing something here?
> 
> I'm also not able to access the ServerRuntime instance from my custom
> DataSourceFactory because the only parameter available is the
> DataNodeDescriptor provided to getDataSource and i think there is no link
> to the ServerRuntime in there as well.
> 
> I know about the "Custom Configuration/Location Hint" property in the
> modeller but this would only allow me to provide some link to a file, etc.
> 
> Is there a chance to replace the DataSourceFactory instance upon
> ServerRuntime initialization with a pre-instantiated object?
> 
> Can anyone help me out on this?
> 
> Thanks in advance!
> 
> Cheers,
> Daniel

Reply via email to