1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use client::{Session, CDRS};
use error::Error as CError;
use authenticators::Authenticator;
use compression::Compression;
use r2d2;
use transport::CDRSTransport;
pub struct ConnectionManager<T, X> {
transport: X,
authenticator: T,
compression: Compression,
}
impl<T: Authenticator + Send + Sync + 'static, X: CDRSTransport + Send + Sync + 'static>
ConnectionManager<T, X> {
pub fn new(transport: X,
authenticator: T,
compression: Compression)
-> ConnectionManager<T, X> {
ConnectionManager {
transport: transport,
authenticator: authenticator,
compression: compression,
}
}
}
impl<T: Authenticator + Send + Sync + 'static,
X: CDRSTransport + Send + Sync + 'static> r2d2::ManageConnection for ConnectionManager<T, X> {
type Connection = Session<T, X>;
type Error = CError;
fn connect(&self) -> Result<Self::Connection, Self::Error> {
let transport = try!(self.transport.try_clone());
let compression = self.compression;
let cdrs = CDRS::new(transport, self.authenticator.clone());
cdrs.start(compression)
}
fn is_valid(&self, connection: &mut Self::Connection) -> Result<(), Self::Error> {
if connection.is_connected() {
Ok(())
} else {
Err("Connection to DB was dropped".into())
}
}
fn has_broken(&self, _connection: &mut Self::Connection) -> bool {
false
}
}