You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by tonywestonuk <to...@totspics.com> on 2016/05/06 08:45:12 UTC

Datasources....Again! Sorry....

Hi.... After moving my datasources to Tomee, I can access any of them from
any application. running on the server.  However, I must define within the
application code, the name of the datasource I want to use... if I do not,
the default is the first one defined in Tomee.

Is there any way of choosing a default per application?...   So, App1 could
have a default datasource of ds1, and app2 could have a default datasource
of ds2/


I think I asked this already, and you mentioned something about putting
alias's in the resource tag. But, I cant see how this can solve the issue?

Thanks.





--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Datasources-Again-Sorry-tp4678367.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Datasources....Again! Sorry....

Posted by Romain Manni-Bucau <rm...@gmail.com>.
This is not reliable AFAIK.

Resources.xml would work but we dont have yet the resource impl returning a
looked up resource - can be in your webapp:

Public class MyResource {
  Private String name;

  Public void create() {
    Return
SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup(name);
  }
}

Then <Resource id="..." class-name="MyResource"
factory-method="create">name=openejb:Resource/foo</Resource> works.
Le 6 mai 2016 20:42, "tonywestonuk" <to...@totspics.com> a écrit :

> Its just what I am used to with tomcat.   A set of global resources are
> defined, and then the one that is required is 'selected' by the context.xml
> choosing a global data resource.
>
> One of the advantages is that it was very easy to change between different
> test environments.... just by change the reference in context.xml,  your
> app
> is now pointing at a different database, without having to update the
> settings at the server level tomee.xml
>
> I think its possible using a public static String to define which id is
> needed, and then have to select. not quite as clean, but at least I can
> change the database looked at by the whole app in one place.
>
> @resource(name=DATABASE_REF)
> DataSource database
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Datasources-Again-Sorry-tp4678367p4678378.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Datasources....Again! Sorry....

Posted by tonywestonuk <to...@totspics.com>.
Its just what I am used to with tomcat.   A set of global resources are
defined, and then the one that is required is 'selected' by the context.xml
choosing a global data resource.  

One of the advantages is that it was very easy to change between different
test environments.... just by change the reference in context.xml,  your app
is now pointing at a different database, without having to update the
settings at the server level tomee.xml

I think its possible using a public static String to define which id is
needed, and then have to select. not quite as clean, but at least I can
change the database looked at by the whole app in one place.

@resource(name=DATABASE_REF)
DataSource database




--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Datasources-Again-Sorry-tp4678367p4678378.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Datasources....Again! Sorry....

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

No you cant. What is the issue of defining the datasource with the right
name?

We support aliases so you can define multiple names for the same real
databse if desired. Think it matches all needs. Worde case using
resources.xml allows to define it in the app directly.
Le 6 mai 2016 11:19, "tonywestonuk" <to...@totspics.com> a écrit :

> Hi.... After moving my datasources to Tomee, I can access any of them from
> any application. running on the server.  However, I must define within the
> application code, the name of the datasource I want to use... if I do not,
> the default is the first one defined in Tomee.
>
> Is there any way of choosing a default per application?...   So, App1 could
> have a default datasource of ds1, and app2 could have a default datasource
> of ds2/
>
>
> I think I asked this already, and you mentioned something about putting
> alias's in the resource tag. But, I cant see how this can solve the issue?
>
> Thanks.
>
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Datasources-Again-Sorry-tp4678367.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>