use std::sync::Arc;
use std::time::Duration;
use super::super::config::auth::AuthToken;
use super::super::config::notification::NotificationFilter;
use super::super::config::ConfigureFetchSizeError;
use super::super::session::bookmarks::{BookmarkManager, Bookmarks};
#[allow(unused)]
use super::super::config::DriverConfig;
#[allow(unused)]
use super::super::Driver;
#[allow(unused)]
use super::Session;
#[allow(unused)]
use crate::error_::Neo4jError;
#[derive(Debug, Clone, Default)]
pub struct SessionConfig {
pub(crate) database: Option<Arc<String>>,
pub(crate) bookmarks: Option<Arc<Bookmarks>>,
pub(crate) impersonated_user: Option<Arc<String>>,
pub(crate) fetch_size: Option<i64>,
pub(crate) auth: Option<Arc<AuthToken>>,
pub(crate) bookmark_manager: Option<Arc<dyn BookmarkManager>>,
pub(crate) notification_filter: NotificationFilter,
}
impl SessionConfig {
#[inline]
pub fn new() -> SessionConfig {
Self::default()
}
#[inline]
pub fn with_database(mut self, database: Arc<String>) -> Self {
self.database = Some(database);
self
}
#[inline]
pub fn with_default_database(mut self) -> Self {
self.database = None;
self
}
#[inline]
pub fn with_bookmarks(mut self, bookmarks: Arc<Bookmarks>) -> Self {
self.bookmarks = Some(bookmarks);
self
}
#[inline]
pub fn without_bookmarks(mut self) -> Self {
self.bookmarks = None;
self
}
#[inline]
pub fn with_bookmark_manager(mut self, manager: Arc<dyn BookmarkManager>) -> Self {
self.bookmark_manager = Some(manager);
self
}
#[inline]
pub fn without_bookmark_manager(mut self) -> Self {
self.bookmark_manager = None;
self
}
#[inline]
pub fn with_impersonated_user(mut self, user: Arc<String>) -> Self {
self.impersonated_user = Some(user);
self
}
#[inline]
pub fn without_impersonated_user(mut self) -> Self {
self.impersonated_user = None;
self
}
#[inline]
pub fn with_fetch_size(
mut self,
fetch_size: u64,
) -> Result<Self, ConfigureFetchSizeError<Self>> {
match i64::try_from(fetch_size) {
Ok(fetch_size) => {
self.fetch_size = Some(fetch_size);
Ok(self)
}
Err(_) => Err(ConfigureFetchSizeError { builder: self }),
}
}
#[inline]
pub fn with_fetch_all(mut self) -> Self {
self.fetch_size = Some(-1);
self
}
#[inline]
pub fn with_default_fetch_size(mut self) -> Self {
self.fetch_size = None;
self
}
#[inline]
pub fn with_session_auth(mut self, auth: Arc<AuthToken>) -> Self {
self.auth = Some(auth);
self
}
#[inline]
pub fn without_session_auth(mut self) -> Self {
self.auth = None;
self
}
#[inline]
pub fn with_notification_filter(mut self, notification_filter: NotificationFilter) -> Self {
self.notification_filter = notification_filter;
self
}
#[inline]
pub fn with_default_notification_filter(mut self) -> Self {
self.notification_filter = Default::default();
self
}
}
impl AsRef<SessionConfig> for SessionConfig {
#[inline]
fn as_ref(&self) -> &SessionConfig {
self
}
}
#[derive(Debug)]
pub(crate) struct InternalSessionConfig {
pub(crate) config: SessionConfig,
pub(crate) idle_time_before_connection_test: Option<Duration>,
pub(crate) eager_begin: bool,
}