trait Connection extends AnyRef
Represents a database connection (session).
Instances of implementations of this trait can be obtained using a
ConnectionFactory. When clients are done with the connection, they are
required to call a release
method co clean up resources such as open sockets.
Invoking any method of this trait when any previous operation has not completed yet is not allowed. Operation is considered complete when a resulting Future completes.
Transaction management has to be done using beginTx
, commitTx
and
rollbackTx
methods. Using SQL statements to manage transaction state is
not allowed.
SqlWithParams instances passed to Connection
's methods can be created
using sql
string interpolator, for example:
import io.rdbc.sapi._ val conn: Connection = ??? val login = "jdoe" conn.statement(sql"select * from users where login = $login").executeForStream()
Alternatively, when bare Strings are used as SQL statements, parameters are specified by name. Parameter name is an alphanumeric string starting with a letter, prefixed with a colon. Example:
import io.rdbc.sapi._ val conn: Connection = ??? val login = "jdoe" conn.statement(sql"select * from users where login = :login") .bind("login" -> login) .executable.executeForStream()
- Grouped
- Alphabetic
- By Inheritance
- Connection
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
beginTx()(implicit timeout: Timeout): Future[Unit]
Begins a database transaction.
Begins a database transaction.
Using this method is a preferred way of starting a transaction, using SQL statements to manage transaction state may lead to undefined behavior.
After the operation takes longer time than
timeout
, operation will be aborted. Note however, that it may not be feasible to abort the operation immediately.Returned future can fail with:
- BeginTxException when general error occurs
- TimeoutException when maximum operation time has been exceeded
-
abstract
def
commitTx()(implicit timeout: Timeout): Future[Unit]
Commits a database transaction.
Commits a database transaction.
Using this method is a preferred way of committing a transaction, using SQL statements to manage transaction state may lead to undefined behavior.
After the operation takes longer time than
timeout
, operation will be aborted. Note however, that it may not be feasible to abort the operation immediately.Returned future can fail with:
- CommmitTxException when general error occurs
- TimeoutException when maximum operation time has been exceeded
-
abstract
def
forceRelease(): Future[Unit]
Releases the connection and underlying resources regardless of whether the connection is currently in use or not.
Releases the connection and underlying resources regardless of whether the connection is currently in use or not.
After calling this method no future operations on the instance are allowed.
Returned future can fail with:
- ConnectionReleaseException when general error occurs
-
abstract
def
release(): Future[Unit]
Releases the connection and underlying resources.
Releases the connection and underlying resources.
Only idle connections can be released using this method. To forcibly release the connection use forceRelease method.
After calling this method no future operations on the instance are allowed.
Returned future can fail with:
- ConnectionReleaseException when general error occurs
-
abstract
def
rollbackTx()(implicit timeout: Timeout): Future[Unit]
Rolls back a database transaction.
Rolls back a database transaction.
Using this method is a preferred way of rolling back a transaction, using SQL statements to manage transaction state may lead to undefined behavior.
After the operation takes longer time than
timeout
, operation will be aborted. Note however, that it may not be feasible to abort the operation immediately.Returned future can fail with:
- RollbackTxException when general error occurs
- TimeoutException when maximum operation time has been exceeded
-
abstract
def
statement(sqlWithParams: SqlWithParams): ExecutableStatement
Returns a ExecutableStatement instance bound to this connection that represents any parametrized SQL statement.
Returns a ExecutableStatement instance bound to this connection that represents any parametrized SQL statement.
It's a shortcut for calling
statement
and thenbind
.SqlWithParams parameter instance is meant to be constructed using
sql
string interpolator, for example:import io.rdbc.sapi.Interpolators._ val x = 1 val y = 10 val stmt = conn.statement(sql"select * from table where colx > $x and coly < $y")
Throws:
- MixedParamTypesException when statement uses both positional and named parameters
- UncategorizedRdbcException when general error occurs
- MissingParamValException when some parameter value was not provided
- NoSuitableConverterFoundException when some parameter value's type is not convertible to a database type
-
abstract
def
statement(sqlWithParams: SqlWithParams, statementOptions: StatementOptions): ExecutableStatement
Returns a ExecutableStatement instance bound to this connection that represents any parametrized SQL statement.
Returns a ExecutableStatement instance bound to this connection that represents any parametrized SQL statement.
It's a shortcut for calling
statement
and thenbind
.SqlWithParams parameter instance is meant to be constructed using
sql
string interpolator, for example:import io.rdbc.sapi.Interpolators._ val x = 1 val y = 10 val stmt = conn.statement(sql"select * from table where colx > $x and coly < $y")
Throws:
- MixedParamTypesException when statement uses both positional and named parameters
- UncategorizedRdbcException when general error occurs
- MissingParamValException when some parameter value was not provided
- NoSuitableConverterFoundException when some parameter value's type is not convertible to a database type
-
abstract
def
statement(sql: String): Statement
Returns a Statement instance bound to this connection that represents any SQL statement.
Returns a Statement instance bound to this connection that represents any SQL statement.
For syntax of statement parametrization see a Connection documentation.
Throws:
- MixedParamTypesException when statement uses both positional and named parameters
- UncategorizedRdbcException when general error occurs
-
abstract
def
statement(sql: String, statementOptions: StatementOptions): Statement
Returns a Statement instance bound to this connection that represents any SQL statement.
Returns a Statement instance bound to this connection that represents any SQL statement.
For syntax of statement parametrization see a Connection documentation.
Throws:
- MixedParamTypesException when statement uses both positional and named parameters
- UncategorizedRdbcException when general error occurs
-
abstract
def
validate()(implicit timeout: Timeout): Future[Unit]
Checks whether the connection is still usable.
Checks whether the connection is still usable.
If checking takes longer than
timeout
, connection is considered unusable.- returns
Successful future of
unit
iff connection is usable, future failed with ConnectionValidationException otherwise.
-
abstract
def
watchForIdle: Future[Connection.this.type]
Returns a future that is complete when this connection is idle and ready for accepting queries.
-
abstract
def
withTransaction[A](body: ⇒ Future[A])(implicit timeout: Timeout): Future[A]
Executes a function in a context of a transaction.
Executes a function in a context of a transaction.
Executes a function (which can be passed as a code block) in a context of a transaction. Before the function is executed, transaction is started. After the function finishes, transaction is committed in case of a success and rolled back in case of a failure.
Because managing transaction state requires invoking functions that require specifying a timeout, this function requires an implicit timeout instance.
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
+(other: String): String
- Implicit
- This member is added by an implicit conversion from Connection to any2stringadd[Connection] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
-
def
->[B](y: B): (Connection, B)
- Implicit
- This member is added by an implicit conversion from Connection to ArrowAssoc[Connection] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
ensuring(cond: (Connection) ⇒ Boolean, msg: ⇒ Any): Connection
- Implicit
- This member is added by an implicit conversion from Connection to Ensuring[Connection] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: (Connection) ⇒ Boolean): Connection
- Implicit
- This member is added by an implicit conversion from Connection to Ensuring[Connection] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean, msg: ⇒ Any): Connection
- Implicit
- This member is added by an implicit conversion from Connection to Ensuring[Connection] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean): Connection
- Implicit
- This member is added by an implicit conversion from Connection to Ensuring[Connection] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from Connection to StringFormat[Connection] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @inline()
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
→[B](y: B): (Connection, B)
- Implicit
- This member is added by an implicit conversion from Connection to ArrowAssoc[Connection] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
TODO