Yeah, the Wiki page refers to Cayenne 3.0 and earlier. In 3.1 it is much easier
and can be done via a DI container. And you don't have to remember all the
classes that might use the DataSource. So you would create a custom module,
bind a custom DataSourceFactory, and pass it to ServerRuntime constructor:
Module m = new Module() {
public void configure(Binder binder) {
binder.bind(DataSourceFactory.class).to(MyDataSourceFactory.class);
}
};
ServerRuntime r = new ServerRuntime("cayenne-myconfig.xml", m);
On May 26, 2011, at 6:19 AM, Wernke zur Borg wrote:
> Hi all,
>
> I am referring to FAQ "Setting Database Connection" here:
> https://cwiki.apache.org/CAY/setting-database-connection.html
>
> Firstly, in 3.1 the SharedConfiguration no longer exists, so we have to use
> the ServerRuntime instead:
>
> ServerRuntime runtime = ...;
> DataDomain domain = runtime.getDataDomain();
> DataNode node = domain.getNode("DB1");
> node.setDataSource(dataSource);
>
> However, this setting does not have the desired effect. When the connection
> to the database is established, still the original definition from the config
> file is taken.
>
> I have traced down this problem and found that the DataNode has a DbAdapter,
> which has its own DataSource object. This gets set in the
> ServerRuntime.getDataDomain() call above.
>
> The only way I found around this is by explicitly creating a new adapter with
> my data source:
>
> node.setAdapter(new AutoAdapter(dataSource));
>
> However, the AutoAdapter default constructor is deprecated, and I could not
> find an easy way to use the recommended method with a DbAdapterFactory.
>
> Any ideas?
>
> Thanks for any hint.
>
> Wernke
>
>
>
>
> --
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> MOIS Helpdesk at ESA/ESOC - B106
> internal phone: "MOIS Helpdsk" or 62066
> email: [email protected] , [email protected]
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> Wernke zur Borg
> Software Engineer, Rhea System S.A.,
> MOIS Support Team, European Space Operations Centre
> Robert Bosch Str 5, 64293 Darmstadt, Germany
> Tel: +49-6151-90-2344 Fax: +49-6151-90-2908
>
>