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.base.Pool; 19 20 import hunt.database.base.AsyncResult; 21 import hunt.database.base.SqlClient; 22 import hunt.database.base.SqlConnection; 23 import hunt.database.base.Transaction; 24 25 import hunt.collection.List; 26 import hunt.concurrency.Future; 27 28 /** 29 * A pool of SQL connections. 30 * 31 * @author <a href="mailto:julien@julienviet.com">Julien Viet</a> 32 */ 33 interface Pool : SqlClient { 34 35 // override 36 // Pool preparedQuery(string sql, RowSetHandler handler); 37 38 // override 39 // <R> Pool preparedQuery(string sql, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 40 41 // override 42 // Pool query(string sql, RowSetHandler handler); 43 44 // override 45 // <R> Pool query(string sql, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 46 47 // override 48 // Pool preparedQuery(string sql, Tuple arguments, RowSetHandler handler); 49 50 // override 51 // <R> Pool preparedQuery(string sql, Tuple arguments, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 52 53 // override 54 // Pool preparedBatch(string sql, List!(Tuple) batch, RowSetHandler handler); 55 56 // override 57 // <R> Pool preparedBatch(string sql, List!(Tuple) batch, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 58 59 /** 60 * Get a connection from the pool. 61 * 62 * @param handler the handler that will get the connection result 63 */ 64 // void getConnection(AsyncSqlConnectionHandler handler); 65 66 67 // Future!(SqlConnection) getConnectionAsync(); 68 69 SqlConnection getConnection(); 70 71 /** 72 * Borrow a connection from the pool and begin a transaction, the underlying connection will be returned 73 * to the pool when the transaction ends. 74 * 75 * @return the transaction 76 */ 77 // void begin(AsyncTransactionHandler handler); 78 Transaction begin(); 79 80 // Future!(Transaction) beginAsync(); 81 82 /** 83 * Close the pool and release the associated resources. 84 */ 85 void close(); 86 87 int available(); 88 89 int waiters(); 90 91 int maxSize(); 92 93 int size(); 94 95 }