*** empty log message ***
[csql.git] / src / storage / Connection.cxx
blob0a484951f8cc0d2f2a766cc4deb81f21a92c288c
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>
22 Connection::~Connection()
24 if (NULL != session) {
25 session->rollback();
26 //session->close();
27 delete session;
28 session = NULL;
30 Index::destroy();
33 char *Connection::getUserName()
35 return session->getUserName();
38 DbRetVal Connection::open(const char *username, const char *password)
40 os::umask(002);
41 if (username == NULL || password == NULL )
43 printError(ErrBadArg, "Username or password should not be NULL\n");
44 return ErrBadArg;
46 if (strlen(username) > IDENTIFIER_LENGTH || strlen(password) > IDENTIFIER_LENGTH) return ErrBadArg;
47 if (session == NULL) session = new SessionImpl();
48 else
50 printError(ErrAlready, "User already logged in");
51 return ErrAlready;
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);
58 Index::init();
59 return OK;
62 DbRetVal Connection::close()
64 if (session == NULL) return ErrNoConnection;
65 logFine(Conf::logger, "User logged out");
66 Conf::logger.stopLogger();
67 session->rollback();
68 delete session; // this inturn calls session->close
69 session = NULL;
70 return OK;
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();