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 18:29:56 GMT

On Jun 4, 2008, at 7:58 AM, ManojS wrote:

>
>
> 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.

Great.  If this route is good for you than we should probably add it  
to the server and in the next release you can switch to using it.  If  
we keep the interface generic enough, it'll be far easier to support  
long term whereas all the little internal api calls are subject to  
change.

If you're willing to contribute back the bean you're using, great.   
Otherwise we'll use something like the one above.

-David




Mime
View raw message