You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Kay Wrobel <ka...@gmx.net> on 2015/04/24 20:03:46 UTC

Database Import Feature

Hi everybody.

How do I use the import-<name either of the datasource or the persistence unit>.sql TomEE feature to pre-populate an in-memory database? If there's an example documented somewhere, a link would be very helpful.

Thank you,

Kay Wrobel

Re: Database Import Feature

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

yes, if you take this example:
https://git-wip-us.apache.org/repos/asf?p=tomee.git;a=tree;f=examples/realm-in-tomee;h=3143ff14eb55c8ec4aeffac4ea4655ca99cb72ca;hb=3d9c644fe8150bb6d345f7e8548f6c24a4aef65e
you have myDataSource (
https://git-wip-us.apache.org/repos/asf?p=tomee.git;a=blob;f=examples/realm-in-tomee/src/main/tomee/conf/tomee.xml;h=f11b0328860657cf281eb1c6171d6773758f6b2c;hb=3d9c644fe8150bb6d345f7e8548f6c24a4aef65e)
and the import script
https://git-wip-us.apache.org/repos/asf?p=tomee.git;a=blob;f=examples/realm-in-tomee/src/main/tomee/lib/import-myDataSource.sql;h=8d89caaa32f4cf3dc137dfc19eb15a8c3f1ade76;hb=3d9c644fe8150bb6d345f7e8548f6c24a4aef65e
(note it is in lib/ cause it is as the same level of classloader as the
datasource, since the ds is in the container (tomee.xml) the script is as
well).


You can also provide a built-in database, there is nothing special to do.
If you want to provide it in the webapp use resources.xml to define it.
About the url it depends what you want but I guess using something like:

JdbcUrl =
jdbc:derby:memory:${catalina.home}/webapps/mywebapp/WEB-INF/mydatabase/
should work

or worse: jdbc:derby:/myclasspath-path/

Side Note: we force derby.system.home if not set in system.properties to
tomee base (to avoid to leak the database outside tomee by default). You
can switch it off in systemm.properties forcing
openejb.datasource.plugin.activated=false



Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-05-07 5:07 GMT+02:00 Kay Wrobel <ka...@gmx.net>:

> Bumping this question. Romain: you mentioned on the OpenJPA thread that
> there was a TomEE solution for supplying an initialization script for a
> database? Do you have a working example of the files involved?
>
> What would be even better, instead of re-initializing an in-memory
> database, would it be possible to provide an embedded database (such as a
> Derby Embedded database) with a web project? If so, where would I put the
> database file(s) and what JDBC URL would I have to provide for TomEE to
> find that data source? But if that's not possible, I'm still interested in
> that SQL initialization script you mentioned.
>
> Thanks,
> Kay
>
> > On Apr 24, 2015, at 1:03 PM, Kay Wrobel <ka...@gmx.net> wrote:
> >
> > Hi everybody.
> >
> > How do I use the import-<name either of the datasource or the
> persistence unit>.sql TomEE feature to pre-populate an in-memory database?
> If there's an example documented somewhere, a link would be very helpful.
> >
> > Thank you,
> >
> > Kay Wrobel
>
>

Re: Database Import Feature

Posted by Kay Wrobel <ka...@gmx.net>.
Bumping this question. Romain: you mentioned on the OpenJPA thread that there was a TomEE solution for supplying an initialization script for a database? Do you have a working example of the files involved?

What would be even better, instead of re-initializing an in-memory database, would it be possible to provide an embedded database (such as a Derby Embedded database) with a web project? If so, where would I put the database file(s) and what JDBC URL would I have to provide for TomEE to find that data source? But if that's not possible, I'm still interested in that SQL initialization script you mentioned.

Thanks,
Kay

> On Apr 24, 2015, at 1:03 PM, Kay Wrobel <ka...@gmx.net> wrote:
> 
> Hi everybody.
> 
> How do I use the import-<name either of the datasource or the persistence unit>.sql TomEE feature to pre-populate an in-memory database? If there's an example documented somewhere, a link would be very helpful.
> 
> Thank you,
> 
> Kay Wrobel