[jira] [Commented] (TORQUE-369) LoadExternalSchemaTransformer recursively includes when cross-referencing
"Max Philipp Wriedt (Jira)" <[email protected]> Thu, 12 Dec 2024 09:37:00 +0000 (UTC)
| Newsgroups | gmane.comp.jakarta.turbine.torque.devel |
|---|---|
| Message-ID | <[email protected]> |
[ https://issues.apache.org/jira/browse/TORQUE-369?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17905085#comment-17905085 ]
Max Philipp Wriedt commented on TORQUE-369:
-------------------------------------------
I must admit that I am not nearly as far into the generation process in general as I would like to be, but I think the foreign key checks are disabled by default in every torque-generated sql file.
As for my specific usecase: i want to split up certain table groups into the following 3 schemata:
* General Tables (e.g. table "gender)
* Account/User/whatever specific tables (e.g. table account)
* Item-specific tables (e.g. table items)
The item and account/user tables reference the general tables (for e.g. different genders) as external schema.
The items table may need a account reference, so we reference the account schema in items and maybe an account table needs a table from the item schema. Now we have item with reference to account and vice-versa. The Generator at this time is not aware, that the schema for account is already read into the graph.
The controller responsible for generation is inside torque-generator and now its origin (getSource of "ControllerState"). The IncludeSchemaTransformer and LoadExternalSchemaTransformer on the other hand are part of torque-templates.
Although they also get the ControllerState, they are not aware of which Files they already stepped through.
My approach is to add a HashSet/List of File to the ControllerState where a file is added, when one of the transformers processes that file.
> LoadExternalSchemaTransformer recursively includes when cross-referencing
> -------------------------------------------------------------------------
>
> Key: TORQUE-369
> URL: https://issues.apache.org/jira/browse/TORQUE-369
> Project: Torque
> Issue Type: Bug
> Components: Templates
> Affects Versions: 5.1, 6.0
> Reporter: Max Philipp Wriedt
> Assignee: Max Philipp Wriedt
> Priority: Major
>
> When referencing an external schema (to use foreign key references in another schema definition) and back referencing to its origin, we get an infinite recursion.
> Affects: org.apache.torque.templates.transformer.LoadExternalSchemaTransformer.transform()
> Example:
> First Schema:
> {code:java}
> <?xml version="1.0" encoding="UTF-8" ?>
> <database>
> <external-schema filename=secondary-schema.xml" />
> <table name="test" javaName="Test">
> <column name="Id" javaName="Id" required="true" type="INTEGER" primaryKey="true"/>
> <column name="Name" javaName="Name" required="true" type="VARCHAR" size="5"/>
> <column name="foreign-key" javaName="ForeignKey" required="true" type="INTEGER" size="2"/>
> <!-- define foreign key to secondary scheme!-->
> </table>
> </database>{code}
> Second Schema:
> {code:java}
> <?xml version="1.0" encoding="UTF-8" ?>
> <database
> xmlns="http://db.apache.org/torque/5.0/templates/database"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://db.apache.org/torque/5.0/templates/database
> https://db.apache.org/torque/torque-5.0/documentation/orm-reference/database-5-0-strict.xsd" name="test" defaultIdMethod="native" defaultJavaType="object">
> <external-schema filename=first-schema.xml" />
> <table name="foreign-key" javaName="Test">
> <column name="Id" javaName="Id" required="true" type="INTEGER" primaryKey="true"/>
> <column name="Name" javaName="Name" required="true" type="VARCHAR" size="5"/>
> </table>
> <table name="test2" javaName="Test2">
> <column name="Id" javaName="Id" required="true" type="INTEGER" primaryKey="true"/>
> <column name="Name" javaName="Name" required="true" type="VARCHAR" size="5"/>
> <column name="foreign-key" javaName="ForeignKey" required="true" type="INTEGER" size="2"/>
> <!-- define foreign key to first scheme!-->
> </table>
> </database>{code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)