Currently, creation of tables are ordered by entities with less foreign keys first principle and during deletion of tables the policy is delete entities with more foreign keys first in order not to break foreign key constraints. This is very poor.
This policy will not always work and implemented very earlier just to get things work – a nasty hack.
Consider the following tables:
Table A --> FK: A.X references C.X
Table B --> FK: B.Y references A.X
Table C
Table D--> FK: D.Z references C.Z & D.W references C.W.
With our algorithm the possible creation orders (first to last):
C, B, A, D
C, A, B, D
however if the first schedule is chosen, it won't work because when attempted to create B we say
CREATE TABLE B ...(..., FOREIGN KEY B.Y REFERENCES A.X)
however A does not exist, yet.
We need to implement a dependency tree plugin (which is constructed just before calling createScheme() in MappingSession.start(). It will help us have safe way to create and drop tables according to SchemeCreationPolicy.
The enough information can be obtained from MappingSession.scheme.getEntities() --> List<Entity> --> e.getFields() --> Field --> (f.isForeignKey(), f.getClazz()`).
Currently, creation of tables are ordered by entities with less foreign keys first principle and during deletion of tables the policy is delete entities with more foreign keys first in order not to break foreign key constraints. This is very poor.
This policy will not always work and implemented very earlier just to get things work – a nasty hack.
Consider the following tables:
Table A --> FK: A.X references C.X Table B --> FK: B.Y references A.X Table C Table D--> FK: D.Z references C.Z
&
D.W references C.W.With our algorithm the possible creation orders (first to last):
however if the first schedule is chosen, it won't work because when attempted to create B we say
however A does not exist, yet.
We need to implement a dependency tree plugin (which is constructed just before calling
createScheme()
inMappingSession.start()
. It will help us have safe way to create and drop tables according toSchemeCreationPolicy
.