| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeConnectionPool.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright 2001-2007 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00023
    00030 #ifndef  __TERRALIB_INTERNAL_CONNECTION_POOL_H
    00031 #define  __TERRALIB_INTERNAL_CONNECTION_POOL_H
    00032
    00033 // TerraLib
    00034 #include "TeConnection.h"
    00035 #include "TeDefines.h"
    00036 #include "TeMutex.h"
    00037 #include "TeDatabaseFactoryParams.h"
    00038 // STL
    00039 #include <ctime>
    00040 #include <set>
    00041 #include <vector>
    00042
    00043 // forward declarations
    00044 class TeDatabase;
    00045
    00046 class TL_DLL TeConnectionPool
    00047 {
    00048
    00049 public:
    00050
    00055
    00060     TeConnectionPool(const unsigned int& maxConnections, const unsigned int& maxIdle=0, const clock_t& maxWait = 10000);
    00061
    00063            ~TeConnectionPool();
    00064
    00066
    00075     bool initialize(const std::string& user, const std::string& password, const std::string& host,
    00076                     const std::string& dbName, const std::string& dbmsName, const int& portNumber);
    00077
    00092     TeConnection* getConnection();
    00093
    00094
    00099     void releaseConnection(TeConnection* conn);
    00100
    00105
    00107     void setTimeOut(const clock_t t);
    00108
    00110
    00111 private:
    00112
    00115
    00117     TeConnection* getFreeConnection();
    00118
    00120     unsigned int getTicket();
    00121
    00123     void clear();
    00125     void createNewConnection();
    00127     void deleteConnection(unsigned int& id);
    00128
    00130
    00131 private:
    00132
    00133     TeDatabaseFactoryParams params_;
    00134     unsigned int maxConnections_;
    00135     unsigned int maxIdle_;
    00136     clock_t maxWait_;
    00137     unsigned int ticket_;
    00138     unsigned int connectionsSeq_;
    00139     std::map<unsigned int, TeDatabase*> databases_;
    00140     std::set<unsigned int> freeConns_;
    00141     std::set<unsigned int> freeTickets_;
    00142     std::vector<unsigned int> requestQueue_;
    00143
    00144     TeMutex mutexLock_;
    00145 };
    00146
    00147 #endif // __TERRALIB_INTERNAL_CONNECTION_POOL_H
    00148

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines