Hello there and nice to meet you all!!!I just registered in your forum.And i intend to be an active user.
I am a 22 yo University student from greece!
I was assigned to develop a PoolManagement library for a lesson in c++
The programm supose to open a X number of connections in a database
and handle them to the main programm( multiple connection asked by threads) for doing general use cases as insert update etc etc.
The problem i have (well the most annoying of many many others)
was when i tryied to aplly the singleton patern to the poolManager class
So there can be only one class for a single database
I made a map<> to store all pool managers for diferent databases
Well after doiing so i had tones of errors!! When i solved them another 25 errors apeared.......and became an error labyrinth!!!
I upoloaded the project on rapidshare if someone wants to check it
Its a visual studio 2008 file.
rapidshare.com/files/242455885/DB_poolManager_exception_.rar
I am in a desperate condition i have a week to deliver the project
and i will not pass the lesson if i dont do so! HELPP!!!!
else the code is
MAIN function
Code:// conDB.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "poolManager.h" #include "dataHandler.h" #include <conio.h> #include <stdio.h> #include <iostream> #include <process.h> #include <windows.h> #include <vector> using namespace std; int main() { //_RecordsetPtr pointerRec; //_bstr_t stringConn; //poolManager *pool; //pool=poolManager::getInstance("ena"); int epil=0; string database; map<string,Handler*> handlers; vector<HANDLE> threads; cout<<"1-Eisagogi dedomenon"; cout<<"2-Anagnosi dedomenon"; switch(epil) { case 1: cout<<"dose vasi dedomenon"; getline(cin,database); if (handlers.find(database) == false) { handlers[database]= new Handler(database); } break; case 2: cout<<"dose vasi dedomenon:"; getline(cin,database); break; default: cout<<"lathos epilogi"; break; } }
class poolmanager .H
Code:#ifndef POOLMANAGER_H #define POOLMANAGER_H #include "stdafx.h" #include <iostream> #include <process.h> #include <windows.h> #include <map> #import "c:\Program Files\Common Files\System\ado\msado15.dll" \ no_namespace rename("EOF", "EndOfFile") #include <conio.h> #include <stdio.h> #include <string> #include "Connection.h" const int N=3; using namespace std; class poolManager { public: static poolManager* getInstance(string name); ~poolManager(); void createConnections(_RecordsetPtr pRst, _bstr_t strCnn); class ConnectionCl giveConnection(); void getStats(); void returnConnection(class ConnectionCl a); private: poolManager(string dbName); static map<string,poolManager*> pm; string dbName; ConnectionCl ConTable[N]; int openedConnections; int freeConnections; bool connectionFree; bool isFree[N]; CRITICAL_SECTION crit; }; #endif
Class pool manager cpp
Code:#include "stdafx.h" #include <iostream> #include <conio.h> #include <stdio.h> #include <vector> #include "poolManager.h" using namespace std; poolManager* poolManager::getInstance(string name) { if( pm.find(name)==false) { poolManager *poolM = new poolManager(name); pm[name]=poolM; } return pm[name]; } poolManager::poolManager(string name) { InitializeCriticalSection(&crit); int i; dbName=name; connectionFree=true; openedConnections=0; freeConnections=N; for(i=0;i<N;i++) { isFree[i]=true; ConTable[N].create(name); ConTable[N].setIndex(N); } cout<<"Etrekse o constructor"<<endl; } poolManager::~poolManager() { DeleteCriticalSection(&crit); } void poolManager::createConnections(_RecordsetPtr pRst, _bstr_t strCnn) { } void poolManager::returnConnection(class ConnectionCl a) { int tmpIndex; tmpIndex=a.getIndex(); isFree[tmpIndex]=true; freeConnections++; } void poolManager::getStats() { cout<<"oi eleftheres sindeseis einai"<<freeConnections; } ConnectionCl poolManager::giveConnection() { int FreeConIndex=0; bool found=false; while((found==false)&&(FreeConIndex<N)) { if(isFree[FreeConIndex]==true) { found =true; isFree[FreeConIndex]=false; freeConnections--; } else { FreeConIndex++; } } if(found==true) return ConTable[FreeConIndex]; //else //Epistrofi error }


LinkBack URL
About LinkBacks




Reply With Quote




Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum