Thanks Christian,

I understand now what you were suggesting. The database type (vendor) will
be the same in all environments (mysql), but with different addresses,
engine types, usernames and passwords, which brings another topic up -
configuration (I will probably ask this in days to come).

I will be separating datasources, it is just the case that I want a working
solution and then smooth it out.

For a begginer it is very hard to get a hibernate mysql combo to work (mine
still does not). There are examples for persistence, but I had to read a
lot until I found that Hibernate does not even has bundles, therefore
tricks has to be performed.

Is there "an official Karaf Hibernate Feature"? If not, what is the
suggested way to run Hibernate in Karaf? I am planning to use Hibernate
Search, Solr and Lucene by using Camel components, so I have lots of ground
to cover.

Cheers,
borut

On 18. apr. 2012, at 09:05, Christian Schneider <[email protected]>
wrote:

If you define the datasource outside the bundle you avoid that the bundle
has to know the driver class. I guess in your solution you have a
dependency to the db driver. As you only define the driver in the blueprint
xml the dependency is maybe just an import package statement the bundle
plugin adds. Still your bundle is tightly coupled to the db type used.

So as long as you do not plan to change the db or have different db types
in dev and prod you should be fine.

Christian

2012/4/16 Borut Bolčina <[email protected]>

> I am trying to understand the separation here.
>
> My Camel route has no referenece to where the objects are to be persisted.
> The accompanying persistence.xml in route's bundle is using jta data source
> as osgi service which is (for now) defined in route's blueprint and is also
> configurable via admin service. So I can (in theory) stop the route, change
> the properties (connection to the database), start the route.
>
> What is this another layer of abstraction you are talking about? Can you
> show me on my example please?
>
> -borut
>
>
> Dne 16. april 2012 15:56 je Christian Schneider 
> <[email protected]>napisal/-a:
>
> Absolutely. The nice thing with extracting the datasource to a service is
>> that your route bundle has no dependency to the database driver. So this
>> makes it easier to for example have different database systems in dev and
>> test. In general it supports the idea of having to know as few things about
>> your environment as possible. In fact I think this idea is what makes OSGi
>> so appealing.
>>
>> Christian
>>
>>
>> 2012/4/16 Jean-Baptiste Onofré <[email protected]>
>>
>>> The way that you did work too ;)
>>>
>>> I would prefer a better separation (the Camel route should use a service
>>> reference to the datasource).
>>>
>>> Regards
>>> JB
>>>
>>>
>>> On 04/16/2012 03:17 PM, Borut Bolčina wrote:
>>>
>>>> OK, to make a first step which doesn't involve creating a separate
>>>> bundle for datasource, but instead adding a datasource configuration
>>>> directly to my Camel route bundle's blueprint.xml:
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <blueprint 
>>>> xmlns="http://www.osgi.org/**xmlns/blueprint/v1.0.0<http://www.osgi.org/xmlns/blueprint/v1.0.0>
>>>> "
>>>> xmlns:xsi="http://www.w3.org/**2001/XMLSchema-instance<http://www.w3.org/2001/XMLSchema-instance>
>>>> "
>>>> xmlns:cm="http://aries.apache.**org/blueprint/xmlns/blueprint-**
>>>> cm/v1.1.0 <http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0>
>>>> "
>>>> xsi:schemaLocation="
>>>> ... ">
>>>> <cm:property-placeholder persistent-id="WeatherCurrent"
>>>> update-strategy="reload">
>>>> <cm:default-properties>
>>>> <cm:property name="sourceUrl"
>>>> value="http://meteo.arso.gov.**si/uploads/probase/www/observ/**
>>>> surface/text/sl/observation_**si_latest.xml<http://meteo.arso.gov.si/uploads/probase/www/observ/surface/text/sl/observation_si_latest.xml>
>>>> "
>>>> />
>>>> <cm:property name="weatherDbConnectionUrl"
>>>> value="jdbc:mysql://my.**company.com:3306/weather?**useUnicode=yes&amp;
>>>> **characterEncoding=UTF-8<http://my.company.com:3306/weather?useUnicode=yes&characterEncoding=UTF-8>
>>>>  <http://my.company.com:3306/**weather?useUnicode=yes&amp;**
>>>> characterEncoding=UTF-8<http://my.company.com:3306/weather?useUnicode=yes&characterEncoding=UTF-8>
>>>> >"
>>>>
>>>> />
>>>> <cm:property name="weatherDbUser" value="testUser" />
>>>> <cm:property name="weatherDbPassword" value="testPass" />
>>>> </cm:default-properties>
>>>> </cm:property-placeholder>
>>>> <bean id="dataSource" class="com.mysql.jdbc.jdbc2.**
>>>> optional.MysqlDataSource">
>>>> <property name="url" value="${**weatherDbConnectionUrl}"/>
>>>> <property name="user" value="${weatherDbUser}"/>
>>>> <property name="password" value="${weatherDbPassword}"/>
>>>> </bean>
>>>> <service interface="javax.sql.**DataSource" ref="dataSource">
>>>> <service-properties>
>>>> <entry key="osgi.jndi.service.name <http://osgi.jndi.service.name**>"
>>>>
>>>> value="jdbc/mysqlds"/>
>>>> </service-properties>
>>>> </service>
>>>>
>>>> <bean id="**weatherCurrentRouteBuilder"
>>>> class="com.mycompany.route.**weather.**WeatherCurrentRouteBuilder"
>>>> init-method="refresh">
>>>> <property name="sourceUrl" value="${sourceUrl}"></**property>
>>>> </bean>
>>>>
>>>> <camelContext id="weather-forecast"
>>>> xmlns="http://camel.apache.**org/schema/blueprint<http://camel.apache.org/schema/blueprint>
>>>> ">
>>>> <routeBuilder ref="**weatherCurrentRouteBuilder" />
>>>> </camelContext>
>>>>
>>>> </blueprint>
>>>>
>>>>
>>>> and the configuration file weather.cfg
>>>>
>>>> sourceUrl=http://meteo.arso.**gov.si/uploads/probase/www/**
>>>> observ/surface/text/sl/**observation_si_latest.xml<http://meteo.arso.gov.si/uploads/probase/www/observ/surface/text/sl/observation_si_latest.xml>
>>>> weatherDbConnectionUrl=jdbc:**mysql://my.comapny.com:3306/**
>>>> weather?useUnicode=yes&amp;**characterEncoding=UTF-8<http://my.comapny.com:3306/weather?useUnicode=yes&characterEncoding=UTF-8>
>>>>  <http://my.comapny.com:3306/**weather?useUnicode=yes&amp;**
>>>> characterEncoding=UTF-8<http://my.comapny.com:3306/weather?useUnicode=yes&characterEncoding=UTF-8>
>>>> >
>>>>
>>>> weatherDbUser=testUser
>>>> weatherDbPassword=testPass
>>>>
>>>> and the persistence.xml
>>>>
>>>> <persistence 
>>>> xmlns="http://java.sun.com/**xml/ns/persistence<http://java.sun.com/xml/ns/persistence>
>>>> "
>>>> xmlns:xsi="http://www.w3.org/**2001/XMLSchema-instance<http://www.w3.org/2001/XMLSchema-instance>
>>>> "
>>>> version="1.0">
>>>>
>>>> <persistence-unit name="weather" transaction-type="JTA">
>>>> <provider>org.hibernate.ejb.**HibernatePersistence</**provider>
>>>> <jta-data-source>osgi:service/**javax.sql.DataSource/(osgi.**
>>>> jndi.service.name <http://osgi.jndi.service.name>
>>>> <http://osgi.jndi.service.name**>=jdbc/mysqlds)</jta-data-**source>
>>>>
>>>> <class>my.company.model.**entities.weather.**WeatherCurrent</class>
>>>> <exclude-unlisted-classes>**true</exclude-unlisted-**classes>
>>>> <properties>
>>>> <property name="hibernate.show_sql" value="true"/>
>>>> <property name="hibernate.format_sql" value="true"/>
>>>> </properties>
>>>> </persistence-unit>
>>>> </persistence>
>>>>
>>>> and features bundle which installs configuration and drivers besides my
>>>> camel route:
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <features 
>>>> xmlns="http://karaf.apache.**org/xmlns/features/v1.0.0<http://karaf.apache.org/xmlns/features/v1.0.0>
>>>> "
>>>> xmlns:xsi="http://www.w3.org/**2001/XMLSchema-instance<http://www.w3.org/2001/XMLSchema-instance>
>>>> "
>>>> xsi:schemaLocation="http://**karaf.apache.org/xmlns/**features/v1.0.0<http://karaf.apache.org/xmlns/features/v1.0.0>
>>>> http://karaf.apache.org/xmlns/**features/v1.0.0<http://karaf.apache.org/xmlns/features/v1.0.0>
>>>> ">
>>>>
>>>> <feature name="weather" version="${pom.version}">
>>>> <bundle>mvn:mvn:org.apache.**servicemix.specs/org.apache.**
>>>> servicemix.specs.stax-api-1.0/**1.9.0</bundle>
>>>> <bundle>mvn:mvn:mysql/mysql-**connector-java/5.1.18</bundle>
>>>> <bundle>mvn:my.company/route-**weather-current/${pom.version}**
>>>> </bundle>
>>>> <configfile
>>>> finalname="/etc/weather.cfg">**mvn:my.company/features-**
>>>> weather/${pom.version}/cfg</**configfile>
>>>> </feature>
>>>>
>>>> </features>
>>>>
>>>>
>>>> Am I heading the right way or am I on the Titanic's route?
>>>>
>>>> Cheers,
>>>> borut
>>>>
>>>>
>>>> Dne 16. april 2012 14:51 je Jean-Baptiste Onofré <[email protected]
>>>> <mailto:[email protected]>> napisal/-a:
>>>>
>>>>
>>>>    Username/password/URL could be in <cm:properties/> and so handle in
>>>>    the "application" config oriented file in etc.
>>>>
>>>>    Regards
>>>>    JB
>>>>
>>>>
>>>>    On 04/16/2012 02:47 PM, Christian Schneider wrote:
>>>>
>>>>        I would simply deploy the blueprint xml by hand. Just treat it
>>>>        like a
>>>>        config file you would have to add.
>>>>        This is of course not everyone´s favorite style.
>>>>
>>>>        The problem with adding the blueprint to the feature is that it
>>>>        would
>>>>        have to be in the maven repo. As the username and password are
>>>>        in this
>>>>        file this is not recommended.
>>>>
>>>>        So another way to achieve what I did is separate the things that
>>>>        should
>>>>        be configured per server or stage from the things that keep the
>>>>        same like
>>>>        driver class name. You could use the config admin service in the
>>>>        blueprint file to move the username / password to a separate
>>>>        config file.
>>>>        This would make the whole thing a bit more complex though but
>>>>        you could
>>>>        then safely put the blueprint file into a feature.
>>>>
>>>>        Christian
>>>>
>>>>
>>>>        2012/4/16 Borut Bolčina <[email protected]
>>>>        <mailto:borut.bolcina@gmail.**com <[email protected]>>
>>>>        <mailto:borut.bolcina@gmail.__**com <mailto:borut.bolcina@gmail.
>>>> **com <[email protected]>>>>
>>>>
>>>>
>>>>
>>>>            Hello,
>>>>
>>>>            my first post here, so bare with me please - newbie on board.
>>>>
>>>>            I am trying to deploy my first camel route to Karaf and this
>>>>        route
>>>>            must be configurable (html address) and must persist some
>>>>        data with
>>>>            jpa component. This route is happily persisting in my test
>>>>        (outside
>>>>            osgi container).
>>>>
>>>>            Now I am reading
>>>>        https://github.com/cschneider/**__Karaf-Tutorial/blob/master/**
>>>> db/__datasource/datasource-**mysql.__xml<https://github.com/cschneider/__Karaf-Tutorial/blob/master/db/__datasource/datasource-mysql.__xml>
>>>>
>>>>        <https://github.com/**cschneider/Karaf-Tutorial/**
>>>> blob/master/db/datasource/**datasource-mysql.xml<https://github.com/cschneider/Karaf-Tutorial/blob/master/db/datasource/datasource-mysql.xml>
>>>> >
>>>>        where
>>>>            it says I should copy the file to Karaf's deploy folder.
>>>>
>>>>            And the question: What is the practice of deploying data
>>>>        sources?
>>>>            Should I create a features project which includes a
>>>>        blueprint for my
>>>>            route's data source?
>>>>
>>>>            Let's say my route needs connection to mysql database, so the
>>>>            feature project would include features.xml
>>>>
>>>>        <?xml version="1.0" encoding="UTF-8"?>
>>>>        <features xmlns="http://karaf.apache.__**
>>>> org/xmlns/features/v1.0.0
>>>>        
>>>> <http://karaf.apache.org/**xmlns/features/v1.0.0<http://karaf.apache.org/xmlns/features/v1.0.0>
>>>> >"
>>>>            
>>>> xmlns:xsi="http://www.w3.org/_**_2001/XMLSchema-instance<http://www.w3.org/__2001/XMLSchema-instance>
>>>>        
>>>> <http://www.w3.org/2001/**XMLSchema-instance<http://www.w3.org/2001/XMLSchema-instance>
>>>> >"
>>>>
>>>>          xsi:schemaLocation="http://__k**araf.apache.org/xmlns/__**
>>>> features/v1.0.0 <http://karaf.apache.org/xmlns/__features/v1.0.0> <
>>>> http://karaf.apache.org/**xmlns/features/v1.0.0<http://karaf.apache.org/xmlns/features/v1.0.0>
>>>> >
>>>>        
>>>> http://karaf.apache.org/xmlns/**__features/v1.0.0<http://karaf.apache.org/xmlns/__features/v1.0.0>
>>>>
>>>>        
>>>> <http://karaf.apache.org/**xmlns/features/v1.0.0<http://karaf.apache.org/xmlns/features/v1.0.0>
>>>> >">
>>>>
>>>>        <feature name="weather" version="${pom.version}">
>>>>        <bundle>mvn:mvn:org.apache.__**servicemix.specs/org.apache.__**
>>>> servicemix.specs.stax-api-1.0/**__1.9.0</bundle>
>>>>        <bundle>mvn:mvn:mysql/mysql-__**connector-java/5.1.18</bundle>
>>>>        <bundle>mvn:my.company/route-_**_weather-current/${pom.**
>>>> version}__</bundle>
>>>>
>>>>            *<bundle>my datasource blueprint</bundle>*
>>>>
>>>>        <configfile
>>>>
>>>>          finalname="/etc/weather.cfg">_**_mvn:my.company/features-__**
>>>> weather/${pom.version}/cfg</__**configfile>
>>>>
>>>>        </feature>
>>>>        </features>
>>>>
>>>>            I guess then the only command to install my Camel route to
>>>> Karaf
>>>>            would then be feature:install and all the dependencies
>>>> including
>>>>            datasource and configuration would be installed before. And
>>>>        how to
>>>>            package the "my datasource blueprint"?
>>>>
>>>>            Or is there some other practice?
>>>>
>>>>            Thanks,
>>>>            borut
>>>>
>>>>
>>>>
>>>>    --
>>>>    Jean-Baptiste Onofré
>>>>    [email protected] <mailto:[email protected]>
>>>>
>>>>    http://blog.nanthrax.net
>>>>    Talend - http://www.talend.com
>>>>
>>>>
>>>>
>>> --
>>> Jean-Baptiste Onofré
>>> [email protected]
>>> http://blog.nanthrax.net
>>> Talend - http://www.talend.com
>>>
>>
>>
>

Reply via email to