reverting back the changes. causes core dump
[csql.git] / include / Session.h
blob5bacdc2620bacfe1d05724e80ea77454c9447262
1 /***************************************************************************
2 * *
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
4 * *
5 ***************************************************************************/
7 #ifndef SESSION_H
8 #define SESSION_H
9 #include<os.h>
10 #include<ErrorType.h>
11 class DatabaseManager;
12 class UserManager;
13 class Session;
14 /**
15 * @enum IsolationLevel
16 * @brief Represents isolation level of the transaction.
18 enum IsolationLevel
20 READ_UNCOMMITTED = 1,
21 READ_COMMITTED = 2,
22 READ_REPEATABLE = 3,
23 WRITE_OSYNC = 4 //this will work only from sqlapi
24 //for dbapi WRITE_OSYNC = READ_REPEATABLE
27 /**
28 * @class Connection
30 * @brief Represents a database connection.
31 * All database operations shall be done within the context of the connection. <br>
32 * Application should first create object of this class for accessing the database.<br/>
33 * Each connection has only one active transaction at any given point of time, all <br/>
34 * operations which happen using this connection object will be done as part of that <br/>
35 * transaction.<br/>
36 * <br/>
37 * Functionality: <br/>
38 * 1.Connection Management (connect and disconnect) <br/>
39 * 2.Transaction Management (start, commit, abort) <br/>
40 * 3.Provides getter methods for database manager and user manager <br/>
41 * 4.Isolation Level support. REPEATABLE READ, <br/>
42 * READ COMMITTED and READ UNCOMMITTED isolation levels<br/>
43 * <br/>
44 * Note: <br/>
45 * SERIALIZABLE isolation level is not supported.
49 class DllExport Connection
51 Session *session;
52 public:
53 Connection() { session = NULL; }
54 ~Connection();
56 /** opens connection to the database
57 * @param username username for authentication
58 * @param password password for authentication
59 * @return DbRetVal
61 DbRetVal open(const char*username, const char*password);
64 /** closes connection to the database and releases all the resources
65 * @return DbRetVal
67 DbRetVal close();
69 /** gets the database manager object.
70 * @return DatabaseManager
72 DatabaseManager* getDatabaseManager();
74 /** gets the user manager object.
75 * @return UserManager
77 UserManager* getUserManager();
79 /** Starts a transaction.
80 * The previous transaction should be either committed or rollback <br/>
81 * before startTransaction is called. <br/>
82 * Application are required to start transaction before they attempt any <br>
83 * database operation.
84 * @return DbRetVal
86 DbRetVal startTransaction(IsolationLevel level = READ_COMMITTED);
88 /** Commits active transaction.
89 * It makes all the changes made in the current transaction permanent and <br/>
90 * it also releases the locks held by the current transaction.<br/>
91 * After a transaction commits, application is required to start another <br/>
92 * transaction for further database operations.
93 * @return DbRetVal
95 DbRetVal commit();
97 /** Aborts the active transaction.
98 * undo all the changes made in the current transaction and it also <br/>
99 * releases the locks held by the current transaction.<br/>
100 * After a transaction rollback, application is required to start another <br/>
101 * transaction for further database operations.
102 * @return DbRetVal
104 DbRetVal rollback();
106 DbRetVal getExclusiveLock();
107 char *getUserName();// { return session->getUserName(); }
111 class DllExport Session
113 public:
114 virtual DbRetVal open(const char*username, const char*password)=0;
115 virtual DbRetVal close()=0;
117 virtual DatabaseManager* getDatabaseManager()=0;
118 virtual UserManager* getUserManager()=0;
120 virtual DbRetVal startTransaction(IsolationLevel level)=0;
121 virtual DbRetVal commit()=0;
122 virtual DbRetVal rollback()=0;
123 virtual DbRetVal getExclusiveLock()=0;
124 virtual char * getUserName()=0;
125 //TODO:: virtual int setAutoCommit(bool flag)=0;
126 //TODO::support for save points
127 virtual ~Session() { }
133 #endif