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

mmsimportsourcedao.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/mmsimportsourcedao.h"
00034 #include "mmstools/tools.h"
00035 #include <stdlib.h>
00036 
00037 MMSImportSourceDAO::MMSImportSourceDAO(IMMSDB *connection) {
00038     setMMSDBConnection(connection);
00039 }
00040 
00041 void MMSImportSourceDAO::setMMSDBConnection(IMMSDB *connection) {
00042     this->dbConnection = connection;
00043 }
00044 
00045 IMMSDB *MMSImportSourceDAO::getMMSDBConnection() {
00046     return this->dbConnection;
00047 }
00048 
00049 void MMSImportSourceDAO::deleteImportSource(MMSImportSourceData *source) {
00050     return;
00051 }
00052 
00053 void MMSImportSourceDAO::save(MMSImportSourceData *data) {
00054     /* do the insert */
00055     this->getMMSDBConnection()->query(
00056         "insert into ImportSource(PluginID,Name,Source,LifeTime) values('"
00057         + iToStr(data->getPluginId()) + "','"
00058         + data->getName() + "','"
00059         + data->getSource() + "','"
00060         + iToStr(data->getLifeTime()) + "')");
00061 /*TODO:return over stack!!!*/
00062     /* set the ID */
00063     data->setId(this->getMMSDBConnection()->getLastInsertedID());
00064 }
00065 
00066 void MMSImportSourceDAO::update(MMSImportSourceData *data) {
00067     /* do the update */
00068     this->getMMSDBConnection()->query(
00069         "update ImportSource set Name='" + data->getName() + "',"
00070         + "Source='" + data->getSource() + "',"
00071         + "LifeTime='" + iToStr(data->getLifeTime()) + "' "
00072         "where ID = '" + iToStr(data->getId()) + "'");
00073 }
00074 
00075 void MMSImportSourceDAO::saveOrUpdate(MMSImportSourceData *data) {
00076     /* check if ID is set */
00077     if (data->getId()<0)
00078         /* no, have to save */
00079         save(data);
00080     else
00081         /* yes, have to update */
00082         update(data);
00083 }
00084 
00085 void MMSImportSourceDAO::saveOrUpdate(vector<MMSImportSourceData *> dataList) {
00086     /* for each item */
00087     for (unsigned i=0;i<dataList.size();i++) {
00088         /* check if ID is set */
00089         if (dataList.at(i)->getId()<0)
00090             /* no, have to save */
00091             save(dataList.at(i));
00092         else
00093             /* yes, have to update */
00094             update(dataList.at(i));
00095     }
00096 }
00097 
00098 MMSImportSourceData *MMSImportSourceDAO::moveRecordToData(MMSRecordSet &rs) {
00099     MMSImportSourceData *data = new MMSImportSourceData();
00100 
00101     data->setId(atoi(rs["ID"].c_str()));
00102     data->setPluginId(atoi(rs["PluginID"].c_str()));
00103     data->setName(rs["Name"]);
00104     data->setSource(rs["Source"]);
00105     data->setLifeTime(atoi(rs["LifeTime"].c_str()));
00106 
00107     return data;
00108 }
00109 
00110 vector<MMSImportSourceData *> MMSImportSourceDAO::findImportSourcesByPlugin(MMSPluginData *plugin) {
00111     vector<MMSImportSourceData *>   sourceList;
00112     MMSRecordSet                    rs;
00113 
00114     /* do query */
00115     this->getMMSDBConnection()->query(
00116         "select * from ImportSource where PluginID = " + iToStr(plugin->getId()), &rs);
00117 
00118     /* check if result is empty */
00119     if (rs.getCount()==0) return sourceList;
00120 
00121     /* for each result record */
00122     do {
00123         /* set the values */
00124         MMSImportSourceData *source = new MMSImportSourceData;
00125         source = moveRecordToData(rs);
00126 
00127         /* push to list */
00128         sourceList.push_back(source);
00129     } while(rs.next() == true);
00130 
00131     return sourceList;
00132 }
00133 MMSImportSourceData *   MMSImportSourceDAO::findImportSourcesByID(int id) {
00134     MMSRecordSet                    rs;
00135 
00136     /* do query */
00137     this->getMMSDBConnection()->query(
00138         "select * from ImportSource where ID = " + iToStr(id),&rs);
00139 
00140     /* check if result is empty */
00141     if (rs.getCount()==0) return NULL;
00142 
00143     MMSImportSourceData *source = moveRecordToData(rs);
00144 
00145 
00146     return source;
00147 
00148 }
00149 
00150 MMSImportSourceData *   MMSImportSourceDAO::findImportSourcesByName(string name) {
00151     MMSRecordSet                    rs;
00152 
00153     /* do query */
00154     this->getMMSDBConnection()->query(
00155         "select * from ImportSource where Name = '" + name  + "'",&rs);
00156 
00157     /* check if result is empty */
00158     if (rs.getCount()==0) return NULL;
00159 
00160     MMSImportSourceData *source = moveRecordToData(rs);
00161 
00162 
00163     return source;
00164 }

Generated by doxygen