tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: Can we add a datasource as resource at runtime ?
Date Wed, 04 Jun 2008 04:22:53 GMT

On May 30, 2008, at 4:27 AM, ManojS wrote:

> In openejb 3.0, after initializing the openejb server, can we add a  
> new
> datasource to the resource configuration ? I mean, adding a datasource
> resource at runtime is possible ?
>
> Any info are welcome.  Thanks in advance.

We support rar file deployment so you could use the deploy tool and do  
it that way, though I think rar files are sort of a pain and overly  
complex.

We've kicked around the idea of allowing the definition of <Resource>  
and <Container> in your openejb-jar.xml so that you could essentially  
ship/deploy your apps required configuration with your app.

If you don't mind using OpenEJB apis directly, you could create an ejb  
that does this:

----------------------------------------------------------------
import org.apache.openejb.assembler.classic.Assembler;
import org.apache.openejb.assembler.classic.ResourceInfo;
import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.config.sys.Resource;
import org.apache.openejb.config.AdminLocal;
import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.OpenEJBException;

import javax.ejb.Stateless;

@Stateless
public class AdminBean implements AdminLocal {

     private static final ConfigurationFactory config = new  
ConfigurationFactory();
     private static final Assembler assembler =  
SystemInstance.get().getComponent(Assembler.class);

     public void addDataSource(String id, Class driver, String url,  
boolean managed) throws Exception {
         try {
             Resource resource = new Resource(id, "DataSource");
             resource.getProperties().put("JdbcDriver",  
driver.getName());
             resource.getProperties().put("JdbcUrl", url);
             resource.getProperties().put("JtaManaged", managed + "");

              
assembler.createResource(config.configureService(resource,  
ResourceInfo.class));
         } catch (OpenEJBException e) {
             throw new Exception("Adding DataSource failed.", e);
         }
     }
}

public interface AdminLocal {
     void addDataSource(String id, Class driver, String url, boolean  
managed) throws Exception;
}
----------------------------------------------------------------

Alternatively, we could cook up a command line tool that you could  
drop into an existing OpenEJB 3.0 server.

There might be something we can do to improve our ability to  
dynamically create Resources like DataSource for you automatically.

If you're ok giving some info on your use case that'd give us a good  
idea which of the many options we might make standard.


-David


Mime
View raw message