bug 1833 : Added distinctness checks to controller generator; also transactions.

This commit is contained in:
sb 2008-05-08 17:26:44 +00:00
parent 363dfd3df9
commit 0e392e6bb3

View file

@ -9,8 +9,8 @@
Transform ADL into (partial) controller classes Transform ADL into (partial) controller classes
$Author: sb $ $Author: sb $
$Revision: 1.22 $ $Revision: 1.23 $
$Date: 2008-04-18 09:27:29 $ $Date: 2008-05-08 17:26:44 $
--> -->
<!-- WARNING WARNING WARNING: Do NOT reformat this file! <!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -71,7 +71,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.22 $', 10)"/> // adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
// //
// This file is automatically generated; DO NOT EDIT IT. // This file is automatically generated; DO NOT EDIT IT.
// //
@ -128,7 +128,7 @@ namespace <xsl:value-of select="$controllerns"/> {
// //
// 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.22 $', 10)"/> // adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
// //
// This file is automatically generated; DO NOT EDIT IT. // This file is automatically generated; DO NOT EDIT IT.
// //
@ -187,17 +187,26 @@ namespace <xsl:value-of select="$controllerns"/> {
// field values and save the entity. // field values and save the entity.
Boolean isnewborn = false; Boolean isnewborn = false;
<xsl:apply-templates select="descendant::adl:property"/>
<xsl:call-template name="fetch-instance"> <xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="."/> <xsl:with-param name="entity" select="."/>
<xsl:with-param name="initialise-locals" select="'true'"/>
</xsl:call-template> </xsl:call-template>
if ( record == null) { try {
/* it seems to be new, create persistent object */ <xsl:if test="adl:property[@distinct='system' or @distinct='all']">
AssertUserCanCreate(); /* declare a list of <xsl:value-of select="@name"/> to use in
try { * distinctness checks */
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>(<xsl:for-each select="adl:key/adl:property"> IList&lt;<xsl:value-of select="@name"/>&gt; matches = null;
</xsl:if>
<xsl:apply-templates select="descendant::adl:property"/>
if ( record == null) {
/* it seems to be new, create persistent object */
AssertUserCanCreate();
try {
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>(<xsl:for-each select="adl:key/adl:property">
<xsl:variable name="basetype"> <xsl:variable name="basetype">
<xsl:call-template name="base-type"> <xsl:call-template name="base-type">
<xsl:with-param name="property" select="."/> <xsl:with-param name="property" select="."/>
@ -227,69 +236,72 @@ namespace <xsl:value-of select="$controllerns"/> {
<xsl:otherwise>, </xsl:otherwise> <xsl:otherwise>, </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:for-each>); </xsl:for-each>);
} }
catch ( FormatException) { catch ( FormatException) {
/* failed to parse a number - not wholly unexpected, since it's most likely /* failed to parse a number - not wholly unexpected, since it's most likely
that an empty string was passed in */ that an empty string was passed in */
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>(); record = new <xsl:value-of select="concat($entityns, '.', @name)"/>();
} }
catch ( NullReferenceException) { catch ( NullReferenceException) {
/* again, probably more normal than otherwise */ /* again, probably more normal than otherwise */
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>(); record = new <xsl:value-of select="concat($entityns, '.', @name)"/>();
} }
messages.Add( "New <xsl:value-of select="@name"/> record created"); messages.Add( "New <xsl:value-of select="@name"/> record created");
isnewborn = true; isnewborn = true;
}
if ( record != 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 { if ( record != null) {
/* actually update the record */ /* a transaction to ensure our database operations are atomic */
BindObjectInstance( record, ParamStore.Form, "instance"); 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 {
/* actually update the record */
BindObjectInstance( record, ParamStore.Form, "instance");
<xsl:if test="descendant::adl:property[@type='message']"> <xsl:if test="descendant::adl:property[@type='message']">
/* there is at least one slot whose value is an internationalised 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 */ * if these have yet to be initialised they must be handled specially */
Locale locale = GetBestLocaleForUser(); Locale locale = GetBestLocaleForUser();
<xsl:for-each select="descendant::adl:property[@type='message']"> <xsl:for-each select="descendant::adl:property[@type='message']">
if ( ! String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'i18n.instance.', @name)"/>"])){ if ( ! String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'i18n.instance.', @name)"/>"])){
/* there's an uninitialised message for this slot */ /* there's an uninitialised message for this slot */
Message mess = record.<xsl:value-of select="@name"/>; Message mess = record.<xsl:value-of select="@name"/>;
if ( mess == null){ if ( mess == null){
mess = new Message(); mess = new Message();
} }
hibernator.Save( mess); hibernator.Save( mess);
Translation trans = mess.GetTranslationObject( locale, hibernator); Translation trans = mess.GetTranslationObject( locale, hibernator);
if ( trans == null) { if ( trans == null) {
trans = new Translation( mess, locale); trans = new Translation( mess, locale);
}
trans.MessageText = Form["<xsl:value-of select="concat( 'i18n.instance.', @name)"/>"];
record.<xsl:value-of select="@name"/> = mess;
hibernator.Save( trans);
} }
trans.MessageText = Form["<xsl:value-of select="concat( 'i18n.instance.', @name)"/>"];
record.<xsl:value-of select="@name"/> = mess;
hibernator.Save( trans);
}
</xsl:for-each> </xsl:for-each>
</xsl:if> </xsl:if>
<xsl:for-each select="descendant::adl:property[@type='entity']"> <xsl:for-each select="descendant::adl:property[@type='entity']">
/* for properties of type 'entity', it should not be necessary to do anything /* for properties of type 'entity', it should not be necessary to do anything
* special - BindObjectInstance /should/ do it all. Unfortunately it sometimes * special - BindObjectInstance /should/ do it all. Unfortunately it sometimes
* doesn't, and I haven't yet characterised why not. */ * doesn't, and I haven't yet characterised why not. */
<xsl:variable name="entityname" select="@entity"/> <xsl:variable name="entityname" select="@entity"/>
<xsl:choose> <xsl:choose>
<xsl:when test="//adl:entity[@name=$entityname]"> <xsl:when test="//adl:entity[@name=$entityname]">
if ( ! String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) if ( ! String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"]))
{ {
record.<xsl:value-of select="@name"/> = <xsl:call-template name="fetch-property-instance"> record.<xsl:value-of select="@name"/> = <xsl:call-template name="fetch-property-instance">
<xsl:with-param name="property" select="."/> <xsl:with-param name="property" select="."/>
<xsl:with-param name="valuename" select="concat( 'instance.', @name)"/> <xsl:with-param name="valuename" select="concat( 'instance.', @name)"/>
</xsl:call-template>; </xsl:call-template>;
} }
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:message terminate="yes"> <xsl:message terminate="yes">
@ -301,120 +313,132 @@ namespace <xsl:value-of select="$controllerns"/> {
</xsl:for-each> </xsl:for-each>
<xsl:for-each select="property[@type='link']"> <xsl:for-each select="property[@type='link']">
/* to update a link table which has no other data than the near and far keys, it is /* 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! */ * sufficient to smash the existing values and create new ones. It's also a lot easier! */
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)"/>");
if ( <xsl:value-of select="concat(@name, 'Values')"/> != null) if ( <xsl:value-of select="concat(@name, 'Values')"/> != null)
{
/* 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(); /* 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)
else {
{ <xsl:value-of select="concat( 'record.', @name)"/>.Clear();
<xsl:value-of select="concat( 'record.', @name)"/> = new HashedSet&lt;<xsl:value-of select="@entity"/>&gt;(); }
} else
{
<xsl:value-of select="concat( 'record.', @name)"/> = new HashedSet&lt;<xsl:value-of select="@entity"/>&gt;();
}
/* then reinstate the values from the indexes passed */ /* then reinstate the values from the indexes passed */
foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>) foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>)
{ {
<xsl:value-of select="concat( 'record.', @name)"/>.Add( <xsl:value-of select="concat( 'record.', @name)"/>.Add(
hibernator.CreateCriteria(typeof(<xsl:value-of select="@entity"/>)) hibernator.CreateCriteria(typeof(<xsl:value-of select="@entity"/>))
.Add(Expression.Eq("<xsl:value-of select="@entity"/>Id", index)) .Add(Expression.Eq("<xsl:value-of select="@entity"/>Id", index))
.UniqueResult&lt;<xsl:value-of select="$entityns"/>.<xsl:value-of select="@entity"/>&gt;()); .UniqueResult&lt;<xsl:value-of select="$entityns"/>.<xsl:value-of select="@entity"/>&gt;());
}
} }
}
</xsl:for-each> </xsl:for-each>
<xsl:for-each select="descendant::adl:property[@type='list']"> <xsl:for-each select="descendant::adl:property[@type='list']">
/* with a list we cannot just smash the old values! Instead we need to check /* with a list we cannot just smash the old values! Instead we need to check
* each one and exclude it if no longer required */ * each one and exclude it if no longer required */
if ( Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>") != null) if ( Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>") != null)
{
string[] <xsl:value-of select="concat(@name, 'Values')"/> = Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>");
/* updating <xsl:value-of select="@name"/> child records; first remove any not on the submitted list */
foreach ( <xsl:value-of select="@entity"/> item in record.<xsl:value-of select="@name"/>)
{ {
String itemId = item.KeyString; string[] <xsl:value-of select="concat(@name, 'Values')"/> = Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>");
bool found = false;
/* updating <xsl:value-of select="@name"/> child records; first remove any not on the submitted list */
foreach ( <xsl:value-of select="@entity"/> item in record.<xsl:value-of select="@name"/>)
{
String itemId = item.KeyString;
bool found = false;
foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>)
{
<!-- TODO: this could definitely be made more efficient -->
if ( index.Equals( itemId))
{
found = true;
break;
}
}
if ( ! found)
{
record.<xsl:value-of select="@name"/>.Remove( item);
}
} /* foreach ( string index... */
/* then add any on the included list which are not already members */
foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>) foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>)
{ {
<!-- TODO: this could definitely be made more efficient -->
if ( index.Equals( itemId))
{
found = true;
}
}
if ( ! found)
{
record.<xsl:value-of select="@name"/>.Remove( item);
}
}
/* then add any on the included list which are not already members */
foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>)
{
<xsl:variable name="entityname" select="@entity"/> <xsl:variable name="entityname" select="@entity"/>
<xsl:value-of select="@entity"/> item = <xsl:value-of select="@entity"/> item =
hibernator.CreateCriteria(typeof(<xsl:value-of select="@entity"/>)) hibernator.CreateCriteria(typeof(<xsl:value-of select="@entity"/>))
.Add(Expression.Eq("<xsl:value-of select="@entity"/>Id", index)) .Add(Expression.Eq("<xsl:value-of select="@entity"/>Id", index))
.UniqueResult&lt;<xsl:value-of select="$entityns"/>.<xsl:value-of select="@entity"/>&gt;(); .UniqueResult&lt;<xsl:value-of select="$entityns"/>.<xsl:value-of select="@entity"/>&gt;();
if ( ! record.<xsl:value-of select="@name"/>.Contains( item)) if ( ! record.<xsl:value-of select="@name"/>.Contains( item))
{ {
record.<xsl:value-of select="@name"/>.Add( item); record.<xsl:value-of select="@name"/>.Add( item);
} }
} } /* foreach ( string index... */
} } /* if ( Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>") != null) */
</xsl:for-each> </xsl:for-each>
/* write the record to the database, in order to guarantee we have a valid key */ /* write the record to the database, in order to guarantee we have a valid key */
hibernator.Save(record); hibernator.Save(record);
hibernator.Flush(); hibernator.Flush();
tx.Commit();
messages.Add( "Record saved successfully"); messages.Add( "Record saved successfully");
} } /* try actually commit */
catch ( DataSuitabilityException dse) catch ( Exception any) {
{ tx.Rollback();
AddError( dse.Message); messages.Add( "Record not saved");
} throw any;
catch ( ApplicationException axe) }
{ } /* if ( record != null) */
AddError( axe.Message); else {
throw new ApplicationException( String.Format( "No record of type <xsl:value-of select="@name"/> with the key values supplied was found"));
} }
} /* try */
catch ( DataSuitabilityException dse)
{
AddError( dse);
}
catch ( ApplicationException axe)
{
AddError( axe.Message);
}
PropertyBag["messages"] = messages; PropertyBag["messages"] = messages;
PropertyBag["instance"] = record; PropertyBag["instance"] = record;
<xsl:if test="$authentication-layer = 'Database'"> <xsl:if test="$authentication-layer = 'Database'">
PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN];
</xsl:if> </xsl:if>
if ( ! AssertNoErrors()) if ( HasNoErrors())
{
/* the session may be polluted; create a new session */
NHibernateHelper.CloseSession();
hibernator = NHibernateHelper.GetCurrentSession(<xsl:if test="$authentication-layer = 'Database'">
Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]
</xsl:if>);
}
<xsl:call-template name="formmenus">
<xsl:with-param name="form" select="adl:form[position()=1]"/>
</xsl:call-template>
RenderViewWithFailover("<xsl:value-of select="concat( adl:form[position()=1]/@name, '.vm')"/>",
"<xsl:value-of select="concat( adl:form[position()=1]/@name, '.auto.vm')"/>");
}
else
{ {
throw new DataRequiredException( "Record not found"); /* the session may be polluted; create a new session */
} NHibernateHelper.CloseSession();
hibernator = NHibernateHelper.GetCurrentSession(<xsl:if test="$authentication-layer = 'Database'">
Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]
</xsl:if>);
<xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="."/>
<xsl:with-param name="initialise-locals" select="'false'"/>
</xsl:call-template>
}
<xsl:call-template name="formmenus">
<xsl:with-param name="form" select="adl:form[position()=1]"/>
</xsl:call-template>
RenderViewWithFailover("<xsl:value-of select="concat( adl:form[position()=1]/@name, '.vm')"/>",
"<xsl:value-of select="concat( adl:form[position()=1]/@name, '.auto.vm')"/>");
} }
</xsl:if> </xsl:if>
@ -436,7 +460,8 @@ namespace <xsl:value-of select="$controllerns"/> {
if ( "true".Equals( reallydelete)) if ( "true".Equals( reallydelete))
{ {
<xsl:call-template name="fetch-instance"> <xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="."/> <xsl:with-param name="entity" select="."/>
<xsl:with-param name="initialise-locals" select="'true'"/>
</xsl:call-template> </xsl:call-template>
if ( record != null) if ( record != null)
@ -486,7 +511,7 @@ namespace <xsl:value-of select="$controllerns"/> {
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN], NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]</xsl:if>); Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
IList&lt;<xsl:value-of select="concat( $entityns, '.', @name)"/>&gt; instances = IList&lt;<xsl:value-of select="concat( $entityns, '.', @name)"/>&gt; instances =
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat($entityns, '.', @name)"/>))<xsl:for-each select="property[@distinct='user']"> hibernator.CreateCriteria(typeof(<xsl:value-of select="concat($entityns, '.', @name)"/>))<xsl:for-each select="adl:property[@distinct='user']">
<xsl:value-of select="concat( '.AddOrder( new Order( &#34;', @name, '&#34;, true))')"/> <xsl:value-of select="concat( '.AddOrder( new Order( &#34;', @name, '&#34;, true))')"/>
</xsl:for-each>.List&lt;<xsl:value-of select="concat($entityns, '.', @name)"/>&gt;(); </xsl:for-each>.List&lt;<xsl:value-of select="concat($entityns, '.', @name)"/>&gt;();
@ -515,16 +540,41 @@ namespace <xsl:value-of select="$controllerns"/> {
</xsl:choose>); </xsl:choose>);
} }
<xsl:choose>
<xsl:when test="adl:property[@distinct='system']">
<xsl:call-template name="check-property-value-distinct">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:when test="adl:property[@distinct='all']">
<xsl:call-template name="check-property-value-distinct">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template> </xsl:template>
<!-- suppress properties otherwise --> <xsl:template match="adl:property[@distinct='system']">
<xsl:template match="adl:property"/> <xsl:call-template name="check-property-value-distinct">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template match="adl:ifmissing"> <xsl:template match="adl:property[@distinct='all']">
"<xsl:value-of select="normalize-space(.)"/>" <xsl:call-template name="check-property-value-distinct">
</xsl:template> <xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template match="adl:form">
<!-- suppress properties otherwise -->
<xsl:template match="adl:property"/>
<xsl:template match="adl:ifmissing">
"<xsl:value-of select="normalize-space(.)"/>"
</xsl:template>
<xsl:template match="adl:form">
<!-- xsl:variable name="key"> <!-- xsl:variable name="key">
<xsl:call-template name="primary-key-name"> <xsl:call-template name="primary-key-name">
<xsl:with-param name="entity" select="ancestor::adl:entity"/> <xsl:with-param name="entity" select="ancestor::adl:entity"/>
@ -539,16 +589,14 @@ namespace <xsl:value-of select="$controllerns"/> {
/// Handle the submission of the form named <xsl:value-of select="@name"/> /// Handle the submission of the form named <xsl:value-of select="@name"/>
/// &lt;/summary&gt; /// &lt;/summary&gt;
[AccessibleThrough(Verb.Post)] [AccessibleThrough(Verb.Post)]
public void <xsl:value-of select="concat( @name, 'SubmitHandler')"/>( ) public void <xsl:value-of select="concat( @name, 'SubmitHandler')"/>( ) {
{ string command = Form[ "command"];
string command = Form[ "command"];
if ( command == null) if ( command == null) {
{ throw new Exception( "No command?");
throw new Exception( "No command?"); }
} else
else <xsl:for-each select=".//verb">
<xsl:for-each select=".//verb">
if ( command.Equals( "<xsl:value-of select="@verb"/>")) if ( command.Equals( "<xsl:value-of select="@verb"/>"))
{ {
/* NOTE: You must write an implementation of this verb in a /* NOTE: You must write an implementation of this verb in a
@ -565,6 +613,7 @@ namespace <xsl:value-of select="$controllerns"/> {
<xsl:call-template name="fetch-instance"> <xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="ancestor::adl:entity"/> <xsl:with-param name="entity" select="ancestor::adl:entity"/>
<xsl:with-param name="initialise-locals" select="'true'"/>
</xsl:call-template> </xsl:call-template>
<xsl:if test="$authentication-layer = 'Database'"> <xsl:if test="$authentication-layer = 'Database'">
@ -716,7 +765,79 @@ namespace <xsl:value-of select="$controllerns"/> {
/* <xsl:apply-templates/> */ /* <xsl:apply-templates/> */
</xsl:template> </xsl:template>
<!-- produce all menus for a given form: harder, but more efficient --> <!-- for properties with @distinct='all' or @distinct='system',
check that values are indeed distinct -->
<xsl:template name="check-property-value-distinct">
<xsl:param name="property"/>
<xsl:variable name="basetype">
<xsl:call-template name="base-type">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$property/ancestor::adl:key and not( $property/ancestor::adl:entity/adl:key[position()=2])">
<!-- if I'm the property of a key field and it is the only key field of my entity then
it is pointless trying to establish my distinctness -->
</xsl:when>
<xsl:when test="$property/@distinct = 'system' or $property/@distinct='all'">
/* <xsl:value-of select="$property/@name"/> should be distinct: check that it is */
matches =
hibernator.CreateCriteria(typeof(<xsl:value-of select="$property/ancestor::adl:entity/@name"/>))
<xsl:choose>
<xsl:when test="$basetype='string'">
.Add(Expression.Eq("<xsl:value-of select="$property/@name"/>", Form["<xsl:value-of select="concat('instance.', $property/@name)"/>"]))
</xsl:when>
<xsl:when test="$basetype='integer'">
.Add(Expression.Eq("<xsl:value-of select="$property/@name"/>", Int32.Parse( Form["<xsl:value-of select="concat('instance.', $property/@name)"/>"])))
</xsl:when>
<xsl:when test="$basetype='entity'">
.Add(Expression.Eq("<xsl:value-of select="$property/@name"/>",
<xsl:call-template name="fetch-property-instance">
<xsl:with-param name="property" select="."/>
<xsl:with-param name="valuename" select="adl:property[position()=1]/@name"/>
</xsl:call-template>))
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
ADL: ERROR: don't yet know how to do distinctness checks for properties
with base type <xsl:value-of select="$basetype"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="$property/ancestor::adl:entity/adl:key">
.Add(Expression.Not(Expression.Eq("<xsl:value-of select="adl:property[position()=1]/@name"/>",<xsl:choose>
<xsl:when test="@type='entity'">
<xsl:call-template name="fetch-property-instance">
<!-- recurse -->
<xsl:with-param name="property" select="."/>
<xsl:with-param name="valuename" select="adl:property[position()=1]/@name"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="@type='integer'">
Int32.Parse( Form["<xsl:value-of select="adl:property[position()=1]/@name"/>"])
</xsl:when>
<xsl:otherwise>
Form["<xsl:value-of select="adl:property[position()=1]/@name"/>"]
</xsl:otherwise>
</xsl:choose>)))
</xsl:for-each>
.List&lt;<xsl:value-of select="$property/ancestor::adl:entity/@name"/>&gt;();
if ( matches.Count > 0)
{
throw new
DataNotDistinctException(
String.Format("There is already a {0} with the {1} '{2}'",
"<xsl:value-of select="$property/ancestor::adl:entity/@name"/>", "<xsl:value-of select="$property/@name"/>", Form["<xsl:value-of select="concat('instance.', $property/@name)"/>"]));
}
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- produce all menus for a given form: harder, but more efficient -->
<xsl:template name="formmenus"> <xsl:template name="formmenus">
<xsl:param name="form"/> <xsl:param name="form"/>
<xsl:choose> <xsl:choose>
@ -876,11 +997,15 @@ namespace <xsl:value-of select="$controllerns"/> {
declared) called 'record' --> declared) called 'record' -->
<xsl:template name="fetch-instance"> <xsl:template name="fetch-instance">
<xsl:param name="entity"/> <xsl:param name="entity"/>
<xsl:value-of select="concat($entityns, '.', $entity/@name)"/> record = null; <xsl:param name="initialise-locals" select="'false'"/>
/* check whether values for all key slots have been passed in; if so, we're probably dealing with an /* check whether values for all key slots have been passed in; if so, we're probably dealing with an
* existing record */ * existing record */
<xsl:if test="$initialise-locals = 'true'">
/* the instance (record) of type <xsl:value-of select="$entity/@name"/> we're dealing with */
<xsl:value-of select="concat($entityns, '.', $entity/@name)"/> record = null;
/* whether we have valid values for all the key fields */
bool allkeys = true; bool allkeys = true;
</xsl:if>
<xsl:for-each select="$entity/adl:key/adl:property"> <xsl:for-each select="$entity/adl:key/adl:property">
if ( String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) { if ( String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
allkeys = false; allkeys = false;
@ -893,7 +1018,6 @@ namespace <xsl:value-of select="$controllerns"/> {
if ( allkeys){ if ( allkeys){
/* it's (probably) existing, retrieve it */ /* it's (probably) existing, retrieve it */
record = hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', $entity/@name)"/>)) record = hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', $entity/@name)"/>))
<xsl:for-each select="$entity/adl:key/adl:property"> <xsl:for-each select="$entity/adl:key/adl:property">
<xsl:variable name="basetype"> <xsl:variable name="basetype">