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>
23 * @enum IsolationLevel
24 * @brief Represents isolation level of the transaction.
31 WRITE_OSYNC
= 4 //this will work only from sqlapi
32 //for dbapi WRITE_OSYNC = READ_REPEATABLE
38 * @brief Represents a database connection.
39 * All database operations shall be done within the context of the connection. <br>
40 * Application should first create object of this class for accessing the database.<br/>
41 * Each connection has only one active transaction at any given point of time, all <br/>
42 * operations which happen using this connection object will be done as part of that <br/>
45 * Functionality: <br/>
46 * 1.Connection Management (connect and disconnect) <br/>
47 * 2.Transaction Management (start, commit, abort) <br/>
48 * 3.Provides getter methods for database manager and user manager <br/>
49 * 4.Isolation Level support. REPEATABLE READ, <br/>
50 * READ COMMITTED and READ UNCOMMITTED isolation levels<br/>
53 * SERIALIZABLE isolation level is not supported.
61 Connection() { session
= NULL
; }
64 /** opens connection to the database
65 * @param username username for authentication
66 * @param password password for authentication
69 DbRetVal
open(const char*username
, const char*password
);
72 /** closes connection to the database and releases all the resources
77 /** gets the database manager object.
78 * @return DatabaseManager
80 DatabaseManager
* getDatabaseManager();
82 /** gets the user manager object.
85 UserManager
* getUserManager();
87 /** Starts a transaction.
88 * The previous transaction should be either committed or rollback <br/>
89 * before startTransaction is called. <br/>
90 * Application are required to start transaction before they attempt any <br>
94 DbRetVal
startTransaction(IsolationLevel level
= READ_COMMITTED
);
96 /** Commits active transaction.
97 * It makes all the changes made in the current transaction permanent and <br/>
98 * it also releases the locks held by the current transaction.<br/>
99 * After a transaction commits, application is required to start another <br/>
100 * transaction for further database operations.
105 /** Aborts the active transaction.
106 * undo all the changes made in the current transaction and it also <br/>
107 * releases the locks held by the current transaction.<br/>
108 * After a transaction rollback, application is required to start another <br/>
109 * transaction for further database operations.
119 virtual DbRetVal
open(const char*username
, const char*password
)=0;
120 virtual DbRetVal
close()=0;
122 virtual DatabaseManager
* getDatabaseManager()=0;
123 virtual UserManager
* getUserManager()=0;
125 virtual DbRetVal
startTransaction(IsolationLevel level
)=0;
126 virtual DbRetVal
commit()=0;
127 virtual DbRetVal
rollback()=0;
128 //TODO:: virtual int setAutoCommit(bool flag)=0;
129 //TODO::support for save points
130 virtual ~Session() { }