You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by David Blevins <da...@visi.com> on 2008/06/04 06:22:53 UTC
Re: Can we add a datasource as resource at runtime ?
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
Re: Can we add a datasource as resource at runtime ?
Posted by ManojS <ma...@yahoo.co.in>.
David Blevins wrote:
>
>
> If you're willing to contribute back the bean you're using, great.
> Otherwise we'll use something like the one above.
>
>
Yes, David, I can do that.
Manoj.
--
View this message in context: http://www.nabble.com/Can-we-add-a-datasource-as-resource-at-runtime---tp17556706p17672245.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Can we add a datasource as resource at runtime ?
Posted by David Blevins <da...@visi.com>.
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
Re: Can we add a datasource as resource at runtime ?
Posted by ManojS <ma...@yahoo.co.in>.
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.