Feature: 1501518
[csql.git] / src / server / Connection.cxx
blobd53f79fa5b557c2c85cff9e545f343b7a3302051
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 delete session;
24 Index::destroy();
27 DbRetVal Connection::open(const char *username, const char *password)
29 if (session == NULL) session = new SessionImpl();
30 else
32 printError(ErrAlready, "User already logged in");
33 return ErrAlready;
35 DbRetVal rv = logger.startLogger(config.getLogFile());
36 if (rv != OK) { delete session; session = NULL; return rv; }
37 logFinest(logger, "User logged in %s",username);
38 return session->open(username, password);
41 DbRetVal Connection::close()
43 if (session == NULL) return ErrNoConnection;
44 logFinest(logger, "User logged out");
45 logger.stopLogger();
46 DbRetVal rv= session->close();
47 delete session;
48 session = NULL;
49 return rv;
52 DatabaseManager* Connection::getDatabaseManager()
54 if (session == NULL) return NULL;
55 return session->getDatabaseManager();
58 UserManager* Connection::getUserManager()
60 if (session == NULL) return NULL;
61 return session->getUserManager();
64 DbRetVal Connection::startTransaction(IsolationLevel level)
66 if (session == NULL) return ErrNoConnection;
67 return session->startTransaction(level);
71 DbRetVal Connection::commit()
73 if (session == NULL) return ErrNoConnection;
74 return session->commit();
78 DbRetVal Connection::rollback()
80 if (session == NULL) return ErrNoConnection;
81 return session->rollback();