pub mod ora_dao;
use parking_lot::{ RwLock};
use r2d2_oracle::OracleConnectionManager;
use r2d2::{Pool, PooledConnection};
use ora_dao::create_oracle_connection_manager;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
lazy_static!{
static ref ORACLE_POOL: RwLock<Pool<OracleConnectionManager>> = {
RwLock::new(create_oracle_connection_manager())
};
}
pub fn connect_db() -> Result<PooledConnection <OracleConnectionManager>, r2d2::Error> {
let conn = ORACLE_POOL.read();
return match conn.get() {
Ok(t) => Ok(t),
Err(e) => {
error!("==> {:?}", e);
drop(conn);
let mut conn = ORACLE_POOL.write();
*conn = create_oracle_connection_manager();
conn.get()
}
};
}
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}