qof-be-utils.h

Go to the documentation of this file.
00001 /********************************************************************\
00002  * qof-be-utils.h: api for data storage backend                     *
00003  * This program is free software; you can redistribute it and/or    *
00004  * modify it under the terms of the GNU General Public License as   *
00005  * published by the Free Software Foundation; either version 2 of   *
00006  * the License, or (at your option) any later version.              *
00007  *                                                                  *
00008  * This program is distributed in the hope that it will be useful,  *
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00011  * GNU General Public License for more details.                     *
00012  *                                                                  *
00013  * You should have received a copy of the GNU General Public License*
00014  * along with this program; if not, contact:                        *
00015  *                                                                  *
00016  * Free Software Foundation           Voice:  +1-617-542-5942       *
00017  * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
00018  * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
00019  *                                                                  *
00020 \********************************************************************/
00035 #ifndef QOF_BE_UTILS_H
00036 #define QOF_BE_UTILS_H
00037 
00038 #include "gnc-trace.h"
00039 #include "gnc-engine-util.h"
00040 #include "qofbackend-p.h"
00041 #include "qofbook.h"
00042 #include "qofinstance.h"
00043 
00054 #define QOF_BEGIN_EDIT(inst)                                        \
00055   QofBackend * be;                                                  \
00056   if (!(inst)) return;                                              \
00057                                                                     \
00058   (inst)->editlevel++;                                              \
00059   if (1 < (inst)->editlevel) return;                                \
00060                                                                     \
00061   if (0 >= (inst)->editlevel)                                       \
00062   {                                                                 \
00063     PERR ("unbalanced call - resetting (was %d)", (inst)->editlevel); \
00064     (inst)->editlevel = 1;                                          \
00065   }                                                                 \
00066   ENTER ("(inst=%p)", (inst));                                      \
00067                                                                     \
00068   /* See if there's a backend.  If there is, invoke it. */          \
00069   be = qof_book_get_backend ((inst)->book);                         \
00070     if (be && qof_backend_begin_exists((be))) {                     \
00071      qof_backend_run_begin((be), (inst));                           \
00072   } else {                                                          \
00073      /* We tried and failed to start transaction! */                \
00074      (inst)->dirty = TRUE;                                          \
00075   }                                                                 \
00076   LEAVE (" ");
00077 
00083 gboolean qof_begin_edit(QofInstance *inst);
00084 
00099 #define QOF_COMMIT_EDIT_PART1(inst) {                            \
00100   if (!(inst)) return;                                           \
00101                                                                  \
00102   (inst)->editlevel--;                                           \
00103   if (0 < (inst)->editlevel) return;                             \
00104                                                                  \
00105   /* The pricedb sufffers from delayed update...     */          \
00106   /* This may be setting a bad precedent for other types, I fear. */ \
00107   /* Other types probably really should handle begin like this. */ \
00108   if ((-1 == (inst)->editlevel) && (inst)->dirty)                \
00109   {                                                              \
00110     QofBackend * be;                                             \
00111     be = qof_book_get_backend ((inst)->book);                    \
00112     if (be && qof_backend_begin_exists((be))) {                  \
00113      qof_backend_run_begin((be), (inst));                        \
00114     }                                                            \
00115     (inst)->editlevel = 0;                                       \
00116   }                                                              \
00117   if (0 > (inst)->editlevel)                                     \
00118   {                                                              \
00119     PERR ("unbalanced call - resetting (was %d)", (inst)->editlevel); \
00120     (inst)->editlevel = 0;                                       \
00121   }                                                              \
00122   ENTER ("(inst=%p) dirty=%d do-free=%d",                        \
00123             (inst), (inst)->dirty, (inst)->do_free);             \
00124 }
00125 
00131 gboolean qof_commit_edit(QofInstance *inst);
00132 
00146 #define QOF_COMMIT_EDIT_PART2(inst,on_error,on_done,on_free) {   \
00147   QofBackend * be;                                               \
00148                                                                  \
00149   /* See if there's a backend.  If there is, invoke it. */       \
00150   be = qof_book_get_backend ((inst)->book);                      \
00151   if (be && qof_backend_commit_exists((be)))                     \
00152   {                                                              \
00153     QofBackendError errcode;                                     \
00154                                                                  \
00155     /* clear errors */                                           \
00156     do {                                                         \
00157       errcode = qof_backend_get_error (be);                      \
00158     } while (ERR_BACKEND_NO_ERR != errcode);                     \
00159                                                                  \
00160     qof_backend_run_commit((be), (inst));                        \
00161     errcode = qof_backend_get_error (be);                        \
00162     if (ERR_BACKEND_NO_ERR != errcode)                           \
00163     {                                                            \
00164       /* XXX Should perform a rollback here */                   \
00165       (inst)->do_free = FALSE;                                   \
00166                                                                  \
00167       /* Push error back onto the stack */                       \
00168       qof_backend_set_error (be, errcode);                       \
00169       (on_error)((inst), errcode);                               \
00170     }                                                            \
00171     /* XXX the backend commit code should clear dirty!! */       \
00172     (inst)->dirty = FALSE;                                       \
00173   }                                                              \
00174   (on_done)(inst);                                               \
00175                                                                  \
00176   LEAVE ("inst=%p, dirty=%d do-free=%d",                         \
00177             (inst), (inst)->dirty, (inst)->do_free);             \
00178   if ((inst)->do_free) {                                         \
00179      (on_free)(inst);                                            \
00180      return;                                                     \
00181   }                                                              \
00182 }
00183 
00184 #endif /* QOF_BE_UTILS_H */
00185 

Generated on Fri Oct 21 15:49:54 2005 for QOF by  doxygen 1.4.5