Changeset 89 for branches/DirectWeb/UWebServer.pas
- Timestamp:
- Dec 18, 2009, 1:42:22 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DirectWeb/UWebServer.pas
r88 r89 10 10 UCommon, syncobjs, 11 11 UMemoryStreamEx, 12 UMIMEType, Synautil, 12 UMIMEType, Synautil, UPool, 13 13 USqlDatabase, DOM, XMLRead, UHTMLControls; 14 14 … … 20 20 { TDatabasePool } 21 21 22 TDatabasePool = class(T ObjectList)22 TDatabasePool = class(TThreadedPool) 23 23 private 24 Lock: TCriticalSection; 24 FActive: Boolean; 25 procedure SetActive(const AValue: Boolean); 25 26 public 26 PoolSize: Integer; 27 property Active: Boolean read FActive write SetActive; 28 public 27 29 HostName: string; 28 30 Schema: string; 29 31 UserName: string; 30 32 Password: string; 31 procedure Allocate;32 function Acquire: TSqlDatabase;33 procedure Release(Database: TSqlDatabase);34 33 constructor Create; 35 34 destructor Destroy; override; … … 103 102 Command: string; 104 103 begin 104 LoadConfiguration; 105 DatabasePool.Active := True; 105 106 WriteLn('WoW hosting web server'); 106 LoadConfiguration;107 107 with HTTPServer do begin 108 108 Socket.Active := True; … … 127 127 PageList: TPageList; 128 128 begin 129 SqlDatabase := DatabasePool.Acquire;129 SqlDatabase := TSqlDatabase(DatabasePool.Acquire); 130 130 with HandlerData, Response, Stream, SqlDatabase do 131 131 begin … … 191 191 192 192 DbRows.Destroy; 193 Destroy;194 193 WriteFooter(Stream); 195 194 end; 196 195 PageList.Destroy; 196 DatabasePool.Release(SqlDatabase); 197 197 end; 198 198 … … 207 207 LinkQuery: TQueryParameterList; 208 208 begin 209 SqlDatabase := TSqlDatabase .Create;209 SqlDatabase := TSqlDatabase(DatabasePool.Acquire); 210 210 with HandlerData, Response, Stream, SqlDatabase do 211 211 begin … … 223 223 WriteString('</table>'); 224 224 DbRows.Destroy; 225 Destroy;226 225 WriteFooter(Stream); 227 226 end; 227 DatabasePool.Release(SqlDatabase); 228 228 end; 229 229 … … 269 269 begin 270 270 WriteHeader(Stream); 271 272 271 WriteString('Index'); 273 272 WriteFooter(Stream); 274 273 end; … … 310 309 inherited Create; 311 310 DatabasePool := TDatabasePool.Create; 312 DatabasePool.Capacity := 20; 313 DatabasePool.Allocate; 311 DatabasePool.TotalCount := 20; 314 312 315 313 SessionStorage := TFileHTTPSessionStorage.Create; … … 341 339 { TDatabasePool } 342 340 343 procedure TDatabasePool. Allocate;341 procedure TDatabasePool.SetActive(const AValue: Boolean); 344 342 var 345 343 I: Integer; 346 344 begin 347 for I := 0 to PoolSize - 1 do 348 with TSqlDatabase(Items[Add(TSqlDatabase.Create)]) do begin 349 HostName := Self.HostName; 350 UserName := Self.UserName; 351 Password := Self.Password; 352 Database := Self.Schema; 353 Connect; 354 end; 355 end; 356 357 function TDatabasePool.Acquire: TSqlDatabase; 358 begin 359 360 end; 361 362 procedure TDatabasePool.Release(Database: TSqlDatabase); 363 begin 364 try 365 Lock.Acquire; 366 367 finally 368 Lock.Release; 369 end; 345 if not FActive and AValue then begin 346 for I := 0 to TotalCount - 1 do 347 with TThreadedPoolItem(Items[I]) do begin 348 Item := TSqlDatabase.Create; 349 with TSqlDatabase(Item) do begin 350 HostName := Self.HostName; 351 UserName := Self.UserName; 352 Password := Self.Password; 353 Database := Self.Schema; 354 Connect; 355 end; 356 end; 357 end else 358 if FActive and not AValue then begin 359 360 end; 361 FActive := AValue; 370 362 end; 371 363 372 364 constructor TDatabasePool.Create; 373 365 begin 374 Lock := TCriticalSection.Create;366 inherited; 375 367 end; 376 368 377 369 destructor TDatabasePool.Destroy; 378 370 begin 379 Lock.Destroy;380 371 inherited Destroy; 381 372 end;
Note:
See TracChangeset
for help on using the changeset viewer.