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/mmsimportpropertydao.h"
00034 #include "mmstools/tools.h"
00035 #include <stdlib.h>
00036
00037 MMSImportPropertyDAO::MMSImportPropertyDAO(IMMSDB *connection) {
00038 setMMSDBConnection(connection);
00039 }
00040
00041 void MMSImportPropertyDAO::setMMSDBConnection(IMMSDB *connection) {
00042 this->dbConnection = connection;
00043 }
00044
00045 IMMSDB *MMSImportPropertyDAO::getMMSDBConnection() {
00046 return this->dbConnection;
00047 }
00048
00049 void MMSImportPropertyDAO::save(MMSImportPropertyData *data) {
00050
00051 this->getMMSDBConnection()->query(
00052 "insert into ImportProperties(PluginID,onStartUp,Time,Interval) values('"
00053 + iToStr(data->getPluginId()) + "','"
00054 + ((data->getOnStartUp())?"Y":"N") + "','"
00055 + iToStr(data->getTime()) + "','"
00056 + iToStr(data->getInterval()) + "')");
00057
00058
00059 data->setId(this->getMMSDBConnection()->getLastInsertedID());
00060 }
00061
00062 void MMSImportPropertyDAO::update(MMSImportPropertyData *data) {
00063
00064 this->getMMSDBConnection()->query(
00065 "update ImportProperties set Time='" + iToStr(data->getTime()) + "',"
00066 + "onStartUp='" + ((data->getOnStartUp())?"Y":"N") + "',"
00067 + "Interval='" + iToStr(data->getInterval()) + "' "
00068 "where ID = '" + iToStr(data->getId()) + "'");
00069 }
00070
00071 void MMSImportPropertyDAO::saveOrUpdate(MMSImportPropertyData *data) {
00072
00073 if (data->getId()<0)
00074
00075 save(data);
00076 else
00077
00078 update(data);
00079 }
00080
00081 MMSImportPropertyData *MMSImportPropertyDAO::moveRecordToData(MMSRecordSet &rs) {
00082 MMSImportPropertyData *data = new MMSImportPropertyData();
00083
00084 data->setId(atoi(rs["ID"].c_str()));
00085 data->setPluginId(atoi(rs["PluginID"].c_str()));
00086 data->setOnStartUp((rs["onStartUp"]=="Y"));
00087 data->setTime(atoi(rs["Time"].c_str()));
00088 data->setInterval(atoi(rs["Interval"].c_str()));
00089
00090 return data;
00091 }
00092
00093 MMSImportPropertyData *MMSImportPropertyDAO::findImportPropertyByPlugin(MMSPluginData *plugin) {
00094 MMSRecordSet rs;
00095
00096 this->getMMSDBConnection()->query(
00097 "select * from ImportProperties where PluginID = " + iToStr(plugin->getId()),
00098 &rs);
00099
00100
00101 if (rs.getCount()==0)
00102 throw MMSImportPropertyDAOError(0,"ImportProperties for PluginID " + iToStr(plugin->getId()) + " not found");
00103
00104
00105 return moveRecordToData(rs);
00106 }
00107