/// <summary>
        /// Generates the DAO interface file.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="classMap">The class map.</param>
        private static void GenerateDai(string path, IClassMap classMap)
        {
            using (StreamWriter file = new StreamWriter(path + GetInterfaceName(classMap) + ".cs", false))
            {
                ClassUtility.AppendHeader(file);

                file.WriteLine("using System.Collections.Generic;");
                file.WriteLine("using DOL.Database.DataTransferObjects;");
                file.WriteLine();

                file.WriteLine("namespace DOL.Database.DataAccessInterfaces");
                file.WriteLine("{");
                file.WriteLine("	public interface "+ GetInterfaceName(classMap) + " : IGenericDao<" + EntityGenerator.GetTypeName(classMap) + ">");
                file.WriteLine("	{");

                // generate 'find' methods
                GenerateFindMethods(classMap, file);

                // generate 'find by' methods
                GenerateFindByMethods(classMap, file);

                // generate 'cout by' methods
                GenerateCountByMethods(classMap, file);

                file.WriteLine("	}");
                file.WriteLine("}");
            }
        }
        /// <summary>
        /// Writes the generic DAO.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="domain">The domain.</param>
        private static void WriteGenericDao(string path, IDomainMap domain)
        {
            string fileName = path + "IGenericDao.cs";

            using (StreamWriter file = new StreamWriter(fileName, false))
            {
                ClassUtility.AppendHeader(file);

                file.WriteLine("using System.Collections.Generic;");
                file.WriteLine();
                file.WriteLine("namespace DOL.Database.DataAccessInterfaces");
                file.WriteLine("{");
                file.WriteLine("	/// <summary>");
                file.WriteLine("	/// Generic interface with base DAO methods.");
                file.WriteLine("	/// </summary>");
                file.WriteLine("	/// <typeparam name=\"TTransferObject\">The transfer object's type.</typeparam>");
                file.WriteLine("	public interface IGenericDao<TTransferObject> : IDataAccessObject");
                file.WriteLine("	{");
                file.WriteLine();
                file.WriteLine("		/// <summary>");
                file.WriteLine("		/// Creates an object in a database.");
                file.WriteLine("		/// </summary>");
                file.WriteLine("		/// <param name=\"obj\">The object to save.</param>");
                file.WriteLine("		void Create(ref TTransferObject obj);");
                file.WriteLine();
                file.WriteLine("		/// <summary>");
                file.WriteLine("		/// Updates the persistent instance with data from transfer object.");
                file.WriteLine("		/// </summary>");
                file.WriteLine("		/// <param name=\"obj\">The data.</param>");
                file.WriteLine("		void Update(TTransferObject obj);");
                file.WriteLine();
                file.WriteLine("		/// <summary>");
                file.WriteLine("		/// Deletes an object from a database.");
                file.WriteLine("		/// </summary>");
                file.WriteLine("		/// <param name=\"obj\">The object to delete.</param>");
                file.WriteLine("		void Delete(TTransferObject obj);");
                file.WriteLine();
                file.WriteLine("		/// <summary>");
                file.WriteLine("		/// Gets all stored objects.");
                file.WriteLine("		/// </summary>");
                file.WriteLine("		/// <value>all objects.</value>");
                file.WriteLine("		IList<TTransferObject> SelectAll();");
                file.WriteLine();
                file.WriteLine("		/// <summary>");
                file.WriteLine("		/// Gets the count of all stored objects.");
                file.WriteLine("		/// </summary>");
                file.WriteLine("		/// <value>The count of all objects.</value>");
                file.WriteLine("		long CountAll();");
                file.WriteLine("	}");
                file.WriteLine("}");
                file.WriteLine();
            }
        }
示例#3
0
        /// <summary>
        /// Generates one entity file.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="classMap">The class map.</param>
        private static void GenerateEntity(string path, IClassMap classMap)
        {
            using (StreamWriter file = new StreamWriter(path + GetTypeName(classMap) + ".cs", false))
            {
                ClassUtility.AppendHeader(file);
                file.WriteLine();

                file.WriteLine("namespace DOL.Database.DataTransferObjects");
                file.WriteLine("{");
                file.WriteLine("	[Serializable]");
                file.WriteLine("	public class "+ GetTypeName(classMap));
                file.WriteLine("	{");

                GeneratePrivateFields(file, classMap);

                file.WriteLine();

                GenerateProperties(file, classMap);

                file.WriteLine("	}");
                file.WriteLine("}");
            }
        }
        /// <summary>
        /// Generates the DAO file.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="classMap">The class map.</param>
        public virtual void GenerateDao(string path, IClassMap classMap)
        {
            using (StreamWriter file = new StreamWriter(path + GetDaoName(classMap) + ".cs", false))
            {
                string entityClassName = EntityGenerator.GetTypeName(classMap);

                ClassUtility.AppendHeader(file);
                InsertUsings(file);
                file.WriteLine();

                // namespace
                file.WriteLine("namespace " + Namespace);
                file.WriteLine("{");
                file.WriteLine("	public class "+ GetDaoName(classMap) + " : " + DataAccessInterfaceGenerator.GetInterfaceName(classMap));
                file.WriteLine("	{");

                // state's object storage and other fields/methods
                GenerateCustomFieldsAndMethods(file, classMap);
                file.WriteLine();

                // find by primary key
                GenerateFind(file, classMap);

                // 'find by properties' methods, if any
                GenerateAllFindBy(file, classMap);

                // 'count by properties' methods, if any
                GenerateAllCountBy(file, classMap);

                // sql "insert"
                file.WriteLine("		public virtual void Create(ref "+ entityClassName + " obj)");
                file.WriteLine("		{");
                GenerateCreate(file, classMap);
                file.WriteLine("		}");
                file.WriteLine();

                // sql "update"
                file.WriteLine("		public virtual void Update("+ entityClassName + " obj)");
                file.WriteLine("		{");
                GenerateUpdate(file, classMap);
                file.WriteLine("		}");
                file.WriteLine();

                // sql "delete"
                file.WriteLine("		public virtual void Delete("+ entityClassName + " obj)");
                file.WriteLine("		{");
                GenerateDelete(file, classMap);
                file.WriteLine("		}");
                file.WriteLine();

                // flush cache
                file.WriteLine("		public virtual void SaveAll()");
                file.WriteLine("		{");
                GenerateSaveAll(file, classMap);
                file.WriteLine("		}");
                file.WriteLine();

                // select all objects
                file.WriteLine("		public virtual IList<"+ entityClassName + "> SelectAll()");
                file.WriteLine("		{");
                GenerateSelectAll(file, classMap);
                file.WriteLine("		}");
                file.WriteLine();

                // count all objects
                file.WriteLine("		public virtual long CountAll()");
                file.WriteLine("		{");
                GenerateCountAll(file, classMap);
                file.WriteLine("		}");
                file.WriteLine();

                // fill entity with DB row
                file.WriteLine("		protected virtual void FillEntityWithRow(ref "+ entityClassName + " entity, MySqlDataReader reader)");
                file.WriteLine("		{");
                GenerateFillEntityWithRow(file, classMap);
                file.WriteLine("		}");
                file.WriteLine();

                // gets the TO's type
                file.WriteLine("		public virtual Type TransferObjectType");
                file.WriteLine("		{");
                file.WriteLine("			get {{ return typeof({0}); }}", entityClassName);
                file.WriteLine("		}");
                file.WriteLine();

                // very schema
                file.WriteLine("		public IList<string> VerifySchema()");
                file.WriteLine("		{");
                GenerateVerifySchema(file, classMap);
                file.WriteLine("		}");
                file.WriteLine();

                // constructor
                file.WriteLine("		public "+ GetDaoName(classMap) + "(" + StateClassName + " state)");
                file.WriteLine("		{");
                file.WriteLine("			if (state == null)");
                file.WriteLine("			{");
                file.WriteLine("				throw new ArgumentNullException(\"state\");");
                file.WriteLine("			}");
                file.WriteLine("			m_state = state;");
                file.WriteLine("		}");

                file.WriteLine("	}");
                file.WriteLine("}");
            }
        }