From 9b6fd82110f37715ad11b084651bfcaa15792149 Mon Sep 17 00:00:00 2001 From: af Date: Mon, 14 Jan 2008 16:53:31 +0000 Subject: [PATCH] Refinements of the ADL transforms to have them better work with more than just the SRU codebase. Note that synthetic primary key is now assumed to be 'Id'.... though actually most of the references to an entity's primary key should be looking it up rather than assuming its name. --- ADL.NET/Trans/adl2controllerclasses.xsl | 111 +++--- ADL.NET/Trans/adl2entityclass.xsl | 472 ++++++++++++++---------- ADL.NET/Trans/adl2views.xsl | 32 +- ADL.NET/Trans/hibernate2adl.xsl | 181 ++++++--- ADL.NET/Trans/types.xml | 10 + 5 files changed, 482 insertions(+), 324 deletions(-) create mode 100755 ADL.NET/Trans/types.xml diff --git a/ADL.NET/Trans/adl2controllerclasses.xsl b/ADL.NET/Trans/adl2controllerclasses.xsl index 68bec4b..6283e9f 100755 --- a/ADL.NET/Trans/adl2controllerclasses.xsl +++ b/ADL.NET/Trans/adl2controllerclasses.xsl @@ -9,8 +9,8 @@ Transform ADL into (partial) controller classes $Author: af $ - $Revision: 1.1 $ - $Date: 2008-01-09 15:01:45 $ + $Revision: 1.2 $ + $Date: 2008-01-14 16:53:31 $ --> + + + select="substring( '$Revision: 1.2 $', 11)"/> @@ -69,25 +73,18 @@ //------------------------------------------------------------------ using System; -using System.Data; using System.Collections.Generic; -using System.Configuration; -using System.Web; -using System.Web.Security; -using System.Web.UI; -using System.Web.UI.WebControls; -using System.Web.UI.WebControls.WebParts; -using System.Web.UI.HtmlControls; using Castle.MonoRail.Framework.Helpers; using Cygnet.Web.Helpers; using Cygnet.Web.Controllers; +using System.Web.Security; using NHibernate; using NHibernate.Expression; using Castle.MonoRail.Framework; -using SRU.Hospitality.Entities; -using SRU.Hospitality.Helpers; +using ADL.Entities; using ADL.Exceptions; using Iesi.Collections.Generic; +using ; namespace { @@ -112,12 +109,10 @@ namespace { /// </summary> private void Store() { - ISession hibernator = - NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], - Session[NHibernateHelper.PASSTOKEN]); + ISession hibernator = NHibernateHelper.GetCurrentSession(); List<string> messages = new List<string>(); - . record; + record; @@ -126,11 +121,7 @@ namespace { if ( String.IsNullOrEmpty( id)) { /* it's new, create persistent object */ - record = new .(Form[] - - , - - ); + record = new (); /* perform any domain knowledge behaviour on the new record * after instantiation */ @@ -143,7 +134,7 @@ namespace { record = hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("", Int32.Parse(id))) - .UniqueResult<.>(); + .UniqueResult<>(); } if ( record != null) @@ -162,7 +153,7 @@ namespace { .Add(Expression.Eq(" ", Int32.Parse(Form[""]))) - .UniqueResult<.>(); + .UniqueResult<>(); @@ -189,8 +180,8 @@ namespace { .Add( hibernator.CreateCriteria(typeof()) - .Add(Expression.Eq("Id", Int32.Parse(index))) - .UniqueResult<.>()); + .Add(Expression.Eq("Id", Int32.Parse(index))) + .UniqueResult<>()); } } @@ -205,7 +196,7 @@ namespace { /* updating child records; first remove any not on the submitted list */ foreach ( item in record.) { - String itemId = item.Key.ToString(); + String itemId = item.KeyString; bool found = false; foreach ( string index in ) @@ -228,8 +219,8 @@ namespace { { item = hibernator.CreateCriteria(typeof()) - .Add(Expression.Eq("Id", Int32.Parse(index))) - .UniqueResult<.>(); + .Add(Expression.Eq("Id", Int32.Parse(index))) + .UniqueResult<>(); if ( ! record..Contains( item)) { @@ -261,13 +252,12 @@ namespace { } PropertyBag["messages"] = messages; - PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["instance"] = record; - RenderViewWithFailover("", ""); + RenderViewWithFailover(""); } else { @@ -281,9 +271,7 @@ namespace { [AccessibleThrough(Verb.Get)] public void Delete() { - ISession hibernator = - NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], - Session[NHibernateHelper.PASSTOKEN]); + ISession hibernator = NHibernateHelper.GetCurrentSession(); string id = Params[""]; string reallydelete = Params["reallydelete"]; @@ -292,7 +280,7 @@ namespace { record = hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("", Int32.Parse(id))) - .UniqueResult<.>(); + .UniqueResult<>(); if ( record != null) { @@ -301,7 +289,7 @@ namespace { hibernator.Delete( hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("", Int32.Parse(id))) - .UniqueResult<.>()); + .UniqueResult<>()); hibernator.Flush(); } @@ -341,19 +329,16 @@ namespace { /// <param name="view">The name of the list view to show</param> public void InternalShowList( String view) { - ISession hibernator = - NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], - Session[NHibernateHelper.PASSTOKEN]); + ISession hibernator = NHibernateHelper.GetCurrentSession(); IList<> instances = hibernator.CreateCriteria(typeof()) .List<>(); - PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["instances"] = PaginationHelper.CreatePagination( this, instances, 25); - RenderViewWithFailover(view + ".vm", view + ".auto.vm"); + RenderViewWithFailover(view); } } @@ -387,7 +372,7 @@ namespace { - + @@ -415,18 +400,15 @@ namespace { if ( command.Equals( "delete")) { - ISession hibernator = - NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], - Session[NHibernateHelper.PASSTOKEN]); + ISession hibernator = NHibernateHelper.GetCurrentSession(); string id = Form[""]; - PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["instance"] = hibernator.CreateCriteria(typeof()) .Add(Expression.Eq("", Int32.Parse(id))) - .UniqueResult<.>(); + .UniqueResult<>(); - RenderViewWithFailover( "maybedelete.vm", "maybedelete.auto.vm"); + RenderViewWithFailover( "maybedelete.vm"); } else if ( command.Equals( "store")) { @@ -444,39 +426,32 @@ namespace { [AccessibleThrough(Verb.Get)] public void ( ) { - ISession hibernator = - NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], - Session[NHibernateHelper.PASSTOKEN]); - - - - - PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; - RenderViewWithFailover("", ""); + ISession hibernator = NHibernateHelper.GetCurrentSession(); + + + + RenderViewWithFailover(""); } /// <summary> /// Show the form named , containing the indicated record /// </summary> - /// <param name="">the key value of the record to show</param> + /// <param name="Id">the key value of the record to show</param> [AccessibleThrough(Verb.Get)] - public void ( Int32 ) + public void ( Int32 Id) { - ISession hibernator = - NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], - Session[NHibernateHelper.PASSTOKEN]); - . record = + ISession hibernator = NHibernateHelper.GetCurrentSession(); + record = hibernator.CreateCriteria(typeof()) - .Add(Expression.Eq("", Id)) - .UniqueResult<.>(); + .Add(Expression.Eq("Id", Id)) + .UniqueResult<>(); - PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; PropertyBag["instance"] = record; - RenderViewWithFailover("", ""); + RenderViewWithFailover(""); } @@ -535,7 +510,7 @@ namespace { - + diff --git a/ADL.NET/Trans/adl2entityclass.xsl b/ADL.NET/Trans/adl2entityclass.xsl index cd09d89..73f257b 100755 --- a/ADL.NET/Trans/adl2entityclass.xsl +++ b/ADL.NET/Trans/adl2entityclass.xsl @@ -8,14 +8,16 @@ Transform ADL into entity classes $Author: af $ - $Revision: 1.1 $ - $Date: 2008-01-09 15:01:45 $ + $Revision: 1.2 $ + $Date: 2008-01-14 16:53:31 $ --> - - + + + + + select="substring( '$Revision: 1.2 $', 11)"/> - /* ---- [ cut here: next file '.auto.cs'] ---------------- */ + + +/* ---- [ cut here: next file '.auto.cs'] ---------------- */ //------------------------------------------------------------- // @@ -66,127 +70,162 @@ //------------------------------------------------------------- namespace { - using System; - using System.Configuration; - using System.Collections; - using System.Collections.Generic; - using System.Text; - using System.Text.RegularExpressions; - using ADL.Exceptions; - using Iesi.Collections.Generic; + using System; + using System.Collections.Generic; + using System.Text; + using System.Text.RegularExpressions; + using ADL.Entities; + using ADL.Exceptions; + using Iesi.Collections.Generic; - /// <summary> - /// Automatically generated from description of entity - /// using adl2entityclass.xsl. Note that manually maintained parts of this - /// class may be defined in a separate file called .cs, q.v. - /// - /// DO NOT EDIT THIS FILE! - /// </summary> - public partial class : Entity - { - /// <summary> - /// Auto-generated no-args constructor; does nothing (but probably should - /// ensure ID slot is initialised correctly) - /// </summary> - public () : base(){ - - } + /// <summary> + /// Automatically generated from description of entity + /// using adl2entityclass.xsl. Note that manually maintained parts of this + /// class may be defined in a separate file called .cs, q.v. + /// + /// DO NOT EDIT THIS FILE! + /// </summary> + public partial class : Entity + { + /// <summary> + /// Auto-generated no-args constructor; does nothing (but probably should + /// ensure ID slot is initialised correctly) + /// </summary> + public () : base(){ + + } - /// <summary> - /// Auto-generated one-arg constructor; initialises Id slot and also all - /// one-to-many slots - /// </summary> - public ( int key) - { - + /* + /// <summary> + /// Auto-generated one-arg constructor; initialises Id slot and also all + /// one-to-many slots + /// </summary> + public ( int key) + { + - - - /* natural primary key exists - not initialising abstract key */ - - - _Id = key; - - - } + + } + */ - - + + /// <summary> + /// Auto-generated overridden property for the Key slot, maps onto + /// </summary> + public override string KeyString { + get { + + + return null; // No primary key; return null. + + + return .ToString(); // Single key. + + + StringBuilder result = new StringBuilder(); + + result.Append('|'); + result.Append(); + + return result.ToString(); - - /// <summary> - /// A user readable distinct identifying string - /// </summary> - public override string UserIdentifier - { - get { - StringBuilder result = new StringBuilder(); + } + } + + /// <summary> + /// A user readable distinct identifying string + /// </summary> + public override string UserIdentifier + { + get { + StringBuilder result = new StringBuilder(); + + + - - - - - - result.Append( ); - - - result.Append(); - - - - - - result.Append( ", "); - - - + result.Append( ); - result.AppendFormat( "#{0}[", _Id); + result.Append(); - - return result.ToString(); - } - } - + + + + result.Append( ", "); + + + + + + result.AppendFormat( "#{0}", ); + + + + return result.ToString(); + } + } + - } + } } + + + + + , + + + + + + - + - // auto generating iv/property pair for slot with name + // auto generating iv/property pair for slot with name @@ -200,69 +239,59 @@ + + + + + + + + + + + + + true + + + + + + + + + ICollection<> ICollection<> - DateTime - DateTime - String - String - bool - TimeStamp - int - double - Decimal - - - - - String - int - double - Decimal - DateTime - DateTime - TimeStamp - - - [unknown?] - - - - - - - ? - ? - ? - ? - ? - ? - + + + + + + - = "" - = + + = "" + + + = + - = null - = false - = 0 - = 0.0 - = 0.0M - = null @@ -277,78 +306,133 @@ - private Regex Validator = new Regex( ""); + private Regex Validator = new Regex( ""); - private _ ; + private _ ; - public virtual + public virtual + { + get { return _; } + set { + + if ( value == null) + { + throw new DataRequiredException( + + + + + "The value for may not be set to null" + + + ); + } + + + + + + + + + + + + + if ( value > ) { - get { return _; } - set { - - if ( value == null) - { - throw new DataRequiredException( - - - - - "The value for may not be set to null" - - - ); - } - - - - - - - - - - - - - if ( value > ) - { - throw new DataRangeException( "The maximum permitted value for is "); - } - - - if ( value < ) - { - throw new DataRangeException( "The minimum permitted value for is "); - } - - - if ( value != null && ! Validator.IsMatch( value)) - { - throw new DataFormatException( string.Format( "The value supplied ({0}) does not match the format required by ", value)); - } - - - - if ( value != null && value.Length > ) - { - value = value.Substring( 0, ); - } - - _ = value; - } + throw new DataRangeException( "The maximum permitted value for is "); } + + + if ( value < ) + { + throw new DataRangeException( "The minimum permitted value for is "); + } + + + if ( value != null && ! Validator.IsMatch( value)) + { + throw new DataFormatException( string.Format( "The value supplied ({0}) does not match the format required by ", value)); + } + + + + if ( value != null && value.Length > ) + { + value = value.Substring( 0, ); + } + + _ = value; + } + } + + + + + + + + + + + + + + + + + + + ? + + + + Error! not found. + + + + + + + + + + + + + + + + + + + + + + true + + + + Error! not found. + + + + + + - + /* */ - + "" diff --git a/ADL.NET/Trans/adl2views.xsl b/ADL.NET/Trans/adl2views.xsl index e9caa45..0ecf911 100755 --- a/ADL.NET/Trans/adl2views.xsl +++ b/ADL.NET/Trans/adl2views.xsl @@ -9,8 +9,8 @@ Transform ADL into velocity view templates $Author: af $ - $Revision: 1.1 $ - $Date: 2008-01-09 15:01:45 $ + $Revision: 1.2 $ + $Date: 2008-01-14 16:53:31 $ --> @@ -31,7 +31,7 @@ stored to CVS --> + select="substring( '$Revision: 1.2 $', 11)"/> @@ -81,7 +81,7 @@ - ${FormHelper.HiddenField( "instance.Id")} + ${FormHelper.HiddenField( "instance.Id")} @@ -146,7 +146,6 @@ ${FormHelper.InstallScripts()} ${Validation.InstallScripts()} ${Scriptaculous.InstallScripts()} - ${DateTime.InstallScripts()} ${ShuffleWidgetHelper.InstallScripts()} @@ -239,7 +238,7 @@ - ${FormHelper.HiddenField( "instance.Id")} + ${FormHelper.HiddenField( "instance.Id")} @@ -336,7 +335,7 @@ - + @@ -349,7 +348,7 @@ - + @@ -464,7 +463,7 @@ @@ -712,14 +711,14 @@ #if ( $instance) - ${FormHelper.Select( "instance.", $instance., , "%{firstoption='[unset]' firstoptionvalue='-1' text='UserIdentifier' value='' title=''}" )} + ${FormHelper.Select( "instance.", $instance., , "%{firstoption='[unset]' firstoptionvalue='-1' text='UserIdentifier' value='' title=''}" )} #else - ${FormHelper.Select( "instance.", $, , "%{firstoption='[unset]' firstoptionvalue='-1' text='UserIdentifier' value='' title=''}" )} + ${FormHelper.Select( "instance.", $, , "%{firstoption='[unset]' firstoptionvalue='-1' text='UserIdentifier' value='' title=''}" )} #end - ${FormHelper.Select( "instance.", $instance., , "%{multiple='multiple' size='8' text='UserIdentifier' value='' title=''}" )} + ${FormHelper.Select( "instance.", $instance., , "%{multiple='multiple' size='8' text='UserIdentifier' value='' title=''}" )} @@ -930,7 +929,6 @@ ${FormHelper.InstallScripts()} ${Validation.InstallScripts()} ${Scriptaculous.InstallScripts()} - ${DateTime.InstallScripts()} @@ -1016,7 +1014,7 @@
- + Edit! @@ -524,7 +523,7 @@ - Computed field? TODO: Not yet implememented + Computed field ''? TODO: Not yet implememented @@ -675,7 +674,7 @@ - none + edit
- + Edit! @@ -1055,7 +1053,7 @@ - + Edit! diff --git a/ADL.NET/Trans/hibernate2adl.xsl b/ADL.NET/Trans/hibernate2adl.xsl index 90f1b7d..f07634b 100755 --- a/ADL.NET/Trans/hibernate2adl.xsl +++ b/ADL.NET/Trans/hibernate2adl.xsl @@ -1,5 +1,7 @@ - - + + - + + + - + - - + + - + - + + + +
+ + + + + + + +
+ + + + + + + + + + +
- + - - date - string - boolean - timestamp - integer - [unknown?] - + + + - - - true - false - - - - - + + + system + true + + + + + true + false + + + + - - + - - date - string - boolean - timestamp - integer - [unknown?] - - - - + + + - - + + + + date + real + string + string + boolean + timestamp + integer + + + + [unknown!] + + + + + + + + + + + + + + + + entity - + + + + + + + + system + true + + + + + true + false + + + + + + + + + + + + + link + + + + - + + + + + + list + + + + + + + + +
\ No newline at end of file diff --git a/ADL.NET/Trans/types.xml b/ADL.NET/Trans/types.xml new file mode 100755 index 0000000..61a6076 --- /dev/null +++ b/ADL.NET/Trans/types.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file