cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hugi Thordarson <h...@karlmenn.is>
Subject Re: Changing database connection programmatically
Date Sat, 23 Jan 2016 19:16:17 GMT
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 <mgentry@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 <hugi@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


Mime
View raw message