uqa_execution/query/
notice_queue.rs1use parking_lot::Mutex;
10use std::sync::atomic::{AtomicU8, Ordering};
11use std::sync::Arc;
12use uqa_sql::semantics::parameters::catalog::message_levels;
13use uqa_sql::SQLNotice;
14
15pub struct NoticeQueue {
17 notices: Mutex<Vec<SQLNotice>>,
18 client_level: Arc<AtomicU8>,
20}
21
22impl Default for NoticeQueue {
23 fn default() -> Self {
24 Self::new(Arc::new(AtomicU8::new(message_levels::NOTICE)))
25 }
26}
27
28impl NoticeQueue {
29 pub fn new(client_level: Arc<AtomicU8>) -> Self {
31 Self {
32 notices: Mutex::new(Vec::new()),
33 client_level,
34 }
35 }
36
37 pub fn push(&self, notice: SQLNotice) {
39 if notice
40 .level
41 .reaches_client(self.client_level.load(Ordering::Acquire))
42 {
43 self.notices.lock().push(notice);
44 }
45 }
46
47 pub fn take(&self) -> Vec<SQLNotice> {
49 std::mem::take(&mut *self.notices.lock())
50 }
51
52 pub fn snapshot(&self) -> Vec<SQLNotice> {
54 self.notices.lock().clone()
55 }
56
57 pub fn len(&self) -> usize {
58 self.notices.lock().len()
59 }
60
61 pub fn is_empty(&self) -> bool {
62 self.notices.lock().is_empty()
63 }
64}