From cadaf246f4301c78bd127f391334393328ffaa11 Mon Sep 17 00:00:00 2001 From: sb Date: Mon, 10 Mar 2008 17:01:26 +0000 Subject: [PATCH] Now handling composite primary keys and (recursively) primary keys of type entity; also i18n handling considerably improved. --- transforms01/adl2controllerclasses.xslt | 296 ++++++++++++++++-------- transforms01/adl2entityclass.xslt | 26 +-- transforms01/adl2views.xslt | 107 +++++---- 3 files changed, 270 insertions(+), 159 deletions(-) diff --git a/transforms01/adl2controllerclasses.xslt b/transforms01/adl2controllerclasses.xslt index f5750fb..74f0f24 100755 --- a/transforms01/adl2controllerclasses.xslt +++ b/transforms01/adl2controllerclasses.xslt @@ -9,8 +9,8 @@ Transform ADL into (partial) controller classes $Author: sb $ - $Revision: 1.13 $ - $Date: 2008-03-05 11:05:12 $ + $Revision: 1.14 $ + $Date: 2008-03-10 17:01:26 $ --> + select="substring( '$Revision: 1.14 $', 11)"/> - + /* ---- [ cut here: next file 'Controller.auto.cs'] ---------------- */ @@ -146,86 +146,115 @@ namespace { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN]); - List<string> messages = new List<string>(); + List<string> messages = new List<string>(); + + - . record; + + + - - - - string id = Form[""]; - - if ( String.IsNullOrEmpty( id)) - { - /* it's new, create persistent object */ - record = new .(Form[] - - , - - ); - - /* perform any domain knowledge behaviour on the new record + if ( record == null) { + /* it seems to be new, create persistent object */ + try { + record = new ( + + + + + + + Int32.Parse( Form[""]) + + + + + + + + + hibernator.CreateCriteria( typeof( )) + .Add(Expression.Eq( "", + Int32.Parse( Form[ ""]) + Form[ ""] + )) + .UniqueResult<>() + Form[""] + + + + , + + ); + } + catch ( FormatException) { + /* failed to parse a number - not wholly unexpected, since it's most likely + that an empty string was passed in */ + record = new (); + } + catch ( NullReferenceException) { + /* again, probably more normal than otherwise */ + record = new (); + } + /* perform any domain knowledge behaviour on the new record * after instantiation */ record.AfterCreationHook( hibernator); messages.Add( "New record created"); } - else - { - /* it's existing, retrieve it */ - - - - - - eid = - hibernator.CreateCriteria( typeof( )) - .Add(Expression.Eq( "", id)) - .UniqueResult<>(); - record = - hibernator.CreateCriteria(typeof()) - .Add(Expression.Eq("", eid)) - .UniqueResult<>(); - - - record = - hibernator.CreateCriteria(typeof()) - .Add(Expression.Eq("", id)) - .UniqueResult<>(); - - - - } - - if ( record != null) - { - try - { + if ( record != null) { + try { /* actually update the record */ BindObjectInstance( record, ParamStore.Form, "instance"); - - + + + /* 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(); + + if ( ! String.IsNullOrEmpty( Form[""])){ + /* there's an uninitialised message for this slot */ + Message mess = record.; + if ( mess == null){ + mess = new Message(); + } + hibernator.Save( mess); + + Translation trans = mess.GetTranslationObject( locale, hibernator); + if ( trans == null) { + trans = new Translation( mess, locale); + } + trans.MessageText = Form[""]; + record. = mess; + hibernator.Save( trans); + } + + + + /* for properties of type 'entity', it should not be necessary to do anything * special - BindObjectInstance /should/ do it all. Unfortunately it sometimes * doesn't, and I haven't yet characterised why not. */ - - - // The broken bit: Entity name is - - + + + if ( ! String.IsNullOrEmpty( Form[""])) + { + record. = + + + ; + } + + + + ADL: ERROR: Could not fix up value of , because no + entity was found called + + + + /* to update a link table which has no other data than the near and far keys, it is @@ -256,7 +285,7 @@ namespace { } - + /* with a list we cannot just smash the old values! Instead we need to check * each one and exclude it if no longer required */ if ( Form.GetValues( "") != null) @@ -346,7 +375,7 @@ namespace { } else { - throw new Exception( String.Format( "No record of type with key value {0} found", id)); + throw new DataRequiredException( "Record not found"); } } @@ -356,30 +385,26 @@ namespace { /// <summary> /// Actually delete the selected record /// </summary> - [AccessibleThrough(Verb.Get)] + [AccessibleThrough(Verb.Post)] public void Delete() { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN]); - string id = Params[""]; + string reallydelete = Params["reallydelete"]; - + if ( "true".Equals( reallydelete)) - { - record = - hibernator.CreateCriteria(typeof()) - .Add(Expression.Eq("", id)) - .UniqueResult<>(); + { + + + if ( record != null) { record.BeforeDeleteHook( hibernator); - hibernator.Delete( - hibernator.CreateCriteria(typeof()) - .Add(Expression.Eq("", id)) - .UniqueResult<>()); + hibernator.Delete( record); hibernator.Flush(); } @@ -461,7 +486,7 @@ namespace { - + /// <summary> /// Handle the submission of the form named /// </summary> @@ -498,15 +523,15 @@ namespace { ISession hibernator = NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN], Session[NHibernateHelper.PASSTOKEN]); - string id = Form[""]; + + + + PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN]; - PropertyBag["instance"] = - hibernator.CreateCriteria(typeof()) - .Add(Expression.Eq("", id)) - .UniqueResult<>(); + PropertyBag["instance"] = record; RenderViewWithFailover( "maybedelete.vm", "maybedelete.auto.vm"); } @@ -710,6 +735,11 @@ namespace { + + + ADL: ERROR: No key for entity: + + @@ -729,4 +759,84 @@ namespace { + + + + + + + + + ADL: ERROR: property passed to fetch-property-instance whose type is not 'entity' + + + hibernator.CreateCriteria(typeof()) + + .Add(Expression.Eq("", + + + + + + Int32.Parse( Form[""]) + Form[""] + )) + + .UniqueResult<>() + + + + + + record = null; + + /* check whether values for all key slots have been passed in; if so, we're probably dealing with an + * existing record */ + bool allkeys = true; + + if ( String.IsNullOrEmpty( Form[""])) { + allkeys = false; + } + else if ( "".Equals( Form[""])) { + /* nasty artefact of NVelocity forms - default 'null value' is dollar followed by fieldname */ + allkeys = false; + } + + + if ( allkeys){ + /* it's (probably) existing, retrieve it */ + + record = hibernator.CreateCriteria(typeof()) + + + + + + + .Add( Expression.Eq( "", + Int32.Parse( Form[ ""]) + + + + + + + + + hibernator.CreateCriteria( typeof( )) + .Add(Expression.Eq( "", + Int32.Parse( Form[ ""]) + Form[ ""])) + .UniqueResult<>() + Form[ ""])) + + .UniqueResult<>(); + } + \ No newline at end of file diff --git a/transforms01/adl2entityclass.xslt b/transforms01/adl2entityclass.xslt index 5463254..bab36e9 100755 --- a/transforms01/adl2entityclass.xslt +++ b/transforms01/adl2entityclass.xslt @@ -8,8 +8,8 @@ Transform ADL into entity classes $Author: sb $ - $Revision: 1.10 $ - $Date: 2008-03-05 11:05:12 $ + $Revision: 1.11 $ + $Date: 2008-03-10 17:01:26 $ --> + select="substring( '$Revision: 1.11 $', 11)"/> @@ -201,19 +201,6 @@ /// </summary> public override string KeyString { get { - - - - - - - - - - - - - StringBuilder result = new StringBuilder(); result.Append(.KeyString); @@ -222,12 +209,7 @@ return result.ToString(); - - - - - - } + } } /// <summary> diff --git a/transforms01/adl2views.xslt b/transforms01/adl2views.xslt index cdc93ea..5d1595c 100755 --- a/transforms01/adl2views.xslt +++ b/transforms01/adl2views.xslt @@ -12,8 +12,8 @@ Transform ADL into velocity view templates $Author: sb $ - $Revision: 1.9 $ - $Date: 2008-03-05 11:05:12 $ + $Revision: 1.10 $ + $Date: 2008-03-10 17:01:26 $ --> @@ -44,7 +44,7 @@ stored to CVS --> + select="substring( '$Revision: 1.10 $', 11)"/> @@ -100,19 +100,34 @@ -
- - - - ${FormHelper.HiddenField( "instance.")} - - - - ${FormHelper.HiddenField( "instance.")} - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -997,7 +1006,17 @@ 60 - ${FormHelper.TextField( "instance.", "%{class='', title='', size='', maxlength=''}")} + + + + + + + + + + + ${FormHelper.TextField( "instance.", "%{class='', title='', size='', maxlength=''}")}
Really delete? @@ -290,33 +305,19 @@ - - - - - - - - - - - - - ${FormHelper.HiddenField( "instance.")} - - - - - - - - - ${FormHelper.HiddenField( "instance.")} - - + + + + + + + + + + ${FormHelper.HiddenField( "instance.")} + + +
@@ -653,8 +654,16 @@ ")}
+ #if( $instance) $FormHelper.HiddenField( "instance.") + #else + + + + + + #end