Re: Changing database connection programmatically

2016-01-24 Thread Andrus Adamchik
> 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 wrote: > > Ah, I see… It sure looks like we should be going DataNode-less too

Re: Changing database connection programmatically

2016-01-23 Thread Hugi Thordarson
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 Adam

Re: Changing database connection programmatically

2016-01-23 Thread Hugi Thordarson
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 wrote: > > Hi Hugi, > > This worked for me in 3.1: >

Re: Changing database connection programmatically

2016-01-23 Thread Andrus Adamchik
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 DataNo

Re: Changing database connection programmatically

2016-01-23 Thread Michael Gentry
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

Re: Changing database connection programmatically

2016-01-23 Thread Hugi Thordarson
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

Re: Changing database connection programmatically

2016-01-22 Thread Michael Gentry
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 wrote: > In addition to Mike and Savv

Re: Changing database connection programmatically

2016-01-22 Thread Michael Gentry
I should get off my butt and actually finish the examples/documentation... On Fri, Jan 22, 2016 at 3:22 PM, Andrus Adamchik 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

Re: Changing database connection programmatically

2016-01-22 Thread Andrus Adamchik
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 betw

Re: Changing database connection programmatically

2016-01-22 Thread Andrus Adamchik
> 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=g

Re: Changing database connection programmatically

2016-01-22 Thread Michael Gentry
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 wrote: > I have an example in 3.0.2, but could update it sometime. With 3.1 (and

Re: Changing database connection programmatically

2016-01-22 Thread Michael Gentry
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 L

Re: Changing database connection programmatically

2016-01-22 Thread Savva Kolbachev
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 : > Hi all, > > I’m writing some tests for my DataObjects. Before the tests run, I’d like > to provision an h2 database and switch

Re: Changing database connection programmatically

2016-01-22 Thread Hugi Thordarson
Ah, sorry about that… I’m using the current 4.0 snapshots. - hugi > On 22. jan. 2016, at 18:47, Michael Gentry wrote: > > Which version of Cayenne are you using? > > > On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson wrote: > >> Hi all, >> >> I’m writing some tests for my DataObjects. Be

Re: Changing database connection programmatically

2016-01-22 Thread Michael Gentry
Which version of Cayenne are you using? On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson 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 t

Changing database connection programmatically

2016-01-22 Thread Hugi Thordarson
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