summaryrefslogtreecommitdiff
path: root/src/dal/dataprovider.h
diff options
context:
space:
mode:
authorHuynh Tran <nthuynh75@gmail.com>2005-06-16 17:19:27 +0000
committerHuynh Tran <nthuynh75@gmail.com>2005-06-16 17:19:27 +0000
commit4a33343730f075018cc7c5424335f2137d11619a (patch)
tree59c579b1dbb6edee819a59a65b0c4c1e52878f71 /src/dal/dataprovider.h
parent154515dbaeff0dfb0501f96464a7016945f45fbd (diff)
downloadmanaserv-4a33343730f075018cc7c5424335f2137d11619a.tar.gz
manaserv-4a33343730f075018cc7c5424335f2137d11619a.tar.bz2
manaserv-4a33343730f075018cc7c5424335f2137d11619a.tar.xz
manaserv-4a33343730f075018cc7c5424335f2137d11619a.zip
Simplified APIs, change namespace from tmw to tmwserv, implemented MySQL data provider, added unit tests (require CPPUnit) and bug fixes.
Diffstat (limited to 'src/dal/dataprovider.h')
-rw-r--r--src/dal/dataprovider.h130
1 files changed, 36 insertions, 94 deletions
diff --git a/src/dal/dataprovider.h b/src/dal/dataprovider.h
index 6975d084..4e897b3c 100644
--- a/src/dal/dataprovider.h
+++ b/src/dal/dataprovider.h
@@ -21,8 +21,8 @@
*/
-#ifndef _TMW_DATA_PROVIDER_H_
-#define _TMW_DATA_PROVIDER_H_
+#ifndef _TMWSERV_DATA_PROVIDER_H_
+#define _TMWSERV_DATA_PROVIDER_H_
#include <string>
@@ -31,7 +31,7 @@
#include "recordset.h"
-namespace tmw
+namespace tmwserv
{
namespace dal
{
@@ -41,13 +41,23 @@ namespace dal
* Enumeration type for the database backends.
*/
typedef enum {
- MYSQL,
- SQLITE
+ DB_BKEND_MYSQL,
+ DB_BKEND_SQLITE
} DbBackends;
/**
* An abstract data provider.
+ *
+ * Notes:
+ * - depending on the database backend, the connection to an unexisting
+ * database may actually create it as a side-effect (e.g. SQLite).
+ *
+ * Limitations:
+ * - this class does not provide APIs for:
+ * - remote connections,
+ * - creating new databases,
+ * - dropping existing databases.
*/
class DataProvider
{
@@ -67,143 +77,75 @@ class DataProvider
/**
- * Get the database backend name.
- *
- * @return the database backend name.
- */
- virtual DbBackends
- getDbBackend(void) const
- throw() = 0;
-
-
- /**
- * Create a new database.
- *
- * @param dbName the database name.
- * @param dbPath the database file path (optional)
+ * Get the connection status.
*
- * @exception DbCreationFailure if unsuccessful creation.
- * @exception std::exception if unexpected exception.
+ * @return true if connected.
*/
- virtual void
- createDb(const std::string& dbName,
- const std::string& dbPath = "")
- throw(DbCreationFailure,
- std::exception) = 0;
+ bool
+ isConnected(void) const
+ throw();
/**
- * Create a connection to the database.
+ * Get the name of the database backend.
*
- * @param dbName the database name.
- * @param userName the user name.
- * @param password the user password.
- *
- * @exception DbConnectionFailure if unsuccessful connection.
- * @exception std::exception if unexpected exception.
+ * @return the database backend name.
*/
- virtual void
- connect(const std::string& dbName,
- const std::string& userName,
- const std::string& password)
- throw(DbConnectionFailure,
- std::exception) = 0;
+ virtual DbBackends
+ getDbBackend(void) const
+ throw() = 0;
/**
* Create a connection to the database.
*
* @param dbName the database name.
- * @param dbPath the database file path.
* @param userName the user name.
* @param password the user password.
*
* @exception DbConnectionFailure if unsuccessful connection.
- * @exception std::exception if unexpected exception.
*/
virtual void
connect(const std::string& dbName,
- const std::string& dbPath,
const std::string& userName,
- const std::string& password)
- throw(DbConnectionFailure,
- std::exception) = 0;
+ const std::string& password) = 0;
/**
* Execute a SQL query.
*
* @param sql the SQL query.
- * @param refresh if true, refresh the cache (optional)
+ * @param refresh if true, refresh the cache (default = false).
*
* @return a recordset.
*
* @exception DbSqlQueryExecFailure if unsuccessful execution.
- * @exception std::exception if unexpected exception.
+ * @exception std::runtime_error if trying to query a closed database.
*/
virtual const RecordSet&
execSql(const std::string& sql,
- const bool refresh = false)
- throw(DbSqlQueryExecFailure,
- std::exception) = 0;
+ const bool refresh = false) = 0;
/**
* Close the connection to the database.
*
* @exception DbDisconnectionFailure if unsuccessful disconnection.
- * @exception std::exception if unexpected exception.
*/
virtual void
- disconnect(void)
- throw(DbDisconnectionFailure,
- std::exception) = 0;
-
-
- /**
- * Get the connection status.
- *
- * @return true if connected.
- */
- bool
- isConnected(void) const
- throw();
+ disconnect(void) = 0;
protected:
- /**
- * The database name.
- */
- std::string mDbName;
-
-
- /**
- * The database path.
- */
- std::string mDbPath;
-
-
- /**
- * The connection status.
- */
- bool mIsConnected;
-
-
- /**
- * Cache the last SQL query.
- */
- std::string mSql;
-
-
- /**
- * Cache the result of the last SQL query.
- */
- RecordSet mRecordSet;
+ std::string mDbName; /**< the database name */
+ bool mIsConnected; /**< the connection status */
+ std::string mSql; /**< cache the last SQL query */
+ RecordSet mRecordSet; /**< cache the result of the last SQL query */
};
} // namespace dal
-} // namespace tmw
+} // namespace tmwserv
-#endif // _TMW_DATA_PROVIDER_H_
+#endif // _TMWSERV_DATA_PROVIDER_H_