You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Daniel Kasmeroglu <da...@kasisoft.net> on 2014/09/25 14:35:35 UTC

Change DataSource at runtime ?

Hi there,

I've got the following intent (similar to the JIRA/Confluence/Jenkins
Homes):

* Server starts with a property "myapp.home" pointing to a writable
directory on the filesystem
* Each module can get a data area "<myapp.home>/<module>"
* One module provides a H2 database whereas the database files will be
stored within the modules data area (f.e. "<myapp.home>/database")

What I need is this:

* Update DataSource setup according to the dynamically provided info
* Run a migration process (I'm using Flyway here instead of OpenEJBs
builtin ImportSql attempt)
* Setup JPA framework (EclipseLink in my case)

Righ now the problem is that the Datasource is configured within the
tomee.xml which requires the location of the db files directory which is
unfortunately available at a later point:

  <Resource id="ratiDS" type="DataSource">
    JdbcDriver  = org.h2.Driver
    JdbcUrl     = jdbc:h2:test
    JtaManaged  = true
  </Resource>

I've tried to use an in-memory url ahead hoping to update the URL later
on but the configured URL is stored within the 'DriverConnectionFactory'.

Does someone here has an idea of a nice solution for this or am I simply
overseeing something ?


Best regards

Daniel Kasmeroglu


Re: Change DataSource at runtime ?

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


2014-09-25 14:35 GMT+02:00 Daniel Kasmeroglu <da...@kasisoft.net>:
> Hi there,
>
> I've got the following intent (similar to the JIRA/Confluence/Jenkins
> Homes):
>
> * Server starts with a property "myapp.home" pointing to a writable
> directory on the filesystem
> * Each module can get a data area "<myapp.home>/<module>"
> * One module provides a H2 database whereas the database files will be
> stored within the modules data area (f.e. "<myapp.home>/database")
>
> What I need is this:
>
> * Update DataSource setup according to the dynamically provided info
> * Run a migration process (I'm using Flyway here instead of OpenEJBs
> builtin ImportSql attempt)

import sql was not linked to migrations actually but more to
provisioning. Migrations need much more than it.

> * Setup JPA framework (EclipseLink in my case)
>
> Righ now the problem is that the Datasource is configured within the
> tomee.xml which requires the location of the db files directory which is
> unfortunately available at a later point:
>
>   <Resource id="ratiDS" type="DataSource">
>     JdbcDriver  = org.h2.Driver
>     JdbcUrl     = jdbc:h2:test
>     JtaManaged  = true
>   </Resource>
>
> I've tried to use an in-memory url ahead hoping to update the URL later
> on but the configured URL is stored within the 'DriverConnectionFactory'.
>
> Does someone here has an idea of a nice solution for this or am I simply
> overseeing something ?
>

Use your custom datasource:
http://rmannibucau.wordpress.com/2014/04/11/openejbtomee-custom-datasource-jta-integration/

Side note: this is also doable more or less with the same idea with
@DataSourceDefinition

>
> Best regards
>
> Daniel Kasmeroglu
>