1 /***************************************************************************
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
5 ***************************************************************************/
11 class DatabaseManager
;
15 * @enum IsolationLevel
16 * @brief Represents isolation level of the transaction.
23 WRITE_OSYNC
= 4 //this will work only from sqlapi
24 //for dbapi WRITE_OSYNC = READ_REPEATABLE
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/>
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/>
45 * SERIALIZABLE isolation level is not supported.
49 class DllExport Connection
53 Connection() { session
= NULL
; }
56 /** opens connection to the database
57 * @param username username for authentication
58 * @param password password for authentication
61 DbRetVal
open(const char*username
, const char*password
);
64 /** closes connection to the database and releases all the resources
69 /** gets the database manager object.
70 * @return DatabaseManager
72 DatabaseManager
* getDatabaseManager();
74 /** gets the user manager object.
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>
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.
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.
106 DbRetVal
getExclusiveLock();
107 char *getUserName();// { return session->getUserName(); }
111 class DllExport Session
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() { }