User: mzywitza
Date: 2010/01/09 06:10 AM

Modified:
 /ActiveRecord/trunk/src/
  Changes.txt
 /ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/
  PrimaryKeyAttribute.cs
 /ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/
  XmlGenerationVisitor.cs

Log:
 Added Patch by xtoff for defaults for PrimaryKeyType by Type.

File Changes:

Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/
==================================================================

File [modified]: PrimaryKeyAttribute.cs
Delta lines: +56 -36
===================================================================

--- 
ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/XmlGenerationVisitor.cs
      2010-01-09 08:45:04 UTC (rev 6603)
+++ 
ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/XmlGenerationVisitor.cs
      2010-01-09 13:09:58 UTC (rev 6604)
@@ -270,43 +270,8 @@
 
                        Ident();
 
-                       String className = null;
+                       string className = GetGeneratorClassName(model);
 
-                       switch(model.PrimaryKeyAtt.Generator)
-                       {
-                               case PrimaryKeyType.Identity:
-                               case PrimaryKeyType.Sequence:
-                               case PrimaryKeyType.HiLo:
-                               case PrimaryKeyType.SeqHiLo:
-                               case PrimaryKeyType.Guid:
-                               case PrimaryKeyType.Native:
-                               case PrimaryKeyType.Assigned:
-                               case PrimaryKeyType.Foreign:
-                               case PrimaryKeyType.Increment:
-                                       className = 
model.PrimaryKeyAtt.Generator.ToString().ToLower(CultureInfo.InvariantCulture);
-                                       break;
-
-                               case PrimaryKeyType.GuidComb:
-                                       className = "guid.comb";
-                                       break;
-
-                               case PrimaryKeyType.UuidHex:
-                                       className = "uuid.hex";
-                                       break;
-
-                               case PrimaryKeyType.UuidString:
-                                       className = "uuid.string";
-                                       break;
-
-                               case PrimaryKeyType.Counter:
-                                       className = "vm";
-                                       break;
-
-                               case PrimaryKeyType.Custom:
-                                       className = 
MakeTypeName(model.PrimaryKeyAtt.CustomGenerator);
-                                       break;
-                       }
-
                        AppendF("<generator{0}>", MakeAtt("class", className));
 
                        if (model.PrimaryKeyAtt.SequenceName != null)
@@ -1024,6 +989,61 @@
                        Append(closingTag);
                }
 
+               private static string GetGeneratorClassName(PrimaryKeyModel 
model)
+               {
+                       if (model.PrimaryKeyAtt.TypeSpecified == false)
+                       {
+                               return GuessGeneratorClassName(model);
+                       }
+
+                       String className = null;
+                       switch (model.PrimaryKeyAtt.Generator)
+                       {
+                               case PrimaryKeyType.Identity:
+                               case PrimaryKeyType.Sequence:
+                               case PrimaryKeyType.HiLo:
+                               case PrimaryKeyType.SeqHiLo:
+                               case PrimaryKeyType.Guid:
+                               case PrimaryKeyType.Native:
+                               case PrimaryKeyType.Assigned:
+                               case PrimaryKeyType.Foreign:
+                               case PrimaryKeyType.Increment:
+                                       className = 
model.PrimaryKeyAtt.Generator.ToString().ToLower(CultureInfo.InvariantCulture);
+                                       break;
+
+                               case PrimaryKeyType.GuidComb:
+                                       className = "guid.comb";
+                                       break;
+
+                               case PrimaryKeyType.UuidHex:
+                                       className = "uuid.hex";
+                                       break;
+
+                               case PrimaryKeyType.UuidString:
+                                       className = "uuid.string";
+                                       break;
+
+                               case PrimaryKeyType.Counter:
+                                       className = "vm";
+                                       break;
+
+                               case PrimaryKeyType.Custom:
+                                       className = 
MakeTypeName(model.PrimaryKeyAtt.CustomGenerator);
+                                       break;
+                       }
+                       return className;
+               }
+
+               private static string GuessGeneratorClassName(PrimaryKeyModel 
model)
+               {
+                       if (model.Property.PropertyType == typeof(Guid))
+                               return "guid.comb";
+                       if (model.Property.PropertyType == typeof(string))
+                               return "assigned";
+                       // NOTE: perhaps this could be extended to some other 
+                       return "native";
+               }
+
                private static string 
TranslateNotFoundBehaviourEnum(NotFoundBehaviour notFoundBehaviourEnum)
                {

Directory: 
/ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/
===================================================================================

File [modified]: XmlGenerationVisitor.cs
Delta lines: +4 -0
===================================================================

--- ActiveRecord/trunk/src/Changes.txt  2010-01-09 08:45:04 UTC (rev 6603)
+++ ActiveRecord/trunk/src/Changes.txt  2010-01-09 13:09:58 UTC (rev 6604)
@@ -9,6 +9,10 @@
       <config db="MsSqlServer2005" csn="MyConnectionStringName"/>
     </activerecord>
   to get default configurations for different DBs (Sql Server, SQLite, Oracle, 
MySql and others)
+- Added defaults for PrimaryKeyType unless specified explicitly:
+    guid.comb for guids
+    assigned for strings
+    native otherwise
 
 - Bugs fixed:

Directory: /ActiveRecord/trunk/src/
===================================

File [modified]: Changes.txt
Delta lines: +0 -0
===================================================================

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Commits" 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-commits?hl=en.


Reply via email to