1 /*
2  * Database - Database abstraction layer for D programing language.
3  *
4  * Copyright (C) 2017  Shanghai Putao Technology Co., Ltd
5  *
6  * Developer: HuntLabs
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.database.DatabaseOption;
13 
14 import hunt.net.util.HttpURI;
15 
16 /**
17  * 
18  */
19 class DatabaseOption {
20 
21     private int _encoderBufferSize = 256;
22     private int _decoderBufferSize = 1024 * 8;
23     private int _maxLifetime = 30000;
24     private int _minimumPoolSize = 1;
25     private int _maximumPoolSize = 5;
26     private int _minldle = 1;
27     private int _connectionTimeout = 10000;
28     private size_t _retry = 5;
29     private int _maxWaitQueueSize = -1;
30     private HttpURI _url;
31 
32     // this()
33     // {
34 
35     // }
36 
37     this(string url) {
38         this._url = new HttpURI(url);
39     }
40 
41     // DatabaseOption addDatabaseSource(string url)
42     // {
43     //     assert(url);
44     //     this._url = new HttpURI(url);
45     //     return this;
46     // }
47 
48     HttpURI url() {
49         return _url;
50     }
51 
52     DatabaseOption maximumPoolSize(int num) {
53         this._maximumPoolSize = num;
54         return this;
55     }
56 
57     int maximumPoolSize() {
58         return _maximumPoolSize;
59     }
60 
61     DatabaseOption minimumPoolSize(int num) {
62         this._minimumPoolSize = num;
63         return this;
64     }
65 
66     int minimumPoolSize() {
67         return _minimumPoolSize;
68     }
69 
70     size_t retry() {
71         return _retry;
72     }
73 
74     DatabaseOption retry(size_t value) {
75         _retry = value;
76         return this;
77     }
78 
79     int maxWaitQueueSize() {
80         return _maxWaitQueueSize;
81     }
82 
83     DatabaseOption maxWaitQueueSize(int value) {
84         _maxWaitQueueSize = value;
85         return this;
86     }
87 
88 
89     DatabaseOption setConnectionTimeout(int time) {
90         assert(time);
91         this._connectionTimeout = time;
92         return this;
93     }
94 
95     int connectionTimeout() {
96         return _connectionTimeout;
97     }
98 
99     int getDecoderBufferSize() {
100         return _decoderBufferSize;
101     }
102 
103     DatabaseOption setDecoderBufferSize(int size) {
104         assert(size > 0, "decoderBufferSize must be > 0");
105         this._decoderBufferSize = size;
106         return this;
107     }
108 
109     int getEncoderBufferSize() {
110         return _encoderBufferSize;
111     }
112 
113     DatabaseOption setEncoderBufferSize(int size) {
114         assert(size > 0, "encoderBufferSize must be > 0");
115         this._encoderBufferSize = size;
116         return this;
117     }
118 
119     string schemeName() {
120         return _url.getScheme();
121     }
122 
123     bool isMysql() {
124         return _url.getScheme() == "mysql";
125     }
126 
127     bool isPgsql() {
128         return _url.getScheme() == "postgresql";
129     }
130 }