You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Hugi Thordarson <hu...@karlmenn.is> on 2016/01/22 19:25:43 UTC
Changing database connection programmatically
Hi all,
I’m writing some tests for my DataObjects. Before the tests run, I’d like to provision an h2 database and switch my model’s connection to it for the purpose of testing.
What’s the preferred way to switch the connection programmatically?
Cheers,
- hugi
Re: Changing database connection programmatically
Posted by Hugi Thordarson <hu...@karlmenn.is>.
I believe this is basically the same thing as:
addModule(binder -> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class))
just using a class instead of a Lambda.
- hugi
> On 23. jan. 2016, at 14:47, Michael Gentry <mg...@masslight.net> wrote:
>
> Hi Hugi,
>
> This worked for me in 3.1:
>
> // Use a custom Cayenne server runtime.
> serverRuntime = new ServerRuntime("my cayenne model", new
> CayenneExtrasModule()));
>
> ...
>
> /**
> * Custom Cayenne DI module.
> */
> private static class CayenneExtrasModule implements Module
> {
> @Override
> public void configure(Binder binder)
> {
> // Change the SchemaUpdateStrategy to create the DB schema for
> unit
> // testing instead of using the model's default which assumes an
> // existing schema.
>
> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class);
> }
> }
>
>
> On Sat, Jan 23, 2016 at 7:33 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
>> Hi Michael, Andrus and Savva.
>>
>> Thanks a lot for all the help with this :). The arguments to the
>> ServerRuntimeBuilder are exactly what I wanted :).
>>
>> One thing though: Setting the SchemaUpdateStrategy in code (in the
>> ServerRuntimeBuilder) doesn’t work for me. Works great if I set it in the
>> cayenne modeler, but if the modeler has the default
>> “SkipSchemaUpdateStrategy” selected, changing it in the
>> ServerRuntimeBuilder doesn’t seem to do anything. Any ideas?
>>
>> This is how I’m currently initializing my server runtime
>>
>> public static ServerRuntime serverRuntime() {
>> if (_serverRuntime == null) {
>> _serverRuntime = new ServerRuntimeBuilder()
>> .addConfig("cayenne-project.xml")
>> .addModule(binder ->
>> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class))
>> .jdbcDriver("org.h2.Driver")
>> .url("jdbc:h2:~/h2-testing")
>> .build();
>> }
>>
>> return _serverRuntime;
>> }
>>
>> Cheers,
>> - hugi
Re: Changing database connection programmatically
Posted by Andrus Adamchik <an...@objectstyle.org>.
> Isn’t it just a question of deleting the datanode in the project, adding the missing configuration in my ServerRuntimeBuilder and carry on with my life?
This is it.
> On Jan 23, 2016, at 10:18 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
> Ah, I see… It sure looks like we should be going DataNode-less too. Any caveats or tricks? Isn’t it just a question of deleting the datanode in the project, adding the missing configuration in my ServerRuntimeBuilder and carry on with my life?
>
> - hugi
>
>
>
>> On 23. jan. 2016, at 17:11, Andrus Adamchik <an...@objectstyle.org> wrote:
>>
>> There's a bug that we've seen with this, just haven't got to the bottom of it yet.
>>
>> All I know is that overriding the strategy does not if another strategy is already present in the XML and sometimes (always?) the Modeler sticks the default strategy in there. As I am currently in favor of DataNode-less projects, I don't ever see it myself, but it was reported a few times by others. Need to open a Jira I guess and create a fix.
>>
>> Andrus
>>
>>
>>> On Jan 23, 2016, at 5:47 PM, Michael Gentry <mg...@masslight.net> wrote:
>>>
>>> Hi Hugi,
>>>
>>> This worked for me in 3.1:
>>>
>>> // Use a custom Cayenne server runtime.
>>> serverRuntime = new ServerRuntime("my cayenne model", new
>>> CayenneExtrasModule()));
>>>
>>> ...
>>>
>>> /**
>>> * Custom Cayenne DI module.
>>> */
>>> private static class CayenneExtrasModule implements Module
>>> {
>>> @Override
>>> public void configure(Binder binder)
>>> {
>>> // Change the SchemaUpdateStrategy to create the DB schema for
>>> unit
>>> // testing instead of using the model's default which assumes an
>>> // existing schema.
>>>
>>> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class);
>>> }
>>> }
>>>
>>>
>>> On Sat, Jan 23, 2016 at 7:33 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>>
>>>> Hi Michael, Andrus and Savva.
>>>>
>>>> Thanks a lot for all the help with this :). The arguments to the
>>>> ServerRuntimeBuilder are exactly what I wanted :).
>>>>
>>>> One thing though: Setting the SchemaUpdateStrategy in code (in the
>>>> ServerRuntimeBuilder) doesn’t work for me. Works great if I set it in the
>>>> cayenne modeler, but if the modeler has the default
>>>> “SkipSchemaUpdateStrategy” selected, changing it in the
>>>> ServerRuntimeBuilder doesn’t seem to do anything. Any ideas?
>>>>
>>>> This is how I’m currently initializing my server runtime
>>>>
>>>> public static ServerRuntime serverRuntime() {
>>>> if (_serverRuntime == null) {
>>>> _serverRuntime = new ServerRuntimeBuilder()
>>>> .addConfig("cayenne-project.xml")
>>>> .addModule(binder ->
>>>> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class))
>>>> .jdbcDriver("org.h2.Driver")
>>>> .url("jdbc:h2:~/h2-testing")
>>>> .build();
>>>> }
>>>>
>>>> return _serverRuntime;
>>>> }
>>>>
>>>> Cheers,
>>>> - hugi
>>
>
Re: Changing database connection programmatically
Posted by Hugi Thordarson <hu...@karlmenn.is>.
Ah, I see… It sure looks like we should be going DataNode-less too. Any caveats or tricks? Isn’t it just a question of deleting the datanode in the project, adding the missing configuration in my ServerRuntimeBuilder and carry on with my life?
- hugi
> On 23. jan. 2016, at 17:11, Andrus Adamchik <an...@objectstyle.org> wrote:
>
> There's a bug that we've seen with this, just haven't got to the bottom of it yet.
>
> All I know is that overriding the strategy does not if another strategy is already present in the XML and sometimes (always?) the Modeler sticks the default strategy in there. As I am currently in favor of DataNode-less projects, I don't ever see it myself, but it was reported a few times by others. Need to open a Jira I guess and create a fix.
>
> Andrus
>
>
>> On Jan 23, 2016, at 5:47 PM, Michael Gentry <mg...@masslight.net> wrote:
>>
>> Hi Hugi,
>>
>> This worked for me in 3.1:
>>
>> // Use a custom Cayenne server runtime.
>> serverRuntime = new ServerRuntime("my cayenne model", new
>> CayenneExtrasModule()));
>>
>> ...
>>
>> /**
>> * Custom Cayenne DI module.
>> */
>> private static class CayenneExtrasModule implements Module
>> {
>> @Override
>> public void configure(Binder binder)
>> {
>> // Change the SchemaUpdateStrategy to create the DB schema for
>> unit
>> // testing instead of using the model's default which assumes an
>> // existing schema.
>>
>> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class);
>> }
>> }
>>
>>
>> On Sat, Jan 23, 2016 at 7:33 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>
>>> Hi Michael, Andrus and Savva.
>>>
>>> Thanks a lot for all the help with this :). The arguments to the
>>> ServerRuntimeBuilder are exactly what I wanted :).
>>>
>>> One thing though: Setting the SchemaUpdateStrategy in code (in the
>>> ServerRuntimeBuilder) doesn’t work for me. Works great if I set it in the
>>> cayenne modeler, but if the modeler has the default
>>> “SkipSchemaUpdateStrategy” selected, changing it in the
>>> ServerRuntimeBuilder doesn’t seem to do anything. Any ideas?
>>>
>>> This is how I’m currently initializing my server runtime
>>>
>>> public static ServerRuntime serverRuntime() {
>>> if (_serverRuntime == null) {
>>> _serverRuntime = new ServerRuntimeBuilder()
>>> .addConfig("cayenne-project.xml")
>>> .addModule(binder ->
>>> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class))
>>> .jdbcDriver("org.h2.Driver")
>>> .url("jdbc:h2:~/h2-testing")
>>> .build();
>>> }
>>>
>>> return _serverRuntime;
>>> }
>>>
>>> Cheers,
>>> - hugi
>
Re: Changing database connection programmatically
Posted by Andrus Adamchik <an...@objectstyle.org>.
There's a bug that we've seen with this, just haven't got to the bottom of it yet.
All I know is that overriding the strategy does not if another strategy is already present in the XML and sometimes (always?) the Modeler sticks the default strategy in there. As I am currently in favor of DataNode-less projects, I don't ever see it myself, but it was reported a few times by others. Need to open a Jira I guess and create a fix.
Andrus
> On Jan 23, 2016, at 5:47 PM, Michael Gentry <mg...@masslight.net> wrote:
>
> Hi Hugi,
>
> This worked for me in 3.1:
>
> // Use a custom Cayenne server runtime.
> serverRuntime = new ServerRuntime("my cayenne model", new
> CayenneExtrasModule()));
>
> ...
>
> /**
> * Custom Cayenne DI module.
> */
> private static class CayenneExtrasModule implements Module
> {
> @Override
> public void configure(Binder binder)
> {
> // Change the SchemaUpdateStrategy to create the DB schema for
> unit
> // testing instead of using the model's default which assumes an
> // existing schema.
>
> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class);
> }
> }
>
>
> On Sat, Jan 23, 2016 at 7:33 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
>> Hi Michael, Andrus and Savva.
>>
>> Thanks a lot for all the help with this :). The arguments to the
>> ServerRuntimeBuilder are exactly what I wanted :).
>>
>> One thing though: Setting the SchemaUpdateStrategy in code (in the
>> ServerRuntimeBuilder) doesn’t work for me. Works great if I set it in the
>> cayenne modeler, but if the modeler has the default
>> “SkipSchemaUpdateStrategy” selected, changing it in the
>> ServerRuntimeBuilder doesn’t seem to do anything. Any ideas?
>>
>> This is how I’m currently initializing my server runtime
>>
>> public static ServerRuntime serverRuntime() {
>> if (_serverRuntime == null) {
>> _serverRuntime = new ServerRuntimeBuilder()
>> .addConfig("cayenne-project.xml")
>> .addModule(binder ->
>> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class))
>> .jdbcDriver("org.h2.Driver")
>> .url("jdbc:h2:~/h2-testing")
>> .build();
>> }
>>
>> return _serverRuntime;
>> }
>>
>> Cheers,
>> - hugi
Re: Changing database connection programmatically
Posted by Michael Gentry <mg...@masslight.net>.
Hi Hugi,
This worked for me in 3.1:
// Use a custom Cayenne server runtime.
serverRuntime = new ServerRuntime("my cayenne model", new
CayenneExtrasModule()));
...
/**
* Custom Cayenne DI module.
*/
private static class CayenneExtrasModule implements Module
{
@Override
public void configure(Binder binder)
{
// Change the SchemaUpdateStrategy to create the DB schema for
unit
// testing instead of using the model's default which assumes an
// existing schema.
binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class);
}
}
On Sat, Jan 23, 2016 at 7:33 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> Hi Michael, Andrus and Savva.
>
> Thanks a lot for all the help with this :). The arguments to the
> ServerRuntimeBuilder are exactly what I wanted :).
>
> One thing though: Setting the SchemaUpdateStrategy in code (in the
> ServerRuntimeBuilder) doesn’t work for me. Works great if I set it in the
> cayenne modeler, but if the modeler has the default
> “SkipSchemaUpdateStrategy” selected, changing it in the
> ServerRuntimeBuilder doesn’t seem to do anything. Any ideas?
>
> This is how I’m currently initializing my server runtime
>
> public static ServerRuntime serverRuntime() {
> if (_serverRuntime == null) {
> _serverRuntime = new ServerRuntimeBuilder()
> .addConfig("cayenne-project.xml")
> .addModule(binder ->
> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class))
> .jdbcDriver("org.h2.Driver")
> .url("jdbc:h2:~/h2-testing")
> .build();
> }
>
> return _serverRuntime;
> }
>
> Cheers,
> - hugi
Re: Changing database connection programmatically
Posted by Hugi Thordarson <hu...@karlmenn.is>.
Hi Michael, Andrus and Savva.
Thanks a lot for all the help with this :). The arguments to the ServerRuntimeBuilder are exactly what I wanted :).
One thing though: Setting the SchemaUpdateStrategy in code (in the ServerRuntimeBuilder) doesn’t work for me. Works great if I set it in the cayenne modeler, but if the modeler has the default “SkipSchemaUpdateStrategy” selected, changing it in the ServerRuntimeBuilder doesn’t seem to do anything. Any ideas?
This is how I’m currently initializing my server runtime
public static ServerRuntime serverRuntime() {
if (_serverRuntime == null) {
_serverRuntime = new ServerRuntimeBuilder()
.addConfig("cayenne-project.xml")
.addModule(binder -> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class))
.jdbcDriver("org.h2.Driver")
.url("jdbc:h2:~/h2-testing")
.build();
}
return _serverRuntime;
}
Cheers,
- hugi
Re: Changing database connection programmatically
Posted by Michael Gentry <mg...@masslight.net>.
Yeah, that's pretty much what I did for my Cayenne 3.1 unit tests, although
I don't like inner classes, so I did it separately. Also didn't use the
expression chaining, but still, very similar concept-wise.
On Fri, Jan 22, 2016 at 3:52 PM, Andrus Adamchik <an...@objectstyle.org>
wrote:
> In addition to Mike and Savva's suggestions, I wanted to point to our
> LinkRest unit tests. Here is a base class (ignore the Jersey part, just
> focus on Cayenne and Derby) [1].
>
> * It manages a lifecycle of a Derby DB instance via simple DerbyManager,
> ensuring filesystem folders are cleaned up between the runs.
> * Cayenne XML is DataNode-less [2], expecting you to define the DataSource
> via API in the unit test (as well as in the main app .. not in this example
> though).
> * ServerRuntime creation procedure includes making an in-memory DataSource
> and a unit test SchemaUpdateStrategy:
>
> CAYENNE_RUNTIME = new ServerRuntimeBuilder()
> .addConfig("cayenne-linkrest-tests.xml")
> .addModule(new Module() {
>
> // Java 7; for Java 8 you can use a lambda for the Module
> @Override
> public void configure(Binder binder) {
>
> binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class);
> }
> })
> .jdbcDriver("org.apache.derby.jdbc.EmbeddedDriver")
> .url("jdbc:derby:target/derby;create=true")
> .build();
>
> Hope this helps.
>
> Andrus
>
> [1]
> https://github.com/nhl/link-rest/blob/master/src/test/java/com/nhl/link/rest/it/fixture/JerseyTestOnDerby.java
> [2]
> https://github.com/nhl/link-rest/blob/master/src/test/resources/cayenne-linkrest-tests.xml
>
> Andrus
>
> > On Jan 22, 2016, at 9:50 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> >
> > Ah, sorry about that… I’m using the current 4.0 snapshots.
> >
> > - hugi
> >
> >
> >
> >> On 22. jan. 2016, at 18:47, Michael Gentry <mg...@masslight.net>
> wrote:
> >>
> >> Which version of Cayenne are you using?
> >>
> >>
> >> On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson <hu...@karlmenn.is>
> wrote:
> >>
> >>> Hi all,
> >>>
> >>> I’m writing some tests for my DataObjects. Before the tests run, I’d
> like
> >>> to provision an h2 database and switch my model’s connection to it for
> the
> >>> purpose of testing.
> >>>
> >>> What’s the preferred way to switch the connection programmatically?
> >>>
> >>> Cheers,
> >>> - hugi
> >
>
>
Re: Changing database connection programmatically
Posted by Andrus Adamchik <an...@objectstyle.org>.
In addition to Mike and Savva's suggestions, I wanted to point to our LinkRest unit tests. Here is a base class (ignore the Jersey part, just focus on Cayenne and Derby) [1].
* It manages a lifecycle of a Derby DB instance via simple DerbyManager, ensuring filesystem folders are cleaned up between the runs.
* Cayenne XML is DataNode-less [2], expecting you to define the DataSource via API in the unit test (as well as in the main app .. not in this example though).
* ServerRuntime creation procedure includes making an in-memory DataSource and a unit test SchemaUpdateStrategy:
CAYENNE_RUNTIME = new ServerRuntimeBuilder()
.addConfig("cayenne-linkrest-tests.xml")
.addModule(new Module() {
// Java 7; for Java 8 you can use a lambda for the Module
@Override
public void configure(Binder binder) {
binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class);
}
})
.jdbcDriver("org.apache.derby.jdbc.EmbeddedDriver")
.url("jdbc:derby:target/derby;create=true")
.build();
Hope this helps.
Andrus
[1] https://github.com/nhl/link-rest/blob/master/src/test/java/com/nhl/link/rest/it/fixture/JerseyTestOnDerby.java
[2] https://github.com/nhl/link-rest/blob/master/src/test/resources/cayenne-linkrest-tests.xml
Andrus
> On Jan 22, 2016, at 9:50 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
> Ah, sorry about that… I’m using the current 4.0 snapshots.
>
> - hugi
>
>
>
>> On 22. jan. 2016, at 18:47, Michael Gentry <mg...@masslight.net> wrote:
>>
>> Which version of Cayenne are you using?
>>
>>
>> On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>
>>> Hi all,
>>>
>>> I’m writing some tests for my DataObjects. Before the tests run, I’d like
>>> to provision an h2 database and switch my model’s connection to it for the
>>> purpose of testing.
>>>
>>> What’s the preferred way to switch the connection programmatically?
>>>
>>> Cheers,
>>> - hugi
>
Re: Changing database connection programmatically
Posted by Michael Gentry <mg...@masslight.net>.
Actually, looking at this example, it should probably set up auto-creating
of the schema during the test as well. I'll try to get you some 3.1 code
that shows that.
On Fri, Jan 22, 2016 at 1:54 PM, Michael Gentry <mg...@masslight.net>
wrote:
> I have an example in 3.0.2, but could update it sometime. With 3.1 (and
> 4.0) you'd use a Cayenne DI Module, which I did on another project, but it
> is far too large to share/etc. Here is my 3.0.2 example:
>
>
> https://github.com/mrg/cbe/blob/master/UnitTesting/src/test/java/cbe/testing/AppTest.java
>
> Let me know if you'd like an updated (to 3.1) version.
>
> mrg
>
>
> On Fri, Jan 22, 2016 at 1:50 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
>> Ah, sorry about that… I’m using the current 4.0 snapshots.
>>
>> - hugi
>>
>>
>>
>> > On 22. jan. 2016, at 18:47, Michael Gentry <mg...@masslight.net>
>> wrote:
>> >
>> > Which version of Cayenne are you using?
>> >
>> >
>> > On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson <hu...@karlmenn.is>
>> wrote:
>> >
>> >> Hi all,
>> >>
>> >> I’m writing some tests for my DataObjects. Before the tests run, I’d
>> like
>> >> to provision an h2 database and switch my model’s connection to it for
>> the
>> >> purpose of testing.
>> >>
>> >> What’s the preferred way to switch the connection programmatically?
>> >>
>> >> Cheers,
>> >> - hugi
>>
>>
>
Re: Changing database connection programmatically
Posted by Michael Gentry <mg...@masslight.net>.
I should get off my butt and actually finish the examples/documentation...
On Fri, Jan 22, 2016 at 3:22 PM, Andrus Adamchik <an...@objectstyle.org>
wrote:
> > Let me know if you'd like an updated (to 3.1) version.
>
> A few people have mentioned to me that "Cayenne by Example" was useful to
> them in their Cayenne work. Would be cool if we could update that to 4.0
> with ServerRuntimeBuilder, and other goodies mentioned in
> https://www.youtube.com/watch?v=gSauEmPnkCU presentation.
>
> Andrus
>
>
> > On Jan 22, 2016, at 9:54 PM, Michael Gentry <mg...@masslight.net>
> wrote:
> >
> > I have an example in 3.0.2, but could update it sometime. With 3.1 (and
> > 4.0) you'd use a Cayenne DI Module, which I did on another project, but
> it
> > is far too large to share/etc. Here is my 3.0.2 example:
> >
> >
> https://github.com/mrg/cbe/blob/master/UnitTesting/src/test/java/cbe/testing/AppTest.java
> >
> > Let me know if you'd like an updated (to 3.1) version.
> >
> > mrg
> >
> >
> > On Fri, Jan 22, 2016 at 1:50 PM, Hugi Thordarson <hu...@karlmenn.is>
> wrote:
> >
> >> Ah, sorry about that… I’m using the current 4.0 snapshots.
> >>
> >> - hugi
> >>
> >>
> >>
> >>> On 22. jan. 2016, at 18:47, Michael Gentry <mg...@masslight.net>
> >> wrote:
> >>>
> >>> Which version of Cayenne are you using?
> >>>
> >>>
> >>> On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson <hu...@karlmenn.is>
> >> wrote:
> >>>
> >>>> Hi all,
> >>>>
> >>>> I’m writing some tests for my DataObjects. Before the tests run, I’d
> >> like
> >>>> to provision an h2 database and switch my model’s connection to it for
> >> the
> >>>> purpose of testing.
> >>>>
> >>>> What’s the preferred way to switch the connection programmatically?
> >>>>
> >>>> Cheers,
> >>>> - hugi
> >>
> >>
>
>
Re: Changing database connection programmatically
Posted by Andrus Adamchik <an...@objectstyle.org>.
> Let me know if you'd like an updated (to 3.1) version.
A few people have mentioned to me that "Cayenne by Example" was useful to them in their Cayenne work. Would be cool if we could update that to 4.0 with ServerRuntimeBuilder, and other goodies mentioned in https://www.youtube.com/watch?v=gSauEmPnkCU presentation.
Andrus
> On Jan 22, 2016, at 9:54 PM, Michael Gentry <mg...@masslight.net> wrote:
>
> I have an example in 3.0.2, but could update it sometime. With 3.1 (and
> 4.0) you'd use a Cayenne DI Module, which I did on another project, but it
> is far too large to share/etc. Here is my 3.0.2 example:
>
> https://github.com/mrg/cbe/blob/master/UnitTesting/src/test/java/cbe/testing/AppTest.java
>
> Let me know if you'd like an updated (to 3.1) version.
>
> mrg
>
>
> On Fri, Jan 22, 2016 at 1:50 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
>> Ah, sorry about that… I’m using the current 4.0 snapshots.
>>
>> - hugi
>>
>>
>>
>>> On 22. jan. 2016, at 18:47, Michael Gentry <mg...@masslight.net>
>> wrote:
>>>
>>> Which version of Cayenne are you using?
>>>
>>>
>>> On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson <hu...@karlmenn.is>
>> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I’m writing some tests for my DataObjects. Before the tests run, I’d
>> like
>>>> to provision an h2 database and switch my model’s connection to it for
>> the
>>>> purpose of testing.
>>>>
>>>> What’s the preferred way to switch the connection programmatically?
>>>>
>>>> Cheers,
>>>> - hugi
>>
>>
Re: Changing database connection programmatically
Posted by Michael Gentry <mg...@masslight.net>.
I have an example in 3.0.2, but could update it sometime. With 3.1 (and
4.0) you'd use a Cayenne DI Module, which I did on another project, but it
is far too large to share/etc. Here is my 3.0.2 example:
https://github.com/mrg/cbe/blob/master/UnitTesting/src/test/java/cbe/testing/AppTest.java
Let me know if you'd like an updated (to 3.1) version.
mrg
On Fri, Jan 22, 2016 at 1:50 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> Ah, sorry about that… I’m using the current 4.0 snapshots.
>
> - hugi
>
>
>
> > On 22. jan. 2016, at 18:47, Michael Gentry <mg...@masslight.net>
> wrote:
> >
> > Which version of Cayenne are you using?
> >
> >
> > On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson <hu...@karlmenn.is>
> wrote:
> >
> >> Hi all,
> >>
> >> I’m writing some tests for my DataObjects. Before the tests run, I’d
> like
> >> to provision an h2 database and switch my model’s connection to it for
> the
> >> purpose of testing.
> >>
> >> What’s the preferred way to switch the connection programmatically?
> >>
> >> Cheers,
> >> - hugi
>
>
Re: Changing database connection programmatically
Posted by Hugi Thordarson <hu...@karlmenn.is>.
Ah, sorry about that… I’m using the current 4.0 snapshots.
- hugi
> On 22. jan. 2016, at 18:47, Michael Gentry <mg...@masslight.net> wrote:
>
> Which version of Cayenne are you using?
>
>
> On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
>> Hi all,
>>
>> I’m writing some tests for my DataObjects. Before the tests run, I’d like
>> to provision an h2 database and switch my model’s connection to it for the
>> purpose of testing.
>>
>> What’s the preferred way to switch the connection programmatically?
>>
>> Cheers,
>> - hugi
Re: Changing database connection programmatically
Posted by Michael Gentry <mg...@masslight.net>.
Which version of Cayenne are you using?
On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> Hi all,
>
> I’m writing some tests for my DataObjects. Before the tests run, I’d like
> to provision an h2 database and switch my model’s connection to it for the
> purpose of testing.
>
> What’s the preferred way to switch the connection programmatically?
>
> Cheers,
> - hugi
Re: Changing database connection programmatically
Posted by Savva Kolbachev <s....@gmail.com>.
Hi Hugi,
I think you want to add some VM options. Take a look at
https://cayenne.apache.org/dev/running-unit-tests.html
2016-01-22 21:25 GMT+03:00 Hugi Thordarson <hu...@karlmenn.is>:
> Hi all,
>
> I’m writing some tests for my DataObjects. Before the tests run, I’d like
> to provision an h2 database and switch my model’s connection to it for the
> purpose of testing.
>
> What’s the preferred way to switch the connection programmatically?
>
> Cheers,
> - hugi
--
Thanks and Regards
Savva Kolbachev