David Blevins wrote:
> 
> 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;
> }
> ----------------------------------------------------------------
> 

Thank you very much David. If I can do this with OpenEJB APIs as you
mentioned above, then that is enough.

Manoj.

-- 
View this message in context: 
http://www.nabble.com/Can-we-add-a-datasource-as-resource-at-runtime---tp17556706p17648808.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to