ConnectionPool

com.github.mauricio.async.db.pool.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.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Concrete methods

def connect: Future[Connection]

Always returns an empty map.

Always returns an empty map.

Attributes

def disconnect: Future[Connection]

Closes the pool, you should discard the object.

Closes the pool, you should discard the object.

Attributes

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.

Attributes

f

operation to execute on a connection

Returns:

result of f, conditional on transaction operations succeeding

Definition Classes
def isConnected: Boolean

Checks whether we are still connected to the database.

Checks whether we are still connected to the database.

Attributes

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.

Attributes

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.

Attributes

Inherited methods

def availables: Iterable[T]

Attributes

Inherited from:
SingleThreadedAsyncObjectPool
def close: Future[AsyncObjectPool[T]]

Closes this pool and future calls to take will cause the scala.concurrent.Future to raise an com.github.mauricio.async.db.pool.PoolAlreadyTerminatedException.

Closes this pool and future calls to take will cause the scala.concurrent.Future to raise an com.github.mauricio.async.db.pool.PoolAlreadyTerminatedException.

Attributes

Inherited from:
SingleThreadedAsyncObjectPool
override def finalize(): Unit

Called by the garbage collector on the receiver object when there are no more references to the object.

Called by the garbage collector on the receiver object when there are no more references to the object.

The details of when and if the finalize method is invoked, as well as the interaction between finalize and non-local returns and exceptions, are all platform dependent.

Attributes

Note:

not specified by SLS as a member of AnyRef

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.

Attributes

Inherited from:
SingleThreadedAsyncObjectPool
def inUse: Iterable[T]

Attributes

Inherited from:
SingleThreadedAsyncObjectPool
def isClosed: Boolean

Attributes

Inherited from:
SingleThreadedAsyncObjectPool
def isFull: Boolean

Attributes

Inherited from:
SingleThreadedAsyncObjectPool
def queued: Iterable[Promise[T]]

Attributes

Inherited from:
SingleThreadedAsyncObjectPool
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.

Attributes

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.

Attributes

f

function that uses the object

Returns:

f wrapped with take and giveBack

Inherited from:
AsyncObjectPool