Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsplugindao.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmsconfig/mmsplugindao.h"
00034 #include "mmstools/mmstools.h"
00035 #include "mmsconfig/mmsconfigqueries.h"
00036 #include <iostream>
00037 #include <stdlib.h>
00038 
00039 MMSPluginDAO::MMSPluginDAO(IMMSDB *myConnection) {
00040     this->setMMSDBConnection(myConnection);
00041 }
00042 
00043 IMMSDB *MMSPluginDAO::getMMSDBConnection() {
00044     return this->dbConnection;
00045 }
00046 
00047 void MMSPluginDAO::setMMSDBConnection(IMMSDB *connection) {
00048     this->dbConnection = connection;
00049 }
00050 
00051 void MMSPluginDAO::deletePlugin(MMSPluginData *plugin) {
00052     // delete from Plugins where (id = 'plugin->id');
00053 }
00054 
00055 
00056 void MMSPluginDAO::save(MMSPluginData *data) {
00057     MMSRecordSet    rs;
00058 
00059     /* do the insert */
00060     this->getMMSDBConnection()->query(PLUGINDAO_SAVE(iToStr(data->getType()->getID()),
00061                                         data->getName(),
00062                                         data->getTitle(),
00063                                         data->getDescription(),
00064                                         data->getFilename(),
00065                                         data->getPath(),
00066                                         ((data->getActive())?"Y":"N"),
00067                                         data->getIcon(),
00068                                         data->getSelectedIcon(),
00069                                         data->getSmallIcon(),
00070                                         data->getSmallSelectedIcon(),
00071                                         iToStr((data->getCategory() != NULL ? data->getCategory()->getID() : 0)),
00072                                         iToStr(data->getOrderpos()),
00073                                         data->getVersion()));
00074 
00075 
00076     /* set the ID */
00077     data->setId(this->getMMSDBConnection()->getLastInsertedID());
00078 }
00079 
00080 void MMSPluginDAO::update(MMSPluginData *data) {
00081     /* do the update */
00082     this->getMMSDBConnection()->query(PLUGINDAO_UPDATE(
00083                                         data->getFilename(),
00084                                         ((data->getActive())?"Y":"N"),
00085                                         data->getDescription(),
00086                                         iToStr((data->getCategory() != NULL ? data->getCategory()->getID() : 0)),
00087                                         iToStr(data->getOrderpos()),
00088                                         iToStr(data->getId()),
00089                                         data->getVersion()));
00090 }
00091 
00092 void MMSPluginDAO::saveOrUpdate(MMSPluginData *data) {
00093     /* check if ID is set */
00094     if (data->getId()==-1)
00095         /* no, have to save */
00096         save(data);
00097     else
00098         /* yes, have to update */
00099         update(data);
00100 }
00101 
00102 void MMSPluginDAO::saveOrUpdate(vector<MMSPluginData *> dataList) {
00103     /* for each item */
00104     for (unsigned i=0;i<dataList.size();i++) {
00105         /* check if ID is set */
00106         if (dataList.at(i)->getId()<0)
00107             /* no, have to save */
00108             save(dataList.at(i));
00109         else
00110             /* yes, have to update */
00111             update(dataList.at(i));
00112     }
00113 }
00114 
00115 MMSPluginData *MMSPluginDAO::moveRecordToData(MMSRecordSet &rs) {
00116     MMSPluginData *data = NULL;
00117     data = new MMSPluginData();
00118 
00119     data->setId(atoi(rs["ID"].c_str()));
00120     data->setName(rs["PluginName"]);
00121     data->setTitle(rs["PluginTitle"]);
00122     data->setDescription(rs["PluginDescription"]);
00123     data->setFilename(rs["Filename"]);
00124     data->setPath(rs["PluginPath"]);
00125     data->setActive((rs["Active"] == "Y"));
00126     data->setIcon(rs["Icon"]);
00127     data->setSelectedIcon(rs["SelectedIcon"]);
00128     data->setSmallIcon(rs["SmallIcon"]);
00129     data->setOrderpos(atoi(rs["Orderpos"].c_str()));
00130     data->setVersion(rs["Version"]);
00131 
00132     return data;
00133 }
00134 
00135 MMSPluginData *MMSPluginDAO::findPluginByName(string name) {
00136     MMSPluginData   *plugin;
00137     MMSRecordSet    rs;
00138 
00139     /* select a plugin */
00140     this->getMMSDBConnection()->query(PLUGINDAO_F_PLUGIN_BY_NAME(name), &rs);
00141 
00142     /* check if result is empty */
00143     if (rs.getCount()==0)
00144         return NULL;
00145 
00146     /* set the values */
00147     plugin = moveRecordToData(rs);
00148     MMSPluginCategoryData *category = new MMSPluginCategoryData();
00149     MMSPluginTypeData *plugintype = new MMSPluginTypeData();
00150 
00151     if(!rs["CategoryID"].empty())
00152         category->setID(atoi(rs["CategoryID"].c_str()));
00153 
00154     if(!rs["CategoryName"].empty())
00155         category->setName(rs["CategoryName"]);
00156 
00157     if(!rs["PluginTypeID"].empty())
00158         plugintype->setID(atoi(rs["PluginTypeID"].c_str()));
00159 
00160     plugintype->setName(rs["PluginTypeName"]);
00161     plugin->setType(plugintype);
00162     plugin->setCategory(category);
00163 
00164     return plugin;
00165 
00166 }
00167 
00168 MMSPluginData *MMSPluginDAO::findPluginByID(int id) {
00169     MMSPluginData   *plugin;
00170     MMSRecordSet    rs;
00171 
00172     /* select a plugin */
00173     this->getMMSDBConnection()->query(PLUGINDAO_F_PLUGIN_BY_ID(iToStr(id)), &rs);
00174 
00175     /* check if result is empty */
00176     if (rs.getCount()==0)
00177         return NULL;
00178 
00179     /* set the values */
00180     plugin = moveRecordToData(rs);
00181     MMSPluginCategoryData *category = new MMSPluginCategoryData();
00182     MMSPluginTypeData *plugintype = new MMSPluginTypeData();
00183 
00184     if(!rs["CategoryID"].empty())
00185         category->setID(atoi(rs["CategoryID"].c_str()));
00186 
00187     if(!rs["CategoryName"].empty())
00188         category->setName(rs["CategoryName"]);
00189 
00190     if(!rs["PluginTypeID"].empty())
00191         plugintype->setID(atoi(rs["PluginTypeID"].c_str()));
00192 
00193     plugintype->setName(rs["PluginTypeName"]);
00194     plugin->setType(plugintype);
00195     plugin->setCategory(category);
00196 
00197     return plugin;
00198 }
00199 
00200 vector<MMSPluginData *> MMSPluginDAO::findAllPlugins(const bool inactiveToo){
00201     string                  query;
00202     vector<MMSPluginData *> pluginList;
00203     MMSRecordSet            rs;
00204 
00205     if(!inactiveToo)
00206         query = PLUGINDAO_FIND_ALL_ACTIVE_PLUGINS;
00207     else
00208         query = PLUGINDAO_FIND_ALL_PLUGINS;
00209 
00210     this->getMMSDBConnection()->query(query, &rs);
00211 
00212     /* check if result is empty */
00213     if (rs.getCount()==0) return pluginList;
00214 
00215     /* for each result record */
00216     do {
00217         /* set the values */
00218         MMSPluginData *plugin = moveRecordToData(rs);
00219         MMSPluginCategoryData *category = new MMSPluginCategoryData();
00220         MMSPluginTypeData *plugintype = new MMSPluginTypeData();
00221 
00222         if(!rs["CategoryID"].empty())
00223             category->setID(atoi(rs["CategoryID"].c_str()));
00224 
00225         if(!rs["CategoryName"].empty())
00226             category->setName(rs["CategoryName"]);
00227 
00228         if(!rs["PluginTypeID"].empty())
00229             plugintype->setID(atoi(rs["PluginTypeID"].c_str()));
00230 
00231         plugintype->setName(rs["PluginTypeName"]);
00232         plugin->setType(plugintype);
00233         plugin->setCategory(category);
00234 
00235         /* push to list */
00236         pluginList.push_back(plugin);
00237     } while(rs.next() == true);
00238 
00239     return pluginList;
00240 }
00241 
00242 vector<MMSPluginData *> MMSPluginDAO::findAllPluginsByCategory(MMSPluginCategoryData *category, const bool inactiveToo){
00243     string                  query;
00244     vector<MMSPluginData *> pluginList;
00245     MMSRecordSet            rs;
00246 
00247     // select all plugins
00248     if(!inactiveToo)
00249         query = PLUGINDAO_F_ACTIVE_PLUGINS_BY_CATEGORY(category->getName());
00250     else
00251         query = PLUGINDAO_F_ALL_PLUGINS_BY_CATEGORY(category->getName());
00252 
00253     this->getMMSDBConnection()->query(query, &rs);
00254 
00255     /* check if result is empty */
00256     if (rs.getCount()==0) return pluginList;
00257 
00258     /* for each result record */
00259     do {
00260         /* set the values */
00261         MMSPluginData *plugin = moveRecordToData(rs);
00262         MMSPluginTypeData *plugintype = new MMSPluginTypeData();
00263 
00264         plugintype->setID(atoi(rs["PluginTypeID"].c_str()));
00265         plugintype->setName(rs["PluginTypeName"]);
00266         plugin->setType(plugintype);
00267 
00268         /* push to list */
00269         pluginList.push_back(plugin);
00270     } while(rs.next() == true);
00271 
00272     return pluginList;
00273 }
00274 
00275 vector<MMSPluginData *> MMSPluginDAO::findAllPluginsByType(MMSPluginTypeData *type, const bool inactiveToo){
00276 
00277     return this->findAllPluginsByType((char *)type->getName().c_str(), inactiveToo);
00278 }
00279 
00280 vector<MMSPluginData *> MMSPluginDAO::findAllPluginsByType(string typeName, const bool inactiveToo) {
00281     string                  query;
00282     vector<MMSPluginData *> pluginList;
00283     MMSRecordSet            rs;
00284 
00285     // select all plugins
00286     if(!inactiveToo)
00287         query = PLUGINDAO_F_ACTIVE_PLUGINS_BY_TYPE(typeName);
00288     else
00289         query = PLUGINDAO_F_ALL_PLUGINS_BY_TYPE(typeName);
00290 
00291     this->getMMSDBConnection()->query(query, &rs);
00292 
00293     DEBUGMSG("MMSPluginDAO", "Found %d records.", rs.getCount());
00294 
00295     /* check if result is empty */
00296     if (rs.getCount()==0) return pluginList;
00297 
00298     // rewind the resultset
00299     rs.setRecordNum(0);
00300 
00301     /* for each result record */
00302     do {
00303         /* set the values */
00304         MMSPluginData *plugin = moveRecordToData(rs);
00305         MMSPluginTypeData *plugintype = new MMSPluginTypeData();
00306         MMSPluginCategoryData *plugincategory = new MMSPluginCategoryData();
00307 
00308         if(!rs["CategoryID"].empty())
00309             plugincategory->setID(atoi(rs["CategoryID"].c_str()));
00310 
00311         if(!rs["CategoryName"].empty())
00312             plugincategory->setName(rs["CategoryName"]);
00313 
00314         plugintype->setID(atoi(rs["PluginTypeID"].c_str()));
00315         plugintype->setName(rs["PluginTypeName"]);
00316         plugin->setType(plugintype);
00317         plugin->setCategory(plugincategory);
00318 
00319         /* push to list */
00320         pluginList.push_back(plugin);
00321     } while(rs.next() == true);
00322 
00323     return pluginList;
00324 }

Generated by doxygen