src/server/Connection.cxx

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015   ***************************************************************************/
00016 #include<SessionImpl.h>
00017 #include<Debug.h>
00018 #include<os.h>
00019 #include<Index.h>
00020 #include<Config.h>
00021 Connection::~Connection()
00022 { 
00023     if (NULL != session) {
00024        session->rollback();
00025        //session->close();
00026        delete session; 
00027        session = NULL;
00028     }
00029     Index::destroy();
00030 }
00031 
00032 DbRetVal Connection::open(const char *username, const char *password)
00033 {
00034     if (username == NULL || password == NULL ) 
00035     {
00036         printError(ErrBadArg, "Username or password should not be NULL\n");
00037         return ErrBadArg;
00038     }
00039     if (strlen(username) > 64 || strlen(password) >64) return ErrBadArg;
00040     if (session == NULL) session = new SessionImpl(); 
00041     else
00042     {
00043        printError(ErrAlready, "User already logged in");
00044        return ErrAlready;
00045     }
00046     DbRetVal rv = session->open(username, password);
00047     if (rv != OK) { delete session; session = NULL; return rv; }
00048     rv = logger.startLogger(Conf::config.getLogFile());
00049     if (rv != OK) { delete session; session = NULL; return rv; }
00050     logFinest(logger, "User logged in %s",username);
00051     Index::init();
00052     return OK;
00053 }
00054 
00055 DbRetVal Connection::close()
00056 {
00057     if (session == NULL) return ErrNoConnection;
00058     logFinest(logger, "User logged out");
00059     logger.stopLogger();
00060     session->rollback();
00061     delete session;  // this inturn calls session->close
00062     session = NULL;
00063     return OK;
00064 }
00065 
00066 DatabaseManager* Connection::getDatabaseManager()
00067 {
00068     if (session == NULL) return NULL;
00069     return session->getDatabaseManager();
00070 }
00071 
00072 UserManager* Connection::getUserManager()
00073 {
00074     if (session == NULL) return NULL;
00075     return session->getUserManager();
00076 }
00077 
00078 DbRetVal Connection::startTransaction(IsolationLevel level)
00079 {
00080     if (session == NULL) return ErrNoConnection;
00081     if (level == WRITE_OSYNC) level = READ_REPEATABLE;
00082     return session->startTransaction(level);
00083 }
00084 
00085 
00086 DbRetVal Connection::commit()
00087 {
00088     if (session == NULL) return ErrNoConnection;
00089     return session->commit();
00090 }
00091 
00092 
00093 DbRetVal Connection::rollback()
00094 {
00095     if (session == NULL) return ErrNoConnection;
00096     return session->rollback();
00097 }

Generated on Mon Jun 9 22:37:15 2008 for csql by  doxygen 1.4.7