public void Test_GetPrimaryKeyDef_ClassWithPKFromSuperClass() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef parentDef = new XmlClassLoader(new DtdLoader(), new DefClassFactory()).LoadClass( @" <class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" > <property name=""TestClassID"" type=""Guid"" /> <primaryKey> <prop name=""TestClassID""/> </primaryKey> </class>" ); IClassDef def = new XmlClassLoader(new DtdLoader(), new DefClassFactory()).LoadClass( @" <class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders""> <superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" /> <property name=""TestProp"" type=""Guid"" /> </class> " ); ClassDefCol classDefCol = new ClassDefCol(); classDefCol.Add(parentDef); //---------------Assert Precondition---------------- Assert.IsNotNull(parentDef.PrimaryKeyDef); Assert.IsNotNull(def.SuperClassDef); Assert.IsNull(def.PrimaryKeyDef); //---------------Execute Test ---------------------- IPrimaryKeyDef primaryKeyDef = ClassDefHelper.GetPrimaryKeyDef(def, classDefCol); //---------------Test Result ----------------------- Assert.IsNotNull(primaryKeyDef); Assert.AreSame(parentDef.PrimaryKeyDef, primaryKeyDef); }
/// <summary> /// Returns a lookup-list for all the business objects stored under /// the class definition held in this instance. An option is included to ignore the default /// timeout, which causes use of a cached version within the timeout /// period. /// </summary> /// <param name="ignoreTimeout">Whether to ignore the timeout and reload from the database regardless of when the lookup list was last loaded.</param> /// <returns>Returns a collection of string-value pairs</returns> public Dictionary <string, string> GetLookupList(bool ignoreTimeout) { if (!ignoreTimeout && CacheHasNotTimedOut()) { _lastCallTime = DateTime.Now; return(DisplayValueDictionary); } var classDef = LookupBoClassDef; var primaryKeyDef = ClassDefHelper.GetPrimaryKeyDef(classDef, ClassDef.ClassDefs); if (primaryKeyDef.Count > 1) { throw new HabaneroDeveloperException ("There is an application setup error. Please contact your system administrator", "The lookup list cannot contain business objects '" + classDef.ClassNameFull + "' with a composite primary key."); } IBusinessObjectCollection col = GetBusinessObjectCollection(); DisplayValueDictionary = CreateDisplayValueDictionary(col, OrderCriteria == null); FillKeyValueDictionary(); _lastCallTime = DateTime.Now; return(DisplayValueDictionary); }
///<summary> /// For a given value e.g. a Guid Identifier '{......}' this will build up a primary key object that can be used to /// load the business object from the Data store (see Business Object loader GetBusinessObjectByValue) /// This can only be used for business objects that have a single property for the primary key /// (i.e. non composite primary keys) ///</summary> ///<param name="classDef">The Class definition of the Business Object to load</param> ///<param name="idValue">The value of the primary key of the business object</param> ///<returns>the BOPrimaryKey if this can be constructed else returns null</returns> public static BOPrimaryKey CreateWithValue(ClassDef classDef, object idValue) { var primaryKeyDef = (PrimaryKeyDef)ClassDefHelper.GetPrimaryKeyDef(classDef, ClassDef.ClassDefs); if (primaryKeyDef.IsCompositeKey) { return(null); } var boPropCol = classDef.CreateBOPropertyCol(true); var boPrimaryKey = primaryKeyDef.CreateBOKey(boPropCol) as BOPrimaryKey; if (boPrimaryKey != null) { boPrimaryKey[0].Value = idValue; } return(boPrimaryKey); }