>Bibliobrol : les interfaces du DAO

Nous avons vu comment découpler l'application du système de persistance dans les pages précédentes, voici è présent les différentes interfaces qui définissent les actions possibles sur les données stockées.

Le rôle de ces interfaces

Nous pouvons penser dans notre classe DAOFactory que nous nous adressons directement è nos interfaces, mais il n'en est rien. La classe abstraite DAOFactory définit que la classe concrète qui l'implémente doit retourner les classes qui implémentent ces interfaces.

Donc, quand nous nous adressons è la classe DAOFactory pour récupérer l'interface IPerson pour enfin faire appel à la méthode de sauvegarde d'une personne, nous utilisons une classe concrète qui étend DAOFactory et qui est adaptée à un système de persistance déterminé. Cette classe nous retourne une classe qui implémente IPerson et qui correspond au système de persistance désiré, et nous pouvons donc sauver une personne en employant les méthodes adaptées au système de persistance utilisé.

Le code des interfaces

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using be.gaudry.observer;
  6.  
  7. namespace be.gaudry.bibliobrol.model.dao
  8. {
  9. public interface IBrolDao : IObservable
  10. {
  11.  
  12. /// <summary>
  13. /// Load all roles
  14. /// </summary>
  15. /// <returns></returns>
  16. List<ActorRole> loadRoles();
  17. /// <summary>
  18. /// Load roles for a person
  19. /// </summary>
  20. /// <param name="person"></param>
  21. /// <returns></returns>
  22. List<ActorRole> loadRoles(Person person);
  23. /// <summary>
  24. /// Load the default role for a person
  25. /// </summary>
  26. /// <param name="person"></param>
  27. /// <returns></returns>
  28. ActorRole loadDefaultRole(Person person);
  29. /// <summary>
  30. /// set the default role for a person
  31. /// </summary>
  32. /// <param name="person"></param>
  33. /// <param name="role"></param>
  34. void setDefaultRole(Person person, ActorRole role);
  35. /// <summary>
  36. /// Load person's roles for the selected type
  37. /// </summary>
  38. /// <param name="brolType"></param>
  39. /// <returns>List of roles strings</returns>
  40. List<ActorRole> loadRoles(BrolType brolType);
  41. /// <summary>
  42. /// get a roles with the id
  43. /// </summary>
  44. /// <param name="roleId">(int) id of the requested role</param>
  45. /// <returns>l(ActorRole) requested role</returns>
  46. ActorRole loadRole(int roleId);
  47. /// <summary>
  48. /// get a roles with the name
  49. /// </summary>
  50. /// <param name="roleName">(string) name of the requested role</param>
  51. /// <returns>(ActorRole) requested role</returns>
  52. ActorRole loadRole(string roleName);
  53. /// <summary>
  54. /// get a list of roles with the same name
  55. /// </summary>
  56. /// <param name="roleName">(string) name of the requested roles</param>
  57. /// <returns>(List of ActorRole) requested roles</returns>
  58. List<ActorRole> loadRoles(string roleName);
  59. /// <summary>
  60. /// Insert a new role. Don't check if the role name exists in the db. You must do it before.
  61. /// </summary>
  62. /// <param name="actor">(ActorRole) role to add</param>
  63. /// <returns></returns>
  64. bool insertRole(ActorRole role);
  65. /// <summary>
  66. /// Insert a brol (i.e. a film) into the Access database
  67. /// </summary>
  68. /// <param name="brol">(Brol) brol to insert</param>
  69. /// <returns>(int) new brol id</returns>
  70. int insertBrol(Brol brol);
  71. int insertBrols(List<Brol> brols, bool insertMediabrol);
  72. /// <summary>
  73. /// Load a brol with the selected id from the Access database.
  74. /// If this brol shoud be modified, editing bool arg is true
  75. /// to avoid concurent modifications (nobody else can save this brol).
  76. /// </summary>
  77. /// <param name="id">(int) Id of the selected bool</param>
  78. /// <param name="editing">(bool) Shoud be modified or not</param>
  79. /// <returns>Selected bool, or a new bool if _ found</returns>
  80. Brol loadBrol(int id, bool editing);
  81. /// <summary>
  82. /// Load all brols for a type from the persistant layer.
  83. /// i.e. films, books, etc.
  84. /// typeId 0 allow to load all types
  85. /// </summary>
  86. /// <returns>List of Brols</returns>
  87. List<Brol> loadBrols(int typeId);
  88. /// <summary>
  89. /// Load all brols for a serie from the persistant layer.
  90. /// </summary>
  91. /// <param name="serie"></param>
  92. /// <returns>List of Brols</returns>
  93. List<Brol> loadBrols(Serie serie);
  94. /// <summary>
  95. /// Load all available categories for a type from the Access database.
  96. /// i.e. for a film : Science-fiction, Horror, etc.
  97. /// </summary>
  98. /// <param name="typeId">(int) selected type (film, book, etc.) negative value to load all</param>
  99. /// <returns>List of BrolCategories</returns>
  100. List<BrolCategory> loadCategories(int typeId);
  101. /// <summary>
  102. /// Load brols value objects (only selected fields) for a type from the Access database.
  103. /// </summary>
  104. /// <param name="fields">List of fields to load for the brols</param>
  105. /// <param name="typeId">
  106. /// (int) selected type (film, book, etc.)
  107. /// 0 allow to load all types
  108. /// </param>
  109. /// <returns>DataTable with selected fields for Brols</returns>
  110. DataTable loadDataTableVos(List<DAOUtils.BROL_FIELD> fields, int typeId);
  111. /// <summary>
  112. /// Store new values for a brol.
  113. /// Verify if some categories or actors had been deleted, and delete it from the persistant layer.
  114. /// Add new categories or actors if exists.
  115. /// Update existing categories or actors.
  116. /// </summary>
  117. /// <param name="person">(Brol) brol with new values to store</param>
  118. /// <returns>(bool) true if update is done</returns>
  119. bool updateBrol(Brol brol);
  120. /// <summary>
  121. /// Lock brol to avoid concurent modifications.
  122. /// </summary>
  123. /// <param name="id">(int) brol's id to lock</param>
  124. /// <returns>(bool) false if a problem occurs (todo : if already locked)</returns>
  125. bool lockBrol(int id);
  126. /// <summary>
  127. /// unlock brol to allow modifications.
  128. /// </summary>
  129. /// <param name="id">(int) brol's id to unlock</param>
  130. void unlockBrol(int id);
  131. /// <summary>
  132. /// Delete a brol from the Access database,
  133. /// and delete all associated actors and categories
  134. /// </summary>
  135. /// <param name="p">(Brol) brol to delete</param>
  136. /// <returns>(bool) true if deleted</returns>
  137. bool deleteBrol(Brol brol);
  138. /// <summary>
  139. /// Insert brols from a batch file (batch filePath is stored into application properties file)
  140. /// </summary>
  141. /// <param name="insertMediabrol">(bool) True if a mediabrol must be inserted for each brol</param>
  142. /// <returns>(int) Number of inserted brols</returns>
  143. int executeBatch(bool insertMediabrol);
  144. }
  145. }

Table des matières Haut

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using be.gaudry.observer;
  6.  
  7. namespace be.gaudry.bibliobrol.model.dao
  8. {
  9. public interface IMediaBrolDao : IObservable
  10. {
  11.  
  12. #region mediabrol
  13. /// <summary>
  14. /// Insert a mediabrol into the persistant layer
  15. /// </summary>
  16. /// <param name="brol">(MediaBrol) mediabrol to insert</param>
  17. /// <returns>(int) new mediabrol id</returns>
  18. int insertMediaBrol(MediaBrol mediabrol);
  19. /// <summary>
  20. /// Load a mediabrol with the selected id from the persistant layer.
  21. /// If this mediabrol shoud be modified, editing bool arg is true
  22. /// to avoid concurent modifications (nobody else can save this mediabrol).
  23. /// </summary>
  24. /// <param name="id">(int) Id of the selected bool</param>
  25. /// <param name="editing">(bool) Shoud be modified or not</param>
  26. /// <returns>Selected bool, or a new bool if _ found</returns>
  27. MediaBrol loadMediaBrol(int id, bool editing);
  28. /// <summary>
  29. /// Load all mediabrols for a brol from the persistant layer.
  30. /// </summary>
  31. /// <param name="brol"></param>
  32. /// <param name="fields">list of fields to load</param>
  33. /// <returns>(DataTable) table with selected columns</returns>
  34. DataTable loadMediaBrols(Brol brol, List<DAOUtils.MEDIABROL_FIELD> fields);
  35. /// <summary>
  36. /// Load all available medias for a type from the persistant layer.
  37. /// i.e. for a film : DVD, VHS, CD, etc.
  38. /// </summary>
  39. /// <param name="typeId">(int) selected type (film, book, etc.)</param>
  40. /// <returns>List of Qualities</returns>
  41. List<Media> loadMedias(int typeId);
  42. /// <summary>
  43. /// Load all available qualities for a mediabrol from the persistant layer.
  44. /// i.e. for a film : sound(DTS), sound(7.1) codec(VOB), etc.
  45. /// </summary>
  46. /// <param name="typeId">(int) selected mediabrol</param>
  47. /// <returns>List of Qualities</returns>
  48. List<Quality> loadQualities(int itemBiblioId);
  49. /// <summary>
  50. /// Load all available qualities for a type from the persistant layer.
  51. /// i.e. for a film : sound(DTS), sound(7.1) codec(VOB), etc.
  52. /// </summary>
  53. /// <param name="typeId">(BrolType) selected type (film, book, etc.)</param>
  54. /// <returns>List of Qualities</returns>
  55. List<Quality> loadQualities(BrolType brolType);
  56. /// <summary>
  57. /// Load brols value objects (only selected fields) for a type from the persistant layer.
  58. /// </summary>
  59. /// <param name="fields">List of fields to load for the mediabrols</param>
  60. /// <param name="typeId">
  61. /// (int) selected type (film, book, etc.)
  62. /// 0 allow to load all types
  63. /// </param>
  64. /// <returns>DataTable with selected fields for mediabrols</returns>
  65. DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId);
  66. /// <summary>
  67. /// Load brols value objects (only selected fields) for a type from the persistant layer.
  68. /// </summary>
  69. /// <param name="fields">List of fields to load for the mediabrols</param>
  70. /// <param name="typeId">
  71. /// (int) selected type (film, book, etc.)
  72. /// 0 allow to load all types
  73. /// </param>
  74. /// <param name="categories">List of categories to match</param>
  75. /// <returns>DataTable with selected fields for mediabrols</returns>
  76. DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId, List<BrolCategory> categories);
  77. /// <summary>
  78. /// Load brols value objects (only selected fields) for a type from the persistant layer.
  79. /// </summary>
  80. /// <param name="fields">List of fields to load for the mediabrols</param>
  81. /// <param name="typeId">
  82. /// (int) selected type (film, book, etc.)
  83. /// 0 allow to load all types
  84. /// </param>
  85. /// <param name="categories">List of categories to match</param>
  86. /// <param name="mediaId">media to match</param>
  87. /// <returns>DataTable with selected fields for mediabrols</returns>
  88. DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId, List<BrolCategory> categories, int mediaId);
  89. /// <summary>
  90. /// Load brols value objects (only selected fields) for a type from the persistant layer.
  91. /// </summary>
  92. /// <param name="fields">List of fields to load for the mediabrols</param>
  93. /// <param name="typeId">
  94. /// (int) selected type (film, book, etc.)
  95. /// 0 allow to load all types
  96. /// </param>
  97. /// <param name="categories">List of categories to match</param>
  98. /// <param name="mediaId">media to match</param>
  99. /// <param name="title">(String) string to find into brol's title</param>
  100. /// <returns>DataTable with selected fields for mediabrols</returns>
  101. DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId, List<BrolCategory> categories, int mediaId, string title);
  102. /// <summary>
  103. /// Store new values for a mediabrol.
  104. /// </summary>
  105. /// <param name="mediaBrol">(MediaBrol) mediaBrol with new values to store</param>
  106. /// <returns>(bool) true if update is done</returns>
  107. bool updateMediaBrol(MediaBrol mediaBrol);
  108. /// <summary>
  109. /// Lock mediaBrol to avoid concurent modifications.
  110. /// </summary>
  111. /// <param name="id">(int) mediaBrol's id to lock</param>
  112. /// <returns>(bool) false if a problem occurs (todo : if already locked)</returns>
  113. bool lockMediaBrol(int id);
  114. /// <summary>
  115. /// unlock mediaBrol to allow modifications.
  116. /// </summary>
  117. /// <param name="id">(int) mediaBrol's id to unlock</param>
  118. void unlockMediaBrol(int id);
  119. /// <summary>
  120. /// If no currents borrows,
  121. /// delete a mediaBrol from the persistant layer all associated borrows,
  122. /// and all qualities relations
  123. /// </summary>
  124. /// <param name="mediaBrol">(Brol) mediaBrol to delete</param>
  125. /// <returns>(bool) true if deleted</returns>
  126. bool deleteMediaBrol(MediaBrol mediaBrol);
  127. /// <summary>
  128. /// If no currents borrows,
  129. /// delete a mediaBrol from the persistant layer all associated borrows,
  130. /// and all qualities relations
  131. /// </summary>
  132. /// <param name="mediabrolId"></param>
  133. /// <param name="title"></param>
  134. /// <param name="deleteBrol">Set true to delete associated brol</param>
  135. /// <returns></returns>
  136. bool deleteMediaBrol(int mediabrolId, String title, bool deleteBrol);
  137. #endregion
  138.  
  139. #region borrows
  140. /// <summary>
  141. /// Insert today new borrow for a mediabrol and a person
  142. /// </summary>
  143. /// <param name="mediabrolId">(int) identifier of a mediabrol object</param>
  144. /// <param name="borrower">(int) identifier of a person</param>
  145. /// <returns>(bool) true if started</returns>
  146. bool startBorrow(int mediabrolId, int borrowerId);
  147. /// <summary>
  148. /// Update borrow, set endDate to now
  149. /// </summary>
  150. /// <param name="borrowId"></param>
  151. /// <returns>(bool) true if stopped</returns>
  152. bool stopBorrow(int borrowId);
  153. /// <summary>
  154. /// Update borrow, set endDate to now
  155. /// </summary>
  156. /// <param name="mediabrol">(MediaBrol) borrowed mediabrol</param>
  157. /// <returns>(bool) true if stopped</returns>
  158. bool stopBorrow(MediaBrol mediabrol);
  159. /// <summary>
  160. /// Delete all borrows for a mediabrol
  161. /// </summary>
  162. /// <param name="mediabrolId">(int) mediabrol identifier</param>
  163. /// <param name="forceDelete">(bool) set true to force delete a borrow which is not closed</param>
  164. /// <returns>(int) -1 if forceDelete = false and a borrow is not closed; number of borrows deleted otherwise</returns>
  165. int cleanBorrows(int mediabrolId, bool forceDelete);
  166. /// <summary>
  167. /// Delete selected borrow
  168. /// </summary>
  169. /// <param name="selectedBorrowId">(int) borrow identifier</param>
  170. void cleanBorrow(int selectedBorrowId);
  171. /// <summary>
  172. /// Update a borrow
  173. /// </summary>
  174. /// <param name="borrow"></param>
  175. bool updateBorrow(Borrow borrow);
  176. /// <summary>
  177. /// Load borrows for a person
  178. /// </summary>
  179. /// <param name="person"></param>
  180. /// <returns></returns>
  181. List<Borrow> loadBorrows(Person person);
  182. /// <summary>
  183. /// Load borrows and fill a DataTable.
  184. /// If mediabrolId equals 0, all borrows are loaded.
  185. /// </summary>
  186. /// <param name="mediabrolId">(int) Selected mediabrol id</param>
  187. /// <param name="borrowFields">List of fields to load for the borrows</param>
  188. /// <param name="typeId">
  189. /// (int) selected type (film, book, etc.)
  190. /// 0 allow to load all types
  191. /// </param>
  192. /// <param name="closed">set true to load closed borrows, false to load only current borrows</param>
  193. /// <param name="title">(String) string to find into brol's title</param>
  194. /// <returns>(DataTable) DataTable with borrows</returns>
  195. DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields, int typeId, bool closed, string title);
  196. /// <summary>
  197. /// Load selected borrow
  198. /// </summary>
  199. /// <param name="mediabrol"></param>
  200. /// <returns></returns>
  201. Borrow loadBorrow(int borrowId);
  202. #endregion
  203. }
  204. }

Table des matières Haut

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using be.gaudry.observer;
  5.  
  6. namespace be.gaudry.bibliobrol.model.dao
  7. {
  8. public interface IPersonDao : IObservable
  9. {
  10. #region person
  11. /// <summary>
  12. /// Test if a person exists with the same name and firstname
  13. /// </summary>
  14. /// <param name="person">(Person) person to test</param>
  15. /// <returns>(int) id of the person found (-1 if not found)</returns>
  16. int personExists(Person person);
  17. /// <summary>
  18. /// Insert a person into the persistant layer
  19. /// </summary>
  20. /// <param name="person">(Person) person to insert</param>
  21. /// <returns>(int) id of the new person (-1 if a problem occurs)</returns>
  22. int insertPerson(Person person);
  23. /// <summary>
  24. /// Load a person from the persistant layer with an id arg.
  25. /// If this person shoud be modified, editing bool arg is true
  26. /// to avoid concurent modifications (nobody else can save this person).
  27. /// </summary>
  28. /// <param name="id">(int) Id of the selected person</param>
  29. /// <param name="editing">(bool) Shoud be modified or not</param>
  30. /// <returns>Selected person, or a new person if _ found</returns>
  31. Person loadPerson(int id, bool editing);
  32. /// <summary>
  33. /// Load a person from the persistant layer with a lastname and a firstname.
  34. /// Search case insensitive.
  35. /// </summary>
  36. /// <param name="lastName">(string) lastname of the searched person</param>
  37. /// <param name="firstName">(string) firstname of the searched person</param>
  38. /// <returns>Persons found, or empty list</returns>
  39. List<Person> loadPersons(string lastName, string firstName);
  40. /// <summary>
  41. /// Load all persons from the persistant layer
  42. /// </summary>
  43. /// <returns>List of Persons</returns>
  44. List<Person> loadPersons();
  45. /// <summary>
  46. /// Load all persons matches (case insensitive) lastName
  47. /// </summary>
  48. /// <param name="lastName">(String) lastName to match</param>
  49. /// <returns>List of persons with the same lastName</returns>
  50. List<Person> loadPersons(String lastName);
  51. /// <summary>
  52. /// Load persons value objects (only display and id)
  53. /// </summary>
  54. /// <returns>List of PersonVos</returns>
  55. List<PersonLO> loadVos();
  56. /// <summary>
  57. /// Load persons value objects with selected role (only display and id)
  58. /// If role id is less or equals than 0, all persons are loaded
  59. /// </summary>
  60. /// <param name="editing">(ActorRole) person's role</param>
  61. /// <returns>List of PersonVos</returns>
  62. List<PersonLO> loadPersonsVos(ActorRole role);
  63. /// <summary>
  64. /// Load persons value objects with the same name
  65. /// </summary>
  66. /// <param name="name">(string) person's lastname</param>
  67. /// <returns>List of PersonVos</returns>
  68. List<PersonLO> loadPersonsVos(string name);
  69. /// <summary>
  70. /// Store new values for a person.
  71. /// Verify if some phones had been deleted, and delete it from the persistant layer.
  72. /// Add new phones if exists.
  73. /// Update existing phones.
  74. /// </summary>
  75. /// <param name="person">Person with new values to store</param>
  76. /// <returns>true if update is done</returns>
  77. bool updatePerson(Person person);
  78. /// <summary>
  79. /// Lock person to avoid concurent modifications.
  80. /// </summary>
  81. /// <param name="id">person's id to lock</param>
  82. /// <returns>false if a problem occurs (todo : if already locked)</returns>
  83. bool lockPerson(int id);
  84. /// <summary>
  85. /// unlock person to allow modifications.
  86. /// </summary>
  87. /// <param name="id">person's id to unlock</param>
  88. bool unlockPerson(int id);
  89. /// <summary>
  90. /// Delete a person from the persistant layer,
  91. /// and delete all associated phones
  92. /// </summary>
  93. /// <param name="p">(Person) person to delete</param>
  94. /// <returns>true if deleted</returns>
  95. bool deletePerson(Person person);
  96. #endregion
  97.  
  98. #region user
  99.  
  100. /// <summary>
  101. /// Insert a person into the persistant layer and add it in the bibliobrolusers group
  102. /// </summary>
  103. /// <param name="person">(Person) person to insert</param>
  104. /// <returns>(int) id of the new person (-1 if a problem occurs)</returns>
  105. int insertBibliobrolUser(Person person);
  106. User loadUser(int persId);
  107. int saveUser(User user);
  108. void deleteUser(User user, bool deletePerson);
  109. #endregion
  110.  
  111. ActorRole getUserRole();
  112. }
  113. }

Table des matières Haut

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using be.gaudry.observer;
  5.  
  6. namespace be.gaudry.bibliobrol.model.dao
  7. {
  8. public interface IConfigDao : IObservable
  9. {
  10. List<BrolType> loadBrolTypes();
  11. Person loadOwner();
  12. bool saveOwner(Person owner);
  13. String loadConfig(String configName);
  14. bool saveConfig(String configName, String configValue);
  15. /// <summary>
  16. /// Test if the application may use the system to store data
  17. /// </summary>
  18. /// <exception cref="PersistanceNotFoundException">If the persistance is not found or may not be used</exception>
  19. void testPersistance();
  20. }
  21. }

Table des matières Haut

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using be.gaudry.observer;
  5.  
  6. namespace be.gaudry.bibliobrol.model.dao
  7. {
  8. public interface ITaskDao : IObservable
  9. {
  10. bool insertTask(Task task);
  11. bool updateTask(Task task);
  12. bool deleteTask(int taskId);
  13. List<Task> loadTasks();
  14. }
  15. }

Version en cache

22/12/2024 02:39:22 Cette version de la page est en cache (à la date du 22/12/2024 02:39:22) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.

Document créé le 06/12/2006, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/bibliobrol-dao-interfaces.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.