1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
| +Header
class SAMRequestEntity: public BaseEntity {
QX_REGISTER_FRIEND_CLASS( sdbs::ifs::SAMRequestEntity)
public:
IFSENTITY_DECL(SAMRequestEntity)
/**
* Enums & Consts
*/
...
/**
*
*/
static boost::shared_ptr<SAMRequestEntity> next(
const EntityConnectionPtr &conn);
...
/**
*
*/
static boost::shared_ptr<SAMRequestEntity> get(
const EntityConnectionPtr &conn, boost::uint64_t id);
/**
* Constructor
*/
SAMRequestEntity(boost::uint64_t id = 0);
/**
* Constructor
*/
SAMRequestEntity(const UserEntityPtr &user);
/**
* Destructor
*/
virtual ~SAMRequestEntity() {
}
/**
* Getters & Setters
*/
...
virtual void onAfterInsert(qx::dao::detail::IxDao_Helper * dao);
...
private:
/// attributes
boost::uint64_t m_id;
/// date & time
QDateTime m_datetime;
/// user id
boost::uint64_t m_user;
/// IP address
QString m_host;
/// SAM request status
boost::uint16_t m_status;
/// SAM request content
QString m_content;
/// processing date & time
QDateTime m_datetime_done;
};
/// data type for a HTTPSAMRequestEntity pointer
typedef boost::shared_ptr<SAMRequestEntity> SAMRequestEntityPtr;
typedef qx::QxCollection<QString, SAMRequestEntityPtr> SAMRequestEntityList;
typedef qx::QxCollectionIterator<QString, SAMRequestEntityPtr>
SAMRequestEntityIterator;
+ Source
...
QX_REGISTER_COMPLEX_CLASS_NAME_CPP_APP(sdbs::ifs::SAMRequestEntity, sdbs_ifs_SAMRequestEntity)
namespace qx {
template<>
void register_class(QxClass<sdbs::ifs::SAMRequestEntity> & t) {
t.setName("sam_request");
t.id(&sdbs::ifs::SAMRequestEntity::m_id, "sam_request_id", 1);
t.data(&sdbs::ifs::SAMRequestEntity::m_datetime, "sam_request_datetime", 1);
t.data(&sdbs::ifs::SAMRequestEntity::m_user, "sam_request_uid_id", 1);
t.data(&sdbs::ifs::SAMRequestEntity::m_datetime_done,
"sam_request_datetime_done", 1);
t.data(&sdbs::ifs::SAMRequestEntity::m_host, "sam_request_host", 1);
t.data(&sdbs::ifs::SAMRequestEntity::m_status, "sam_request_status", 1);
t.data(&sdbs::ifs::SAMRequestEntity::m_content, "sam_request_content", 1);
}
}
...
IFSENTITY_REGISTER(SAMRequestEntity)
/**
* Consts
*/
...
/**
*
*/
SAMRequestEntityPtr SAMRequestEntity::next(const EntityConnectionPtr &conn) {
qx::QxSqlQuery query(
QString::fromUtf8(
"WHERE sam_request.sam_request_status = :status LIMIT 1"));
query.bind(":status", STATUS_SAM_READY);
SAMRequestEntityList list;
QSqlError dao_error = qx::dao::fetch_by_query(query, list,
&conn->getConnection());
if (dao_error.isValid())
boost::throw_exception(
EntityQueryException(dao_error));
if (list.empty())
boost::throw_exception(EntityNotFoundException("No SAM request"));
return list.getFirst();
}
...
/**
* Constructor
*/
SAMRequestEntity::SAMRequestEntity(boost::uint64_t id) :
BaseEntity(), m_id(id), m_user(0), m_status(0) {
setLogger(PION_GET_LOGGER("sdbs.ifs.SAMRequestEntity"));
}
/**
* Constructor
*/
SAMRequestEntity::SAMRequestEntity(const UserEntityPtr &user) :
BaseEntity(), m_id(0), m_datetime(QDateTime::currentDateTime().toUTC()),
m_user(user->getId()), m_host("0.0.0.0"), m_status(STATUS_NONE) {
setLogger(PION_GET_LOGGER("sdbs.ifs.SAMRequestEntity"));
}
void SAMRequestEntity::onAfterInsert(qx::dao::detail::IxDao_Helper * dao) {
qx::QxSqlQuery query(QString::fromUtf8("WHERE oid = :oid"));
query.bind(":oid", (qlonglong) m_id);
SAMRequestEntityList list;
QSqlError dao_error =
qx::dao::fetch_by_query(query, list, &dao->database());
// If an error occured : transfert error to dao parameter
if (dao_error.isValid()) {
PION_LOG_ERROR(m_logger, "Failed to retrieve SAMRequestEntity[OID:" << m_id << "]");
dao->updateError(dao_error);
} else {
SAMRequestEntityPtr entity = list.getFirst();
m_id = entity->getId();
PION_LOG_DEBUG(m_logger, "SAMRequest #" << m_id);
}
} |
Partager