| QxOrm 1.1.8 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Private Attributes
qx::QxSoftDelete Class Reference
QxDao : QxOrm library database communication used by persistence engine (ORM - Object Relational Mapping)

qx::QxSoftDelete : soft delete (or logical delete) behavior to update a row into database (flag it as deleted) instead of delete it from database More...

`#include <QxSoftDelete.h>`

List of all members.

## Public Types
enum | mode { mode_flag, mode_date_time }
## Public Member Functions
| QxSoftDelete ()
| QxSoftDelete (const QString &sColumn)
| QxSoftDelete (const QString &sColumn, mode eMode)
| ~QxSoftDelete ()
QString | getTableName () const
QString | getColumnName () const
QString | getSqlQueryToFetch () const
QString | getSqlQueryToUpdate () const
QString | getSqlQueryToCreateTable () const
mode | getMode () const
void | setTableName (const QString &sTable)
void | setColumnName (const QString &sColumn)
void | setSqlQueryToFetch (const QString &s)
void | setSqlQueryToUpdate (const QString &s)
void | setSqlQueryToCreateTable (const QString &s)
void | setMode (mode eMode)
bool | isEmpty () const
QString | buildSqlTablePointName (const QString &sTable=QString()) const
QString | buildSqlQueryToFetch (const QString &sTable=QString()) const
QString | buildSqlQueryToUpdate () const
QString | buildSqlQueryToCreateTable () const
## Private Attributes
QString | m_sTable
| Table name where soft delete behavior is applied.
QString | m_sColumn
| Column name to store soft delete information.
QString | m_sSqlQueryToFetch
| Overrided user SQL query to fetch an item, if empty QxOrm library builds a default SQL query.
QString | m_sSqlQueryToUpdate
| Overrided user SQL query to update an item, if empty QxOrm library builds a default SQL query.
QString | m_sSqlQueryToCreateTable
| Overrided user SQL query to create table, if empty QxOrm library builds a default SQL query.
mode | m_eMode
| Soft delete mode : 'mode_flag' with a boolean column, 'mode_date_time' with a date-time column containing deletion date-time.

## Detailed Description

qx::QxSoftDelete : soft delete (or logical delete) behavior to update a row into database (flag it as deleted) instead of delete it from database

A soft delete doesn't remove rows from database (this is not a physical delete) : a new column is added to the table definition to flag a row as deleted or not. This column can contain a boolean (1 means row deleted, 0 or NULL means row not deleted), or can contain deletion date-time (if empty or NULL, row is not deleted). So you can reactivate a deleted row by setting NULL or empty value into database.

To define a soft delete behavior with QxOrm library, you have to use the class qx::QxSoftDelete in function mapping by class qx::register_class<T>. Here is an example with the class Bar containing 2 properties m_id and m_desc :

    namespace qx {
    template <> void register_class(QxClass<Bar> & t)
    {
       t.setSoftDelete(qx::QxSoftDelete("deleted_at"));

       t.id(& Bar::m_id, "id");
       t.data(& Bar::m_desc, "desc");
    }}

SQL queries builded by QxOrm library will take into account this soft delete parameter to add conditions (don't fetch deleted item, don't delete physically a row, etc.). For example, if you execute this code with the class Bar :

    Bar_ptr pBar; pBar.reset(new Bar());
    pBar->setId(5);
    QSqlError daoError = qx::dao::delete_by_id(pBar);     qAssert(! daoError.isValid());
    qx_bool bDaoExist = qx::dao::exist(pBar);             qAssert(! bDaoExist);
    daoError = qx::dao::delete_all<Bar>();                qAssert(! daoError.isValid());
    long lBarCount = qx::dao::count<Bar>();               qAssert(lBarCount == 0);
    daoError = qx::dao::destroy_all<Bar>();               qAssert(! daoError.isValid());

You will obtain following output trace :

    [QxOrm] sql query (93 ms) : UPDATE Bar SET deleted_at = '20110617115148615' WHERE id = :id
    [QxOrm] sql query (0 ms) : SELECT Bar.id AS Bar_id_0, Bar.deleted_at FROM Bar WHERE Bar.id = :id AND (Bar.deleted_at IS NULL OR Bar.deleted_at = '')
    [QxOrm] sql query (78 ms) : UPDATE Bar SET deleted_at = '20110617115148724'
    [QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM Bar WHERE (Bar.deleted_at IS NULL OR Bar.deleted_at = '')
    [QxOrm] sql query (110 ms) : DELETE FROM Bar

Note : To delete physically a row from database, you have to use followings functions : qx::dao::destroy_by_id() and qx::dao::destroy_all().

Other note : it is recommended to define into database an index on column deleted_at to optimize execution of SQL queries.

Definition at line 90 of file QxSoftDelete.h.

## Member Enumeration Documentation

enum qx::QxSoftDelete::mode

Enumerator:

  mode_flag |
  mode_date_time |

Definition at line 95 of file QxSoftDelete.h.

## Constructor & Destructor Documentation

qx::QxSoftDelete::QxSoftDelete | ( |  | ) | `[inline]`

Definition at line 108 of file QxSoftDelete.h.

qx::QxSoftDelete::QxSoftDelete | ( | const QString & | sColumn | ) | `[inline]`

Definition at line 109 of file QxSoftDelete.h.

qx::QxSoftDelete::QxSoftDelete | ( | const QString & | sColumn,
|  | mode | eMode
| ) |  | `[inline]`

Definition at line 110 of file QxSoftDelete.h.

qx::QxSoftDelete::~QxSoftDelete | ( |  | ) | `[inline]`

Definition at line 111 of file QxSoftDelete.h.

## Member Function Documentation

QString qx::QxSoftDelete::buildSqlQueryToCreateTable | ( |  | ) | const`[inline]`

Definition at line 154 of file QxSoftDelete.h.

QString qx::QxSoftDelete::buildSqlQueryToFetch | ( | const QString & | sTable = `QString()` | ) | const`[inline]`

Definition at line 135 of file QxSoftDelete.h.

QString qx::QxSoftDelete::buildSqlQueryToUpdate | ( |  | ) | const`[inline]`

Definition at line 145 of file QxSoftDelete.h.

QString qx::QxSoftDelete::buildSqlTablePointName | ( | const QString & | sTable = `QString()` | ) | const`[inline]`

Definition at line 129 of file QxSoftDelete.h.

QString qx::QxSoftDelete::getColumnName | ( |  | ) | const`[inline]`

Definition at line 114 of file QxSoftDelete.h.

mode qx::QxSoftDelete::getMode | ( |  | ) | const`[inline]`

Definition at line 118 of file QxSoftDelete.h.

QString qx::QxSoftDelete::getSqlQueryToCreateTable | ( |  | ) | const`[inline]`

Definition at line 117 of file QxSoftDelete.h.

QString qx::QxSoftDelete::getSqlQueryToFetch | ( |  | ) | const`[inline]`

Definition at line 115 of file QxSoftDelete.h.

QString qx::QxSoftDelete::getSqlQueryToUpdate | ( |  | ) | const`[inline]`

Definition at line 116 of file QxSoftDelete.h.

QString qx::QxSoftDelete::getTableName | ( |  | ) | const`[inline]`

Definition at line 113 of file QxSoftDelete.h.

bool qx::QxSoftDelete::isEmpty | ( |  | ) | const`[inline]`

Definition at line 127 of file QxSoftDelete.h.

void qx::QxSoftDelete::setColumnName | ( | const QString & | sColumn | ) | `[inline]`

Definition at line 121 of file QxSoftDelete.h.

void qx::QxSoftDelete::setMode | ( | mode | eMode | ) | `[inline]`

Definition at line 125 of file QxSoftDelete.h.

void qx::QxSoftDelete::setSqlQueryToCreateTable | ( | const QString & | s | ) | `[inline]`

Definition at line 124 of file QxSoftDelete.h.

void qx::QxSoftDelete::setSqlQueryToFetch | ( | const QString & | s | ) | `[inline]`

Definition at line 122 of file QxSoftDelete.h.

void qx::QxSoftDelete::setSqlQueryToUpdate | ( | const QString & | s | ) | `[inline]`

Definition at line 123 of file QxSoftDelete.h.

void qx::QxSoftDelete::setTableName | ( | const QString & | sTable | ) | `[inline]`

Definition at line 120 of file QxSoftDelete.h.

## Member Data Documentation

mode qx::QxSoftDelete::m_eMode`[private]`

Soft delete mode : 'mode_flag' with a boolean column, 'mode_date_time' with a date-time column containing deletion date-time.

Definition at line 104 of file QxSoftDelete.h.

QString qx::QxSoftDelete::m_sColumn`[private]`

Column name to store soft delete information.

Definition at line 100 of file QxSoftDelete.h.

QString qx::QxSoftDelete::m_sSqlQueryToCreateTable`[private]`

Overrided user SQL query to create table, if empty QxOrm library builds a default SQL query.

Definition at line 103 of file QxSoftDelete.h.

QString qx::QxSoftDelete::m_sSqlQueryToFetch`[private]`

Overrided user SQL query to fetch an item, if empty QxOrm library builds a default SQL query.

Definition at line 101 of file QxSoftDelete.h.

QString qx::QxSoftDelete::m_sSqlQueryToUpdate`[private]`

Overrided user SQL query to update an item, if empty QxOrm library builds a default SQL query.

Definition at line 102 of file QxSoftDelete.h.

QString qx::QxSoftDelete::m_sTable`[private]`

Table name where soft delete behavior is applied.

Definition at line 99 of file QxSoftDelete.h.

The documentation for this class was generated from the following file:

- D:/Dvlp/_Perso/QxOrm/include/QxDao/QxSoftDelete.h

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines