SessionImpl Class Reference

#include <SessionImpl.h>

Inheritance diagram for SessionImpl:

Inheritance graph
[legend]
Collaboration diagram for SessionImpl:

Collaboration graph
[legend]

Public Member Functions

 SessionImpl ()
 ~SessionImpl ()
DbRetVal initSystemDatabase ()
DbRetVal destroySystemDatabase ()
DbRetVal open (const char *username, const char *password)
DbRetVal close ()
DatabaseManagergetDatabaseManager ()
UserManagergetUserManager ()
DbRetVal startTransaction (IsolationLevel level)
DbRetVal commit ()
DbRetVal rollback ()
DbRetVal readConfigFile ()
DatabasegetSystemDatabase ()

Detailed Description

Definition at line 25 of file SessionImpl.h.


Constructor & Destructor Documentation

SessionImpl::SessionImpl (  )  [inline]

Definition at line 35 of file SessionImpl.h.

00036     {
00037         dbMgr = NULL; uMgr = NULL; 
00038     }

SessionImpl::~SessionImpl (  )  [inline]

Definition at line 39 of file SessionImpl.h.

References close().

00040     {
00041         close();
00042     }

Here is the call graph for this function:


Member Function Documentation

DbRetVal SessionImpl::close (  )  [virtual]

Implements Session.

Definition at line 166 of file SessionImpl.cxx.

References DatabaseManagerImpl::closeDatabase(), DatabaseManagerImpl::closeSystemDatabase(), DatabaseManagerImpl::deregisterThread(), ErrBadCall, and OK.

Referenced by ~SessionImpl().

00167 {
00168     DbRetVal rv = OK;
00169     if (dbMgr)
00170     {
00171         rv = dbMgr->closeDatabase();
00172         if (rv != OK) { return ErrBadCall;  }
00173         rv = dbMgr->deregisterThread();
00174         if (rv != OK) {  return ErrBadCall;  }
00175         rv = dbMgr->closeSystemDatabase();
00176         if (rv != OK) { return ErrBadCall;  }
00177         delete dbMgr;
00178         dbMgr = NULL;
00179     }
00180     if (uMgr)
00181     {
00182         delete uMgr;
00183         uMgr = NULL;
00184     }
00185     return OK;
00186 }

Here is the call graph for this function:

Here is the caller graph for this function:

DbRetVal SessionImpl::commit (  )  [virtual]

Implements Session.

Definition at line 230 of file SessionImpl.cxx.

References TransactionManager::commit(), ErrSysFatal, DatabaseManagerImpl::lockMgr(), OK, printError, and DatabaseManagerImpl::txnMgr().

00231 {
00232     DbRetVal rv = OK;
00233     if (NULL == dbMgr || NULL == dbMgr->txnMgr())
00234     {
00235         printError(ErrSysFatal, "Database Manager or Txn Manager object is NULL");
00236         return ErrSysFatal;
00237     }
00238     rv = dbMgr->txnMgr()->commit(dbMgr->lockMgr());
00239     if (OK != rv)
00240     {
00241         printError(rv,"Transaction commit failed\n");
00242         return rv;
00243     }
00244     return OK;
00245 }

Here is the call graph for this function:

DbRetVal SessionImpl::destroySystemDatabase (  ) 

Definition at line 86 of file SessionImpl.cxx.

References DatabaseManagerImpl::deleteDatabase(), OK, and SYSTEMDB.

Referenced by main().

00087 {
00088     DbRetVal rv = OK;
00089     rv = dbMgr->deleteDatabase(SYSTEMDB);
00090     if (OK != rv) return rv;
00091     rv = dbMgr->deleteDatabase("userdb");
00092     if (OK != rv) return rv;
00093     delete dbMgr;
00094     dbMgr = NULL;
00095     return OK;
00096 }

Here is the call graph for this function:

Here is the caller graph for this function:

DatabaseManager * SessionImpl::getDatabaseManager (  )  [virtual]

Implements Session.

Definition at line 188 of file SessionImpl.cxx.

References ErrNoPrivilege, and printError.

00189 {
00190     if (isAuthenticated) return dbMgr;
00191     printError(ErrNoPrivilege, "Not Authenticated: Returning NULL");
00192     return NULL;
00193 }

Database * SessionImpl::getSystemDatabase (  ) 

Definition at line 279 of file SessionImpl.cxx.

References DatabaseManagerImpl::sysDb().

Referenced by main().

00280 {
00281     return dbMgr->sysDb();
00282 }

Here is the call graph for this function:

Here is the caller graph for this function:

UserManager * SessionImpl::getUserManager (  )  [virtual]

Implements Session.

Definition at line 195 of file SessionImpl.cxx.

References DBAUSER, ErrNoPrivilege, printError, UserManagerImpl::setDba(), UserManagerImpl::setSysDb(), UserManagerImpl::setUserName(), and DatabaseManagerImpl::sysDb().

00196 {
00197     if (!isAuthenticated)
00198     {
00199         printError(ErrNoPrivilege, "Not Authenticated: Returning NULL");
00200         return NULL;
00201     }
00202     if (uMgr != NULL) return uMgr;
00203     UserManagerImpl *userMgr =  new UserManagerImpl();
00204     if(0 == strcmp(userName, DBAUSER))
00205         userMgr->setDba(true);
00206     else
00207         userMgr->setDba(false);
00208 
00209     userMgr->setSysDb(dbMgr->sysDb());
00210 
00211     userMgr->setUserName(userName);
00212     uMgr = userMgr;
00213     return userMgr;
00214 }

Here is the call graph for this function:

DbRetVal SessionImpl::initSystemDatabase (  ) 

Definition at line 29 of file SessionImpl.cxx.

References Database::allocLockHashBuckets(), Conf::config, Database::createAllCatalogTables(), DatabaseManagerImpl::createDatabase(), DatabaseManagerImpl::db(), DBAPASS, DBAUSER, ErrLockTimeOut, ErrSysInit, Database::getDatabaseMutex(), CatalogTableUSER::insert(), OK, Config::print(), printError, readConfigFile(), Database::releaseDatabaseMutex(), DatabaseManagerImpl::setDb(), DatabaseManagerImpl::setSysDb(), DatabaseManagerImpl::sysDb(), and SYSTEMDB.

Referenced by main().

00031 {
00032     DbRetVal rv = OK;
00033     rv = readConfigFile();
00034     if (rv != OK) 
00035     {
00036        printError(ErrSysInit, "Configuration file read failed\n");
00037        return ErrSysInit;
00038     }
00039 
00040     Conf::config.print();
00041 
00042     dbMgr = new DatabaseManagerImpl();
00043     rv = dbMgr->createDatabase(SYSTEMDB, Conf::config.getMaxSysDbSize());
00044     if (OK != rv) return rv;
00045     dbMgr->setSysDb(dbMgr->db());
00046     dbMgr->setDb(NULL);
00047 
00048     Database *db = dbMgr->sysDb();
00049 
00050     rv = db->getDatabaseMutex();
00051     if (OK != rv)
00052     {
00053         printError(ErrLockTimeOut, "Unable to get Database Mutex");
00054         return rv;
00055     }
00056 
00057 
00058     db->createAllCatalogTables();
00059 
00060     //create the default dba user
00061     CatalogTableUSER cUser(db);
00062     rv = cUser.insert(DBAUSER, DBAPASS);
00063     if (OK != rv)
00064     {
00065         db->releaseDatabaseMutex();
00066         return rv;
00067     }
00068     void *ret = NULL;
00069     //Allocate space for the lock hash bucket
00070     ret = db->allocLockHashBuckets();
00071     if (NULL == ret)
00072     {
00073         db->releaseDatabaseMutex();
00074         printError(ErrSysInit, "Allocation of Lock buckets failed");
00075         return ErrSysInit;
00076     }
00077 
00078     db->releaseDatabaseMutex();
00079     printf("sysdb size %ld dbsize %ld\n", Conf::config.getMaxSysDbSize(), Conf::config.getMaxDbSize());
00080     //create user database
00081     rv = dbMgr->createDatabase("userdb", Conf::config.getMaxDbSize());
00082     if (OK != rv) return rv;
00083     return OK;
00084 }

Here is the call graph for this function:

Here is the caller graph for this function:

DbRetVal SessionImpl::open ( const char *  username,
const char *  password 
) [virtual]

Implements Session.

Definition at line 98 of file SessionImpl.cxx.

References DatabaseManagerImpl::closeSystemDatabase(), DatabaseManagerImpl::createLockManager(), DatabaseManagerImpl::createTransactionManager(), ErrSysFatal, OK, DatabaseManagerImpl::openDatabase(), DatabaseManagerImpl::openSystemDatabase(), printError, readConfigFile(), and DatabaseManagerImpl::registerThread().

00099 {
00100     DbRetVal rv = OK;
00101     rv = readConfigFile();
00102     if (rv != OK)
00103     {
00104        printError(ErrSysFatal, "Configuration file read failed\n");
00105        return ErrSysFatal;
00106     }
00107 
00108     if ( NULL == dbMgr)
00109     {
00110         dbMgr = new DatabaseManagerImpl();
00111         rv = dbMgr->openSystemDatabase();
00112     }
00113     if (OK != rv)
00114     {
00115         printError(rv,"Unable to open the system database");
00116         return rv;
00117     }
00118 
00119     rv = authenticate(username, password);
00120     if (OK != rv)
00121     {
00122         dbMgr->closeSystemDatabase();
00123         delete dbMgr; dbMgr = NULL;
00124         return rv;
00125     }
00126 
00127     dbMgr->createTransactionManager();
00128     dbMgr->createLockManager();
00129     rv = dbMgr->registerThread();
00130     if (OK != rv)
00131     {
00132         printError(rv,"Unable to register to csql server");
00133         dbMgr->closeSystemDatabase();
00134         delete dbMgr; dbMgr = NULL;
00135         return rv;
00136     }
00137     rv = dbMgr->openDatabase("userdb");
00138     if (OK != rv) {
00139         dbMgr->closeSystemDatabase();
00140         delete dbMgr; dbMgr = NULL;
00141         return rv;
00142     }
00143     ((DatabaseManagerImpl*)dbMgr)->setProcSlot();
00144     //ProcessManager::systemDatabase = dbMgr->sysDb();
00145     return OK;
00146 }

Here is the call graph for this function:

DbRetVal SessionImpl::readConfigFile (  ) 

Definition at line 265 of file SessionImpl.cxx.

References Conf::config, ErrSysInit, os::getenv(), OK, printError, and Config::readAllValues().

Referenced by initSystemDatabase(), main(), and open().

00266 {
00267     // Check if env variable is set or not
00268     char *confFilename = os::getenv("CSQL_CONFIG_FILE");
00269     if (confFilename == NULL)
00270     {
00271         printError(ErrSysInit, "CSQL_CONFIG_FILE environment variable should be set.");
00272         return ErrSysInit;
00273     }
00274 
00275     int  rv = Conf::config.readAllValues(confFilename);
00276     if (rv != 0) return ErrSysInit;
00277     return OK;
00278 }

Here is the call graph for this function:

Here is the caller graph for this function:

DbRetVal SessionImpl::rollback (  )  [virtual]

Implements Session.

Definition at line 248 of file SessionImpl.cxx.

References ErrSysFatal, DatabaseManagerImpl::lockMgr(), OK, printError, TransactionManager::rollback(), and DatabaseManagerImpl::txnMgr().

00249 {
00250     DbRetVal rv = OK;
00251     if (NULL == dbMgr || NULL == dbMgr->txnMgr())
00252     {
00253         printError(ErrSysFatal, "Database Manager or Txn Manager object is NULL");
00254         return ErrSysFatal;
00255     }
00256     rv = dbMgr->txnMgr()->rollback(dbMgr->lockMgr());
00257     if (OK != rv)
00258     {
00259         printError(rv, "Transaction rollback failed\n");
00260         return rv;
00261     }
00262     return OK;
00263 }

Here is the call graph for this function:

DbRetVal SessionImpl::startTransaction ( IsolationLevel  level  )  [virtual]

Implements Session.

Definition at line 216 of file SessionImpl.cxx.

References ErrSysFatal, DatabaseManagerImpl::lockMgr(), OK, printError, TransactionManager::startTransaction(), and DatabaseManagerImpl::txnMgr().

00217 {
00218     if (NULL == dbMgr || NULL == dbMgr->txnMgr())
00219     {
00220         printError(ErrSysFatal, "Database Manager or Txn Manager object is NULL");
00221         return ErrSysFatal;
00222     }
00223     DbRetVal rv = OK;
00224 
00225     rv = dbMgr->txnMgr()->startTransaction(dbMgr->lockMgr(), level);
00226     return rv;
00227 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 22:51:05 2008 for csql by  doxygen 1.4.7