submitting patch from enterprise version
[csql.git] / include / Session.h
blobad6509cb45be61a5faa7af8aefabd058ee1262cb
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 * 4.Isolation Level support. REPEATABLE READ, <br/>
50 * READ COMMITTED and READ UNCOMMITTED isolation levels<br/>
51 * <br/>
52 * Note: <br/>
53 * SERIALIZABLE isolation level is not supported.
57 class Connection
59 Session *session;
60 public:
61 Connection() { session = NULL; }
62 ~Connection();
64 /** opens connection to the database
65 * @param username username for authentication
66 * @param password password for authentication
67 * @return DbRetVal
69 DbRetVal open(const char*username, const char*password);
72 /** closes connection to the database and releases all the resources
73 * @return DbRetVal
75 DbRetVal close();
77 /** gets the database manager object.
78 * @return DatabaseManager
80 DatabaseManager* getDatabaseManager();
82 /** gets the user manager object.
83 * @return UserManager
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>
91 * database operation.
92 * @return DbRetVal
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.
101 * @return DbRetVal
103 DbRetVal commit();
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.
110 * @return DbRetVal
112 DbRetVal rollback();
113 DbRetVal getExclusiveLock();
117 class Session
119 public:
120 virtual DbRetVal open(const char*username, const char*password)=0;
121 virtual DbRetVal close()=0;
123 virtual DatabaseManager* getDatabaseManager()=0;
124 virtual UserManager* getUserManager()=0;
126 virtual DbRetVal startTransaction(IsolationLevel level)=0;
127 virtual DbRetVal commit()=0;
128 virtual DbRetVal rollback()=0;
129 virtual DbRetVal getExclusiveLock()=0;
130 //TODO:: virtual int setAutoCommit(bool flag)=0;
131 //TODO::support for save points
132 virtual ~Session() { }
138 #endif