/// <summary> /// Generates all the 'find by' methods of this interface. /// </summary> /// <param name="classMap">The class map.</param> /// <param name="file">The file.</param> private static void GenerateFindByMethods(IClassMap classMap, StreamWriter file) { foreach (KeyValuePair <int, IList <IPropertyMap> > pair in classMap.DOLGetFindByGroups()) { IList <IPropertyMap> paramProps = pair.Value; string findBy = StringUtility.CombineObjects(paramProps, MapToStringConverters.PropertyAnd) .ToString(); // method name file.Write(" IList<"+ EntityGenerator.GetTypeName(classMap) + "> FindBy" + findBy); // method's params file.Write("("); bool first = true; foreach (IPropertyMap propertyMap in paramProps) { if (!first) { file.Write(", "); } // param type and name string paramName = ClassUtility.GetParamName(propertyMap); string paramType = ClassUtility.ConvertColumnTypeToCsType(propertyMap.GetColumnMap().DataType); file.Write(paramType + " " + paramName); first = false; } file.Write(");"); file.WriteLine(); } }
/// <summary> /// Generates all the 'find' methods of this interface. /// </summary> /// <param name="classMap">The class map.</param> /// <param name="file">The file.</param> private static void GenerateFindMethods(IClassMap classMap, StreamWriter file) { // method name file.Write(" "+ EntityGenerator.GetTypeName(classMap) + " Find("); ArrayList primaryColumns = classMap.GetTableMap().GetPrimaryKeyColumnMaps(); // method's params bool first = true; foreach (IColumnMap columnMap in primaryColumns) { IPropertyMap propertyMap = classMap.GetPropertyMapForColumnMap(columnMap); if (!first) { file.Write(", "); } // param type and name string paramName = ClassUtility.GetParamName(propertyMap); string paramType = ClassUtility.ConvertColumnTypeToCsType(columnMap.DataType); file.Write(paramType + " " + paramName); first = false; } file.Write(");"); file.WriteLine(); }
/// <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> /// 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("}"); } }