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

mmsimportpropertydao.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/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     /* do the insert */
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 /*TODO:return over stack!!!*/
00058     /* set the ID */
00059     data->setId(this->getMMSDBConnection()->getLastInsertedID());
00060 }
00061 
00062 void MMSImportPropertyDAO::update(MMSImportPropertyData *data) {
00063     /* do the update */
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     /* check if ID is set */
00073     if (data->getId()<0)
00074         /* no, have to save */
00075         save(data);
00076     else
00077         /* yes, have to update */
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     /* check if result is empty */
00101     if (rs.getCount()==0)
00102         throw MMSImportPropertyDAOError(0,"ImportProperties for PluginID " + iToStr(plugin->getId()) + " not found");
00103 
00104     /* fill the return data */
00105     return moveRecordToData(rs);
00106 }
00107 

Generated by doxygen