openejb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luis Fernando Planella Gonzalez <lfpg....@gmail.com>
Subject Re: Resolve datasource from the application name
Date Fri, 13 Nov 2009 17:06:40 GMT
Well, I'm starting to look at this issue today.

Just a small recap: I'm starting to write a patch to automatically
configure data sources in a persistence unit which match the deployed
web application context name. SO, if I have N instances of the same
app in the same server, all I need to do is setup N data sources, each
with the exact name of the web application context for each instance.

>From my previous post, you've answered the "Where is this heuristic
implemented?" question: in AutoConfig.
But I still need the answer for the second one "How to get the current
application name?".
My first idea would be to pick up the first WebModule in
AppModule.getWebModules() (if any) and invoke it's getContextRoot().
Is this ok? If that is the way to go, I would also have to change the
deploy(PersistenceModule) into deploy(AppModule, PersistenceModule),
so that the web applications may be read.

Am I in the right path?

For now, I'm also creating a new test in AutoConfigPersistenceUnitsTest:
    public void testFromWebApp() throws Exception {

        ResourceInfo jta = addDataSource("OrangeWeb",
OrangeDriver.class, "jdbc:orange-web:some:stuff", null);
        ResourceInfo nonJta = addDataSource("OrangeWebUnmanaged",
OrangeDriver.class, "jdbc:orange-web:some:stuff", null);

        PersistenceUnit persistenceUnit = new PersistenceUnit("orange");

        ClassLoader cl = this.getClass().getClassLoader();
        AppModule app = new AppModule(cl, "orange-app");
        app.getPersistenceModules().add(new PersistenceModule("root",
new Persistence(persistenceUnit)));
        WebApp webApp = new WebApp();
        webApp.setMetadataComplete(true);
        app.getWebModules().add(new WebModule(webApp, "orange-web",
cl, "war", "orange-web"));

        // Create app
        AppInfo appInfo = config.configureApplication(app);
        assembler.createApplication(appInfo);

        // Check results
        PersistenceUnitInfo orangeUnit = appInfo.persistenceUnits.get(0);

        assertEquals(jta.id, orangeUnit.jtaDataSource);
        assertEquals(nonJta.id, orangeUnit.nonJtaDataSource);
    }

--
Luis Fernando Planella Gonzalez
lfpg.dev@gmail.com

Mime
View raw message