1

Currently I am using Cayenne as my ORM. I need to get DataSource for initializing Velocity Engine in my code. I can manually create the datasource but I don't want to do it and want to use the existing datasource from Cayenne.

Gray
  • 115,027
  • 24
  • 293
  • 354
Narendra
  • 5,635
  • 10
  • 42
  • 54

1 Answers1

1

In Cayenne 3.1 it is rather trivial:

ServerRuntime runtime = .. // this exists in every app
DataSource ds = runtime.getDataSource("MyDataNode");

In the earlier versions it is only marginally harder:

DataDomain dd = context.getParentDataDomain();
DataSource ds = dd.getDataNode("MyDataNode").getDataSource();

The last approach works on 3.1 too BTW.

andrus_a
  • 2,528
  • 1
  • 16
  • 10
  • As Cayenne 3.1 is still in Beta phase I am using 3.0 version. And Thanks for your answer. It worked for me. – Narendra Jan 08 '13 at 11:52