1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 ***************************************************************************/
18 #include<DatabaseManager.h>
19 #include<UserManager.h>
33 * @brief Represents a database connection.
34 * All database operations shall be done within the context of the connection. <br>
35 * Application should first create object of this class for accessing the database.<br/>
36 * Each connection has only one active transaction at any given point of time, all <br/>
37 * operations which happen using this connection object will be done as part of that <br/>
40 * Functionality: <br/>
41 * 1.Connection Management (connect and disconnect) <br/>
42 * 2.Transaction Management (start, commit, abort) <br/>
43 * 3.Provides getter methods for database manager and user manager <br/>
46 * 1.Isolation Level support needs to be added. Currently it supports REPEATABLE READ <br/>
47 * isolation level as the default. It will soon support READ COMMITTED and <br/>
48 * READ UNCOMMITTED isolation levels<br/>
49 * 2.AutoCommit mode<br/>
52 * SERIALIZABLE isolation level is not supported.
53 * @author Prabakaran Thirumalai
60 Connection() { session
= NULL
; }
63 /** opens connection to the database
64 * @param username username for authentication
65 * @param password password for authentication
68 DbRetVal
open(const char*username
, const char*password
);
71 /** closes connection to the database and releases all the resources
76 /** gets the database manager object.
77 * @return DatabaseManager
79 DatabaseManager
* getDatabaseManager();
81 /** gets the user manager object.
84 UserManager
* getUserManager();
86 /** Starts a transaction.
87 * The previous transaction should be either committed or rollback <br/>
88 * before startTransaction is called. <br/>
89 * Application are required to start transaction before they attempt any <br>
93 DbRetVal
startTransaction(IsolationLevel level
= READ_COMMITTED
);
95 /** Commits active transaction.
96 * It makes all the changes made in the current transaction permanent and <br/>
97 * it also releases the locks held by the current transaction.<br/>
98 * After a transaction commits, application is required to start another <br/>
99 * transaction for further database operations.
104 /** Aborts the active transaction.
105 * undo all the changes made in the current transaction and it also <br/>
106 * releases the locks held by the current transaction.<br/>
107 * After a transaction rollback, application is required to start another <br/>
108 * transaction for further database operations.
118 virtual DbRetVal
open(const char*username
, const char*password
)=0;
119 virtual DbRetVal
close()=0;
121 virtual DatabaseManager
* getDatabaseManager()=0;
122 virtual UserManager
* getUserManager()=0;
124 virtual DbRetVal
startTransaction(IsolationLevel level
)=0;
125 virtual DbRetVal
commit()=0;
126 virtual DbRetVal
rollback()=0;
127 //TODO:: virtual int setAutoCommit(bool flag)=0;
128 //TODO::support for save points
129 virtual ~Session() { }