Removing unwanted comments which are misleading
[csql.git] / include / Session.h
blobcdbca86eca04f2b7a904812b68c7043beabb0bf0
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
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. *
9 * *
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. *
14 * *
15 ***************************************************************************/
16 #ifndef SESSION_H
17 #define SESSION_H
18 #include<DatabaseManager.h>
19 #include<UserManager.h>
20 #include<ErrorType.h>
21 class Session;
23 enum IsolationLevel
25 READ_UNCOMMITTED,
26 READ_COMMITTED,
27 READ_REPEATABLE
30 /**
31 * @class Connection
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/>
38 * transaction.<br/>
39 * <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/>
44 * <br/>
45 * TODO: <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/>
50 * <br/>
51 * Note: <br/>
52 * SERIALIZABLE isolation level is not supported.
53 * @author Prabakaran Thirumalai
56 class Connection
58 Session *session;
59 public:
60 Connection() { session = NULL; }
61 ~Connection();
63 /** opens connection to the database
64 * @param username username for authentication
65 * @param password password for authentication
66 * @return DbRetVal
68 DbRetVal open(const char*username, const char*password);
71 /** closes connection to the database and releases all the resources
72 * @return DbRetVal
74 DbRetVal close();
76 /** gets the database manager object.
77 * @return DatabaseManager
79 DatabaseManager* getDatabaseManager();
81 /** gets the user manager object.
82 * @return UserManager
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>
90 * database operation.
91 * @return DbRetVal
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.
100 * @return DbRetVal
102 DbRetVal commit();
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.
109 * @return DbRetVal
111 DbRetVal rollback();
115 class Session
117 public:
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() { }
133 #endif