[ 
https://issues.apache.org/jira/browse/TORQUE-369?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17905200#comment-17905200
 ] 

Georg Kallidis commented on TORQUE-369:
---------------------------------------

This explains the intention for me at least better, thanks!

I checked as you mentioned the {{LoadExternalDatabaseTransformer }}the 
{{transform}} method, which gets invoked {{SQLModelTransformer transform}} 
method, After getting the externalDatabase (an instance of  
{{org.apache.torque.templates.model.Database}} {{rootDatabaseName }}is set 
(from null):

 
{code:java}
...
toModelTransformer.transform
..
externalDatabase.rootDatabaseName = database.rootDatabaseName;
{code}
A recursion will follow, if this externalDatabase.name is equal to 
database.rootDatabaseName.

If we have only two databases, this would be sufficient (after name check is 
not null):
{code:java}
externalDatabase.name equals externalDatabase.rootDatabaseName -> continue
{code}
invocation of the transform method would stop. But it's a short-cut - we drop 
the intermediary (external) database name with more than two schemata. To 
remedy this current information loss of the intermediaries we could change the 
\{{Database }}model above and save all databaseNames, not only just the (first) 
rootDatabaseName.

This would allow just to check e.g.  with i{{{}ntermediaries.contain( 
databaseName) {{}}}}as a condition to skip any redundant includes.

Though, I am not entirely sure, if this might be a solution .. we have to check 
it :) And I am not sure, if it would help at other places, or just for external 
includes ..
 

> 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)

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org
For additional commands, e-mail: torque-dev-h...@db.apache.org

Reply via email to