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

mmspluginpropertydao.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/mmspluginpropertydao.h"
00034 #include "mmstools/tools.h"
00035 #include "mmstools/mmslogger.h"
00036 #include "mmsconfig/mmsconfigqueries.h"
00037 #include <stdlib.h>
00038 
00039 MMSPluginPropertyDAO::MMSPluginPropertyDAO(IMMSDB *myConnection) {
00040     MMSPluginPropertyDAO::setMMSDBConnection(myConnection);
00041 }
00042 
00043 IMMSDB *MMSPluginPropertyDAO::getMMSDBConnection() {
00044     return this->dbConnection;
00045 }
00046 
00047 void MMSPluginPropertyDAO::setMMSDBConnection(IMMSDB *connection) {
00048     this->dbConnection = connection;
00049 }
00050 
00051 void MMSPluginPropertyDAO::saveOrUpdate(vector<MMSPluginData *> plugins) {
00052     for(vector<MMSPluginData *>::iterator it = plugins.begin();it!=plugins.end();it++)
00053         this->saveOrUpdate(*it);
00054 }
00055 
00056 void MMSPluginPropertyDAO::saveOrUpdate(MMSPluginData *plugin) {
00057     string                      query;
00058     vector<MMSPropertyData *>   pluginPropertyList;
00059     MMSRecordSet                rs;
00060     MMSLogger                   logger;
00061     string                      tmpValList = "";
00062 
00063     vector <string>             vallist;
00064 
00065     pluginPropertyList = plugin->getProperties();
00066     for(vector<MMSPropertyData *>::iterator it = pluginPropertyList.begin(); it!=pluginPropertyList.end();it++) {
00067         query = "select * from PluginProperties where PluginID = '" +
00068                 iToStr(plugin->getId())  + "' and Parameter = '" +
00069                 (*it)->getParameter() + "';";
00070 
00071         this->getMMSDBConnection()->query(query, &rs);
00072         /* check if result is empty */
00073         if (rs.getCount()==0) {
00074             //insert...
00075 
00076             //create value list string
00077             vector<string> vallist = (*it)->getVallist();
00078             string valliststr = "";
00079             for(vector<string>::iterator val = vallist.begin();val!=vallist.end();val++) {
00080                 valliststr = valliststr + cToStr((*it)->getSeparator()) + *val;
00081             }
00082 
00083             query = "insert into PluginProperties (Parameter,Value,TYPE,MAX,MIN,VALLIST,SEPARATOR,PluginID) VALUES('" +
00084                     (*it)->getParameter() + "','" +
00085                     (*it)->getValue() + "','" +
00086                     (*it)->getType() + "','" +
00087                     iToStr((*it)->getMax()) + "','" +
00088                     iToStr((*it)->getMin()) + "','" +
00089                     valliststr + "','" +
00090                     cToStr((*it)->getSeparator()) + "','" +
00091                     iToStr(plugin->getId()) + "');";
00092 
00093                     this->getMMSDBConnection()->query(query);
00094         }
00095         else {
00096             //update...
00097 
00098             //create value list string
00099             vector<string> vallist = (*it)->getVallist();
00100             string valliststr = "";
00101             for(vector<string>::iterator val = vallist.begin();val!=vallist.end();val++) {
00102                 valliststr = valliststr + cToStr((*it)->getSeparator()) + *val;
00103             }
00104 
00105             query = "update PluginProperties Set Value='" +
00106                     (*it)->getValue() +
00107                     "',TYPE='" + (*it)->getType() +
00108                     "',MAX='" + iToStr((*it)->getMax()) +
00109                     "',MIN='" + iToStr((*it)->getMin()) +
00110                     "',VALLIST='" + valliststr +
00111                     "',SEPARATOR='" + cToStr((*it)->getSeparator()) +
00112                     "' where PluginID='" + iToStr(plugin->getId()) +
00113                     "' and Parameter='" + (*it)->getParameter() + "';";
00114 
00115                     this->getMMSDBConnection()->query(query);
00116         }
00117     }
00118 }
00119 
00120 
00121 vector <MMSPropertyData *> MMSPluginPropertyDAO::findAllPluginPropertiesByPlugin(MMSPluginData *plugin)
00122 {
00123     string                      query;
00124     vector<MMSPropertyData *>   pluginPropertyList;
00125     MMSRecordSet                rs;
00126     string                      tmpValList = "";
00127 
00128     vector <string>             vallist;
00129     size_t                      tmpBegin;
00130     size_t                      tmpEnd;
00131 
00132     this->getMMSDBConnection()->query(PLUGINPROPERTYDAO_FIND_ALL_PLUGIN_PROPERTIES_BY_PLUGIN(iToStr(plugin->getId())), &rs);
00133         /* check if result is empty */
00134 
00135     if (rs.getCount()==0) {
00136         return pluginPropertyList;
00137     }
00138 
00139     /* for each result record */
00140     do {
00141         /* set the values */
00142         MMSPropertyData *pluginProperty = new MMSPropertyData;
00143         if(!rs["ID"].empty())
00144             pluginProperty->setID(atoi(rs["ID"].c_str()));
00145         pluginProperty->setParameter(rs["Parameter"]);
00146         pluginProperty->setValue(rs["Value"]);
00147         pluginProperty->setType(rs["TYPE"]);
00148         if(!rs["MAX"].empty())
00149             pluginProperty->setMax(atoi(rs["MAX"].c_str()));
00150         else
00151             pluginProperty->setMax(0);
00152         if(!rs["MIN"].empty())
00153             pluginProperty->setMin(atoi(rs["MIN"].c_str()));
00154         else
00155             pluginProperty->setMin(0);
00156 
00157         if(!rs["SEPARATOR"].empty())
00158             pluginProperty->setSeparator(rs["SEPARATOR"].c_str()[0]);
00159 
00160         tmpValList = rs["VALLIST"];
00161 
00162         tmpBegin = 0;
00163 
00164         while ((tmpEnd = tmpValList.find(pluginProperty->getSeparator(), tmpBegin)) != string::npos) {
00165             vallist.push_back(tmpValList.substr(tmpBegin, tmpEnd - tmpBegin));
00166             tmpBegin = tmpEnd + 1;
00167         }
00168         vallist.push_back(tmpValList.substr(tmpBegin, tmpValList.length() - tmpBegin));
00169 
00170         pluginProperty->setVallist(vallist);
00171         vallist.clear();
00172 
00173         /* push to list */
00174         pluginPropertyList.push_back(pluginProperty);
00175     } while(rs.next() == true);
00176 
00177     return pluginPropertyList;
00178 }

Generated by doxygen