BiblioBrol : Autres classes du modèle
Nous allons créer certaines classes dans notre modèle, pour faciliter l'usage du modèle.
ModelAdapter
Tout d'abord, nous allons créer une classe ModelAdapter, dans laquelle nous allons simplement relayer les méthodes qui nous permettent d'accéder au DAO. Nous évitons ainsi aux classes qui accèdent au modèle de devoir savoir quelle interface du DAO demander pour effectuer une opération sur les données stockées.
Nous pouvons aussi remarquer une différence dans les noms de certaines méthodes : quand nous nous adressons de l'extérieur à notre classe ModelAdapter, nous utilisons le préfixe get pour signifier que nous désirons obtenir un objet, alors que quand la classe ModelAdapter demande ce même objet au DAO nous employons le préfixe load pour signifier qu'il faut le charger depuis le système de persistance.
Nous allons qualifier toutes les méthodes de la classe ModelAdapter avec le mot réservé static afin d'éviter de devoir créer une instance de ModelAdapter pour utiliser ces méthodes.
Code c# (ModelAdapter.cs) (880 lignes)
using System; using System.Collections.Generic; using System.Text; using be.gaudry.bibliobrol.model.dao; using be.gaudry.observer; using be.gaudry.model; namespace be.gaudry.bibliobrol.model { /// <summary> /// Adapter for all model actions. Trade with dao. /// </summary> public class ModelAdapter : Observable { #region singleton static ModelAdapter instance = null; ModelAdapter() { } public static ModelAdapter Instance { get { lock (padlock) { if (instance == null) { } return instance; } } } #endregion #region static observer private static void setModified(String msg) { Notification.VERBOSE.modified, msg, ModelAdapter.Instance )); } #endregion #region persistance /// <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> public static void isAvailablePersistance() { DAOFactory.Instance.getConfigDao().testPersistance(); } #endregion #region tasks /// <summary> /// Get the tasks /// </summary> /// <returns>List of tasks</returns> public static List<Task> getTasks() { return DAOFactory.Instance.getTaskDao().loadTasks(); } /// <summary> /// Modify a task /// </summary> /// <param name="currentTask">task to update</param> public static void updateTask(Task currentTask) { if (DAOFactory.Instance.getTaskDao().updateTask(currentTask)) { setModified("updateTask"); } } /// <summary> /// Delete a task /// </summary> /// <param name="taskId">id of the task to delete</param> public static void deleteTask(int taskId) { if (DAOFactory.Instance.getTaskDao().deleteTask(taskId)) { setModified("deleteTask"); } } #endregion #region brol /// <summary> /// Unlock a brol /// </summary> /// <param name="id">(int) id of the brol to unlock</param> public static void unlockBrol(int id) { DAOFactory.Instance.getBrolDao().unlockBrol(id); } /// <summary> /// load a brol from the persistant layer /// </summary> /// <param name="id">(int) id of the brol to load</param> /// <param name="edit">(bool) true if load to modify (edit mode)</param> /// <returns>(Brol) brol</returns> public static Brol getBrol(int id, bool edit) { return DAOFactory.Instance.getBrolDao().loadBrol(id, edit); } /// <summary> /// Insert a brol (i.e. a film) into the persistant layer /// </summary> /// <param name="brol">(Brol) brol to insert</param> /// <returns>(int) new brol id</returns> public static int insertBrol(Brol brol) { int r = DAOFactory.Instance.getBrolDao().insertBrol(brol); setModified("insertBrol"); return r; } /// <summary> /// Delete a brol (i.e. a film) into the persistant layer /// </summary> /// <param name="brol">(Brol) brol to insert</param> /// <returns>(bool) true if deleted</returns> public static bool deleteBrol(Brol brol) { bool r = DAOFactory.Instance.getBrolDao().deleteBrol(brol); setModified("deleteBrol"); return r; } /// <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> public static bool updateBrol(Brol brol) { bool r = DAOFactory.Instance.getBrolDao().updateBrol(brol); setModified("updateBrol"); return r; } /// <summary> /// Get all brol types /// </summary> /// <returns>list of brol types</returns> public static List<BrolType> getBrolTypes() { return DAOFactory.Instance.getConfigDao().loadBrolTypes(); } /// <summary> /// Get categories for a brol type /// </summary> /// <param name="typeId">id of the brol type</param> /// <returns>list of categories</returns> public static List<BrolCategory> getCategories(int typeId) { return DAOFactory.Instance.getBrolDao().loadCategories(typeId); } #endregion #region roles public static ActorRole getUserRole() { return DAOFactory.Instance.getPersonDao().getUserRole(); } /// <summary> /// get all roles /// </summary> /// <returns>list of roles (ActorRole)</returns> public static List<ActorRole> getRoles() { return DAOFactory.Instance.getBrolDao().loadRoles(); } /// <summary> /// get the default role for a person /// </summary> /// <param name="person"></param> /// <returns></returns> public static ActorRole getDefaultRole(Person person) { return DAOFactory.Instance.getBrolDao().loadDefaultRole(person); } /// <summary> /// set the default role for a person /// </summary> /// <param name="person"></param> /// <param name="role"></param> public static void setDefaultRole(Person person, ActorRole role) { DAOFactory.Instance.getBrolDao().setDefaultRole(person, role); } /// <summary> /// get the roles for a person /// </summary> /// <param name="person">person for witch we want the roles</param> /// <returns>list of roles (ActorRole)</returns> public static List<ActorRole> getRoles(Person person) { return DAOFactory.Instance.getBrolDao().loadRoles(person); } /// <summary> /// get a roles with the id /// </summary> /// <param name="roleId">(int) id of the requested role</param> /// <returns>l(ActorRole) requested role</returns> public static ActorRole getRole(int roleId) { return DAOFactory.Instance.getBrolDao().loadRole(roleId); } /// <summary> /// get a roles with the name /// </summary> /// <param name="roleName">(string) name of the requested role</param> /// <returns>(ActorRole) requested role</returns> public static ActorRole loadRole(string roleName) { return DAOFactory.Instance.getBrolDao().loadRole(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> public static List<ActorRole> loadRoles(string roleName) { return DAOFactory.Instance.getBrolDao().loadRoles(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> public static bool insertRole(ActorRole role) { return DAOFactory.Instance.getBrolDao().insertRole(role); } #endregion #region persons #region get personsVos /// <summary> /// get a list of personsVos (value objects) for a role /// </summary> /// <param name="role">role where the persons may be</param> /// <returns>list of personsVos</returns> public static List<PersonLO> getPersonsVos(ActorRole role) { return DAOFactory.Instance.getPersonDao().loadPersonsVos(role); } /// <summary> /// get a list of personsVos (value objects) /// </summary> /// <returns>list of personsVos</returns> public static List<PersonLO> getPersonsVos() { return DAOFactory.Instance.getPersonDao().loadVos(); } /// <summary> /// Load a person from the persistant layer all persons matches (case insensitive) with lastName /// </summary> /// <param name="lastName">(String) lastName to match</param> /// <returns>List of persons with the same lastName</returns> public static List<PersonLO> getPersonsVos(String lastName) { return DAOFactory.Instance.getPersonDao().loadPersonsVos(lastName); } #endregion #region user /// <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> public static User getUser(int persId) { return DAOFactory.Instance.getPersonDao().loadUser(persId); } /// <summary> /// Insert or update a user /// </summary> /// <param name="user">user to insert or update</param> /// <returns>(int) id of the new person (-1 if a problem occurs in case of insert)</returns> public static int saveUser(User user) { return DAOFactory.Instance.getPersonDao().saveUser(user); } /// <summary> /// Delete a user /// </summary> /// <param name="person">user to delete</param> /// <param name="deletePerson">true if the person must also be deleted</param> public static void deleteUser(User user, bool deletePerson) { DAOFactory.Instance.getPersonDao().deleteUser(user, deletePerson); } #endregion #region getPerson public static List<Person> getOwners() { } /// <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> public static Person getPerson(int persId, bool edited) { return DAOFactory.Instance.getPersonDao().loadPerson(persId, edited); } /// <summary> /// Load a person from the persistant layer all persons matches (case insensitive) with lastName /// </summary> /// <param name="lastName">(String) lastName to match</param> /// <returns>List of persons with the same lastName</returns> public static List<Person> getPersons(String lastName) { return DAOFactory.Instance.getPersonDao().loadPersons(lastName); } #endregion #region person actions /// <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> public static int personExists(Person person) { return DAOFactory.Instance.getPersonDao().personExists(person); } /// <summary> /// Unlock a person (locked when loaded in update mode) /// </summary> /// <param name="personId">id of the locked person</param> public static bool unlockPerson(int personId) { return DAOFactory.Instance.getPersonDao().unlockPerson(personId); } /// <summary> /// Insert a new person /// </summary> /// <param name="person">person to insert</param> /// <returns>(int) id of the new person (-1 if a problem occurs)</returns> public static int insertPerson(Person person) { int persId = DAOFactory.Instance.getPersonDao().insertPerson(person); setModified("insertPerson"); return persId; } /// <summary> /// Insert a new person and add it in the bibliobrolusers group /// </summary> /// <param name="person">person to insert</param> /// <returns>(int) id of the new person (-1 if a problem occurs)</returns> public static int insertBibliobrolUser(Person person) { int persId = DAOFactory.Instance.getPersonDao().insertBibliobrolUser(person); setModified("insertPerson"); return persId; } /// <summary> /// Update a person /// </summary> /// <param name="person">person to update</param> public static void updatePerson(Person person) { DAOFactory.Instance.getPersonDao().updatePerson(person); setModified("updatePerson"); } /// <summary> /// Delete a person /// </summary> /// <param name="person">person to delete</param> public static void deletePerson(Person person) { DAOFactory.Instance.getPersonDao().deletePerson(person); setModified("deletePerson"); } /// <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> public static List<Person> getPersons(string lastName, string firstName) { return DAOFactory.Instance.getPersonDao().loadPersons(lastName, firstName); } #endregion #endregion #region brol actions /// <summary> /// Execute batch actions (to add a lot of brols) /// </summary> /// <param name="insertMediabrol">true if we must insert a mediabrol for each brol</param> public static void executeBrolBatch(bool insertMediabrol) { DAOFactory.Instance.getBrolDao().executeBatch(insertMediabrol); } #endregion #region MediaBrol /// <summary> /// load a datatable with selected fields of mediabrols /// </summary> /// <param name="mediabrolFields">fields of mediabrols to load</param> /// <param name="typeId">id of the brol type</param> /// <returns>datatable with mediabrols</returns> public static System.Data.DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> brolFields, int typeId) { return DAOFactory.Instance.getMediaBrolDao().loadDataTableVos(brolFields, typeId); } /// <summary> /// load a datatable with selected fields of mediabrols /// </summary> /// <param name="mediabrolFields">fields of mediabrols to load</param> /// <param name="typeId">id of the brol type</param> /// <param name="categories">categories where may be the mediabrols</param> /// <returns>datatable with mediabrols</returns> public static System.Data.DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> brolFields, int typeId, List<BrolCategory> categories) { return DAOFactory.Instance.getMediaBrolDao().loadDataTableVos(brolFields, typeId, categories); } /// <summary> /// load a datatable with selected fields of mediabrols /// </summary> /// <param name="mediabrolFields">fields of mediabrols to load</param> /// <param name="typeId">id of the brol type</param> /// <param name="categories">categories where may be the mediabrols</param> /// <param name="mediaId">id of the media</param> /// <returns>datatable with mediabrols</returns> public static System.Data.DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> brolFields, int typeId, List<BrolCategory> categories, int mediaId) { return DAOFactory.Instance.getMediaBrolDao().loadDataTableVos(brolFields, typeId, categories, mediaId); } /// <summary> /// load a datatable with selected fields of mediabrols /// </summary> /// <param name="mediabrolFields">fields of mediabrols to load</param> /// <param name="typeId">id of the brol type</param> /// <param name="categories">categories where may be the mediabrols</param> /// <param name="mediaId">id of the media</param> /// <param name="title"></param> /// <returns>datatable with mediabrols</returns> public static System.Data.DataTable loadDataTableVos(List<DAOUtils.MEDIABROL_FIELD> brolFields, int typeId, List<BrolCategory> categories, int mediaId, string title) { return DAOFactory.Instance.getMediaBrolDao().loadDataTableVos(brolFields, typeId, categories, mediaId, title); } /// <summary> /// load a mediabrol /// </summary> /// <param name="id">id of the mediabrol</param> /// <param name="editing">true if we will edit values (lock the record)</param> /// <returns>selected mediabrol</returns> public static MediaBrol loadMediaBrol(int id, bool editing) { return DAOFactory.Instance.getMediaBrolDao().loadMediaBrol(id, editing); } /// <summary> /// Load medias for a brol type /// </summary> /// <param name="typeId">id of the brol type</param> /// <returns>list of medias</returns> public static List<Media> loadMedias(int typeId) { return DAOFactory.Instance.getMediaBrolDao().loadMedias(typeId); } /// <summary> /// load qualities for a brol type /// </summary> /// <param name="brolType">id of the brol type</param> /// <returns>list of qualities</returns> public static List<Quality> loadQualities(BrolType brolType) { return DAOFactory.Instance.getMediaBrolDao().loadQualities(brolType); } /// <summary> /// Delete a mediabrol /// </summary> /// <param name="mediabrol">mediabrol to delete</param> public static void deleteMediaBrol(MediaBrol mediabrol) { DAOFactory.Instance.getMediaBrolDao().deleteMediaBrol(mediabrol); setModified("deleteMediaBrol"); } /// <summary> /// Delete a mediabrol /// </summary> /// <param name="mediabrolId">id of the mediabrol</param> /// <param name="title"></param> /// <param name="deleteBrol">true if we want also delete the associated brol</param> public static void deleteMediaBrol(int mediabrolId, String title, bool deleteBrol) { DAOFactory.Instance.getMediaBrolDao().deleteMediaBrol(mediabrolId, title, deleteBrol); setModified("deleteMediaBrol"); } /// <summary> /// Update a mediabrol /// </summary> /// <param name="mediabrol">mediabrol to update</param> public static void updateMediaBrol(MediaBrol mediabrol) { DAOFactory.Instance.getMediaBrolDao().updateMediaBrol(mediabrol); setModified("updateMediaBrol"); } /// <summary> /// Insert a mediabrol /// </summary> /// <param name="mediabrol">mediabrol to insert</param> /// <returns>id of the new mediabrol</returns> public static int insertMediaBrol(MediaBrol mediabrol) { int r = DAOFactory.Instance.getMediaBrolDao().insertMediaBrol(mediabrol); setModified("insertMediaBrol"); return r; } #endregion #region borrows #region modify borrows /// <summary> /// Start a borrow /// </summary> /// <param name="mediabrolId">id of the borrowed mediabrol</param> /// <param name="borrowerId">id of the borrower</param> public static bool startBorrow(int mediabrolId, int borrowerId) { if (DAOFactory.Instance.getMediaBrolDao().startBorrow(mediabrolId, borrowerId)) { setModified("startBorrow"); return true; } return false; } /// <summary> /// Stop a borrow (set end date) /// </summary> /// <param name="borrowId">id of the borrow</param> public static void stopBorrow(int borrowId) { DAOFactory.Instance.getMediaBrolDao().stopBorrow(borrowId); setModified("stopBorrow"); } /// <summary> /// Update borrow, set endDate to now /// </summary> /// <param name="mediabrol">(MediaBrol) borrowed mediabrol</param> /// <returns>(bool) true if stopped</returns> public static void stopBorrow(MediaBrol mediabrol) { DAOFactory.Instance.getMediaBrolDao().stopBorrow(mediabrol); setModified("stopBorrow"); } /// <summary> /// update a borrow /// </summary> /// <param name="borrow">borrow to update</param> public static void updateBorrow(Borrow borrow) { DAOFactory.Instance.getMediaBrolDao().updateBorrow(borrow); setModified("updateBorrow"); } /// <summary> /// Delete all borrows for a mediabrol /// </summary> /// <param name="mediabrolId">id of the mediabrol</param> /// <param name="forceDelete">set true to force to delete if the borrow is not closed</param> public static void cleanBorrows(int mediabrolId, bool forceDelete) { DAOFactory.Instance.getMediaBrolDao().cleanBorrows(mediabrolId, forceDelete); setModified("cleanBorrows"); } /// <summary> /// Delete a borrow /// </summary> /// <param name="selectedBorrowId">id of the borrow to delete</param> public static void cleanBorrow(int selectedBorrowId) { DAOFactory.Instance.getMediaBrolDao().cleanBorrow(selectedBorrowId); setModified("cleanBorrow"); } #endregion #region load borrows /// <summary> /// Load borrows for a mediabrol /// </summary> /// <param name="mediabrolId">id of the mediabrol</param> /// <param name="borrowFields">fields to load</param> /// <returns>datatable with borrows</returns> public static System.Data.DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields) { return ModelAdapter.loadBorrows(mediabrolId, borrowFields, 0); } /// <summary> /// Load borrows for a mediabrol /// </summary> /// <param name="mediabrolId">id of the mediabrol</param> /// <param name="borrowFields">fields to load</param> /// <param name="typeId"></param> /// <returns>datatable with borrows</returns> public static System.Data.DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields, int typeId) { return ModelAdapter.loadBorrows(mediabrolId, borrowFields, typeId, true); } /// <summary> /// Load borrows for a mediabrol /// </summary> /// <param name="mediabrolId">id of the mediabrol</param> /// <param name="borrowFields">fields to load</param> /// <param name="typeId"></param> /// <param name="closed"></param> /// <returns>datatable with borrows</returns> public static System.Data.DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields, int typeId, bool closed) { return ModelAdapter.loadBorrows(mediabrolId, borrowFields, typeId, closed, ""); } /// <summary> /// Load borrows for a mediabrol /// </summary> /// <param name="mediabrolId">id of the mediabrol</param> /// <param name="borrowFields">fields to load</param> /// <param name="typeId"></param> /// <param name="closed"></param> /// <param name="title"></param> /// <returns>datatable with borrows</returns> public static System.Data.DataTable loadBorrows(int mediabrolId, List<DAOUtils.BORROW_FIELD> borrowFields, int typeId, bool closed, string title) { return DAOFactory.Instance.getMediaBrolDao().loadBorrows(mediabrolId, borrowFields, typeId, closed, title); } /// <summary> /// Load a borrow /// </summary> /// <param name="borrowId">id of the borrow</param> /// <returns>selected borrow</returns> public static Borrow loadBorrow(int borrowId) { return DAOFactory.Instance.getMediaBrolDao().loadBorrow(borrowId); } #endregion #endregion #region import export /// <summary> /// Export mediabrols into an xml file /// </summary> /// <param name="mediabrolIds">ids of the mediabrols to export</param> /// <param name="path">Exportation file path</param> public static void exportXMLMediaBrol(int[] mediabrolIds, String path) { DAOFactory.Instance.getExporterDao().exportXMLMediaBrol(mediabrolIds, path); } /// <summary> /// Export mediabrols into a serialized file /// </summary> /// <param name="mediabrolIds">ids of the mediabrols to export</param> /// <param name="path">Exportation file path</param> /// <param name="exportMediabrol"></param> /// <param name="exportAllBrols"></param> /// <param name="anonymous"></param> public static void exportBinaryMediaBrol(int[] mediabrolIds, String path, bool exportMediabrol, bool exportAllBrols, bool anonymous) { DAOFactory.Instance.getExporterDao().exportBinaryMediaBrol(mediabrolIds, path, exportMediabrol, exportAllBrols, anonymous); } /// <summary> /// Export mediabrols into a serialized file /// </summary> /// <param name="mediabrolIds">ids of the mediabrols to export</param> /// <param name="path">Exportation file path</param> /// <param name="exportMediabrol"></param> /// <param name="exportAllBrols"></param> /// <param name="anonymous"></param> public static void exportBinaryMediaBrolTest(int[] mediabrolIds, String path, bool exportMediabrol, bool exportAllBrols, bool anonymous) { DAOFactory.Instance.getExporterDao().exportBinaryMediaBrolTest(mediabrolIds, path, exportMediabrol, exportAllBrols, anonymous); } /// <summary> /// Add an observer into the exporter (observable) observers list /// </summary> /// <param name="observer">observer to add</param> public static void addImportExporterObserver(IObserver observer) { DAOFactory.Instance.getExporterDao().addObserver(observer); DAOFactory.Instance.getImporterDao().addObserver(observer); } /// <summary> /// Remove an observer from the exporter (observable) observers list /// </summary> /// <param name="observer">observer to remove</param> public static void removeImportExporterObserver(IObserver observer) { DAOFactory.Instance.getExporterDao().removeObserver(observer); DAOFactory.Instance.getImporterDao().removeObserver(observer); } /// <summary> /// Import mediabrols objects from a serialized file /// </summary> /// <param name="path">path of the importation file</param> public static void importBinaryMediaBrol(String path) { DAOFactory.Instance.getImporterDao().importBinaryMediaBrol(path); setModified("importBinaryMediaBrol"); } /// <summary> /// Get a list of images from a serialized file /// </summary> /// <param name="path">path of the importation file</param> /// <returns>List of images</returns> public static List<System.Drawing.Image> importImages(string path) { return DAOFactory.Instance.getImporterDao().importImages(path); } /// <summary> /// Export mediabrols in an Excel Sheet, or in CSV file /// </summary> /// <param name="mediabrolIds">ids of the mediabrols to export</param> /// <param name="path">path of the exportation file</param> /// <param name="type">Type of the exportation (csv or sheet)</param> public static void exportExcelMediaBrol(int[] mediabrolIds, String path, int type) { DAOFactory.Instance.getExporterDao().exportExcelMediaBrol(mediabrolIds, path, type); } #endregion #region stats /// <summary> /// Get counters /// </summary> /// <returns>Counter object</returns> public static Counter getCounters() { return DAOFactory.Instance.getStatsDao().loadCounters(); } /// <summary> /// Get stats for actor roles /// </summary> /// <returns>Stat object</returns> public static Stat getStatsActorRoles() { return DAOFactory.Instance.getStatsDao().loadActorRoles(); } /// <summary> /// Get stats for current borrows /// </summary> /// <returns>Stat object</returns> public static Stat getStatsCurrentBorrows() { return DAOFactory.Instance.getStatsDao().loadCurrentBorrows(); } /// <summary> /// Get stats for all borrows /// </summary> /// <returns>Stat object</returns> public static Stat getStatsAllBorrows() { return DAOFactory.Instance.getStatsDao().loadAllBorrows(); } /// <summary> /// Get stats for brols by types /// </summary> /// <returns>Stat object</returns> public static Stat getStatsBrolTypes() { return DAOFactory.Instance.getStatsDao().loadBrolTypes(); } /// <summary> /// Get stats for mediabrols by types /// </summary> /// <returns>Stat object</returns> public static Stat getStatsMediaBrolTypes() { return DAOFactory.Instance.getStatsDao().loadMediaBrolTypes(); } #endregion #region serie /// <summary> /// Get the serie /// </summary> /// <returns>List of serie</returns> public static List<Serie> getSeries() { return DAOFactory.Instance.getSerieDao().loadSeries(); } /// <summary> /// Modify a Serie /// </summary> /// <param name="currentTask">Serie to update</param> public static bool updateSerie(Serie serie) { bool test = DAOFactory.Instance.getSerieDao().updateSerie(serie); if (test) { setModified("updateSerie"); } return test; } /// <summary> /// Delete a Serie /// </summary> /// <param name="taskId">id of the Serie to delete</param> public static bool deleteSerie(int serieId) { bool test = DAOFactory.Instance.getSerieDao().deleteSerie(serieId); if (test) { setModified("deleteSerie"); } return test; } #endregion } }
DAOUtils
Nous pouvons demander de ne charger que partiellement certains objets depuis notre système de persistance. Pour cette raison, nous allons créer certaines énumérations qui contiendront les attributs à charger. En interne, le DAO utilisera ces valeurs pour en déduire les actions à effectuer.
Code c# (DAOUtils.cs) (76 lignes)
using System; using System.Collections.Generic; using System.Text; namespace be.gaudry.bibliobrol.model.dao { public class DAOUtils { /// <summary> /// Fields of Borrow object that we want to load from persistant layer, independant from table structure, fields names, or other persistant structure. /// Mediabrol Id is allways loaded, no need to define here. /// </summary> public enum BORROW_FIELD { /// <summary> /// Id of the borrowed mediabrol. /// Be carrefull : using this id disallow using borrow id /// </summary> id, /// <summary> /// Name of the borrowed mediabrol /// </summary> name, /// <summary> /// Title of brol /// </summary> title, startDate, endDate, planDate, comment, /// <summary> /// Name of the borrower /// </summary> borrower, /// <summary> /// /// </summary> brolId, /// <summary> /// type name /// </summary> type }; /// <summary> /// Fields of Brol object that we want to load from persistant layer, independant from table structure, fields names, or other persistant structure. /// </summary> public enum BROL_FIELD { id, title, category, synopsis, actors, cotation, date, serie }; /// <summary> /// Fields of MediaBrol object that we want to load from persistant layer, independant from table structure, fields names, or other persistant structure. /// </summary> public enum MEDIABROL_FIELD { id, name, date, i_title, i_category, i_cotation, i_date, owner, brolId }; } }
Version en cache
21/11/2024 00:31:32 Cette version de la page est en cache (à la date du 21/11/2024 00:31: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-model-misc.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.