Skip to content

Commit ef53c39

Browse files
committed
JsonManager JSONObject 반환 get 메소드 제거
1 parent 2d1a102 commit ef53c39

File tree

3 files changed

+27
-49
lines changed

3 files changed

+27
-49
lines changed

.idea/workspace.xml

Lines changed: 2 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/com/inzapp/jsonToSqlParser/core/Parser.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import net.sf.jsqlparser.statement.insert.Insert;
1515
import net.sf.jsqlparser.statement.select.*;
1616
import net.sf.jsqlparser.statement.update.Update;
17-
import org.json.JSONException;
1817
import org.json.JSONObject;
1918

2019
import java.util.ArrayList;
@@ -25,14 +24,14 @@ public String parse(JSONObject json) {
2524
injectJson(json);
2625

2726
Statement statement;
28-
String crud = getListFromJson(JsonKey.CRUD).get(0);
27+
String crud = getFromJson(JsonKey.CRUD).get(0);
2928
switch (crud) {
3029
case JsonKey.INSERT:
3130
statement = getInsert();
3231
break;
3332

3433
case JsonKey.SELECT:
35-
if (getListFromJson(JsonKey.UNION + 1) != null || getListFromJson(JsonKey.UNION_ALL + 1) != null)
34+
if (getFromJson(JsonKey.UNION + 1) != null || getFromJson(JsonKey.UNION_ALL + 1) != null)
3635
statement = getUnionSelect();
3736
else statement = getSelect();
3837
break;
@@ -57,7 +56,7 @@ public String parse(JSONObject json, boolean exceptUnion) {
5756
injectJson(json);
5857

5958
Statement statement;
60-
String crud = getListFromJson(JsonKey.CRUD).get(0);
59+
String crud = getFromJson(JsonKey.CRUD).get(0);
6160
switch (crud) {
6261
case JsonKey.INSERT:
6362
statement = getInsert();
@@ -87,22 +86,22 @@ private Insert getInsert() {
8786
Insert insert = new Insert();
8887

8988
// table
90-
List<String> tables = getListFromJson(JsonKey.FROM);
89+
List<String> tables = getFromJson(JsonKey.FROM);
9190
if (tables != null) {
9291
String tableName = tables.get(0);
9392
insert.setTable(new Table(tableName));
9493
}
9594

9695
// columns
97-
List<String> columns = getListFromJson(JsonKey.COLUMN);
96+
List<String> columns = getFromJson(JsonKey.COLUMN);
9897
if (columns != null) {
9998
List<Column> columnList = new ArrayList<>();
10099
columns.forEach(column -> columnList.add(new Column(column)));
101100
insert.setColumns(columnList);
102101
}
103102

104103
// values
105-
List<String> values = getListFromJson(JsonKey.VALUE);
104+
List<String> values = getFromJson(JsonKey.VALUE);
106105
if (values != null) {
107106
List<Expression> expressions = new ArrayList<>();
108107
values.forEach(value -> {
@@ -144,7 +143,7 @@ private Select getUnionSelect() {
144143
List<SetOperation> setOperations = new ArrayList<>();
145144
// add select body of default json except union
146145
String mainJsonSelectBodySql = new Parser().parse(this.getJson(), true);
147-
SelectBody mainJsonSelectBody = new SelectBody(){
146+
SelectBody mainJsonSelectBody = new SelectBody() {
148147
@Override
149148
public void accept(SelectVisitor selectVisitor) {
150149
// empty
@@ -159,9 +158,9 @@ public String toString() {
159158

160159
while (true) {
161160
brackets.add(true);
162-
List<String> unions = getListFromJson(JsonKey.UNION + idx);
163-
List<String> unionAlls = getListFromJson(JsonKey.UNION_ALL + idx);
164-
if(unions == null && unionAlls == null)
161+
List<String> unions = getFromJson(JsonKey.UNION + idx);
162+
List<String> unionAlls = getFromJson(JsonKey.UNION_ALL + idx);
163+
if (unions == null && unionAlls == null)
165164
break;
166165

167166
SetOperation setOperation = new SetOperation(SetOperationList.SetOperationType.UNION) {
@@ -200,12 +199,12 @@ private Select getSelect() {
200199
PlainSelect plainSelect = new PlainSelect();
201200

202201
// distinct
203-
List<String> distincts = getListFromJson(JsonKey.DISTINCT);
202+
List<String> distincts = getFromJson(JsonKey.DISTINCT);
204203
if (distincts != null)
205204
plainSelect.setDistinct(new Distinct(true));
206205

207206
// columns
208-
List<String> columns = getListFromJson(JsonKey.COLUMN);
207+
List<String> columns = getFromJson(JsonKey.COLUMN);
209208
if (columns != null) {
210209
List<SelectItem> selectItemList = new ArrayList<>();
211210
columns.forEach(column -> {
@@ -236,7 +235,7 @@ public String toString() {
236235
}
237236

238237
// table
239-
List<String> table = getListFromJson(JsonKey.FROM);
238+
List<String> table = getFromJson(JsonKey.FROM);
240239
if (table != null) {
241240
FromItem fromItem = new FromItem() {
242241
@Override
@@ -246,7 +245,7 @@ public void accept(FromItemVisitor fromItemVisitor) {
246245

247246
@Override
248247
public Alias getAlias() {
249-
List<String> aliases = getListFromJson(JsonKey.FROM_ALIAS);
248+
List<String> aliases = getFromJson(JsonKey.FROM_ALIAS);
250249
return aliases == null ? null : new Alias(aliases.get(0));
251250
}
252251

@@ -274,7 +273,7 @@ public String toString() {
274273
}
275274

276275
// where
277-
List<String> wheres = getListFromJson(JsonKey.WHERE);
276+
List<String> wheres = getFromJson(JsonKey.WHERE);
278277
if (wheres != null) {
279278
Expression whereExpression = new Expression() {
280279
@Override
@@ -301,7 +300,7 @@ public String toString() {
301300
}
302301

303302
// group by
304-
List<String> groupBys = getListFromJson(JsonKey.GROUP_BY);
303+
List<String> groupBys = getFromJson(JsonKey.GROUP_BY);
305304
if (groupBys != null) {
306305
GroupByElement groupByElement = new GroupByElement();
307306
groupBys.forEach(groupBy -> {
@@ -332,7 +331,7 @@ public String toString() {
332331
}
333332

334333
// order by
335-
List<String> orderBys = getListFromJson(JsonKey.ORDER_BY);
334+
List<String> orderBys = getFromJson(JsonKey.ORDER_BY);
336335
if (orderBys != null) {
337336
List<OrderByElement> orderByElementList = new ArrayList<>();
338337
orderBys.forEach(orderBy -> {
@@ -368,7 +367,7 @@ public String toString() {
368367
int idx = 1;
369368
List<Join> joinList = new ArrayList<>();
370369
while (true) {
371-
List<String> joins = getListFromJson(JsonKey.JOIN + idx++);
370+
List<String> joins = getFromJson(JsonKey.JOIN + idx++);
372371
if (joins != null) {
373372
joins.forEach(joinStr -> {
374373
Join join = new Join() {
@@ -391,23 +390,23 @@ private Update getUpdate() {
391390
Update update = new Update();
392391

393392
// columns
394-
List<String> columns = getListFromJson(JsonKey.COLUMN);
393+
List<String> columns = getFromJson(JsonKey.COLUMN);
395394
if (columns != null) {
396395
List<Column> columnList = new ArrayList<>();
397396
columns.forEach(column -> columnList.add(new Column(column)));
398397
update.setColumns(columnList);
399398
}
400399

401400
// tables
402-
List<String> tables = getListFromJson(JsonKey.FROM);
401+
List<String> tables = getFromJson(JsonKey.FROM);
403402
if (tables != null) {
404403
List<Table> tableList = new ArrayList<>();
405404
tables.forEach(table -> tableList.add(new Table(table)));
406405
update.setTables(tableList);
407406
}
408407

409408
// values
410-
List<String> values = getListFromJson(JsonKey.VALUE);
409+
List<String> values = getFromJson(JsonKey.VALUE);
411410
if (values != null) {
412411
List<Expression> expressionList = new ArrayList<>();
413412
values.forEach(value -> {
@@ -439,7 +438,7 @@ public String toString() {
439438
}
440439

441440
// where
442-
List<String> wheres = getListFromJson(JsonKey.WHERE);
441+
List<String> wheres = getFromJson(JsonKey.WHERE);
443442
if (wheres != null) {
444443
Expression whereExpression = new Expression() {
445444
@Override
@@ -473,12 +472,12 @@ private Delete getDelete() {
473472
Delete delete = new Delete();
474473

475474
// table
476-
List<String> tables = getListFromJson(JsonKey.FROM);
475+
List<String> tables = getFromJson(JsonKey.FROM);
477476
if (tables != null)
478477
delete.setTable(new Table(tables.get(0)));
479478

480479
// where
481-
List<String> wheres = getListFromJson(JsonKey.WHERE);
480+
List<String> wheres = getFromJson(JsonKey.WHERE);
482481
if (wheres != null) {
483482
Expression whereExpression = new Expression() {
484483
@Override

src/com/inzapp/jsonToSqlParser/core/json/JsonManager.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected void injectJson(JSONObject json) {
1717
this.json = json;
1818
}
1919

20-
protected List<String> getListFromJson(String jsonKey) {
20+
protected List<String> getFromJson(String jsonKey) {
2121
try {
2222
JSONArray jsonArray = (JSONArray) this.json.get(jsonKey);
2323
return convertJsonArrayToList(jsonArray);
@@ -26,14 +26,6 @@ protected List<String> getListFromJson(String jsonKey) {
2626
}
2727
}
2828

29-
protected JSONObject getJsonObjectFromJson(String jsonKey) {
30-
try {
31-
return this.json.getJSONObject(jsonKey);
32-
} catch (Exception e) {
33-
return null;
34-
}
35-
}
36-
3729
private List<String> convertJsonArrayToList(JSONArray jsonArray) {
3830
try {
3931
List<String> list = new ArrayList<>();

0 commit comments

Comments
 (0)