bool TSessionSqlObjectStore::store(TSession &session)
{
    TSqlORMapper<TSessionObject> mapper;
    TCriteria cri(TSessionObject::Id, TSql::Equal, session.id());
    TSessionObject so = mapper.findFirst(cri);

#ifndef TF_NO_DEBUG
    {
        QByteArray badummy;
        QDataStream dsdmy(&badummy, QIODevice::ReadWrite);
        dsdmy << *static_cast<const QVariantMap *>(&session);

        TSession dummy;
        dsdmy.device()->seek(0);
        dsdmy >> *static_cast<QVariantMap *>(&dummy);
        if (dsdmy.status() != QDataStream::Ok) {
            tSystemError("Failed to store a session into the cookie store. Must set objects that can be serialized.");
        }
    }
#endif

    QDataStream ds(&so.data, QIODevice::WriteOnly);
    ds << *static_cast<const QVariantMap *>(&session);

    if (ds.status() != QDataStream::Ok) {
        tSystemError("Failed to store session. Must set objects that can be serialized.");
        return false;
    }

    if (so.isNull()) {
        so.id = session.id();
        return so.create();
    }
    return so.update();
}
Пример #2
0
ParkAttendants ParkAttendants::get(int id, int lockRevision)
{
    TSqlORMapper<ParkAttendantsObject> mapper;
    TCriteria cri;
    cri.add(ParkAttendantsObject::Id, id);
    cri.add(ParkAttendantsObject::LockRevision, lockRevision);
    return ParkAttendants(mapper.findFirst(cri));
}
Пример #3
0
RefPackingDef RefPackingDef::get(const QString &createdBy, const QString &updatedBy)
{
    TCriteria cri;
    cri.add(RefPackingDefObject::CreatedBy, createdBy);
    cri.add(RefPackingDefObject::UpdatedBy, updatedBy);
    TSqlORMapper<RefPackingDefObject> mapper;
    return RefPackingDef(mapper.findFirst(cri));
}
Пример #4
0
ChatLog ChatLog::get(int id, int lockRevision)
{
    TSqlORMapper<ChatLogObject> mapper;
    TCriteria cri;
    cri.add(ChatLogObject::Id, id);
    cri.add(ChatLogObject::LockRevision, lockRevision);
    return ChatLog(mapper.findFirst(cri));
}
Пример #5
0
Vehicles Vehicles::get(int id, int lockRevision)
{
    TSqlORMapper<VehiclesObject> mapper;
    TCriteria cri;
    cri.add(VehiclesObject::Id, id);
    cri.add(VehiclesObject::LockRevision, lockRevision);
    return Vehicles(mapper.findFirst(cri));
}
Пример #6
0
UserVehicle UserVehicle::get(int id, int lockRevision)
{
    TSqlORMapper<UserVehicleObject> mapper;
    TCriteria cri;
    cri.add(UserVehicleObject::Id, id);
    cri.add(UserVehicleObject::LockRevision, lockRevision);
    return UserVehicle(mapper.findFirst(cri));
}
Пример #7
0
void ChatLog::removeOldLogs(int remainingCount)
{
    int del = count() - remainingCount;
    if (del > 0) {
        TSqlORMapper<ChatLogObject> mapper;
        mapper.setSortOrder(ChatLogObject::Id, Tf::DescendingOrder);
        auto log = mapper.findFirst();
        int maxId = log.id;

        TCriteria ctr(ChatLogObject::Id, TSql::LessEqual, maxId - remainingCount);
        mapper.removeAll(ctr);
    }
}
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;  
}
TSession TSessionSqlObjectStore::find(const QByteArray &id)
{
    QDateTime modified = QDateTime::currentDateTime().addSecs(-lifeTimeSecs());
    TSqlORMapper<TSessionObject> mapper;
    TCriteria cri;
    cri.add(TSessionObject::Id, TSql::Equal, id);
    cri.add(TSessionObject::UpdatedAt, TSql::GreaterEqual, modified);

    TSessionObject so = mapper.findFirst(cri);
    if (so.isNull()) {
        return TSession();
    }

    TSession session(id);
    QDataStream ds(&so.data, QIODevice::ReadOnly);
    ds >> *static_cast<QVariantMap *>(&session);

    if (ds.status() != QDataStream::Ok) {
        tSystemError("Failed to load a session from the sqlobject store.");
    }
    return session;
}
Пример #11
0
VMenusGroupMenuRole VMenusGroupMenuRole::get(int roleId, int menusGroupOrder, int menusGroupId, const QString &menusGroupCd, const QString &menusGroupNameZh, const QString &menusGroupNameEn, const QString &menusGroupTooltip, const QString &menusGroupDesc, int menuId, int menuOrder, const bool &breakBool, const QString &menuCd, const QString &menuNameZh, const QString &menuNameEn, const QString &menuTooltip, const QString &menuDesc, const QString &controller, const QString &action)
{
    TCriteria cri;
    cri.add(VMenusGroupMenuRoleObject::RoleId, roleId);
    cri.add(VMenusGroupMenuRoleObject::MenusGroupOrder, menusGroupOrder);
    cri.add(VMenusGroupMenuRoleObject::MenusGroupId, menusGroupId);
    cri.add(VMenusGroupMenuRoleObject::MenusGroupCd, menusGroupCd);
    cri.add(VMenusGroupMenuRoleObject::MenusGroupNameZh, menusGroupNameZh);
    cri.add(VMenusGroupMenuRoleObject::MenusGroupNameEn, menusGroupNameEn);
    cri.add(VMenusGroupMenuRoleObject::MenusGroupTooltip, menusGroupTooltip);
    cri.add(VMenusGroupMenuRoleObject::MenusGroupDesc, menusGroupDesc);
    cri.add(VMenusGroupMenuRoleObject::MenuId, menuId);
    cri.add(VMenusGroupMenuRoleObject::MenuOrder, menuOrder);
    cri.add(VMenusGroupMenuRoleObject::BreakBool, breakBool);
    cri.add(VMenusGroupMenuRoleObject::MenuCd, menuCd);
    cri.add(VMenusGroupMenuRoleObject::MenuNameZh, menuNameZh);
    cri.add(VMenusGroupMenuRoleObject::MenuNameEn, menuNameEn);
    cri.add(VMenusGroupMenuRoleObject::MenuTooltip, menuTooltip);
    cri.add(VMenusGroupMenuRoleObject::MenuDesc, menuDesc);
    cri.add(VMenusGroupMenuRoleObject::Controller, controller);
    cri.add(VMenusGroupMenuRoleObject::Action, action);
    TSqlORMapper<VMenusGroupMenuRoleObject> mapper;
    return VMenusGroupMenuRole(mapper.findFirst(cri));
}