ConnectionPool

class ConnectionPool[T <: Connection](factory: ObjectFactory[T], configuration: PoolConfiguration, executionContext: ExecutionContext) extends SingleThreadedAsyncObjectPool[T] with Connection

Pool specialized in database connections that also simplifies connection handling by implementing the com.github.mauricio.async.db.Connection trait and saving clients from having to implement the "give back" part of pool management. This lets you do your job without having to worry about managing and giving back connection objects to the pool.

The downside of this is that you should not start transactions or any kind of long running process in this object as the object will be sent back to the pool right after executing a query. If you need to start transactions you will have to take an object from the pool, do it and then give it back manually.

class Object
trait Matchable
class Any

Value members

Concrete methods

def connect: Future[Connection]

Always returns an empty map.

Always returns an empty map.

def disconnect: Future[Connection]

Closes the pool, you should discard the object.

Closes the pool, you should discard the object.

override
def inTransaction[A](f: Connection => Future[A])(implicit context: ExecutionContext): Future[A]

Picks one connection and executes an (asynchronous) function on it within a transaction block. If the function completes successfully, the transaction is committed, otherwise it is aborted. Either way, the connection is returned to the pool on completion.

Picks one connection and executes an (asynchronous) function on it within a transaction block. If the function completes successfully, the transaction is committed, otherwise it is aborted. Either way, the connection is returned to the pool on completion.

Value Params
f

operation to execute on a connection

Returns

result of f, conditional on transaction operations succeeding

Definition Classes
def isConnected: Boolean
def sendPreparedStatement(query: String, values: Seq[Any]): Future[QueryResult]

Picks one connection and runs this query against it. The query should be stateless, it should not start transactions and should not leave anything to be cleaned up in the future. The behavior of this object is undefined if you start a transaction from this method.

Picks one connection and runs this query against it. The query should be stateless, it should not start transactions and should not leave anything to be cleaned up in the future. The behavior of this object is undefined if you start a transaction from this method.

def sendQuery(query: String): Future[QueryResult]

Picks one connection and runs this query against it. The query should be stateless, it should not start transactions and should not leave anything to be cleaned up in the future. The behavior of this object is undefined if you start a transaction from this method.

Picks one connection and runs this query against it. The query should be stateless, it should not start transactions and should not leave anything to be cleaned up in the future. The behavior of this object is undefined if you start a transaction from this method.

Inherited methods

def availables: Iterable[T]
override
def finalize(): Unit
Definition Classes
Inherited from
SingleThreadedAsyncObjectPool
def giveBack(item: T): Future[AsyncObjectPool[T]]

Returns an object to the pool. The object is validated before being added to the collection of available objects to make sure we have a usable object. If the object isn't valid it's discarded.

Returns an object to the pool. The object is validated before being added to the collection of available objects to make sure we have a usable object. If the object isn't valid it's discarded.

Inherited from
SingleThreadedAsyncObjectPool
def inUse: Iterable[T]
def isClosed: Boolean
def isFull: Boolean
def queued: Iterable[Promise[T]]
def take: Future[T]

Asks for an object from the pool, this object should be returned to the pool when not in use anymore.

Asks for an object from the pool, this object should be returned to the pool when not in use anymore.

Inherited from
SingleThreadedAsyncObjectPool
def use[A](f: T => Future[A])(implicit executionContext: ExecutionContext): Future[A]

Retrieve and use an object from the pool for a single computation, returning it when the operation completes.

Retrieve and use an object from the pool for a single computation, returning it when the operation completes.

Value Params
f

function that uses the object

Returns

f wrapped with take and giveBack

Inherited from
AsyncObjectPool