*** empty log message ***
[csql.git] / include / Session.h
blob6392e966180c0b4d5d2833c4199f6195da17446f
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;
22 /**
23 * @enum IsolationLevel
24 * @brief Represents isolation level of the transaction.
26 enum IsolationLevel
28 READ_UNCOMMITTED = 1,
29 READ_COMMITTED = 2,
30 READ_REPEATABLE = 3,
31 WRITE_OSYNC = 4 //this will work only from sqlapi
32 //for dbapi WRITE_OSYNC = READ_REPEATABLE
35 /**
36 * @class Connection
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/>
43 * transaction.<br/>
44 * <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 * <br/>
50 * TODO: <br/>
51 * 1.Isolation Level support needs to be added. Currently it supports REPEATABLE READ <br/>
52 * isolation level as the default. It will soon support READ COMMITTED and <br/>
53 * READ UNCOMMITTED isolation levels<br/>
54 * 2.AutoCommit mode<br/>
55 * <br/>
56 * Note: <br/>
57 * SERIALIZABLE isolation level is not supported.
58 * @author Prabakaran Thirumalai
61 class Connection
63 Session *session;
64 public:
65 Connection() { session = NULL; }
66 ~Connection();
68 /** opens connection to the database
69 * @param username username for authentication
70 * @param password password for authentication
71 * @return DbRetVal
73 DbRetVal open(const char*username, const char*password);
76 /** closes connection to the database and releases all the resources
77 * @return DbRetVal
79 DbRetVal close();
81 /** gets the database manager object.
82 * @return DatabaseManager
84 DatabaseManager* getDatabaseManager();
86 /** gets the user manager object.
87 * @return UserManager
89 UserManager* getUserManager();
91 /** Starts a transaction.
92 * The previous transaction should be either committed or rollback <br/>
93 * before startTransaction is called. <br/>
94 * Application are required to start transaction before they attempt any <br>
95 * database operation.
96 * @return DbRetVal
98 DbRetVal startTransaction(IsolationLevel level = READ_COMMITTED);
100 /** Commits active transaction.
101 * It makes all the changes made in the current transaction permanent and <br/>
102 * it also releases the locks held by the current transaction.<br/>
103 * After a transaction commits, application is required to start another <br/>
104 * transaction for further database operations.
105 * @return DbRetVal
107 DbRetVal commit();
109 /** Aborts the active transaction.
110 * undo all the changes made in the current transaction and it also <br/>
111 * releases the locks held by the current transaction.<br/>
112 * After a transaction rollback, application is required to start another <br/>
113 * transaction for further database operations.
114 * @return DbRetVal
116 DbRetVal rollback();
120 class Session
122 public:
123 virtual DbRetVal open(const char*username, const char*password)=0;
124 virtual DbRetVal close()=0;
126 virtual DatabaseManager* getDatabaseManager()=0;
127 virtual UserManager* getUserManager()=0;
129 virtual DbRetVal startTransaction(IsolationLevel level)=0;
130 virtual DbRetVal commit()=0;
131 virtual DbRetVal rollback()=0;
132 //TODO:: virtual int setAutoCommit(bool flag)=0;
133 //TODO::support for save points
134 virtual ~Session() { }
140 #endif