>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
Code c# (IBrolDao.cs) (145 lignes)
using System; using System.Collections.Generic; using System.Text; using System.Data; using be.gaudry.observer; namespace be.gaudry.bibliobrol.model.dao { public interface IBrolDao : IObservable { /// <summary> /// Load all roles /// </summary> /// <returns></returns> List<ActorRole> loadRoles(); /// <summary> /// Load roles for a person /// </summary> /// <param name="person"></param> /// <returns></returns> List<ActorRole> loadRoles(Person person); /// <summary> /// Load the default role for a person /// </summary> /// <param name="person"></param> /// <returns></returns> ActorRole loadDefaultRole(Person person); /// <summary> /// set the default role for a person /// </summary> /// <param name="person"></param> /// <param name="role"></param> void setDefaultRole(Person person, ActorRole role); /// <summary> /// Load person's roles for the selected type /// </summary> /// <param name="brolType"></param> /// <returns>List of roles strings</returns> List<ActorRole> loadRoles(BrolType brolType); /// <summary> /// get a roles with the id /// </summary> /// <param name="roleId">(int) id of the requested role</param> /// <returns>l(ActorRole) requested role</returns> ActorRole loadRole(int roleId); /// <summary> /// get a roles with the name /// </summary> /// <param name="roleName">(string) name of the requested role</param> /// <returns>(ActorRole) requested role</returns> ActorRole loadRole(string roleName); /// <summary> /// get a list of roles with the same name /// </summary> /// <param name="roleName">(string) name of the requested roles</param> /// <returns>(List of ActorRole) requested roles</returns> List<ActorRole> loadRoles(string roleName); /// <summary> /// Insert a new role. Don't check if the role name exists in the db. You must do it before. /// </summary> /// <param name="actor">(ActorRole) role to add</param> /// <returns></returns> bool insertRole(ActorRole role); /// <summary> /// Insert a brol (i.e. a film) into the Access database /// </summary> /// <param name="brol">(Brol) brol to insert</param> /// <returns>(int) new brol id</returns> int insertBrol(Brol brol); int insertBrols(List<Brol> brols, bool insertMediabrol); /// <summary> /// Load a brol with the selected id from the Access database. /// If this brol shoud be modified, editing bool arg is true /// to avoid concurent modifications (nobody else can save this brol). /// </summary> /// <param name="id">(int) Id of the selected bool</param> /// <param name="editing">(bool) Shoud be modified or not</param> /// <returns>Selected bool, or a new bool if _ found</returns> Brol loadBrol(int id, bool editing); /// <summary> /// Load all brols for a type from the persistant layer. /// i.e. films, books, etc. /// typeId 0 allow to load all types /// </summary> /// <returns>List of Brols</returns> List<Brol> loadBrols(int typeId); /// <summary> /// Load all brols for a serie from the persistant layer. /// </summary> /// <param name="serie"></param> /// <returns>List of Brols</returns> List<Brol> loadBrols(Serie serie); /// <summary> /// Load all available categories for a type from the Access database. /// i.e. for a film : Science-fiction, Horror, etc. /// </summary> /// <param name="typeId">(int) selected type (film, book, etc.) negative value to load all</param> /// <returns>List of BrolCategories</returns> List<BrolCategory> loadCategories(int typeId); /// <summary> /// Load brols value objects (only selected fields) for a type from the Access database. /// </summary> /// <param name="fields">List of fields to load for the brols</param> /// <param name="typeId"> /// (int) selected type (film, book, etc.) /// 0 allow to load all types /// </param> /// <returns>DataTable with selected fields for Brols</returns> DataTable loadDataTableVos(List<DAOUtils.BROL_FIELD> fields, int typeId); /// <summary> /// Store new values for a brol. /// Verify if some categories or actors had been deleted, and delete it from the persistant layer. /// Add new categories or actors if exists. /// Update existing categories or actors. /// </summary> /// <param name="person">(Brol) brol with new values to store</param> /// <returns>(bool) true if update is done</returns> bool updateBrol(Brol brol); /// <summary> /// Lock brol to avoid concurent modifications. /// </summary> /// <param name="id">(int) brol's id to lock</param> /// <returns>(bool) false if a problem occurs (todo : if already locked)</returns> bool lockBrol(int id); /// <summary> /// unlock brol to allow modifications. /// </summary> /// <param name="id">(int) brol's id to unlock</param> void unlockBrol(int id); /// <summary> /// Delete a brol from the Access database, /// and delete all associated actors and categories /// </summary> /// <param name="p">(Brol) brol to delete</param> /// <returns>(bool) true if deleted</returns> bool deleteBrol(Brol brol); /// <summary> /// Insert brols from a batch file (batch filePath is stored into application properties file) /// </summary> /// <param name="insertMediabrol">(bool) True if a mediabrol must be inserted for each brol</param> /// <returns>(int) Number of inserted brols</returns> int executeBatch(bool insertMediabrol); } }
Code c# (IMediaBrolDao.cs) (204 lignes)
using System; using System.Collections.Generic; using System.Text; using System.Data; using be.gaudry.observer; namespace be.gaudry.bibliobrol.model.dao { public interface IMediaBrolDao : IObservable { #region mediabrol /// <summary> /// Insert a mediabrol into the persistant layer /// </summary> /// <param name="brol">(MediaBrol) mediabrol to insert</param> /// <returns>(int) new mediabrol id</returns> int insertMediaBrol(MediaBrol mediabrol); /// <summary> /// Load a mediabrol with the selected id from the persistant layer. /// If this mediabrol shoud be modified, editing bool arg is true /// to avoid concurent modifications (nobody else can save this mediabrol). /// </summary> /// <param name="id">(int) Id of the selected bool</param> /// <param name="editing">(bool) Shoud be modified or not</param> /// <returns>Selected bool, or a new bool if _ found</returns> MediaBrol loadMediaBrol(int id, bool editing); /// <summary> /// Load all mediabrols for a brol from the persistant layer. /// </summary> /// <param name="brol"></param> /// <param name="fields">list of fields to load</param> /// <returns>(DataTable) table with selected columns</returns> DataTable loadMediaBrols(Brol brol, List<DAOUtils.MEDIABROL_FIELD> fields); /// <summary> /// Load all available medias for a type from the persistant layer. /// i.e. for a film : DVD, VHS, CD, etc. /// </summary> /// <param name="typeId">(int) selected type (film, book, etc.)</param> /// <returns>List of Qualities</returns> List<Media> loadMedias(int typeId); /// <summary> /// Load all available qualities for a mediabrol from the persistant layer. /// i.e. for a film : sound(DTS), sound(7.1) codec(VOB), etc. /// </summary> /// <param name="typeId">(int) selected mediabrol</param> /// <returns>List of Qualities</returns> List<Quality> loadQualities(int itemBiblioId); /// <summary> /// Load all available qualities for a type from the persistant layer. /// i.e. for a film : sound(DTS), sound(7.1) codec(VOB), etc. /// </summary> /// <param name="typeId">(BrolType) selected type (film, book, etc.)</param> /// <returns>List of Qualities</returns> List<Quality> loadQualities(BrolType brolType); /// <summary> /// Load brols value objects (only selected fields) for a type from the persistant layer. /// </summary> /// <param name="fields">List of fields to load for the mediabrols</param> /// <param name="typeId"> /// (int) selected type (film, book, etc.) /// 0 allow to load all types /// </param> /// <returns>DataTable with selected fields for mediabrols</returns> DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId); /// <summary> /// Load brols value objects (only selected fields) for a type from the persistant layer. /// </summary> /// <param name="fields">List of fields to load for the mediabrols</param> /// <param name="typeId"> /// (int) selected type (film, book, etc.) /// 0 allow to load all types /// </param> /// <param name="categories">List of categories to match</param> /// <returns>DataTable with selected fields for mediabrols</returns> DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId, List<BrolCategory> categories); /// <summary> /// Load brols value objects (only selected fields) for a type from the persistant layer. /// </summary> /// <param name="fields">List of fields to load for the mediabrols</param> /// <param name="typeId"> /// (int) selected type (film, book, etc.) /// 0 allow to load all types /// </param> /// <param name="categories">List of categories to match</param> /// <param name="mediaId">media to match</param> /// <returns>DataTable with selected fields for mediabrols</returns> DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId, List<BrolCategory> categories, int mediaId); /// <summary> /// Load brols value objects (only selected fields) for a type from the persistant layer. /// </summary> /// <param name="fields">List of fields to load for the mediabrols</param> /// <param name="typeId"> /// (int) selected type (film, book, etc.) /// 0 allow to load all types /// </param> /// <param name="categories">List of categories to match</param> /// <param name="mediaId">media to match</param> /// <param name="title">(String) string to find into brol's title</param> /// <returns>DataTable with selected fields for mediabrols</returns> DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> fields, int typeId, List<BrolCategory> categories, int mediaId, string title); /// <summary> /// Store new values for a mediabrol. /// </summary> /// <param name="mediaBrol">(MediaBrol) mediaBrol with new values to store</param> /// <returns>(bool) true if update is done</returns> bool updateMediaBrol(MediaBrol mediaBrol); /// <summary> /// Lock mediaBrol to avoid concurent modifications. /// </summary> /// <param name="id">(int) mediaBrol's id to lock</param> /// <returns>(bool) false if a problem occurs (todo : if already locked)</returns> bool lockMediaBrol(int id); /// <summary> /// unlock mediaBrol to allow modifications. /// </summary> /// <param name="id">(int) mediaBrol's id to unlock</param> void unlockMediaBrol(int id); /// <summary> /// If no currents borrows, /// delete a mediaBrol from the persistant layer all associated borrows, /// and all qualities relations /// </summary> /// <param name="mediaBrol">(Brol) mediaBrol to delete</param> /// <returns>(bool) true if deleted</returns> bool deleteMediaBrol(MediaBrol mediaBrol); /// <summary> /// If no currents borrows, /// delete a mediaBrol from the persistant layer all associated borrows, /// and all qualities relations /// </summary> /// <param name="mediabrolId"></param> /// <param name="title"></param> /// <param name="deleteBrol">Set true to delete associated brol</param> /// <returns></returns> bool deleteMediaBrol(int mediabrolId, String title, bool deleteBrol); #endregion #region borrows /// <summary> /// Insert today new borrow for a mediabrol and a person /// </summary> /// <param name="mediabrolId">(int) identifier of a mediabrol object</param> /// <param name="borrower">(int) identifier of a person</param> /// <returns>(bool) true if started</returns> bool startBorrow(int mediabrolId, int borrowerId); /// <summary> /// Update borrow, set endDate to now /// </summary> /// <param name="borrowId"></param> /// <returns>(bool) true if stopped</returns> bool stopBorrow(int borrowId); /// <summary> /// Update borrow, set endDate to now /// </summary> /// <param name="mediabrol">(MediaBrol) borrowed mediabrol</param> /// <returns>(bool) true if stopped</returns> bool stopBorrow(MediaBrol mediabrol); /// <summary> /// Delete all borrows for a mediabrol /// </summary> /// <param name="mediabrolId">(int) mediabrol identifier</param> /// <param name="forceDelete">(bool) set true to force delete a borrow which is not closed</param> /// <returns>(int) -1 if forceDelete = false and a borrow is not closed; number of borrows deleted otherwise</returns> int cleanBorrows(int mediabrolId, bool forceDelete); /// <summary> /// Delete selected borrow /// </summary> /// <param name="selectedBorrowId">(int) borrow identifier</param> void cleanBorrow(int selectedBorrowId); /// <summary> /// Update a borrow /// </summary> /// <param name="borrow"></param> bool updateBorrow(Borrow borrow); /// <summary> /// Load borrows for a person /// </summary> /// <param name="person"></param> /// <returns></returns> List<Borrow> loadBorrows(Person person); /// <summary> /// Load borrows and fill a DataTable. /// If mediabrolId equals 0, all borrows are loaded. /// </summary> /// <param name="mediabrolId">(int) Selected mediabrol id</param> /// <param name="borrowFields">List of fields to load for the borrows</param> /// <param name="typeId"> /// (int) selected type (film, book, etc.) /// 0 allow to load all types /// </param> /// <param name="closed">set true to load closed borrows, false to load only current borrows</param> /// <param name="title">(String) string to find into brol's title</param> /// <returns>(DataTable) DataTable with borrows</returns> DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields, int typeId, bool closed, string title); /// <summary> /// Load selected borrow /// </summary> /// <param name="mediabrol"></param> /// <returns></returns> Borrow loadBorrow(int borrowId); #endregion } }
Code c# (IPersonDao.cs) (113 lignes)
using System; using System.Collections.Generic; using System.Text; using be.gaudry.observer; namespace be.gaudry.bibliobrol.model.dao { public interface IPersonDao : IObservable { #region person /// <summary> /// Test if a person exists with the same name and firstname /// </summary> /// <param name="person">(Person) person to test</param> /// <returns>(int) id of the person found (-1 if not found)</returns> int personExists(Person person); /// <summary> /// Insert a person into the persistant layer /// </summary> /// <param name="person">(Person) person to insert</param> /// <returns>(int) id of the new person (-1 if a problem occurs)</returns> int insertPerson(Person person); /// <summary> /// Load a person from the persistant layer with an id arg. /// If this person shoud be modified, editing bool arg is true /// to avoid concurent modifications (nobody else can save this person). /// </summary> /// <param name="id">(int) Id of the selected person</param> /// <param name="editing">(bool) Shoud be modified or not</param> /// <returns>Selected person, or a new person if _ found</returns> Person loadPerson(int id, bool editing); /// <summary> /// Load a person from the persistant layer with a lastname and a firstname. /// Search case insensitive. /// </summary> /// <param name="lastName">(string) lastname of the searched person</param> /// <param name="firstName">(string) firstname of the searched person</param> /// <returns>Persons found, or empty list</returns> List<Person> loadPersons(string lastName, string firstName); /// <summary> /// Load all persons from the persistant layer /// </summary> /// <returns>List of Persons</returns> List<Person> loadPersons(); /// <summary> /// Load all persons matches (case insensitive) lastName /// </summary> /// <param name="lastName">(String) lastName to match</param> /// <returns>List of persons with the same lastName</returns> List<Person> loadPersons(String lastName); /// <summary> /// Load persons value objects (only display and id) /// </summary> /// <returns>List of PersonVos</returns> List<PersonLO> loadVos(); /// <summary> /// Load persons value objects with selected role (only display and id) /// If role id is less or equals than 0, all persons are loaded /// </summary> /// <param name="editing">(ActorRole) person's role</param> /// <returns>List of PersonVos</returns> List<PersonLO> loadPersonsVos(ActorRole role); /// <summary> /// Load persons value objects with the same name /// </summary> /// <param name="name">(string) person's lastname</param> /// <returns>List of PersonVos</returns> List<PersonLO> loadPersonsVos(string name); /// <summary> /// Store new values for a person. /// Verify if some phones had been deleted, and delete it from the persistant layer. /// Add new phones if exists. /// Update existing phones. /// </summary> /// <param name="person">Person with new values to store</param> /// <returns>true if update is done</returns> bool updatePerson(Person person); /// <summary> /// Lock person to avoid concurent modifications. /// </summary> /// <param name="id">person's id to lock</param> /// <returns>false if a problem occurs (todo : if already locked)</returns> bool lockPerson(int id); /// <summary> /// unlock person to allow modifications. /// </summary> /// <param name="id">person's id to unlock</param> bool unlockPerson(int id); /// <summary> /// Delete a person from the persistant layer, /// and delete all associated phones /// </summary> /// <param name="p">(Person) person to delete</param> /// <returns>true if deleted</returns> bool deletePerson(Person person); #endregion #region user /// <summary> /// Insert a person into the persistant layer and add it in the bibliobrolusers group /// </summary> /// <param name="person">(Person) person to insert</param> /// <returns>(int) id of the new person (-1 if a problem occurs)</returns> int insertBibliobrolUser(Person person); User loadUser(int persId); int saveUser(User user); void deleteUser(User user, bool deletePerson); #endregion ActorRole getUserRole(); } }
Code c# (IConfigDao.cs) (21 lignes)
using System; using System.Collections.Generic; using System.Text; using be.gaudry.observer; namespace be.gaudry.bibliobrol.model.dao { public interface IConfigDao : IObservable { List<BrolType> loadBrolTypes(); Person loadOwner(); bool saveOwner(Person owner); String loadConfig(String configName); bool saveConfig(String configName, String configValue); /// <summary> /// Test if the application may use the system to store data /// </summary> /// <exception cref="PersistanceNotFoundException">If the persistance is not found or may not be used</exception> void testPersistance(); } }
Code c# (ITaskDao.cs) (15 lignes)
using System; using System.Collections.Generic; using System.Text; using be.gaudry.observer; namespace be.gaudry.bibliobrol.model.dao { public interface ITaskDao : IObservable { bool insertTask(Task task); bool updateTask(Task task); bool deleteTask(int taskId); List<Task> loadTasks(); } }
Version en cache
21/11/2024 10:01:32 Cette version de la page est en cache (à la date du 21/11/2024 10:01:32) 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.