00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00073 if (rs.getCount()==0) {
00074
00075
00076
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
00097
00098
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
00134
00135 if (rs.getCount()==0) {
00136 return pluginPropertyList;
00137 }
00138
00139
00140 do {
00141
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
00174 pluginPropertyList.push_back(pluginProperty);
00175 } while(rs.next() == true);
00176
00177 return pluginPropertyList;
00178 }