bug 2840 : This one proved to have much more subtlety than one would have expected. Changes to adl2controllerclasses and new support class, LinkTableUpdater, in Cygnet.Utils
This commit is contained in:
parent
97fd52777b
commit
e32f089d27
|
@ -9,8 +9,8 @@
|
||||||
Transform ADL into (partial) controller classes
|
Transform ADL into (partial) controller classes
|
||||||
|
|
||||||
$Author: sb $
|
$Author: sb $
|
||||||
$Revision: 1.37 $
|
$Revision: 1.38 $
|
||||||
$Date: 2009-04-28 18:27:59 $
|
$Date: 2009-04-29 13:58:51 $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
|
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
//
|
//
|
||||||
// Automatically generated abstract super class for controllers for the
|
// Automatically generated abstract super class for controllers for the
|
||||||
// <xsl:value-of select="/adl:application/@name"/> application; generated using
|
// <xsl:value-of select="/adl:application/@name"/> application; generated using
|
||||||
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
|
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
|
||||||
//
|
//
|
||||||
// <xsl:value-of select="/adl:application/@revision"/>
|
// <xsl:value-of select="/adl:application/@revision"/>
|
||||||
//
|
//
|
||||||
|
@ -180,7 +180,7 @@
|
||||||
//
|
//
|
||||||
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
|
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
|
||||||
// Automatically generated from application description using
|
// Automatically generated from application description using
|
||||||
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
|
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
|
||||||
//
|
//
|
||||||
// This file is automatically generated; DO NOT EDIT IT.
|
// This file is automatically generated; DO NOT EDIT IT.
|
||||||
//
|
//
|
||||||
|
@ -202,6 +202,7 @@
|
||||||
using Cygnet.Web.Helpers;
|
using Cygnet.Web.Helpers;
|
||||||
using Cygnet.Web.Controllers;
|
using Cygnet.Web.Controllers;
|
||||||
using Cygnet.Web.SmartControls;
|
using Cygnet.Web.SmartControls;
|
||||||
|
using Cygnet.Utility;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
using NHibernate.Expression;
|
using NHibernate.Expression;
|
||||||
using Castle.MonoRail.Framework;
|
using Castle.MonoRail.Framework;
|
||||||
|
@ -470,6 +471,7 @@
|
||||||
</xsl:for-each>
|
</xsl:for-each>
|
||||||
|
|
||||||
<xsl:for-each select="descendant::adl:property[@type='link']">
|
<xsl:for-each select="descendant::adl:property[@type='link']">
|
||||||
|
<xsl:variable name="nearentityname" select="ancestor::adl:entity/@name"/>
|
||||||
<xsl:variable name="farentityname" select="@entity"/>
|
<xsl:variable name="farentityname" select="@entity"/>
|
||||||
<xsl:variable name="entity" select="//adl:entity[@name=$farentityname]"/>
|
<xsl:variable name="entity" select="//adl:entity[@name=$farentityname]"/>
|
||||||
<xsl:variable name="farkey" select="$entity/adl:key/adl:property[position()=1]/@name"/>
|
<xsl:variable name="farkey" select="$entity/adl:key/adl:property[position()=1]/@name"/>
|
||||||
|
@ -483,52 +485,43 @@
|
||||||
<xsl:with-param name="entity" select="$entity"/>
|
<xsl:with-param name="entity" select="$entity"/>
|
||||||
</xsl:call-template>
|
</xsl:call-template>
|
||||||
</xsl:variable>
|
</xsl:variable>
|
||||||
/* to update a link table which has no other data than the near and far keys, it is
|
/* For a link, collect changes to link table and process them */
|
||||||
* sufficient to smash the existing values and create new ones. It's also a lot easier! */
|
|
||||||
/* TODO: 20090427: rewrite so we don't do this - also add changes to 'modified' */
|
|
||||||
<xsl:if test="$authentication-layer = 'Database'">
|
<xsl:if test="$authentication-layer = 'Database'">
|
||||||
if ( <xsl:for-each select="exsl:node-set( $deletegroups)/*">InGroup( "<xsl:value-of select="./@name"/>") ||</xsl:for-each> false) {
|
if ( <xsl:for-each select="exsl:node-set( $deletegroups)/*">InGroup( "<xsl:value-of select="./@name"/>") ||</xsl:for-each> false) {
|
||||||
/* however, we cannot do anything unless we have delete permissions on the table, so
|
/* however, we cannot do anything unless we have delete permissions on the table, so
|
||||||
* should not try. */
|
* should not try. */
|
||||||
</xsl:if>
|
</xsl:if>
|
||||||
string[] <xsl:value-of select="concat(@name, 'Values')"/> = Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>");
|
LinkChanges<<xsl:value-of select="concat( $entityns, '.', @entity)"/>> changes =
|
||||||
|
LinkTableUpdater<<xsl:value-of select="concat( $entityns, '.', @entity)"/>>.Changes( <xsl:value-of select="concat( 'record.', @name)"/>, Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>"),
|
||||||
|
hibernator);
|
||||||
|
|
||||||
List<Entity> toAdd = new List<Entity>();
|
foreach ( var item in changes.ToRemove) {
|
||||||
List<Entity> toRemove = new List<Entity>();
|
|
||||||
|
|
||||||
foreach (<xsl:value-of select="concat( $entityns, '.', @entity)"/> item in <xsl:value-of select="concat( 'record.', @name)"/>) {
|
|
||||||
foreach (string value in <xsl:value-of select="concat(@name, 'Values')"/>) {
|
|
||||||
if (item.KeyString.Equals(value)) {
|
|
||||||
toRemove.Add(item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (string value in <xsl:value-of select="concat(@name, 'Values')"/>) {
|
|
||||||
Boolean add = true;
|
|
||||||
foreach (<xsl:value-of select="concat( $entityns, '.', @entity)"/> item in <xsl:value-of select="concat( 'record.', @name)"/>) {
|
|
||||||
if (item.KeyString.Equals(value)) {
|
|
||||||
add = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (add) {
|
|
||||||
toAdd.Add(hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @entity)"/>))
|
|
||||||
<xsl:call-template name="add-hibernate-expression-eq">
|
|
||||||
<xsl:with-param name="property" select="//adl:entity[@name=$farentityname]/adl:key/adl:property[position()=1]"/>
|
|
||||||
<xsl:with-param name="value" select="'value'"/>
|
|
||||||
</xsl:call-template>
|
|
||||||
.UniqueResult<<xsl:value-of select="concat( $entityns, '.', @entity)"/>>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (<xsl:value-of select="concat( $entityns, '.', @entity)"/> item in toRemove) {
|
|
||||||
modified.Add(item);
|
modified.Add(item);
|
||||||
<xsl:value-of select="concat( 'record.', @name)"/>.Remove(item);
|
<xsl:value-of select="concat( 'record.', @name)"/>.Remove(item);
|
||||||
|
<xsl:for-each select="$entity//adl:property[@type='link' and @entity=$nearentityname]">
|
||||||
|
<xsl:value-of select="concat( 'item.', @name)"/>.Remove( record);
|
||||||
|
<xsl:if test="position() != 1">
|
||||||
|
/* WARNING WARNING WARNING! Could not uniquely determine the far side property;
|
||||||
|
* redesign your application or manually maintain this code! */
|
||||||
|
<xsl:message terminate="no">
|
||||||
|
WARNING: Could not uniquely determine far end of link represented by property <xsl:value-of select="@name"/> of <xsl:value-of select="$nearentityname"/>
|
||||||
|
</xsl:message>
|
||||||
|
</xsl:if>
|
||||||
|
</xsl:for-each>
|
||||||
}
|
}
|
||||||
foreach (<xsl:value-of select="concat( $entityns, '.', @entity)"/> item in toAdd) {
|
foreach ( var item in changes.ToAdd) {
|
||||||
modified.Add(item);
|
modified.Add(item);
|
||||||
<xsl:value-of select="concat( 'record.', @name)"/>.Add(item);
|
<xsl:value-of select="concat( 'record.', @name)"/>.Add(item);
|
||||||
|
<xsl:for-each select="$entity//adl:property[@type='link' and @entity=$nearentityname]">
|
||||||
|
<xsl:value-of select="concat( 'item.', @name)"/>.Add( record);
|
||||||
|
<xsl:if test="position() != 1">
|
||||||
|
/* WARNING WARNING WARNING! Could not uniquely determine the far side property;
|
||||||
|
* redesign your application or manually maintain this code! */
|
||||||
|
<xsl:message terminate="no">
|
||||||
|
WARNING: Could not uniquely determine far end of link represented by property <xsl:value-of select="@name"/> of <xsl:value-of select="$nearentityname"/>
|
||||||
|
</xsl:message>
|
||||||
|
</xsl:if>
|
||||||
|
</xsl:for-each>
|
||||||
}
|
}
|
||||||
|
|
||||||
<xsl:if test="$authentication-layer = 'Database'">
|
<xsl:if test="$authentication-layer = 'Database'">
|
||||||
|
|
Loading…
Reference in a new issue