1 /*
2  * Copyright (C) 2019, HuntLabs
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 module hunt.database.driver.postgresql.impl.PostgreSQLPoolImpl;
19 
20 import hunt.database.driver.postgresql.impl.PostgreSQLConnectionFactory;
21 import hunt.database.driver.postgresql.impl.PostgreSQLConnectionImpl;
22 
23 import hunt.database.driver.postgresql.PostgreSQLConnectOptions;
24 import hunt.database.driver.postgresql.PostgreSQLPool;
25 
26 import hunt.database.base.impl.Connection;
27 import hunt.database.base.impl.PoolBase;
28 import hunt.database.base.impl.SqlConnectionImpl;
29 import hunt.database.base.PoolOptions;
30 import hunt.database.base.SqlConnection;
31 
32 /**
33  * Todo :
34  *
35  * - handle timeout when acquiring a connection
36  * - for per statement pooling, have several physical connection and use the less busy one to avoid head of line blocking effect
37  *
38  * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
39  * @author <a href="mailto:emad.albloushi@gmail.com">Emad Alblueshi</a>
40  */
41 class PgPoolImpl : PoolBase!(PgPoolImpl), PgPool {
42 
43     private PgConnectionFactory factory;
44 
45     this(PgConnectOptions connectOptions, PoolOptions poolOptions) {
46         super(poolOptions);
47         this.factory = new PgConnectionFactory(connectOptions);
48     }
49 
50     override
51     void connect(AsyncDbConnectionHandler completionHandler) {
52         factory.connectAndInit(completionHandler);
53     }
54 
55     override
56     protected SqlConnection wrap(DbConnection conn) {
57         return new PgConnectionImpl(factory, conn);
58     }
59 
60     // override
61     // protected void doClose() {
62     //     if(factory !is null) {
63     //         factory.close();
64     //     }
65     //     super.doClose();
66     // }
67 
68     override string toString() {
69         return super.toString();
70     }    
71 }