コード例 #1
0
        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);
        }
コード例 #2
0
 public static void AssertNotObjectID(this IPrimaryKeyDef primaryKey)
 {
     Assert.IsNotNull(primaryKey, "primary Key Should not be null");
     Assert.AreEqual(1, primaryKey.Count, "Should have one prop");
     Assert.IsFalse(primaryKey.IsCompositeKey, "should not be composite");
     Assert.IsFalse(primaryKey.IsGuidObjectID, "Should be object ID");
 }
コード例 #3
0
        public void TestSimplePrimaryKey()
        {
            IPrimaryKeyDef def =
                itsLoader.LoadPrimaryKey(@"<primaryKey><prop name=""TestProp"" /></primaryKey>", itsPropDefs);

            Assert.AreEqual(1, def.Count, "Def should have one property in it.");
            Assert.AreEqual(true, def.IsGuidObjectID, "Def should by default be an objectID");
        }
コード例 #4
0
        /// <summary>
        /// Loads the data from the reader
        /// </summary>
        protected override void LoadFromReader()
        {
            _primaryKeyDef = _defClassFactory.CreatePrimaryKeyDef();
            //_primaryKeyDef = new PrimaryKeyDef();

            _reader.Read();
            LoadIsObjectID();
            _reader.Read();
            LoadPropertyDefs();
        }
コード例 #5
0
        public void TestCompositeKey()
        {
            itsPropDefs.Add(GetDefClassFactory().CreatePropDef("TestProp2", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 255, null, null, false));
            IPrimaryKeyDef def =
                itsLoader.LoadPrimaryKey(
                    @"<primaryKey isObjectID=""false""><prop name=""TestProp"" /><prop name=""TestProp2"" /></primaryKey>",
                    itsPropDefs);

            Assert.AreEqual(2, def.Count, "Def should have one property in it.");
            Assert.AreEqual(false, def.IsGuidObjectID, "Def should not be an objectID");
        }
コード例 #6
0
ファイル: PgEnvironmentBase.cs プロジェクト: nQuantums/tips
 static void Drop(ElementCode context, string tableName, IPrimaryKeyDef primaryKey)
 {
     if (primaryKey == null)
     {
         return;
     }
     context.Add(SqlKeyword.AlterTable, SqlKeyword.IfExists);
     context.Concat(tableName);
     context.Add(SqlKeyword.DropConstraint, SqlKeyword.IfExists);
     context.Concat(primaryKey.Name);
     context.Go();
 }
コード例 #7
0
        public static void AssertHasOneIntProp(this IPrimaryKeyDef primaryKey)
        {
            Assert.IsNotNull(primaryKey, "primary Key Should not be null");
            Assert.AreEqual(1, primaryKey.Count, "Should have one prop");
            Assert.IsFalse(primaryKey.IsCompositeKey, "should not be composite");
            Assert.IsFalse(primaryKey.IsGuidObjectID, "Should be object ID");
            var pkProp = primaryKey[0];

            Assert.AreEqual(PropReadWriteRule.WriteNew, pkProp.ReadWriteRule);
            Assert.IsTrue(pkProp.Compulsory);
            Assert.AreEqual(typeof(int), pkProp.PropertyType);
        }
コード例 #8
0
ファイル: ClassDefHelper.cs プロジェクト: SaberZA/habanero
/*
 *      private static bool IsRelatedProperty(string propertyName)
 *      {
 *          return propertyName.IndexOf(".") != -1;
 *      }*/
        ///<summary>
        /// Returns the <see cref="ClassDef.PrimaryKeyDef"/> for the specified <see cref="ClassDef"/>.
        /// This may be an inherited <see cref="ClassDef.PrimaryKeyDef"/> from a super class.
        ///</summary>
        ///<param name="classDef">The <see cref="ClassDef"/> for which the <see cref="ClassDef.PrimaryKeyDef"/> needs to be found.</param>
        ///<param name="classDefCol">The <see cref="ClassDefCol"/> to use when searching the super classes for the <see cref="ClassDef.PrimaryKeyDef"/>.</param>
        ///<returns>Returns the <see cref="ClassDef.PrimaryKeyDef"/> for the specified <see cref="ClassDef"/>.</returns>
        ///<exception cref="InvalidXmlDefinitionException"></exception>
        public static IPrimaryKeyDef GetPrimaryKeyDef(IClassDef classDef, ClassDefCol classDefCol)
        {
            IPrimaryKeyDef primaryKeyDef = classDef.PrimaryKeyDef;

            if (primaryKeyDef == null)
            {
                ClassDef superClassClassDef = GetSuperClassClassDef(classDef.SuperClassDef, classDefCol);
                if (superClassClassDef != null)
                {
                    primaryKeyDef = GetPrimaryKeyDef(superClassClassDef, classDefCol);
                }
            }
            return(primaryKeyDef);
        }
コード例 #9
0
        /// <summary>
        /// Returns the primary key of the super-class.  If not found, it
        /// searches higher up the Hierarchy and returns the higher primary
        /// key or null if none is found.
        /// </summary>
        /// <param name="subClassDef">The class definition to search on</param>
        /// <param name="subClassObj">The business object</param>
        /// <returns>Returns a BOKey object or null</returns>
        public static IBOKey GetSuperClassKey(ClassDef subClassDef, BusinessObject subClassObj)
        {
            IPrimaryKeyDef primaryKeyDef = subClassDef.SuperClassClassDef.PrimaryKeyDef;

            while (primaryKeyDef == null)
            {
                if (subClassDef.SuperClassClassDef == null)
                {
                    return(null);
                }

                subClassDef   = (ClassDef)subClassDef.SuperClassClassDef;
                primaryKeyDef = subClassDef.PrimaryKeyDef;
            }
            return(primaryKeyDef.CreateBOKey(subClassObj.Props));
        }
コード例 #10
0
        private static void createPrimaryKeyXml(XmlElement classDMElement, IClassDef classDef)
        {
            IPrimaryKeyDef primaryKeyDef = classDef.PrimaryKeyDef;

            if (primaryKeyDef == null)
            {
                return;
            }

            if (primaryKeyDef.Count == 0)
            {
                return;
            }
            XmlElement primaryKeyDMElement = XmlUtilities.createXmlElement(classDMElement, "primaryKey");

            XmlUtilities.setXmlAttribute(primaryKeyDMElement, "isObjectID", primaryKeyDef.IsGuidObjectID, true);
            foreach (IPropDef dmKeyProperty in primaryKeyDef)
            {
                XmlElement keyPropElement = XmlUtilities.createXmlElement(primaryKeyDMElement, "prop");
                XmlUtilities.setXmlAttribute(keyPropElement, "name", dmKeyProperty.PropertyName);
            }
        }
コード例 #11
0
        /// <summary>
        /// Loads the primary key definition data
        /// </summary>
        private void LoadPrimaryKeyDef(string xmlDef)
        {
            try
            {
                if (xmlDef == null && _superClassDef == null)
                {
                    throw new InvalidXmlDefinitionException
                              (String.Format
                                  ("Could not find a " + "'primaryKey' element in the class definition for the class '{0}'. "
                                  + "Each class definition requires a primary key "
                                  + "definition, which is composed of one or more property definitions, "
                                  + "implying that you will need at least one 'prop' element as " + "well.", _className));
                }
                if (xmlDef == null)
                {
                    return;
                }

                XmlPrimaryKeyLoader primaryKeyLoader = new XmlPrimaryKeyLoader(DtdLoader, _defClassFactory);
                _primaryKeyDef = primaryKeyLoader.LoadPrimaryKey(xmlDef, _propDefCol);
                if (_primaryKeyDef == null)
                {
                    throw new InvalidXmlDefinitionException
                              (String.Format
                                  ("There was an error loading "
                                  + "the 'primaryKey' element in the class definition for the class '{0}. '"
                                  + "Each class definition requires a primary key "
                                  + "definition, which is composed of one or more property definitions, "
                                  + "implying that you will need at least one 'prop' element as " + "well.", _className));
                }
            }
            catch (Exception ex)
            {
                //This is a RecordingExceptionNotifier so this error will be logged and thrown later
                // thus allowing the entire XML File to be read and all errors reported
                GlobalRegistry.UIExceptionNotifier.Notify(ex, "", "Error ");
            }
        }
コード例 #12
0
        /// <summary>
        /// Loads the primary key definition data
        /// </summary>
        private void LoadPrimaryKeyDef(string xmlDef)
        {
            try
            {
                if (xmlDef == null && _superClassDef == null)
                {
                    throw new InvalidXmlDefinitionException
                        (String.Format
                             ("Could not find a " + "'primaryKey' element in the class definition for the class '{0}'. "
                              + "Each class definition requires a primary key "
                              + "definition, which is composed of one or more property definitions, "
                              + "implying that you will need at least one 'prop' element as " + "well.", _className));
                }
                if (xmlDef == null) return;

                XmlPrimaryKeyLoader primaryKeyLoader = new XmlPrimaryKeyLoader(DtdLoader, _defClassFactory);
                _primaryKeyDef = primaryKeyLoader.LoadPrimaryKey(xmlDef, _propDefCol);
                if (_primaryKeyDef == null)
                {
                    throw new InvalidXmlDefinitionException
                        (String.Format
                             ("There was an error loading "
                              + "the 'primaryKey' element in the class definition for the class '{0}. '"
                              + "Each class definition requires a primary key "
                              + "definition, which is composed of one or more property definitions, "
                              + "implying that you will need at least one 'prop' element as " + "well.", _className));
                }
            }
            catch (Exception ex)
            {
                //This is a RecordingExceptionNotifier so this error will be logged and thrown later
                // thus allowing the entire XML File to be read and all errors reported
                GlobalRegistry.UIExceptionNotifier.Notify(ex, "", "Error ");
            }
        }
コード例 #13
0
		///<summary>
		///</summary>
		///<param name="assemblyName"></param>
		///<param name="className"></param>
		///<param name="displayName"></param>
		///<param name="primaryKeyDef"></param>
		///<param name="propDefCol"></param>
		///<param name="keyDefCol"></param>
		///<param name="relationshipDefCol"></param>
		///<param name="uiDefCol"></param>
		///<returns></returns>
		public IClassDef CreateClassDef(string assemblyName, string className, string displayName, IPrimaryKeyDef primaryKeyDef,
									   IPropDefCol propDefCol, KeyDefCol keyDefCol, IRelationshipDefCol relationshipDefCol,
									   UIDefCol uiDefCol)
		{
			return new ClassDef(assemblyName, className, displayName, primaryKeyDef, propDefCol, keyDefCol, relationshipDefCol, uiDefCol);
		}
コード例 #14
0
ファイル: TestClassDef.cs プロジェクト: kevinbosman/habanero
 public void SetPrimaryKeyDef(IPrimaryKeyDef pkDef)
 {
     PrimaryKeyDef = pkDef;
 }
コード例 #15
0
 ///<summary>
 ///</summary>
 ///<param name="assemblyName"></param>
 ///<param name="className"></param>
 ///<param name="displayName"></param>
 ///<param name="primaryKeyDef"></param>
 ///<param name="propDefCol"></param>
 ///<param name="keyDefCol"></param>
 ///<param name="relationshipDefCol"></param>
 ///<param name="uiDefCol"></param>
 ///<returns></returns>
 public IClassDef CreateClassDef(string assemblyName, string className, string displayName, IPrimaryKeyDef primaryKeyDef,
                                 IPropDefCol propDefCol, KeyDefCol keyDefCol, IRelationshipDefCol relationshipDefCol,
                                 UIDefCol uiDefCol)
 {
     return(new ClassDef(assemblyName, className, displayName, primaryKeyDef, propDefCol, keyDefCol, relationshipDefCol, uiDefCol));
 }
コード例 #16
0
        /// <summary>
        /// Loads the data from the reader
        /// </summary>
        protected override void LoadFromReader()
        {
			_primaryKeyDef = _defClassFactory.CreatePrimaryKeyDef();
			//_primaryKeyDef = new PrimaryKeyDef();

            _reader.Read();
            LoadIsObjectID();
            _reader.Read();
            LoadPropertyDefs();
        }