Feature: 1501518
[csql.git] / src / server / Connection.cxx
blob7dd754b497405c5ce3a1b02cb3741199763d9d16
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
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. *
9 * *
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. *
14 * *
15 ***************************************************************************/
16 #include<SessionImpl.h>
17 #include<Debug.h>
18 #include<os.h>
19 #include<Index.h>
20 #include<Config.h>
21 Connection::~Connection()
23 if (NULL != session) {
24 session->rollback();
25 session->close();
27 delete session;
28 session = NULL;
29 Index::destroy();
32 DbRetVal Connection::open(const char *username, const char *password)
34 if (session == NULL) session = new SessionImpl();
35 else
37 printError(ErrAlready, "User already logged in");
38 return ErrAlready;
40 DbRetVal rv = logger.startLogger(config.getLogFile());
41 if (rv != OK) { delete session; session = NULL; return rv; }
42 logFinest(logger, "User logged in %s",username);
43 rv = session->open(username, password);
44 if (rv != OK) { delete session; session = NULL; return rv; }
47 DbRetVal Connection::close()
49 if (session == NULL) return ErrNoConnection;
50 logFinest(logger, "User logged out");
51 logger.stopLogger();
52 session ->rollback();
53 DbRetVal rv= session->close();
54 delete session;
55 session = NULL;
56 return rv;
59 DatabaseManager* Connection::getDatabaseManager()
61 if (session == NULL) return NULL;
62 return session->getDatabaseManager();
65 UserManager* Connection::getUserManager()
67 if (session == NULL) return NULL;
68 return session->getUserManager();
71 DbRetVal Connection::startTransaction(IsolationLevel level)
73 if (session == NULL) return ErrNoConnection;
74 return session->startTransaction(level);
78 DbRetVal Connection::commit()
80 if (session == NULL) return ErrNoConnection;
81 return session->commit();
85 DbRetVal Connection::rollback()
87 if (session == NULL) return ErrNoConnection;
88 return session->rollback();