Changeset 0d995ed for src/mvc/event.cpp


Ignore:
Timestamp:
05/05/10 15:57:37 (12 years ago)
Author:
kirilma <kirilma@…>
Branches:
master, qt5
Children:
508de33
Parents:
58eb7cc
Message:

refactor: cache whole Room object in Event

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/event.cpp

    r58eb7cc r0d995ed  
    3939
    4040Event::Event() :
    41     mRoomId( 0 )
     41    room_(NULL)
    4242{
    4343}
     
    120120}
    121121
    122 QString Event::room()
    123 {
    124     if ( mRoomName.isEmpty() )
    125     {
    126         QSqlQuery query;
    127         // TODO: conference ID isn't used here
    128         query.prepare("SELECT name FROM room WHERE id = :roomId");
    129         query.bindValue(":roomId", roomId());
    130         query.exec();
    131         // TODO: handle qeury error
    132         //qDebug() << query.lastError();
    133         if(query.next())
    134             mRoomName = query.record().value("name").toString();
    135         else
    136             mRoomName = QString("not-available");
    137     }
    138     return mRoomName;
    139 }
    140 
    141 int Event::roomId()
    142 {
    143     if ( mRoomId == 0 )
     122Room* Event::room()
     123{
     124    if (room_ == NULL)
    144125    {
    145126        QSqlQuery query;
     
    155136            throw OrmNoObjectException();
    156137        }
    157         mRoomId = query.record().value("xid_room").toInt();
    158     }
    159     return mRoomId;
     138        int id = query.record().value("xid_room").toInt();
     139        room_ = new Room(Room::retrieve(id));
     140    }
     141    return room_;
     142}
     143
     144QString Event::roomName()
     145{
     146    return room()->name();
     147}
     148
     149int Event::roomId()
     150{
     151    return room()->id();
    160152}
    161153
Note: See TracChangeset for help on using the changeset viewer.