/
db_quick.java
314 lines (222 loc) · 10.8 KB
/
db_quick.java
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package accessory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
//Use the methods in this class very carefully! Low-to-no checks are performed.
public abstract class db_quick
{
static String[] _cols = new String[0];
public static boolean is_ok(String source_) { return (is_quicker(source_) ? db_quicker.is_ok() : db.is_ok(source_)); }
public static String get_select_count_col(String source_, String type_) { return (is_quicker(source_) ? db_quicker.get_select_count_col(type_) : db.get_select_count_col(source_)); }
public static boolean is_quicker(String source_) { return db_quicker.is_ok(source_); }
public static boolean is_quicker_mysql(String source_) { return db_quicker.is_mysql(source_); }
public static void update_conn_info(String source_)
{
if (is_quicker(source_)) db_quicker.update_conn_info(source_);
}
public static void update_conn_info(String source_, String username_, String password_, String db_name_, String host_, String user_, String max_pool_)
{
if (is_quicker(source_)) db_quicker.update_conn_info(username_, password_, db_name_, host_, user_, max_pool_);
}
public static boolean change_db_name_queries(String source_, String name_)
{
boolean output = db.change_db_name_queries(source_, name_);
if (output) update_conn_info(source_);
return output;
}
public static boolean change_table_name_queries(String source_, String name_)
{
boolean output = db.change_table_name_queries(source_, name_);
if (output && is_quicker(source_)) db_quicker.update_table(source_, name_);
return output;
}
public static boolean change_col_name_queries(String source_, String field_, String name_)
{
boolean output = db.change_col_name_queries(source_, field_, name_);
if (output) db_quick.populate_col(source_, field_);
return output;
}
public static String get_table(String source_) { return (is_quicker(source_) ? db_quicker.get_table(source_) : db.get_table(source_)); }
public static String get_col(String source_, String field_)
{
int i = db.get_field_i(source_, field_);
return (i > arrays.WRONG_I ? _cols[i] : db.get_col(source_, field_));
}
public static String[] get_cols(String source_)
{
String[] output = null;
int[] min_max = db.get_source_min_max(source_);
if (min_max == null) return output;
output = new String[db.get_source_fields_tot(min_max)];
int i2 = -1;
for (int i = min_max[0]; i <= min_max[1]; i++)
{
i2++;
output[i2] = _cols[i];
}
return output;
}
public static String[] get_cols(String source_, String[] fields_)
{
int tot = arrays.get_size(fields_);
if (tot == 0) return null;
String[] cols = new String[tot];
for (int i = 0; i < tot; i++)
{
String col = get_col(source_, fields_[i]);
if (!strings.is_ok(col)) continue;
cols[i] = col;
}
return cols;
}
public static void update_cols(String source_) { populate_cols(source_, db.get_source_fields(source_)); }
public static boolean input_is_ok(Object input_) { return (db.input_is_ok(input_) && !arrays.hashmap_is_xy(input_)); }
public static boolean exists(String source_, String where_cols_)
{
boolean output = db.WRONG_BOOLEAN;
if (is_quicker_mysql(source_)) output = db_quicker_mysql.exists(source_, where_cols_);
else output = db.exists(source_, where_cols_);
return output;
}
public static String select_one_string(String source_, String col_, String where_cols_, String order_cols_)
{
String output = db.WRONG_STRING;
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_one_string(source_, col_, where_cols_, order_cols_);
else output = db.select_one_string_quick(source_, col_, where_cols_, order_cols_);
return output;
}
public static double select_one_decimal(String source_, String col_, String where_cols_, String order_cols_)
{
double output = db.WRONG_DECIMAL;
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_one_decimal(source_, col_, where_cols_, order_cols_);
else output = db.select_one_decimal_quick(source_, col_, where_cols_, order_cols_);
return output;
}
public static long select_one_long(String source_, String col_, String where_cols_, String order_cols_)
{
long output = db.WRONG_LONG;
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_one_long(source_, col_, where_cols_, order_cols_);
else output = db.select_one_long_quick(source_, col_, where_cols_, order_cols_);
return output;
}
public static int select_one_int(String source_, String col_, String where_cols_, String order_cols_)
{
int output = db.WRONG_INT;
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_one_int(source_, col_, where_cols_, order_cols_);
else output = db.select_one_int_quick(source_, col_, where_cols_, order_cols_);
return output;
}
public static boolean select_one_boolean(String source_, String col_, String where_cols_, String order_cols_)
{
boolean output = db.WRONG_BOOLEAN;
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_one_boolean(source_, col_, where_cols_, order_cols_);
else output = db.select_one_boolean_quick(source_, col_, where_cols_, order_cols_);
return output;
}
public static HashMap<String, String> select_one(String source_, String[] cols_, String where_cols_, String order_cols_)
{
HashMap<String, String> output = new HashMap<String, String>();
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_one(source_, cols_, where_cols_, order_cols_);
else output = db.select_one_quick(source_, cols_, where_cols_, order_cols_);
return output;
}
public static ArrayList<String> select_some_strings(String source_, String col_, String where_cols_, int max_rows_, String order_cols_)
{
ArrayList<String> output = new ArrayList<String>();
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_some_strings(source_, col_, where_cols_, max_rows_, order_cols_);
else output = db.select_some_strings_quick(source_, col_, where_cols_, max_rows_, order_cols_);
return output;
}
public static ArrayList<Double> select_some_decimals(String source_, String col_, String where_cols_, int max_rows_, String order_cols_)
{
ArrayList<Double> output = new ArrayList<Double>();
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_some_decimals(source_, col_, where_cols_, max_rows_, order_cols_);
else output = db.select_some_decimals_quick(source_, col_, where_cols_, max_rows_, order_cols_);
return output;
}
public static ArrayList<Long> select_some_longs(String source_, String col_, String where_cols_, int max_rows_, String order_cols_)
{
ArrayList<Long> output = new ArrayList<Long>();
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_some_longs(source_, col_, where_cols_, max_rows_, order_cols_);
else output = db.select_some_longs_quick(source_, col_, where_cols_, max_rows_, order_cols_);
return output;
}
public static ArrayList<Integer> select_some_ints(String source_, String col_, String where_cols_, int max_rows_, String order_cols_)
{
ArrayList<Integer> output = new ArrayList<Integer>();
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_some_ints(source_, col_, where_cols_, max_rows_, order_cols_);
else output = db.select_some_ints_quick(source_, col_, where_cols_, max_rows_, order_cols_);
return output;
}
public static ArrayList<Boolean> select_some_booleans(String source_, String col_, String where_cols_, int max_rows_, String order_cols_)
{
ArrayList<Boolean> output = new ArrayList<Boolean>();
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_some_booleans(source_, col_, where_cols_, max_rows_, order_cols_);
else output = db.select_some_booleans_quick(source_, col_, where_cols_, max_rows_, order_cols_);
return output;
}
public static ArrayList<HashMap<String, String>> select(String source_, String[] cols_, String where_cols_, int max_rows_, String order_cols_)
{
ArrayList<HashMap<String, String>> output = new ArrayList<HashMap<String, String>>();
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select(source_, cols_, where_cols_, max_rows_, order_cols_);
else output = db.select_quick(source_, cols_, where_cols_, max_rows_, order_cols_);
return output;
}
public static int select_count(String source_, String where_cols_)
{
int output = 0;
if (is_quicker_mysql(source_)) output = db_quicker_mysql.select_count(source_, where_cols_);
else output = db.select_count(source_, where_cols_);
return output;
}
public static void insert_update(String source_, String any_col_, HashMap<String, String> vals_, String where_cols_)
{
if (is_quicker_mysql(source_)) db_quicker_mysql.insert_update(source_, any_col_, vals_, where_cols_);
else db.insert_update_quick(source_, vals_, where_cols_);
}
public static void insert(String source_, HashMap<String, String> vals_)
{
if (is_quicker_mysql(source_)) db_quicker_mysql.insert(source_, vals_);
else db.insert_quick(source_, vals_);
}
public static void update(String source_, HashMap<String, String> vals_, String where_cols_)
{
if (is_quicker_mysql(source_)) db_quicker_mysql.update(source_, vals_, where_cols_);
else db.update_quick(source_, vals_, where_cols_);
}
static void populate_cols_ini()
{
int tot = db.SOURCES.length;
if (tot == 0) return;
for (String source: db.SOURCES) populate_cols(source, db.get_source_fields(source));
}
static ArrayList<HashMap<String, String>> execute(String source_, String query_type_, String[] cols_, HashMap<String, String> vals_, String where_, int max_rows_, String order_, HashMap<String, db_field> cols_info_)
{
ArrayList<HashMap<String, String>> output = null;
if (is_quicker_mysql(source_)) output = db_quicker_mysql.execute(source_, query_type_, cols_, vals_, where_, max_rows_, order_, cols_info_);
else db.execute(source_, query_type_, cols_, vals_, where_, max_rows_, order_, cols_info_);
return output;
}
static ArrayList<HashMap<String, String>> execute_query(String type_, String source_, String query_, boolean return_data_, String[] cols_)
{
ArrayList<HashMap<String, String>> output = null;
if (is_quicker(source_))
{
db_quicker.initialise();
output = db_quicker.execute_query(type_, source_, query_, return_data_, cols_);
}
else output = db.execute_query(type_, source_, query_, return_data_, cols_);
return output;
}
private static void populate_cols(String source_, HashMap<String, db_field> fields_)
{
if (!arrays.is_ok(fields_)) return;
for (Entry<String, db_field> item: fields_.entrySet()) { populate_col(source_, item.getKey()); }
}
private static void populate_col(String source_, String field_)
{
int i = db.get_field_i(source_, field_);
String col = db.get_col(source_, field_);
if (i > arrays.WRONG_I && strings.is_ok(col)) _cols = arrays_quick.add(_cols, i, col);
}
}