You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by FERJANI <fe...@gmail.com> on 2013/05/20 18:26:55 UTC
Dynamic configuration of datasource
Hello everyone,
I developed an example that uses JPA to persist some data.
Right know, here is the configuration of my datasource
<blueprint>
[...]
<bean id="dataSource"
class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/user />
<property name="user" value="root" />
<property name="password" value="root" />
</bean>
[...]
</blueprint>
I'd like to dynamically set the different values (with a configuration
service maybe ?) and I don't know how to do it.
Best regards,
Khadija
Re: Dynamic configuration of datasource
Posted by FERJANI <fe...@gmail.com>.
Hi Christian,
Yes I'm exporting the DataSource as a service in my db-mysql and
db-derby bundles.
Right now I'm only considering mysql and derby databases. I will check
after for other databases types.
Regards,
Khadija
On 05/22/2013 09:40 AM, Christian Schneider wrote:
> Sounds good. Did you export the DataSource as a service in the
> db-mysql bundle or how did you connect it to your persistence bundle?
>
> The only thing you need to consider is if this works with pooling. For
> some drivers the DataSources are not poolable. In that case you could
> use the first option I described and implement the DataSourceFactory
> yourself.
>
> Christian
>
> Am 22.05.2013 10:08, schrieb FERJANI:
>> Hello Christian,
>>
>> I tried something that seems working but I'd like a confirmation that
>> I'm not writing a bomb-code :)
>>
>> I separated my persistence bundle (META-INF/persistence.xml, Entity
>> classes,..) (db-common) from the blueprint.xml file.
>> I created a bundle database-mysql that only contains a blueprint file
>> for the mysql DB configuration (db-mysql), and I'm thinking of
>> creating a similar bundle with a blueprint.xml file for a derby DB
>> configuration (db-derby).
>> After that, I'd have to install one of those bundles (db-mysql or
>> db-derby) with my initial bundle (db-common) to make it work.
>>
>> Right know, I tested this with the bundles db-mysql and db-common and
>> it seems working.
>>
>> Is it an OSGi compliant implementation ?
>>
>> Best regards,
>> Khadija
>>
>>
>>
>> On 05/22/2013 08:12 AM, Christian Schneider wrote:
>>> This is possible in two ways.
>>>
>>> You can use the
>>> http://www.osgi.org/javadoc/r4v42/org/osgi/service/jdbc/DataSourceFactory.html
>>> sepcified in the OSGi spec if your drivers supports it.
>>>
>>> If not then you can try this tutorial:
>>> http://www.liquid-reality.de/x/LYBk
>>> Basically the idea is to publish a DataSource as an OSGi service
>>> using a separate blueprint file and using the service in your user
>>> bundle. This
>>> way you can have the filter to reference the OSGi service in a
>>> config of your user bundle. So you can switch db types.
>>>
>>> Christian
>>>
>>> Am 21.05.2013 17:40, schrieb FERJANI:
>>>> Hello everyone,
>>>>
>>>> I'd like to configure the database type (mysql, derby,..) from an
>>>> external configuration type. Is this possible using blueprint ?
>>>>
>>>> Regards,
>>>> Khadija
>>>>
>>>
>>> --
>>>
>>> Christian Schneider
>>> http://www.liquid-reality.de
>>>
>>> Open Source Architect
>>> Talend Application Integration Divisionhttp://www.talend.com
>>
>
>
> --
>
> Christian Schneider
> http://www.liquid-reality.de
>
> Open Source Architect
> Talend Application Integration Divisionhttp://www.talend.com
Re: Dynamic configuration of datasource
Posted by Christian Schneider <ch...@die-schneider.net>.
Sounds good. Did you export the DataSource as a service in the db-mysql
bundle or how did you connect it to your persistence bundle?
The only thing you need to consider is if this works with pooling. For
some drivers the DataSources are not poolable. In that case you could
use the first option I described and implement the DataSourceFactory
yourself.
Christian
Am 22.05.2013 10:08, schrieb FERJANI:
> Hello Christian,
>
> I tried something that seems working but I'd like a confirmation that
> I'm not writing a bomb-code :)
>
> I separated my persistence bundle (META-INF/persistence.xml, Entity
> classes,..) (db-common) from the blueprint.xml file.
> I created a bundle database-mysql that only contains a blueprint file
> for the mysql DB configuration (db-mysql), and I'm thinking of
> creating a similar bundle with a blueprint.xml file for a derby DB
> configuration (db-derby).
> After that, I'd have to install one of those bundles (db-mysql or
> db-derby) with my initial bundle (db-common) to make it work.
>
> Right know, I tested this with the bundles db-mysql and db-common and
> it seems working.
>
> Is it an OSGi compliant implementation ?
>
> Best regards,
> Khadija
>
>
>
> On 05/22/2013 08:12 AM, Christian Schneider wrote:
>> This is possible in two ways.
>>
>> You can use the
>> http://www.osgi.org/javadoc/r4v42/org/osgi/service/jdbc/DataSourceFactory.html
>> sepcified in the OSGi spec if your drivers supports it.
>>
>> If not then you can try this tutorial:
>> http://www.liquid-reality.de/x/LYBk
>> Basically the idea is to publish a DataSource as an OSGi service
>> using a separate blueprint file and using the service in your user
>> bundle. This
>> way you can have the filter to reference the OSGi service in a config
>> of your user bundle. So you can switch db types.
>>
>> Christian
>>
>> Am 21.05.2013 17:40, schrieb FERJANI:
>>> Hello everyone,
>>>
>>> I'd like to configure the database type (mysql, derby,..) from an
>>> external configuration type. Is this possible using blueprint ?
>>>
>>> Regards,
>>> Khadija
>>>
>>
>> --
>>
>> Christian Schneider
>> http://www.liquid-reality.de
>>
>> Open Source Architect
>> Talend Application Integration Divisionhttp://www.talend.com
>
--
Christian Schneider
http://www.liquid-reality.de
Open Source Architect
Talend Application Integration Division http://www.talend.com
Re: Dynamic configuration of datasource
Posted by FERJANI <fe...@gmail.com>.
Hello Christian,
I tried something that seems working but I'd like a confirmation that
I'm not writing a bomb-code :)
I separated my persistence bundle (META-INF/persistence.xml, Entity
classes,..) (db-common) from the blueprint.xml file.
I created a bundle database-mysql that only contains a blueprint file
for the mysql DB configuration (db-mysql), and I'm thinking of creating
a similar bundle with a blueprint.xml file for a derby DB configuration
(db-derby).
After that, I'd have to install one of those bundles (db-mysql or
db-derby) with my initial bundle (db-common) to make it work.
Right know, I tested this with the bundles db-mysql and db-common and it
seems working.
Is it an OSGi compliant implementation ?
Best regards,
Khadija
On 05/22/2013 08:12 AM, Christian Schneider wrote:
> This is possible in two ways.
>
> You can use the
> http://www.osgi.org/javadoc/r4v42/org/osgi/service/jdbc/DataSourceFactory.html
> sepcified in the OSGi spec if your drivers supports it.
>
> If not then you can try this tutorial:
> http://www.liquid-reality.de/x/LYBk
> Basically the idea is to publish a DataSource as an OSGi service using
> a separate blueprint file and using the service in your user bundle. This
> way you can have the filter to reference the OSGi service in a config
> of your user bundle. So you can switch db types.
>
> Christian
>
> Am 21.05.2013 17:40, schrieb FERJANI:
>> Hello everyone,
>>
>> I'd like to configure the database type (mysql, derby,..) from an
>> external configuration type. Is this possible using blueprint ?
>>
>> Regards,
>> Khadija
>>
>
> --
>
> Christian Schneider
> http://www.liquid-reality.de
>
> Open Source Architect
> Talend Application Integration Divisionhttp://www.talend.com
Re: Dynamic configuration of datasource
Posted by Christian Schneider <ch...@die-schneider.net>.
This is possible in two ways.
You can use the
http://www.osgi.org/javadoc/r4v42/org/osgi/service/jdbc/DataSourceFactory.html
sepcified in the OSGi spec if your drivers supports it.
If not then you can try this tutorial:
http://www.liquid-reality.de/x/LYBk
Basically the idea is to publish a DataSource as an OSGi service using a
separate blueprint file and using the service in your user bundle. This
way you can have the filter to reference the OSGi service in a config of
your user bundle. So you can switch db types.
Christian
Am 21.05.2013 17:40, schrieb FERJANI:
> Hello everyone,
>
> I'd like to configure the database type (mysql, derby,..) from an
> external configuration type. Is this possible using blueprint ?
>
> Regards,
> Khadija
>
--
Christian Schneider
http://www.liquid-reality.de
Open Source Architect
Talend Application Integration Division http://www.talend.com
Re: Dynamic configuration of datasource
Posted by FERJANI <fe...@gmail.com>.
Hello everyone,
I'd like to configure the database type (mysql, derby,..) from an
external configuration type. Is this possible using blueprint ?
Regards,
Khadija
On 05/21/2013 11:08 AM, Siano, Stephan wrote:
>
> Hi,
>
> The properties file part depends on the felix file installer as it is
> configured in karaf. You can use and configure the file installer on
> other OSGi servers the same way (I have done this on equinox) or you
> have to set your config admin properties by other means.
>
> The blueprint property placeholder requires aries-blueprint-cm (and of
> course the config admin service), so it's not specific to karaf.
>
> Best regards
>
> Stephan
>
> *From:*FERJANI [mailto:ferjani.khadija@gmail.com]
> *Sent:* Dienstag, 21. Mai 2013 10:20
> *To:* Martin Lichtin
> *Cc:* user@aries.apache.org
> *Subject:* Re: Dynamic configuration of datasource
>
> Hello Martin,
>
> Is this a karaf solution ? because I can't use karaf for my example :(
>
> Regards,
> Khadija
>
>
> On 05/20/2013 08:21 PM, Martin Lichtin wrote:
>
> Yould could do
>
> <blueprint>
> <cm:property-placeholder id="p"
> persistent-id="my.persistent.id.jdbc.mysql">
> <cm:default-properties>
> <cm:property name="database" value="user" />
> <cm:property name="server" value="localhost" />
> <cm:property name="port" value="3306" />
> <cm:property name="user" value="root" />
> <cm:property name="password" value="root" />
> </cm:default-properties>
> </cm:property-placeholder>
>
> <bean id="dataSource"
> class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
> <property name="url"
> value="jdbc:mysql://${server}:${port}/${database}/>
> <property name="user" value="${user}" />
> <property name="password" value="${password}" />
> </bean>
> </blueprint>
>
> The defaults can be overridden with a
> etc/my.persistent.id.jdbc.mysql.cfg properties file.
>
> Martin
>
> On 20/05/2013 18:26, FERJANI wrote:
>
> Hello everyone,
>
> I developed an example that uses JPA to persist some data.
> Right know, here is the configuration of my datasource
>
> <blueprint>
> [...]
> <bean id="dataSource"
> class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
> <property name="url"
> value="jdbc:mysql://localhost:3306/user />
> <property name="user" value="root" />
> <property name="password" value="root" />
> </bean>
> [...]
> </blueprint>
>
> I'd like to dynamically set the different values (with a
> configuration service maybe ?) and I don't know how to do it.
>
> Best regards,
> Khadija
>
Re: Dynamic configuration of datasource
Posted by FERJANI <fe...@gmail.com>.
Hi Stephan,
This worked fine, thanks a lot !
Regards,
Khadija
On 05/21/2013 11:08 AM, Siano, Stephan wrote:
>
> Hi,
>
> The properties file part depends on the felix file installer as it is
> configured in karaf. You can use and configure the file installer on
> other OSGi servers the same way (I have done this on equinox) or you
> have to set your config admin properties by other means.
>
> The blueprint property placeholder requires aries-blueprint-cm (and of
> course the config admin service), so it's not specific to karaf.
>
> Best regards
>
> Stephan
>
> *From:*FERJANI [mailto:ferjani.khadija@gmail.com]
> *Sent:* Dienstag, 21. Mai 2013 10:20
> *To:* Martin Lichtin
> *Cc:* user@aries.apache.org
> *Subject:* Re: Dynamic configuration of datasource
>
> Hello Martin,
>
> Is this a karaf solution ? because I can't use karaf for my example :(
>
> Regards,
> Khadija
>
>
> On 05/20/2013 08:21 PM, Martin Lichtin wrote:
>
> Yould could do
>
> <blueprint>
> <cm:property-placeholder id="p"
> persistent-id="my.persistent.id.jdbc.mysql">
> <cm:default-properties>
> <cm:property name="database" value="user" />
> <cm:property name="server" value="localhost" />
> <cm:property name="port" value="3306" />
> <cm:property name="user" value="root" />
> <cm:property name="password" value="root" />
> </cm:default-properties>
> </cm:property-placeholder>
>
> <bean id="dataSource"
> class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
> <property name="url"
> value="jdbc:mysql://${server}:${port}/${database}/>
> <property name="user" value="${user}" />
> <property name="password" value="${password}" />
> </bean>
> </blueprint>
>
> The defaults can be overridden with a
> etc/my.persistent.id.jdbc.mysql.cfg properties file.
>
> Martin
>
> On 20/05/2013 18:26, FERJANI wrote:
>
> Hello everyone,
>
> I developed an example that uses JPA to persist some data.
> Right know, here is the configuration of my datasource
>
> <blueprint>
> [...]
> <bean id="dataSource"
> class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
> <property name="url"
> value="jdbc:mysql://localhost:3306/user />
> <property name="user" value="root" />
> <property name="password" value="root" />
> </bean>
> [...]
> </blueprint>
>
> I'd like to dynamically set the different values (with a
> configuration service maybe ?) and I don't know how to do it.
>
> Best regards,
> Khadija
>
RE: Dynamic configuration of datasource
Posted by "Siano, Stephan" <st...@sap.com>.
Hi,
The properties file part depends on the felix file installer as it is configured in karaf. You can use and configure the file installer on other OSGi servers the same way (I have done this on equinox) or you have to set your config admin properties by other means.
The blueprint property placeholder requires aries-blueprint-cm (and of course the config admin service), so it's not specific to karaf.
Best regards
Stephan
From: FERJANI [mailto:ferjani.khadija@gmail.com]
Sent: Dienstag, 21. Mai 2013 10:20
To: Martin Lichtin
Cc: user@aries.apache.org
Subject: Re: Dynamic configuration of datasource
Hello Martin,
Is this a karaf solution ? because I can't use karaf for my example :(
Regards,
Khadija
On 05/20/2013 08:21 PM, Martin Lichtin wrote:
Yould could do
<blueprint>
<cm:property-placeholder id="p" persistent-id="my.persistent.id.jdbc.mysql">
<cm:default-properties>
<cm:property name="database" value="user" />
<cm:property name="server" value="localhost" />
<cm:property name="port" value="3306" />
<cm:property name="user" value="root" />
<cm:property name="password" value="root" />
</cm:default-properties>
</cm:property-placeholder>
<bean id="dataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
<property name="url" value="jdbc:mysql://${server}:${port}/${database}/>
<property name="user" value="${user}" />
<property name="password" value="${password}" />
</bean>
</blueprint>
The defaults can be overridden with a etc/my.persistent.id.jdbc.mysql.cfg properties file.
Martin
On 20/05/2013 18:26, FERJANI wrote:
Hello everyone,
I developed an example that uses JPA to persist some data.
Right know, here is the configuration of my datasource
<blueprint>
[...]
<bean id="dataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/user />
<property name="user" value="root" />
<property name="password" value="root" />
</bean>
[...]
</blueprint>
I'd like to dynamically set the different values (with a configuration service maybe ?) and I don't know how to do it.
Best regards,
Khadija
Re: Dynamic configuration of datasource
Posted by FERJANI <fe...@gmail.com>.
Hello Martin,
Is this a karaf solution ? because I can't use karaf for my example :(
Regards,
Khadija
On 05/20/2013 08:21 PM, Martin Lichtin wrote:
>
> Yould could do
>
> <blueprint>
> <cm:property-placeholder id="p"
> persistent-id="my.persistent.id.jdbc.mysql">
> <cm:default-properties>
> <cm:property name="database" value="user" />
> <cm:property name="server" value="localhost" />
> <cm:property name="port" value="3306" />
> <cm:property name="user" value="root" />
> <cm:property name="password" value="root" />
> </cm:default-properties>
> </cm:property-placeholder>
>
> <bean id="dataSource"
> class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
> <property name="url"
> value="jdbc:mysql://${server}:${port}/${database}/>
> <property name="user" value="${user}" />
> <property name="password" value="${password}" />
> </bean>
> </blueprint>
>
> The defaults can be overridden with a
> etc/my.persistent.id.jdbc.mysql.cfg properties file.
>
> Martin
>
> On 20/05/2013 18:26, FERJANI wrote:
>> Hello everyone,
>>
>> I developed an example that uses JPA to persist some data.
>> Right know, here is the configuration of my datasource
>>
>> <blueprint>
>> [...]
>> <bean id="dataSource"
>> class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
>> <property name="url" value="jdbc:mysql://localhost:3306/user />
>> <property name="user" value="root" />
>> <property name="password" value="root" />
>> </bean>
>> [...]
>> </blueprint>
>>
>> I'd like to dynamically set the different values (with a
>> configuration service maybe ?) and I don't know how to do it.
>>
>> Best regards,
>> Khadija
>
Re: Dynamic configuration of datasource
Posted by Martin Lichtin <li...@yahoo.com>.
Yould could do
<blueprint>
<cm:property-placeholder id="p"
persistent-id="my.persistent.id.jdbc.mysql">
<cm:default-properties>
<cm:property name="database" value="user" />
<cm:property name="server" value="localhost" />
<cm:property name="port" value="3306" />
<cm:property name="user" value="root" />
<cm:property name="password" value="root" />
</cm:default-properties>
</cm:property-placeholder>
<bean id="dataSource"
class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
<property name="url"
value="jdbc:mysql://${server}:${port}/${database}/>
<property name="user" value="${user}" />
<property name="password" value="${password}" />
</bean>
</blueprint>
The defaults can be overridden with a
etc/my.persistent.id.jdbc.mysql.cfg properties file.
Martin
On 20/05/2013 18:26, FERJANI wrote:
> Hello everyone,
>
> I developed an example that uses JPA to persist some data.
> Right know, here is the configuration of my datasource
>
> <blueprint>
> [...]
> <bean id="dataSource"
> class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
> <property name="url" value="jdbc:mysql://localhost:3306/user />
> <property name="user" value="root" />
> <property name="password" value="root" />
> </bean>
> [...]
> </blueprint>
>
> I'd like to dynamically set the different values (with a configuration
> service maybe ?) and I don't know how to do it.
>
> Best regards,
> Khadija
Re: Dynamic configuration of datasource
Posted by FERJANI <fe...@gmail.com>.
Hello Lissuan,
It's clear that some bundles are missing
Here is a link that may help you
http://stackoverflow.com/questions/11861414/openjpa-in-osgi-not-finding-mysql-jdbc-connector-bundle
Regards,
Khadija
On 05/20/2013 08:41 PM, Lissuan Fadraga Artiles wrote:
> Hi guys :
>
> I am using JPA + Blueprint +Apache Aries in my persistence layer, but
> Blueprint is not creating the Entity Manager because the persistence bundle
> is waiting for some namespace. Here is the Blueprint log:
>
> Bundle test.AriesComplemento is waiting for namespace handlers
> [http://aries.apache.org/xmlns/transactions/v1.0.0]
>
> Somebody know what to do ?..
>
> Regards Lissuan...
>
>
> http://www.uci.cu
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
RE: Dynamic configuration of datasource
Posted by Lissuan Fadraga Artiles <lf...@uci.cu>.
Hi guys :
I am using JPA + Blueprint +Apache Aries in my persistence layer, but
Blueprint is not creating the Entity Manager because the persistence bundle
is waiting for some namespace. Here is the Blueprint log:
Bundle test.AriesComplemento is waiting for namespace handlers
[http://aries.apache.org/xmlns/transactions/v1.0.0]
Somebody know what to do ?..
Regards Lissuan...
http://www.uci.cu
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org