@capgo/capacitor-data-storage-sqlite 6.0.59 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CapgoCapacitorDataStorageSqlite.podspec +2 -2
  2. package/Package.swift +30 -0
  3. package/README.md +724 -0
  4. package/android/build.gradle +11 -11
  5. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/CapgoCapacitorDataStorageSqlite.java +290 -320
  6. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/CapgoCapacitorDataStorageSqlitePlugin.java +373 -388
  7. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/RetHandler.java +97 -97
  8. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/Data.java +3 -3
  9. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/Global.java +2 -2
  10. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonStore.java +108 -110
  11. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonTable.java +78 -80
  12. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonValue.java +62 -64
  13. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/StorageDatabaseHelper.java +557 -624
  14. package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/UtilsSQLCipher.java +103 -144
  15. package/dist/docs.json +0 -64
  16. package/dist/esm/definitions.d.ts +0 -19
  17. package/dist/esm/definitions.js.map +1 -1
  18. package/dist/esm/index.d.ts +2 -2
  19. package/dist/esm/index.js +5 -6
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/web-utils/StorageDatabaseHelper.d.ts +2 -2
  22. package/dist/esm/web-utils/StorageDatabaseHelper.js +8 -8
  23. package/dist/esm/web-utils/StorageDatabaseHelper.js.map +1 -1
  24. package/dist/esm/web-utils/json-utils.js +15 -18
  25. package/dist/esm/web-utils/json-utils.js.map +1 -1
  26. package/dist/esm/web.d.ts +2 -3
  27. package/dist/esm/web.js +37 -44
  28. package/dist/esm/web.js.map +1 -1
  29. package/dist/plugin.cjs.js +56 -67
  30. package/dist/plugin.cjs.js.map +1 -1
  31. package/dist/plugin.js +56 -67
  32. package/dist/plugin.js.map +1 -1
  33. package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/CapgoCapacitorDataStorageSqlitePlugin.swift +27 -10
  34. package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/StorageDatabaseHelper.swift +1 -1
  35. package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/UtilsFile.swift +1 -1
  36. package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/UtilsSQLCipher.swift +3 -3
  37. package/ios/Tests/CapgoCapacitorDataStorageSqlitePluginTests/CapacitorDataStorageSqlitePluginTests.swift +13 -0
  38. package/package.json +34 -38
  39. package/electron/dist/plugin.js +0 -1044
  40. package/electron/dist/plugin.js.map +0 -1
  41. package/ios/Plugin/CapgoCapacitorDataStorageSqlitePlugin.h +0 -10
  42. package/ios/Plugin/CapgoCapacitorDataStorageSqlitePlugin.m +0 -29
  43. package/ios/Plugin/Info.plist +0 -24
  44. package/readme.md +0 -210
  45. /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/CapgoCapacitorDataStorageSqlite.swift +0 -0
  46. /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Data.swift +0 -0
  47. /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Global.swift +0 -0
  48. /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/ImportExportJson/JsonStore.swift +0 -0
  49. /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/ReturnHandler.swift +0 -0
  50. /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/Blob.swift +0 -0
  51. /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/UtilsBinding.swift +0 -0
  52. /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/UtilsEncryption.swift +0 -0
@@ -12,376 +12,346 @@ import java.util.List;
12
12
 
13
13
  public class CapgoCapacitorDataStorageSqlite {
14
14
 
15
- private StorageDatabaseHelper mDb;
16
- private Context context;
15
+ private StorageDatabaseHelper mDb;
16
+ private Context context;
17
17
 
18
- public CapgoCapacitorDataStorageSqlite(Context context) {
19
- this.context = context;
20
- }
21
-
22
- /**
23
- * Echo
24
- *
25
- * @param value
26
- * @return String
27
- */
28
- public String echo(String value) {
29
- return value;
30
- }
18
+ public CapgoCapacitorDataStorageSqlite(Context context) {
19
+ this.context = context;
20
+ }
31
21
 
32
- public void openStore(
33
- String dbName,
34
- String tableName,
35
- Boolean encrypted,
36
- String inMode,
37
- int version
38
- ) throws Exception {
39
- try {
40
- mDb = new StorageDatabaseHelper(
41
- context,
42
- dbName + "SQLite.db",
43
- tableName,
44
- encrypted,
45
- inMode,
46
- version
47
- );
48
- if (mDb != null) {
49
- mDb.open();
50
- if (mDb.isOpen) {
51
- return;
52
- } else {
53
- throw new Exception("mDb is not opened");
22
+ public void openStore(String dbName, String tableName, Boolean encrypted, String inMode, int version) throws Exception {
23
+ try {
24
+ mDb = new StorageDatabaseHelper(context, dbName + "SQLite.db", tableName, encrypted, inMode, version);
25
+ if (mDb != null) {
26
+ mDb.open();
27
+ if (mDb.isOpen) {
28
+ return;
29
+ } else {
30
+ throw new Exception("mDb is not opened");
31
+ }
32
+ } else {
33
+ throw new Exception("mDb is null");
34
+ }
35
+ } catch (Exception e) {
36
+ throw new Exception(e.getMessage());
54
37
  }
55
- } else {
56
- throw new Exception("mDb is null");
57
- }
58
- } catch (Exception e) {
59
- throw new Exception(e.getMessage());
60
38
  }
61
- }
62
39
 
63
- public void closeStore(String dbName) throws Exception {
64
- String database = dbName + "SQLite.db";
65
- if (mDb != null && mDb.isOpen && mDb.getStoreName().equals(database)) {
66
- try {
67
- mDb.close();
68
- return;
69
- } catch (Exception e) {
70
- throw new Exception(e.getMessage());
71
- }
72
- } else {
73
- throw new Exception("mDb " + dbName + " is not opened or null");
40
+ public void closeStore(String dbName) throws Exception {
41
+ String database = dbName + "SQLite.db";
42
+ if (mDb != null && mDb.isOpen && mDb.getStoreName().equals(database)) {
43
+ try {
44
+ mDb.close();
45
+ return;
46
+ } catch (Exception e) {
47
+ throw new Exception(e.getMessage());
48
+ }
49
+ } else {
50
+ throw new Exception("mDb " + dbName + " is not opened or null");
51
+ }
74
52
  }
75
- }
76
53
 
77
- public boolean isStoreOpen(String dbName) throws Exception {
78
- String database = dbName + "SQLite.db";
79
- if (mDb != null && mDb.getStoreName().equals(database)) {
80
- return mDb.isOpen;
81
- } else {
82
- throw new Exception("mDb " + dbName + " is not the current one or null");
54
+ public boolean isStoreOpen(String dbName) throws Exception {
55
+ String database = dbName + "SQLite.db";
56
+ if (mDb != null && mDb.getStoreName().equals(database)) {
57
+ return mDb.isOpen;
58
+ } else {
59
+ throw new Exception("mDb " + dbName + " is not the current one or null");
60
+ }
83
61
  }
84
- }
85
62
 
86
- public void set(String key, String value) throws Exception {
87
- if (mDb != null && mDb.isOpen) {
88
- try {
89
- Data data = new Data();
90
- data.name = key;
91
- data.value = value;
92
- mDb.set(data);
93
- return;
94
- } catch (Exception e) {
95
- throw new Exception(e.getMessage());
96
- }
97
- } else {
98
- throw new Exception("mDb is not opened or null");
63
+ public void set(String key, String value) throws Exception {
64
+ if (mDb != null && mDb.isOpen) {
65
+ try {
66
+ Data data = new Data();
67
+ data.name = key;
68
+ data.value = value;
69
+ mDb.set(data);
70
+ return;
71
+ } catch (Exception e) {
72
+ throw new Exception(e.getMessage());
73
+ }
74
+ } else {
75
+ throw new Exception("mDb is not opened or null");
76
+ }
99
77
  }
100
- }
101
78
 
102
- public String get(String key) throws Exception {
103
- if (mDb != null && mDb.isOpen) {
104
- try {
105
- Data data = mDb.get(key);
106
- if (data.id == null) {
107
- return "";
79
+ public String get(String key) throws Exception {
80
+ if (mDb != null && mDb.isOpen) {
81
+ try {
82
+ Data data = mDb.get(key);
83
+ if (data.id == null) {
84
+ return "";
85
+ } else {
86
+ return data.value;
87
+ }
88
+ } catch (Exception e) {
89
+ throw new Exception(e.getMessage());
90
+ }
108
91
  } else {
109
- return data.value;
92
+ throw new Exception("mDb is not opened or null");
110
93
  }
111
- } catch (Exception e) {
112
- throw new Exception(e.getMessage());
113
- }
114
- } else {
115
- throw new Exception("mDb is not opened or null");
116
94
  }
117
- }
118
95
 
119
- public void remove(String name) throws Exception {
120
- if (mDb != null && mDb.isOpen) {
121
- try {
122
- mDb.remove(name);
123
- return;
124
- } catch (Exception e) {
125
- throw new Exception(e.getMessage());
126
- }
127
- } else {
128
- throw new Exception("mDb is not opened or null");
96
+ public void remove(String name) throws Exception {
97
+ if (mDb != null && mDb.isOpen) {
98
+ try {
99
+ mDb.remove(name);
100
+ return;
101
+ } catch (Exception e) {
102
+ throw new Exception(e.getMessage());
103
+ }
104
+ } else {
105
+ throw new Exception("mDb is not opened or null");
106
+ }
129
107
  }
130
- }
131
108
 
132
- public void clear() throws Exception {
133
- if (mDb != null && mDb.isOpen) {
134
- try {
135
- mDb.clear();
136
- return;
137
- } catch (Exception e) {
138
- throw new Exception(e.getMessage());
139
- }
140
- } else {
141
- throw new Exception("mDb is not opened or null");
109
+ public void clear() throws Exception {
110
+ if (mDb != null && mDb.isOpen) {
111
+ try {
112
+ mDb.clear();
113
+ return;
114
+ } catch (Exception e) {
115
+ throw new Exception(e.getMessage());
116
+ }
117
+ } else {
118
+ throw new Exception("mDb is not opened or null");
119
+ }
142
120
  }
143
- }
144
121
 
145
- public boolean iskey(String name) throws Exception {
146
- boolean ret = false;
147
- if (mDb != null && mDb.isOpen) {
148
- try {
149
- ret = mDb.iskey(name);
150
- return ret;
151
- } catch (Exception e) {
152
- throw new Exception(e.getMessage());
153
- }
154
- } else {
155
- throw new Exception("mDb is not opened or null");
122
+ public boolean iskey(String name) throws Exception {
123
+ boolean ret = false;
124
+ if (mDb != null && mDb.isOpen) {
125
+ try {
126
+ ret = mDb.iskey(name);
127
+ return ret;
128
+ } catch (Exception e) {
129
+ throw new Exception(e.getMessage());
130
+ }
131
+ } else {
132
+ throw new Exception("mDb is not opened or null");
133
+ }
156
134
  }
157
- }
158
135
 
159
- public String[] keys() throws Exception {
160
- if (mDb != null && mDb.isOpen) {
161
- try {
162
- List<String> resKeys = mDb.keys();
163
- String[] keyArray = resKeys.toArray(new String[resKeys.size()]);
164
- return keyArray;
165
- } catch (Exception e) {
166
- throw new Exception(e.getMessage());
167
- }
168
- } else {
169
- throw new Exception("mDb is not opened or null");
136
+ public String[] keys() throws Exception {
137
+ if (mDb != null && mDb.isOpen) {
138
+ try {
139
+ List<String> resKeys = mDb.keys();
140
+ String[] keyArray = resKeys.toArray(new String[resKeys.size()]);
141
+ return keyArray;
142
+ } catch (Exception e) {
143
+ throw new Exception(e.getMessage());
144
+ }
145
+ } else {
146
+ throw new Exception("mDb is not opened or null");
147
+ }
170
148
  }
171
- }
172
149
 
173
- public String[] values() throws Exception {
174
- if (mDb != null && mDb.isOpen) {
175
- try {
176
- List<String> resValues = mDb.values();
177
- String[] valueArray = resValues.toArray(new String[resValues.size()]);
178
- return valueArray;
179
- } catch (Exception e) {
180
- throw new Exception(e.getMessage());
181
- }
182
- } else {
183
- throw new Exception("mDb is not opened or null");
150
+ public String[] values() throws Exception {
151
+ if (mDb != null && mDb.isOpen) {
152
+ try {
153
+ List<String> resValues = mDb.values();
154
+ String[] valueArray = resValues.toArray(new String[resValues.size()]);
155
+ return valueArray;
156
+ } catch (Exception e) {
157
+ throw new Exception(e.getMessage());
158
+ }
159
+ } else {
160
+ throw new Exception("mDb is not opened or null");
161
+ }
184
162
  }
185
- }
186
163
 
187
- public String[] filtervalues(String filter) throws Exception {
188
- if (mDb != null && mDb.isOpen) {
189
- try {
190
- List<String> resValues = mDb.filtervalues(filter);
191
- String[] valueArray = resValues.toArray(new String[resValues.size()]);
192
- return valueArray;
193
- } catch (Exception e) {
194
- throw new Exception(e.getMessage());
195
- }
196
- } else {
197
- throw new Exception("mDb is not opened or null");
164
+ public String[] filtervalues(String filter) throws Exception {
165
+ if (mDb != null && mDb.isOpen) {
166
+ try {
167
+ List<String> resValues = mDb.filtervalues(filter);
168
+ String[] valueArray = resValues.toArray(new String[resValues.size()]);
169
+ return valueArray;
170
+ } catch (Exception e) {
171
+ throw new Exception(e.getMessage());
172
+ }
173
+ } else {
174
+ throw new Exception("mDb is not opened or null");
175
+ }
198
176
  }
199
- }
200
177
 
201
- public JSObject[] keysvalues() throws Exception {
202
- if (mDb != null && mDb.isOpen) {
203
- try {
204
- List<Data> resKeysValues = mDb.keysvalues();
205
- JSObject[] jsObjArray = new JSObject[resKeysValues.size()];
178
+ public JSObject[] keysvalues() throws Exception {
179
+ if (mDb != null && mDb.isOpen) {
180
+ try {
181
+ List<Data> resKeysValues = mDb.keysvalues();
182
+ JSObject[] jsObjArray = new JSObject[resKeysValues.size()];
206
183
 
207
- for (int i = 0; i < resKeysValues.size(); i++) {
208
- JSObject res = new JSObject();
209
- res.put("key", resKeysValues.get(i).name);
210
- res.put("value", resKeysValues.get(i).value);
211
- jsObjArray[i] = res;
184
+ for (int i = 0; i < resKeysValues.size(); i++) {
185
+ JSObject res = new JSObject();
186
+ res.put("key", resKeysValues.get(i).name);
187
+ res.put("value", resKeysValues.get(i).value);
188
+ jsObjArray[i] = res;
189
+ }
190
+ return jsObjArray;
191
+ } catch (Exception e) {
192
+ throw new Exception(e.getMessage());
193
+ }
194
+ } else {
195
+ throw new Exception("mDb is not opened or null");
212
196
  }
213
- return jsObjArray;
214
- } catch (Exception e) {
215
- throw new Exception(e.getMessage());
216
- }
217
- } else {
218
- throw new Exception("mDb is not opened or null");
219
197
  }
220
- }
221
198
 
222
- public void setTable(String table) throws Exception {
223
- if (mDb != null && mDb.isOpen) {
224
- try {
225
- mDb.setTable(table, true);
226
- return;
227
- } catch (Exception e) {
228
- throw new Exception(e.getMessage());
229
- }
230
- } else {
231
- throw new Exception("mDb is not opened or null");
199
+ public void setTable(String table) throws Exception {
200
+ if (mDb != null && mDb.isOpen) {
201
+ try {
202
+ mDb.setTable(table, true);
203
+ return;
204
+ } catch (Exception e) {
205
+ throw new Exception(e.getMessage());
206
+ }
207
+ } else {
208
+ throw new Exception("mDb is not opened or null");
209
+ }
232
210
  }
233
- }
234
211
 
235
- public boolean isTable(String table) throws Exception {
236
- boolean ret = false;
237
- if (mDb != null && mDb.isOpen) {
238
- try {
239
- ret = mDb.isTable(table);
240
- return ret;
241
- } catch (Exception e) {
242
- throw new Exception(e.getMessage());
243
- }
244
- } else {
245
- throw new Exception("mDb is not opened or null");
212
+ public boolean isTable(String table) throws Exception {
213
+ boolean ret = false;
214
+ if (mDb != null && mDb.isOpen) {
215
+ try {
216
+ ret = mDb.isTable(table);
217
+ return ret;
218
+ } catch (Exception e) {
219
+ throw new Exception(e.getMessage());
220
+ }
221
+ } else {
222
+ throw new Exception("mDb is not opened or null");
223
+ }
246
224
  }
247
- }
248
225
 
249
- public String[] tables() throws Exception {
250
- if (mDb != null && mDb.isOpen) {
251
- try {
252
- List<String> resTables = mDb.tables();
253
- String[] tableArray = resTables.toArray(new String[resTables.size()]);
254
- return tableArray;
255
- } catch (Exception e) {
256
- throw new Exception(e.getMessage());
257
- }
258
- } else {
259
- throw new Exception("mDb is not opened or null");
226
+ public String[] tables() throws Exception {
227
+ if (mDb != null && mDb.isOpen) {
228
+ try {
229
+ List<String> resTables = mDb.tables();
230
+ String[] tableArray = resTables.toArray(new String[resTables.size()]);
231
+ return tableArray;
232
+ } catch (Exception e) {
233
+ throw new Exception(e.getMessage());
234
+ }
235
+ } else {
236
+ throw new Exception("mDb is not opened or null");
237
+ }
260
238
  }
261
- }
262
239
 
263
- public void deleteTable(String table) throws Exception {
264
- if (mDb != null && mDb.isOpen) {
265
- try {
266
- mDb.deleteTable(table);
267
- return;
268
- } catch (Exception e) {
269
- throw new Exception(e.getMessage());
270
- }
271
- } else {
272
- throw new Exception("mDb is not opened or null");
240
+ public void deleteTable(String table) throws Exception {
241
+ if (mDb != null && mDb.isOpen) {
242
+ try {
243
+ mDb.deleteTable(table);
244
+ return;
245
+ } catch (Exception e) {
246
+ throw new Exception(e.getMessage());
247
+ }
248
+ } else {
249
+ throw new Exception("mDb is not opened or null");
250
+ }
273
251
  }
274
- }
275
252
 
276
- public void deleteStore(String dbName) throws Exception {
277
- try {
278
- context.deleteDatabase(dbName + "SQLite.db");
279
- context.deleteFile(dbName + "SQLite.db");
280
- File databaseFile = context.getDatabasePath(dbName + "SQLite.db");
281
- if (databaseFile.exists()) {
282
- throw new Exception("failed to delete the store");
283
- } else {
284
- return;
285
- }
286
- } catch (Exception e) {
287
- throw new Exception(e.getMessage());
253
+ public void deleteStore(String dbName) throws Exception {
254
+ try {
255
+ context.deleteDatabase(dbName + "SQLite.db");
256
+ context.deleteFile(dbName + "SQLite.db");
257
+ File databaseFile = context.getDatabasePath(dbName + "SQLite.db");
258
+ if (databaseFile.exists()) {
259
+ throw new Exception("failed to delete the store");
260
+ } else {
261
+ return;
262
+ }
263
+ } catch (Exception e) {
264
+ throw new Exception(e.getMessage());
265
+ }
288
266
  }
289
- }
290
267
 
291
- public boolean isStoreExists(String dbName) throws Exception {
292
- boolean ret = false;
293
- try {
294
- File databaseFile = context.getDatabasePath(dbName + "SQLite.db");
295
- if (databaseFile.exists()) ret = true;
296
- return ret;
297
- } catch (Exception e) {
298
- throw new Exception(e.getMessage());
268
+ public boolean isStoreExists(String dbName) throws Exception {
269
+ boolean ret = false;
270
+ try {
271
+ File databaseFile = context.getDatabasePath(dbName + "SQLite.db");
272
+ if (databaseFile.exists()) ret = true;
273
+ return ret;
274
+ } catch (Exception e) {
275
+ throw new Exception(e.getMessage());
276
+ }
299
277
  }
300
- }
301
278
 
302
- public Boolean isJsonValid(String parsingData) throws Exception {
303
- try {
304
- JSObject jsonObject = new JSObject(parsingData);
305
- JsonStore jsonSQL = new JsonStore();
306
- Boolean isValid = jsonSQL.isJsonStore(jsonObject);
307
- return isValid;
308
- } catch (Exception e) {
309
- throw new Exception(e.getMessage());
279
+ public Boolean isJsonValid(String parsingData) throws Exception {
280
+ try {
281
+ JSObject jsonObject = new JSObject(parsingData);
282
+ JsonStore jsonSQL = new JsonStore();
283
+ Boolean isValid = jsonSQL.isJsonStore(jsonObject);
284
+ return isValid;
285
+ } catch (Exception e) {
286
+ throw new Exception(e.getMessage());
287
+ }
310
288
  }
311
- }
312
289
 
313
- public JSObject importFromJson(String parsingData) throws Exception {
314
- try {
315
- JSObject retObj = new JSObject();
316
- JSObject jsonObject = new JSObject(parsingData);
317
- JsonStore jsonSQL = new JsonStore();
318
- Boolean isValid = jsonSQL.isJsonStore(jsonObject);
319
- if (!isValid) {
320
- String msg = "Stringify Json Object not Valid";
321
- throw new Exception(msg);
322
- }
323
- int totalChanges = 0;
324
- String dbName = jsonSQL.getDatabase();
325
- Boolean encrypted = jsonSQL.getEncrypted();
326
- String inMode = "";
327
- if (encrypted) {
328
- inMode = "secret";
329
- }
330
- ArrayList<JsonTable> tables = jsonSQL.getTables();
331
- for (JsonTable table : tables) {
332
- // open the database
333
- mDb = new StorageDatabaseHelper(
334
- context,
335
- dbName + "SQLite.db",
336
- table.getName(),
337
- encrypted,
338
- inMode,
339
- 1
340
- );
341
- if (mDb != null) {
342
- mDb.open();
343
- if (mDb.isOpen) {
344
- int changes = mDb.importFromJson(table.getValues());
345
- mDb.close();
346
- if (changes < 1) {
347
- throw new Exception("changes < 1");
348
- } else {
349
- totalChanges += changes;
290
+ public JSObject importFromJson(String parsingData) throws Exception {
291
+ try {
292
+ JSObject retObj = new JSObject();
293
+ JSObject jsonObject = new JSObject(parsingData);
294
+ JsonStore jsonSQL = new JsonStore();
295
+ Boolean isValid = jsonSQL.isJsonStore(jsonObject);
296
+ if (!isValid) {
297
+ String msg = "Stringify Json Object not Valid";
298
+ throw new Exception(msg);
350
299
  }
351
- } else {
352
- throw new Exception("mDb is not opened");
353
- }
354
- } else {
355
- throw new Exception("mDb is null");
300
+ int totalChanges = 0;
301
+ String dbName = jsonSQL.getDatabase();
302
+ Boolean encrypted = jsonSQL.getEncrypted();
303
+ String inMode = "";
304
+ if (encrypted) {
305
+ inMode = "secret";
306
+ }
307
+ ArrayList<JsonTable> tables = jsonSQL.getTables();
308
+ for (JsonTable table : tables) {
309
+ // open the database
310
+ mDb = new StorageDatabaseHelper(context, dbName + "SQLite.db", table.getName(), encrypted, inMode, 1);
311
+ if (mDb != null) {
312
+ mDb.open();
313
+ if (mDb.isOpen) {
314
+ int changes = mDb.importFromJson(table.getValues());
315
+ mDb.close();
316
+ if (changes < 1) {
317
+ throw new Exception("changes < 1");
318
+ } else {
319
+ totalChanges += changes;
320
+ }
321
+ } else {
322
+ throw new Exception("mDb is not opened");
323
+ }
324
+ } else {
325
+ throw new Exception("mDb is null");
326
+ }
327
+ }
328
+ retObj.put("changes", totalChanges);
329
+ return retObj;
330
+ } catch (Exception e) {
331
+ String msg = "importFromJson : " + e.getMessage();
332
+ throw new Exception(msg);
356
333
  }
357
- }
358
- retObj.put("changes", totalChanges);
359
- return retObj;
360
- } catch (Exception e) {
361
- String msg = "importFromJson : " + e.getMessage();
362
- throw new Exception(msg);
363
334
  }
364
- }
365
335
 
366
- public JSObject exportToJson() throws Exception {
367
- if (mDb != null && mDb.isOpen) {
368
- try {
369
- JSObject ret = mDb.exportToJson();
370
- JsonStore jsonSQL = new JsonStore();
371
- Boolean isValid = jsonSQL.isJsonStore(ret);
372
- if (isValid) {
373
- return ret;
336
+ public JSObject exportToJson() throws Exception {
337
+ if (mDb != null && mDb.isOpen) {
338
+ try {
339
+ JSObject ret = mDb.exportToJson();
340
+ JsonStore jsonSQL = new JsonStore();
341
+ Boolean isValid = jsonSQL.isJsonStore(ret);
342
+ if (isValid) {
343
+ return ret;
344
+ } else {
345
+ String msg = "ExportToJson: return Obj is not a JsonStore Obj";
346
+ throw new Exception(msg);
347
+ }
348
+ } catch (Exception e) {
349
+ String msg = "ExportToJson " + e.getMessage();
350
+ throw new Exception(msg);
351
+ }
374
352
  } else {
375
- String msg = "ExportToJson: return Obj is not a JsonStore Obj";
376
- throw new Exception(msg);
353
+ String msg = "mDb is not opened or null ";
354
+ throw new Exception(msg);
377
355
  }
378
- } catch (Exception e) {
379
- String msg = "ExportToJson " + e.getMessage();
380
- throw new Exception(msg);
381
- }
382
- } else {
383
- String msg = "mDb is not opened or null ";
384
- throw new Exception(msg);
385
356
  }
386
- }
387
357
  }