On May 6, 2012, at 1:32 PM, David Blevins wrote:
> I recall your app and I'd guess the heart of your distaste is that you
> essentially configure two datasources and then pick one at runtime.
>
> In static code, this is possible (there is equivalent xml):
>
> @DataSourceDefinition(name = "java:app/test/ds" ....)
> @DataSourceDefinition(name = "java:app/prod/ds" ....)
> @Resource(name = "java:app/ds", lookup="java:app/prod/ds")
> public class SomeCdiBean {
> }
>
> Two datasources are declared and one symlink that the application can use
> safely. Clearly the above "symlink" is still hardcoded, so to get some more
> dynamic behavior you could potentially put the "@Resource" link on a separate
> class in a separate jar. Perhaps a "prod.jar" to hold all the mappings for
> production and a "test.jar" to hold all the mappings for test, then make sure
> only one of them is in the application at any given time.
>
> Still limited of course as changing the archive is required and often that
> isn't allowed between test and production.
For the sake of completeness, I should also say that swapping the descriptors
out without modifying the archive is the reason for the alternate deployment
descriptor functionality (alt-dd) all full profile certified servers support.
So even that concept has been addressed at the spec level.
One of the things not supported by plain Tomcat or Jetty, so also not commonly
known or used.
-David