Just checked and Hibernate states, "Properties marked as generated must additionally be non-insertable and non-updateable". So I'll add a test to ensure the parameters conform.
On Nov 29, 7:02 pm, "[email protected]" <[email protected]> wrote: > Thanks all top replies. > > Ok I'll grab tortoiseGit and give it a go over this week. > > Great comments! > > Patrick - absolutely I thought of the enum, but went with a more > flexible (, lazy) and consistent approach. I'll change this for the > better! > Henry - I certainly thought of that. I'd have to find out what the > Hibernate behaviour is (obviously false, false is valid I'm just not > sure of your given combinations) so I should research those and apply > the relevant tests to ensure it's conformant. > > On Nov 29, 11:29 am, Henry Conceição <[email protected]> > wrote: > > > > > > > > > Also, how does this is related to the Insert=True|False and > > Update=True|False mapping attributes? > > > Cheers, > > Henry Conceição > > > On Mon, Nov 29, 2010 at 2:14 PM, Patrick Earl <[email protected]> wrote: > > > Hi Ian. > > > Thanks for thinking to contribute. It's pretty straight-forward to get > > > going with GIT if you use something like TortoiseGIT. You can just clone > > > a > > > repo you've forked on github, commit, then push. It helps the team > > > significantly if your patch is easier to apply. > > > In any case, it would be better to use an enum to specify the generated > > > type. > > > Patrick Earl > > > > On Mon, Nov 29, 2010 at 6:16 AM, [email protected] > > > <[email protected]> wrote: > > > >> Hi, > > > >> I've subscribed to the Dev List for a while and have been encouraged > > >> to submit a new feature for Castle.ActiveRecord. nHibermnate has the > > >> ability (via mapping files) to specify if a field is generated or not > > >> (none|insert|always). > > > >> I've added support to my local ActiveRecord source and have the > > >> following test to ensure it's implemented ok. As I'm not a committer I > > >> hoped I could post it up and hope that someone could commit it for me > > >> (with perhaps a mention). Anyway if I'm going about this all wrong > > >> please let me know, but I think it's a handy feature to add to > > >> ActiveRecord..... > > > >> I've provided the test and detailed some of the code I used to get it > > >> working... but I'm sure there could be a better way, > > > >> Cheers > > >> ian pender > > > >> test : > > >> namespace Castle.ActiveRecord.Framework.Internal.Tests.Model > > >> { > > >> using Castle.ActiveRecord; > > > >> [ActiveRecord] > > >> public class ClassWithGeneratedProperties : ActiveRecordBase > > >> { > > >> [PrimaryKey] > > >> public int Id { get; set; } > > > >> [Property(GeneratedType = "insert")] > > >> public int ColumnGeneratedInsert { get; set; } > > > >> [Property(GeneratedType = "none")] > > >> public int ColumnGeneratedNone { get; set; } > > > >> [Property(GeneratedType = "always")] > > >> public int ColumnGeneratedAlways { get; set; } > > > >> [Property] > > >> public int ColumnNoGenerated { get; set; } > > >> } > > >> } > > > >> namespace Castle.ActiveRecord.Framework.Internal.Tests : > > > >> XmlGenerationTestCase > > > >> [Test] > > >> public void SimpleCaseGeneratedType() > > >> { > > >> ActiveRecordModelBuilder builder = new > > >> ActiveRecordModelBuilder(); > > >> ActiveRecordModel model = > > >> builder.Create(typeof(ClassWithGeneratedProperties)); > > >> Assert.IsNotNull(model); > > > >> SemanticVerifierVisitor semanticVisitor = new > > >> SemanticVerifierVisitor(builder.Models); > > >> semanticVisitor.VisitNode(model); > > > >> XmlGenerationVisitor xmlVisitor = new > > >> XmlGenerationVisitor(); > > >> xmlVisitor.CreateXml(model); > > > >> String xml = xmlVisitor.Xml; > > > >> const string expected = > > >> "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + > > >> "<hibernate-mapping auto-import=\"true\" default-lazy= > > >> \"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi= > > >> \"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate- > > >> mapping-2.2\">\r\n" + > > >> " <class name= > > > >> \"Castle.ActiveRecord.Framework.Internal.Tests.Model.ClassWithGeneratedProp > > >> erties, > > >> Castle.ActiveRecord.Framework.Internal.Tests\" table= > > >> \"ClassWithGeneratedProperties\">\r\n" + > > >> " <id name=\"Id\" access=\"property\" column=\"Id\" > > >> type=\"Int32\" unsaved-value=\"0\">\r\n" + > > >> " <generator class=\"native\">\r\n" + > > >> " </generator>\r\n" + > > >> " </id>\r\n" + > > >> " <property name=\"ColumnGeneratedInsert\" access= > > >> \"property\" type=\"Int32\" generated=\"insert\">\r\n" + > > >> " <column name=\"ColumnGeneratedInsert\"/>\r\n" + > > >> " </property>\r\n" + > > >> " <property name=\"ColumnGeneratedNone\" access= > > >> \"property\" type=\"Int32\" generated=\"none\">\r\n" + > > >> " <column name=\"ColumnGeneratedNone\"/>\r\n" + > > >> " </property>\r\n" + > > >> " <property name=\"ColumnGeneratedAlways\" access= > > >> \"property\" type=\"Int32\" generated=\"always\">\r\n" + > > >> " <column name=\"ColumnGeneratedAlways\"/>\r\n" + > > >> " </property>\r\n" + > > >> " <property name=\"ColumnNoGenerated\" access= > > >> \"property\" type=\"Int32\">\r\n" + > > >> " <column name=\"ColumnNoGenerated\"/>\r\n" + > > >> " </property>\r\n" + > > >> " </class>\r\n" + > > >> "</hibernate-mapping>\r\n"; > > > >> Assert.AreEqual(expected, xml); > > >> } > > > >> I got this test working by adding to > > > >> namespace Castle.ActiveRecord.PropertyAttribute > > > >> /// <summary> > > >> /// Set to never|insert|always to specify how the property is > > >> generated. If blank not included in mapping > > >> /// </summary> > > >> public string GeneratedType > > >> { > > >> get { return generatedType; } > > >> set { generatedType = value; } > > >> } > > > >> and amending > > > >> namespace Castle.ActiveRecord.Framework.Internal > > > >> public class XmlGenerationVisitor : AbstractDepthFirstVisitor > > > >> private void WriteProperty(String name, Type propType, String > > >> accessString, String columnType, > > >> bool insert, bool update, > > >> String > > >> formula, > > >> String column, int length, bool > > >> notNull, > > >> bool unique, > > >> String uniqueKey, String > > >> sqlType, String > > >> index, String check, String @default) > > >> { > > >> WriteProperty(name, propType, accessString, > > >> columnType, insert, > > >> update, formula, column, > > >> length, notNull, unique, uniqueKey, sqlType, index, > > >> check, @default, null); > > >> } > > > >> private void WriteProperty(String name, Type propType, > > >> String accessString, String columnType, > > >> bool insert, bool update, > > >> String > > >> formula, > > >> String column, int length, bool > > >> notNull, > > >> bool unique, > > >> String uniqueKey, String > > >> sqlType, String > > >> index, String check, String @default, > > >> string generatedFlag) > > >> { > > >> BeginWriteProperty(accessString, columnType, formula, > > >> insert, name, propertyType, update, generatedFlag); > > > >> Ident(); > > > >> WriteColumn(check, column, index, length, notNull, > > >> sqlType, unique, uniqueKey, @default); > > > >> Dedent(); > > > >> EndWriteProperty(); > > >> } > > > >> and finally > > > >> private void BeginWriteProperty(string accessString, > > >> string columnType, > > >> string formula, > > >> bool insert, > > >> string name, > > >> Type propertyType, > > >> bool update, > > >> string generatedValue) > > >> { > > >> AppendF("<property{0}{1}{2}{3}{4}{5}{6}>", > > >> MakeAtt("name", name), > > >> WriteIfNonNull("access", accessString), > > >> MakeTypeAtt(propertyType, columnType), > > >> WriteIfFalse("insert", insert), > > >> WriteIfFalse("update", update), > > >> WriteIfNonNull("formula", formula), > > >> WriteIfNonNull("generated", generatedValue)); > > >> } > > ... > > read more » -- You received this message because you are subscribed to the Google Groups "Castle Project Development List" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.
