bool TSessionSqlObjectStore::store(TSession &session) { TSqlORMapper<TSessionObject> mapper; TCriteria cri(TSessionObject::Id, TSql::Equal, session.id()); TSessionObject so = mapper.findFirst(cri); QDataStream ds(&so.data, QIODevice::WriteOnly); ds << *static_cast<const QVariantHash *>(&session); if (so.isEmpty()) { so.id = session.id(); return so.create(); } return so.update(); }
TSession TSessionSqlObjectStore::find(const QByteArray &id, const QDateTime &modified) { TSqlORMapper<TSessionObject> mapper; TCriteria cri; cri.add(TSessionObject::Id, TSql::Equal, id); cri.add(TSessionObject::UpdatedAt, TSql::GreaterEqual, modified); TSessionObject sess = mapper.findFirst(cri); if (sess.isEmpty()) return TSession(); TSession result(id); QDataStream ds(&sess.data, QIODevice::ReadOnly); ds >> *static_cast<QVariantHash *>(&result); return result; }