From 947b76cda8b28f8b07e30977ca1c902ed8736dbe Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 6 Sep 2013 08:16:39 +0200 Subject: database: Add interface to handle transactions --- src/libstrongswan/database/database.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/libstrongswan/database/database.h') diff --git a/src/libstrongswan/database/database.h b/src/libstrongswan/database/database.h index d46fc3d34..77d4da144 100644 --- a/src/libstrongswan/database/database.h +++ b/src/libstrongswan/database/database.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2013 Tobias Brunner * Copyright (C) 2008 Martin Willi * Hochschule fuer Technik Rapperswil * @@ -102,7 +103,7 @@ struct database_t { enumerator_t* (*query)(database_t *this, char *sql, ...); /** - * Execute a query which dows not return rows, such as INSERT. + * Execute a query which does not return rows, such as INSERT. * * @param rowid pointer to write inserted AUTO_INCREMENT row ID, or NULL * @param sql sql string, containing '?' placeholders @@ -111,6 +112,36 @@ struct database_t { */ int (*execute)(database_t *this, int *rowid, char *sql, ...); + /** + * Start a transaction. + * + * @note Either commit() or rollback() has to be called to end the + * transaction. + * @note Transactions are thread-specific. So commit()/rollbak() has to be + * called from the same thread. + * @note While this method can be called multiple times (commit/rollback + * have to be called an equal number of times) real nested transactions are + * not supported. So if any if the "inner" transactions are rolled back + * the outer most transaction is rolled back. + * + * @return TRUE on success + */ + bool (*transaction)(database_t *this); + + /** + * Commit all changes made during the current transaction. + * + * @return TRUE on success + */ + bool (*commit)(database_t *this); + + /** + * Rollback/revert all changes made during the current transaction. + * + * @return TRUE on success + */ + bool (*rollback)(database_t *this); + /** * Get the database implementation type. * -- cgit v1.2.3 From b283a6e9efd2ff16ec5b189435604b0d82d714cd Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 10 Oct 2013 10:58:40 +0200 Subject: database: Add support for serializable transactions --- src/libstrongswan/database/database.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/libstrongswan/database/database.h') diff --git a/src/libstrongswan/database/database.h b/src/libstrongswan/database/database.h index 77d4da144..ad5ccf95e 100644 --- a/src/libstrongswan/database/database.h +++ b/src/libstrongswan/database/database.h @@ -115,6 +115,10 @@ struct database_t { /** * Start a transaction. * + * A serializable transaction forces a strict separation between other + * transactions. Due to the performance overhead they should only be used + * in certain situations (e.g. SELECT->INSERT|UPDATE). + * * @note Either commit() or rollback() has to be called to end the * transaction. * @note Transactions are thread-specific. So commit()/rollbak() has to be @@ -124,9 +128,10 @@ struct database_t { * not supported. So if any if the "inner" transactions are rolled back * the outer most transaction is rolled back. * - * @return TRUE on success + * @param serializable TRUE to create a serializable transaction + * @return TRUE on success */ - bool (*transaction)(database_t *this); + bool (*transaction)(database_t *this, bool serializable); /** * Commit all changes made during the current transaction. -- cgit v1.2.3