Skip to content

Commit 66c7d1a

Browse files
committed
Server:新增key<>:[]包含条件;新增支持key$:[]多条件搜索;新增Logic并优化QueryConfig代码;优化Parser.getRealKey性能
1 parent e882880 commit 66c7d1a

5 files changed

Lines changed: 295 additions & 53 deletions

File tree

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/SQL.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
*/
2020
public class SQL {
2121

22+
public static final String OR = " OR ";
23+
public static final String AND = " AND ";
24+
public static final String NOT = " NOT ";
25+
public static final String IS = " IS ";
26+
public static final String NULL = " NULL ";
27+
2228
/**
2329
* @param isNull
2430
* @return
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package zuo.biao.apijson.server;
2+
3+
import zuo.biao.apijson.StringUtil;
4+
5+
public class Logic {
6+
7+
public static final int TYPE_OR = 0;
8+
public static final int TYPE_AND = 1;
9+
public static final int TYPE_NOT = 2;
10+
public static final int[] TYPES = {TYPE_OR, TYPE_AND, TYPE_NOT};
11+
12+
public static final String CHAR_OR = "|";
13+
public static final String CHAR_AND = "&";
14+
public static final String CHAR_NOT = "!";
15+
public static final String[] CHARS = {CHAR_OR, CHAR_AND, CHAR_NOT};
16+
17+
public static final String NAME_OR = "OR";
18+
public static final String NAME_AND = "AND";
19+
public static final String NAME_NOT = "NOT";
20+
public static final String[] NAMES = {NAME_OR, NAME_AND, NAME_NOT};
21+
22+
23+
private int type;
24+
private String key;
25+
26+
public Logic() {
27+
super();
28+
}
29+
30+
public Logic(int type) {
31+
this();
32+
this.type = type;
33+
}
34+
public Logic(String key) {
35+
key = StringUtil.getString(key);
36+
37+
int type = getType(key.isEmpty() ? "" : key.substring(key.length() - 1));
38+
39+
if (type >= 0 && type <= 2) {
40+
key = key.substring(0, key.length() - 1);
41+
}
42+
if (type < 0) {
43+
type = 0;
44+
}
45+
46+
47+
setType(type);
48+
setKey(key);
49+
}
50+
51+
52+
public int getType() {
53+
return type;
54+
}
55+
56+
public void setType(int type) {
57+
this.type = type;
58+
}
59+
60+
public String getKey() {
61+
return key;
62+
}
63+
public void setKey(String key) {
64+
this.key = key;
65+
}
66+
67+
68+
public boolean isOr() {
69+
return isOr(type);
70+
}
71+
public static boolean isOr(int type) {
72+
return type == TYPE_OR;
73+
}
74+
public boolean isAnd() {
75+
return isAnd(type);
76+
}
77+
public static boolean isAnd(int type) {
78+
return type == TYPE_AND;
79+
}
80+
public boolean isNot() {
81+
return isNot(type);
82+
}
83+
public static boolean isNot(int type) {
84+
return type == TYPE_NOT;
85+
}
86+
87+
88+
public static int getType(char logicChar) {
89+
return getType(String.valueOf(logicChar));
90+
}
91+
public static int getType(String logicChar) {
92+
int type = -1;
93+
if (logicChar != null && logicChar.isEmpty() == false) {
94+
if ("|".equals(logicChar)) {
95+
type = 0;
96+
} else if ("&".equals(logicChar)) {
97+
type = 1;
98+
} else if ("!".equals(logicChar)) {
99+
type = 2;
100+
}
101+
}
102+
return type;
103+
}
104+
105+
public String getChar() {
106+
return getChar(type);
107+
}
108+
public static String getChar(int type) {
109+
return type < 0 || type >= CHARS.length ? "" : CHARS[type];
110+
}
111+
112+
public String getName() {
113+
return getName(type);
114+
}
115+
public static String getName(int type) {
116+
return type < 0 || type >= NAMES.length ? "" : NAMES[type];
117+
}
118+
119+
}

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Parser.java‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ private JSONObject getArray(String parentPath, String name, JSONObject request)
845845
return transferredRequest;
846846
}
847847

848+
//TODO 获取status和message,如果发生异常就throw new Exception(message!),不行,不知道Exception类型,还是传boolean catchException到parse好
848849
/**估计最大总数,去掉value中所有依赖引用.
849850
* TODO 返回一个{"total":10, name:value}更好,省去了之后的parseRelation
850851
* @param path
@@ -882,14 +883,18 @@ public int estimateMaxCount(String path, String table, JSONObject value) throws
882883
}
883884

884885
valid = new String(k);
885-
if (valid.endsWith("{}")) {
886-
valid = valid.substring(0, valid.length() - 2);
887-
} else if (valid.endsWith("$")) {
886+
if (valid.endsWith("$")) {
888887
valid = valid.substring(0, valid.length() - 1);
888+
} else if (valid.endsWith("{}")) {
889+
valid = valid.substring(0, valid.length() - 2);
890+
} else if (valid.endsWith("<>")) {
891+
valid = valid.substring(0, valid.length() - 2);
889892
}
890-
if (valid.endsWith("&") || valid.endsWith("|") || valid.endsWith("!")) {
893+
894+
if (valid.endsWith("|") || valid.endsWith("&") || valid.endsWith("!")) {
891895
valid = valid.substring(0, valid.length() - 1);
892896
}
897+
893898
if (isWord(valid)) {
894899
request.put(k, v);
895900
}
@@ -1195,20 +1200,22 @@ public static String getRealKey(RequestMethod method, String originKey, boolean
11951200

11961201
String key = new String(originKey);
11971202
if (key.endsWith("$")) {//搜索,查询时处理
1198-
key = key.substring(0, key.lastIndexOf("$"));
1199-
} else if (key.endsWith("{}")) {//被包含,或者说处于value的范围内。查询时处理 "key[]":{} 和 "key{}":[]正好反过来
1200-
key = key.substring(0, key.lastIndexOf("{}"));
1203+
key = key.substring(0, key.length() - 1);
1204+
} else if (key.endsWith("{}")) {//被包含,或者说key对应值处于value的范围内。查询时处理
1205+
key = key.substring(0, key.length() - 2);
1206+
} else if (key.endsWith("<>")) {//包含,或者说value处于key对应值的范围内。查询时处理
1207+
key = key.substring(0, key.length() - 2);
12011208
} else if (key.endsWith("()")) {//方法,查询完后处理,先用一个Map<key,function>保存?
1202-
key = key.substring(0, key.lastIndexOf("()"));
1209+
key = key.substring(0, key.length() - 2);
12031210
} else if (key.endsWith("@")) {//引用,引用对象查询完后处理。fillTarget中暂时不用处理,因为非GET请求都是由给定的id确定,不需要引用
1204-
key = key.substring(0, key.lastIndexOf("@"));
1211+
key = key.substring(0, key.length() - 1);
12051212
} else if (key.endsWith("+")) {//延长,PUT查询时处理
12061213
if (method == PUT) {//不为PUT就抛异常
1207-
key = key.substring(0, key.lastIndexOf("+"));
1214+
key = key.substring(0, key.length() - 1);
12081215
}
12091216
} else if (key.endsWith("-")) {//缩减,PUT查询时处理
12101217
if (method == PUT) {//不为PUT就抛异常
1211-
key = key.substring(0, key.lastIndexOf("-"));
1218+
key = key.substring(0, key.length() - 1);
12121219
}
12131220
}
12141221

0 commit comments

Comments
 (0)