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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#[derive(Clone, Debug)]
pub struct DatabaseConfiguration {
    pub database: String,
    pub endpoints: Vec<String>,
    pub username: String,
    pub password: String,
    pub jwt_token: String,
    pub tls_cert: Option<String>,
}

impl Default for DatabaseConfiguration {
    fn default() -> Self {
        DatabaseConfigurationBuilder::new().build()
    }
}

pub struct DatabaseConfigurationBuilder {
    database: Option<String>,
    endpoints: Option<Vec<String>>,
    username: Option<String>,
    password: Option<String>,
    jwt_token: Option<String>,
    tls_cert: Option<String>,
}

impl Default for DatabaseConfigurationBuilder {
    fn default() -> Self {
        Self::new()
    }
}

impl DatabaseConfigurationBuilder {
    pub fn new() -> Self {
        DatabaseConfigurationBuilder {
            database: None,
            endpoints: None,
            username: None,
            password: None,
            jwt_token: None,
            tls_cert: None,
        }
    }

    pub fn database(mut self, database: String) -> Self {
        self.database = Some(database);
        self
    }

    pub fn endpoints(mut self, endpoints: Vec<String>) -> Self {
        self.endpoints = Some(endpoints);
        self
    }

    pub fn username(mut self, username: String) -> Self {
        self.username = Some(username);
        self
    }

    pub fn password(mut self, password: String) -> Self {
        self.password = Some(password);
        self
    }

    pub fn jwt_token(mut self, jwt_token: String) -> Self {
        self.jwt_token = Some(jwt_token);
        self
    }

    pub fn tls_cert(mut self, tls_cert: String) -> Self {
        self.tls_cert = Some(tls_cert);
        self
    }

    pub fn build(self) -> DatabaseConfiguration {
        DatabaseConfiguration {
            database: self.database.unwrap_or_else(|| "_system".to_string()),
            endpoints: self
                .endpoints
                .unwrap_or_else(|| vec!["http://localhost:8529".to_string()]),
            username: self.username.unwrap_or_else(|| "root".to_string()),
            password: self.password.unwrap_or_default(),
            jwt_token: self.jwt_token.unwrap_or_default(),
            tls_cert: self.tls_cert,
        }
    }
}

#[derive(Clone, Debug)]
pub struct DataLoadConfiguration {
    pub parallelism: u32,
    pub batch_size: u64,
    pub prefetch_count: u32,
    pub load_all_vertex_attributes: bool,
    pub load_all_edge_attributes: bool,
}

impl Default for DataLoadConfiguration {
    fn default() -> Self {
        DataLoadConfigurationBuilder::new().build()
    }
}

impl DataLoadConfiguration {
    pub fn new(
        parallelism: Option<u32>,
        batch_size: Option<u64>,
        prefetch_count: Option<u32>,
        load_all_vertex_attributes: bool,
        load_all_edge_attributes: bool,
    ) -> Self {
        DataLoadConfiguration {
            parallelism: parallelism.unwrap_or(8),
            batch_size: batch_size.unwrap_or(100_000),
            prefetch_count: prefetch_count.unwrap_or(5),
            load_all_vertex_attributes,
            load_all_edge_attributes,
        }
    }
}

pub struct DataLoadConfigurationBuilder {
    parallelism: Option<u32>,
    batch_size: Option<u64>,
    prefetch_count: Option<u32>,
    load_all_vertex_attributes: bool,
    load_all_edge_attributes: bool,
}

impl Default for DataLoadConfigurationBuilder {
    fn default() -> Self {
        Self::new()
    }
}

impl DataLoadConfigurationBuilder {
    pub fn new() -> Self {
        DataLoadConfigurationBuilder {
            parallelism: None,
            batch_size: None,
            prefetch_count: None,
            load_all_vertex_attributes: false,
            load_all_edge_attributes: false,
        }
    }

    pub fn parallelism(mut self, parallelism: u32) -> Self {
        self.parallelism = Some(parallelism);
        self
    }

    pub fn batch_size(mut self, batch_size: u64) -> Self {
        self.batch_size = Some(batch_size);
        self
    }

    pub fn prefetch_count(mut self, prefetch_count: u32) -> Self {
        self.prefetch_count = Some(prefetch_count);
        self
    }

    pub fn load_all_vertex_attributes(mut self, load_all_vertex_attributes: bool) -> Self {
        self.load_all_vertex_attributes = load_all_vertex_attributes;
        self
    }

    pub fn load_all_edge_attributes(mut self, load_all_edge_attributes: bool) -> Self {
        self.load_all_edge_attributes = load_all_edge_attributes;
        self
    }

    pub fn build(self) -> DataLoadConfiguration {
        DataLoadConfiguration::new(
            self.parallelism,
            self.batch_size,
            self.prefetch_count,
            self.load_all_vertex_attributes,
            self.load_all_edge_attributes,
        )
    }
}