1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
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. *
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. *
15 ***************************************************************************/
16 #include<SessionImpl.h>
22 Connection::~Connection()
24 if (NULL
!= session
) {
33 char *Connection::getUserName()
35 return session
->getUserName();
38 DbRetVal
Connection::open(const char *username
, const char *password
)
41 if (username
== NULL
|| password
== NULL
)
43 printError(ErrBadArg
, "Username or password should not be NULL\n");
46 if (strlen(username
) > IDENTIFIER_LENGTH
|| strlen(password
) > IDENTIFIER_LENGTH
) return ErrBadArg
;
47 if (session
== NULL
) session
= new SessionImpl();
50 printError(ErrAlready
, "User already logged in");
53 DbRetVal rv
= session
->open(username
, password
);
54 if (rv
!= OK
) { delete session
; session
= NULL
; return rv
; }
55 rv
= Conf::logger
.startLogger(Conf::config
.getLogFile());
56 if (rv
!= OK
) { delete session
; session
= NULL
; return rv
; }
57 logFine(Conf::logger
, "User logged in %s",username
);
62 DbRetVal
Connection::close()
64 if (session
== NULL
) return ErrNoConnection
;
65 logFine(Conf::logger
, "User logged out");
66 Conf::logger
.stopLogger();
68 delete session
; // this inturn calls session->close
73 DatabaseManager
* Connection::getDatabaseManager()
75 if (session
== NULL
) return NULL
;
76 return session
->getDatabaseManager();
79 UserManager
* Connection::getUserManager()
81 if (session
== NULL
) return NULL
;
82 return session
->getUserManager();
85 DbRetVal
Connection::startTransaction(IsolationLevel level
)
87 if (session
== NULL
) return ErrNoConnection
;
88 if (level
== WRITE_OSYNC
) level
= READ_REPEATABLE
;
89 return session
->startTransaction(level
);
93 DbRetVal
Connection::commit()
95 if (session
== NULL
) return ErrNoConnection
;
96 return session
->commit();
100 DbRetVal
Connection::rollback()
102 if (session
== NULL
) return ErrNoConnection
;
103 return session
->rollback();
106 DbRetVal
Connection::getExclusiveLock()
108 if (session
== NULL
) return ErrNoConnection
;
109 return session
->getExclusiveLock();