bug 2840 : Major work on adl2controllerclasses to collect up modified entities and call before- and after- update hooks on all of them. It complies and looks convincing but at this stage a great deal more testing is required!
This commit is contained in:
parent
133b53fd23
commit
97fd52777b
|
@ -9,8 +9,8 @@
|
|||
Transform ADL into (partial) controller classes
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.36 $
|
||||
$Date: 2009-04-28 13:44:51 $
|
||||
$Revision: 1.37 $
|
||||
$Date: 2009-04-28 18:27:59 $
|
||||
-->
|
||||
|
||||
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
|
||||
|
@ -70,7 +70,7 @@
|
|||
//
|
||||
// Automatically generated abstract super class for controllers for the
|
||||
// <xsl:value-of select="/adl:application/@name"/> application; generated using
|
||||
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.36 $', 10)"/>
|
||||
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
|
||||
//
|
||||
// <xsl:value-of select="/adl:application/@revision"/>
|
||||
//
|
||||
|
@ -180,7 +180,7 @@
|
|||
//
|
||||
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
|
||||
// Automatically generated from application description using
|
||||
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.36 $', 10)"/>
|
||||
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
|
||||
//
|
||||
// This file is automatically generated; DO NOT EDIT IT.
|
||||
//
|
||||
|
@ -197,6 +197,7 @@
|
|||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using Castle.MonoRail.Framework.Helpers;
|
||||
using Cygnet.Entities;
|
||||
using Cygnet.Exceptions;
|
||||
using Cygnet.Web.Helpers;
|
||||
using Cygnet.Web.Controllers;
|
||||
|
@ -388,27 +389,31 @@
|
|||
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>();
|
||||
}
|
||||
messages.Add( "New <xsl:value-of select="@name"/> record created");
|
||||
isnewborn = true;
|
||||
}
|
||||
isnewborn = true;
|
||||
}
|
||||
|
||||
if ( record != null) {
|
||||
/* a transaction to ensure our database operations are atomic */
|
||||
ITransaction tx = null;
|
||||
if ( record != null) {
|
||||
/* a transaction to ensure our database operations are atomic */
|
||||
ITransaction tx = null;
|
||||
|
||||
if ( ! isnewborn) {
|
||||
/* isnewborn cannot be true unless we've already checked user can create
|
||||
* so no need to do it again here */
|
||||
AssertUserCanUpdate();
|
||||
}
|
||||
|
||||
try {
|
||||
/* begin our atomic transaction */
|
||||
tx = hibernator.BeginTransaction();
|
||||
if ( ! isnewborn) {
|
||||
/* isnewborn cannot be true unless we've already checked user can create
|
||||
* so no need to do it again here */
|
||||
AssertUserCanUpdate();
|
||||
}
|
||||
|
||||
/* actually update the record */
|
||||
BindObjectInstance( record, ParamStore.Form, "instance");
|
||||
try {
|
||||
/* begin our atomic transaction */
|
||||
tx = hibernator.BeginTransaction();
|
||||
/* list of entities modified in this transaction */
|
||||
List<Entity> modified = new List<Entity>();
|
||||
|
||||
<xsl:if test="descendant::adl:property[@type='message']">
|
||||
/* actually update the record */
|
||||
BindObjectInstance( record, ParamStore.Form, "instance");
|
||||
modified.Add( record);
|
||||
|
||||
<xsl:if test="descendant::adl:property[@type='message']">
|
||||
/* there is at least one slot whose value is an internationalised message;
|
||||
* if these have yet to be initialised they must be handled specially */
|
||||
Locale locale = GetBestLocaleForUser();
|
||||
|
@ -451,6 +456,8 @@
|
|||
Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"]
|
||||
</xsl:with-param>
|
||||
</xsl:call-template>;
|
||||
|
||||
modified.Add( record.<xsl:value-of select="@name"/>);
|
||||
}
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
|
@ -478,44 +485,57 @@
|
|||
</xsl:variable>
|
||||
/* to update a link table which has no other data than the near and far keys, it is
|
||||
* 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'">
|
||||
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
|
||||
* should not try. */
|
||||
</xsl:if>
|
||||
string[] <xsl:value-of select="concat(@name, 'Values')"/> = Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>");
|
||||
string[] <xsl:value-of select="concat(@name, 'Values')"/> = Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>");
|
||||
|
||||
/* update the linking table for my <xsl:value-of select="@name"/>; first smash the old values */
|
||||
if ( <xsl:value-of select="concat( 'record.', @name)"/> != null)
|
||||
{
|
||||
<xsl:value-of select="concat( 'record.', @name)"/>.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
<xsl:value-of select="concat( 'record.', @name)"/> = new HashedSet<<xsl:value-of select="concat( $entityns, '.', @entity)"/>>();
|
||||
} /* if ( <xsl:value-of select="concat( 'record.', @name)"/> != null) */
|
||||
List<Entity> toAdd = new List<Entity>();
|
||||
List<Entity> toRemove = new List<Entity>();
|
||||
|
||||
if ( <xsl:value-of select="concat(@name, 'Values')"/> != null)
|
||||
{
|
||||
/* then reinstate the values from the indexes passed */
|
||||
foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>)
|
||||
{
|
||||
<xsl:value-of select="concat( 'record.', @name)"/>.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="'index'"/>
|
||||
</xsl:call-template>
|
||||
.UniqueResult<<xsl:value-of select="concat( $entityns, '.', @entity)"/>>());
|
||||
} /* foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>) */
|
||||
} /* if ( <xsl:value-of select="concat(@name, 'Values')"/> != null) */
|
||||
<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) */
|
||||
</xsl:if>
|
||||
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);
|
||||
<xsl:value-of select="concat( 'record.', @name)"/>.Remove(item);
|
||||
}
|
||||
foreach (<xsl:value-of select="concat( $entityns, '.', @entity)"/> item in toAdd) {
|
||||
modified.Add(item);
|
||||
<xsl:value-of select="concat( 'record.', @name)"/>.Add(item);
|
||||
}
|
||||
|
||||
<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) */
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
|
||||
<xsl:for-each select="descendant::adl:property[@type='list']">
|
||||
|
@ -574,6 +594,7 @@
|
|||
if ( ! found)
|
||||
{
|
||||
record.<xsl:value-of select="@name"/>.Remove( item);
|
||||
modified.Add( item);
|
||||
break;
|
||||
}
|
||||
} /* foreach ( <xsl:value-of select="@entity"/> item ... */
|
||||
|
@ -597,17 +618,14 @@
|
|||
<xsl:value-of select="concat( 'item.', $foreignkey)"/>;
|
||||
if ( oldparent != null) {
|
||||
oldparent.<xsl:value-of select="@name"/>.Remove( item);
|
||||
oldparent.BeforeUpdateHook( hibernator);
|
||||
hibernator.SaveOrUpdate( oldparent);
|
||||
oldparent.AfterUpdateHook( hibernator);
|
||||
|
||||
modified.Add( oldparent);
|
||||
}
|
||||
|
||||
/* then add it to my <xsl:value-of select="@name"/> */
|
||||
record.<xsl:value-of select="@name"/>.Add( item);
|
||||
<xsl:value-of select="concat( 'item.', $foreignkey)"/> = record;
|
||||
item.BeforeUpdateHook( hibernator);
|
||||
hibernator.SaveOrUpdate( item);
|
||||
item.AfterUpdateHook( hibernator);
|
||||
modified.Add( item);
|
||||
}
|
||||
} /* foreach ( string index... */
|
||||
} /* if ( Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>") != null) */
|
||||
|
@ -617,14 +635,13 @@
|
|||
|
||||
</xsl:for-each>
|
||||
|
||||
/* write the record to the database, in order to guarantee we have a valid key */
|
||||
/* 20090416 we have a significant problem in that the ILifecycle interface is not
|
||||
doing what we expect - or, at least, not consistently!
|
||||
Reinstating the before- and after- update hooks */
|
||||
record.BeforeUpdateHook( hibernator);
|
||||
hibernator.SaveOrUpdate(record);
|
||||
record.AfterUpdateHook( hibernator);
|
||||
|
||||
/* write the modified records to the database */
|
||||
foreach ( Entity item in modified) {
|
||||
item.BeforeUpdateHook( hibernator);
|
||||
hibernator.SaveOrUpdate(item);
|
||||
item.AfterUpdateHook( hibernator);
|
||||
}
|
||||
/* and if no exceptions, commit */
|
||||
tx.Commit();
|
||||
|
||||
messages.Add( "<xsl:call-template name="i18n-record-saved"/>");
|
||||
|
|
Loading…
Reference in a new issue