1pub mod ora_dao;
2
3use parking_lot::{ RwLock};
4use r2d2_oracle::OracleConnectionManager;
5use r2d2::{Pool, PooledConnection};
6use ora_dao::create_oracle_connection_manager;
7
8#[macro_use]
9extern crate lazy_static;
10#[macro_use]
11extern crate log;
12
13lazy_static!{
14
15 static ref ORACLE_POOL: RwLock<Pool<OracleConnectionManager>> = {
16 RwLock::new(create_oracle_connection_manager())
17 };
18}
19
20pub fn connect_db() -> Result<PooledConnection <OracleConnectionManager>, r2d2::Error> {
21
22 let conn = ORACLE_POOL.read();
23 return match conn.get() {
24 Ok(t) => Ok(t),
25 Err(e) => {
26 error!("==> {:?}", e);
27
28 drop(conn);
29
30 let mut conn = ORACLE_POOL.write();
31 *conn = create_oracle_connection_manager();
32 conn.get()
33 }
34 };
35}
36
37pub fn add(left: usize, right: usize) -> usize {
38 left + right
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn it_works() {
47 let result = add(2, 2);
48 assert_eq!(result, 4);
49 }
50}