| QxOrm 1.1.9 C++ Object Relational Mapping library

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

- File List
- File Members

QxSession.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** http://www.qxorm.com/
    00004 ** http://sourceforge.net/projects/qxorm/
    00005 ** Original file by Lionel Marty
    00006 **
    00007 ** This file is part of the QxOrm library
    00008 **
    00009 ** This software is provided 'as-is', without any express or implied
    00010 ** warranty. In no event will the authors be held liable for any
    00011 ** damages arising from the use of this software.
    00012 **
    00013 ** GNU Lesser General Public License Usage
    00014 ** This file must be used under the terms of the GNU Lesser
    00015 ** General Public License version 2.1 as published by the Free Software
    00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the
    00017 ** packaging of this file.  Please review the following information to
    00018 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00020 **
    00021 ** If you have questions regarding the use of this file, please contact :
    00022 ** contact@qxorm.com
    00023 **
    00024 ****************************************************************************/
    00025
    00026 #ifndef _QX_DAO_SESSION_H_
    00027 #define _QX_DAO_SESSION_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00040 #include <boost/noncopyable.hpp>
    00041
    00042 #include <QtSql/qsqldatabase.h>
    00043 #include <QtSql/qsqlquery.h>
    00044 #include <QtSql/qsqlerror.h>
    00045 #include <QtSql/qsqldriver.h>
    00046
    00047 #include <QtCore/qlist.h>
    00048
    00049 #include <QxDao/QxSqlError.h>
    00050
    00051 namespace qx {
    00052
    00083 class QX_DLL_EXPORT QxSession : private boost::noncopyable
    00084 {
    00085
    00086 private:
    00087
    00088    QSqlDatabase m_database;
    00089    QList<QSqlError> m_lstSqlError;
    00090    bool m_bTransaction;
    00091    bool m_bThrowable;
    00092    bool m_bThrowInEvent;
    00093    bool m_bAutoOpenClose;
    00094
    00095 public:
    00096
    00097    QxSession();
    00098    QxSession(const QSqlDatabase & database);
    00099    QxSession(const QSqlDatabase & database, bool bOpenTransaction);
    00100    QxSession(const QSqlDatabase & database, bool bOpenTransaction, bool bThrowable);
    00101    virtual ~QxSession() { close(); }
    00102
    00103    inline bool isThrowable() const              { return m_bThrowable; }
    00104    inline bool isOpened() const                 { return m_bTransaction; }
    00105    inline bool isValid() const                  { return (m_lstSqlError.count() <= 0); }
    00106    inline QSqlError firstError() const          { return ((m_lstSqlError.count() > 0) ? m_lstSqlError.first() : QSqlError()); }
    00107    inline QSqlError lastError() const           { return ((m_lstSqlError.count() > 0) ? m_lstSqlError.last() : QSqlError()); }
    00108    inline QList<QSqlError> allErrors() const    { return m_lstSqlError; }
    00109    inline const QSqlDatabase * database() const { return (& m_database); }
    00110    inline QSqlDatabase * database()             { return (& m_database); }
    00111
    00112    bool open();
    00113    bool close();
    00114    bool commit();
    00115    bool rollback();
    00116
    00117    QxSession & operator+= (const QSqlError & err);
    00118
    00119 private:
    00120
    00121    void appendSqlError(const QSqlError & err);
    00122    void clear();
    00123
    00124 };
    00125
    00126 } // namespace qx
    00127
    00128 #endif // _QX_DAO_SESSION_H_

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines