You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Schönfisch, Jörg <jo...@softplant.de> on 2011/11/25 09:57:50 UTC

CreateIfNoSchema vs ThrowOnPartialOrCreate strategy

Hi,

I wanted to change the schema update strategy in my project from CreateIfNoSchema to ThrowOnPartialOrCreate, but I noticed that the later does not create any PK or FK constraints. By looking at the code for generate(DataNode) this seems to be intende, but why? Shouldn't these strategies behave the same way if no schema is present?

Cheers,
Joerg

Re: CreateIfNoSchema vs ThrowOnPartialOrCreate strategy

Posted by Andrus Adamchik <an...@objectstyle.org>.
Yes, a familiar problem - SchemaUpdateStrategy is defined as a Java class with no extra configuration options, so each configuration set has to be encapsulated in a separate class. The chosen defaults for each bundled strategy may not be appropriate for every user. And if you want a custom variety of a standard strategy, you have to subclass.

In 3.1 it is possible to bind the strategy via DI (so Modeler configuration is something of a legacy), and this gives users more flexibility in writing strategies. Maybe we at Cayenne should take another look at the existing strategies and provide configuration options to them that would reduce the need for subclassing.

Andrus


On Nov 25, 2011, at 6:12 AM, Tomas Stenlund wrote:

> Hi Jörg,
> 
> I have had exactly the same reflection and I think I have seen different versions of the same schema strategy where the
> behaviour have been changed between version (setShouldCreateFKConstrants, etc. from false to true or the other way around).
> 
> I actually though it was intended so I wrote my own strategy instead so I have full control of it.
> 
> Cheers,
> 
> Tomas
> 
> On 11/25/2011 09:57 AM, Schönfisch, Jörg wrote:
>> Hi,
>> 
>> I wanted to change the schema update strategy in my project from CreateIfNoSchema to ThrowOnPartialOrCreate, but I noticed that the later does not create any PK or FK constraints. By looking at the code for generate(DataNode) this seems to be intende, but why? Shouldn't these strategies behave the same way if no schema is present?
>> 
>> Cheers,
>> Joerg
>> 
> 
> 


Re: CreateIfNoSchema vs ThrowOnPartialOrCreate strategy

Posted by Tomas Stenlund <to...@telia.com>.
Hi Jörg,

I have had exactly the same reflection and I think I have seen different 
versions of the same schema strategy where the
behaviour have been changed between version 
(setShouldCreateFKConstrants, etc. from false to true or the other way 
around).

I actually though it was intended so I wrote my own strategy instead so 
I have full control of it.

Cheers,

Tomas

On 11/25/2011 09:57 AM, Schönfisch, Jörg wrote:
> Hi,
>
> I wanted to change the schema update strategy in my project from CreateIfNoSchema to ThrowOnPartialOrCreate, but I noticed that the later does not create any PK or FK constraints. By looking at the code for generate(DataNode) this seems to be intende, but why? Shouldn't these strategies behave the same way if no schema is present?
>
> Cheers,
> Joerg
>