Skip to content

Commit c046619

Browse files
committed
Server:同步eclipse版至idea版
1 parent 7b5ec60 commit c046619

File tree

5 files changed

+383
-88
lines changed

5 files changed

+383
-88
lines changed

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

Lines changed: 84 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,116 +19,165 @@
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+
28+
/**
29+
* isNull = true
30+
* @return {@link #isNull(boolean)}
31+
*/
32+
public static String isNull() {
33+
return isNull(true);
34+
}
2235
/**
2336
* @param isNull
24-
* @return
37+
* @return IS + (isNull ? "" : NOT) + NULL;
2538
*/
2639
public static String isNull(boolean isNull) {
27-
return "is" + (isNull ? "" : " not") + " null";
40+
return IS + (isNull ? "" : NOT) + NULL;
41+
}
42+
/**
43+
* isNull = true
44+
* @param s
45+
* @return {@link #isNull(String, boolean)}
46+
*/
47+
public static String isNull(String s) {
48+
return isNull(s, true);
49+
}
50+
/**
51+
* @param s
52+
* @param isNull
53+
* @return s + {@link #isNull(boolean)}
54+
*/
55+
public static String isNull(String s, boolean isNull) {
56+
return s + isNull(isNull);
57+
}
58+
59+
/**
60+
* isEmpty = true
61+
* @param s
62+
* @return {@link #isEmpty(String, boolean)}
63+
*/
64+
public static String isEmpty(String s) {
65+
return isEmpty(s, true);
2866
}
2967
/**
3068
* trim = false
3169
* @param s
3270
* @param isEmpty
33-
* @return
71+
* @return {@link #isEmpty(String, boolean, boolean)}
3472
*/
3573
public static String isEmpty(String s, boolean isEmpty) {
3674
return isEmpty(s, isEmpty, false);
3775
}
3876
/**
77+
* nullable = true
3978
* @param s
40-
* @param isEmpty
41-
* @param trim
42-
* @return
79+
* @param isEmpty <=0
80+
* @param trim s = trim(s);
81+
* @return {@link #isEmpty(String, boolean, boolean, boolean)}
4382
*/
4483
public static String isEmpty(String s, boolean isEmpty, boolean trim) {
84+
return isEmpty(s, isEmpty, trim, true);
85+
}
86+
/**
87+
* @param s
88+
* @param isEmpty <=0
89+
* @param trim s = trim(s);
90+
* @param nullable isNull(s, true) + OR +
91+
* @return {@link #lengthCompare(String, String)}
92+
*/
93+
public static String isEmpty(String s, boolean isEmpty, boolean trim, boolean nullable) {
4594
if (trim) {
4695
s = trim(s);
4796
}
48-
return lengthCompare(s, (isEmpty ? ">" : "<=") + "0");
97+
return (nullable ? isNull(s, true) + OR : "") + lengthCompare(s, (isEmpty ? "<=" : ">") + "0");
4998
}
5099
/**
51100
* @param s 因为POWER(x,y)等函数含有不只一个key,所以需要客户端添加进去,服务端检测到条件中有'('和')'时就不转换,直接当SQL语句查询
52-
* @return
101+
* @return {@link #length(String)} + compare
53102
*/
54103
public static String lengthCompare(String s, String compare) {
55104
return length(s) + compare;
56105
}
57-
58-
106+
107+
59108
/**
60109
* @param s 因为POWER(x,y)等函数含有不只一个key,所以需要客户端添加进去,服务端检测到条件中有'('和')'时就不转换,直接当SQL语句查询
61-
* @return
110+
* @return "length(" + s + ")"
62111
*/
63112
public static String length(String s) {
64113
return "length(" + s + ")";
65114
}
66115
/**
67116
* @param s 因为POWER(x,y)等函数含有不只一个key,所以需要客户端添加进去,服务端检测到条件中有'('和')'时就不转换,直接当SQL语句查询
68-
* @return
117+
* @return "char_length(" + s + ")"
69118
*/
70119
public static String charLength(String s) {
71120
return "char_length(" + s + ")";
72121
}
73-
122+
74123
/**
75124
* @param s
76-
* @return
125+
* @return "trim(" + s + ")"
77126
*/
78127
public static String trim(String s) {
79128
return "trim(" + s + ")";
80129
}
81130
/**
82131
* @param s
83-
* @return
132+
* @return "ltrim(" + s + ")"
84133
*/
85134
public static String trimLeft(String s) {
86135
return "ltrim(" + s + ")";
87136
}
88137
/**
89138
* @param s
90-
* @return
139+
* @return "rtrim(" + s + ")"
91140
*/
92141
public static String trimRight(String s) {
93142
return "rtrim(" + s + ")";
94143
}
95-
144+
96145
/**
97146
* @param s
98147
* @param n
99-
* @return
148+
* @return "left(" + s + "," + n + ")"
100149
*/
101150
public static String left(String s, int n) {
102151
return "left(" + s + "," + n + ")";
103152
}
104153
/**
105154
* @param s
106155
* @param n
107-
* @return
156+
* @return "right(" + s + "," + n + ")"
108157
*/
109158
public static String right(String s, int n) {
110159
return "right(" + s + "," + n + ")";
111160
}
112-
161+
113162
/**
114163
* @param s
115164
* @param start
116165
* @param end
117-
* @return
166+
* @return "substring(" + s + "," + start + "," + (end-start) + ")"
118167
*/
119168
public static String subString(String s, int start, int end) {
120169
return "substring(" + s + "," + start + "," + (end-start) + ")";
121170
}
122-
171+
123172
/**
124173
* @param s
125174
* @param c
126-
* @return
175+
* @return "instr(" + s + "," + c + ")"
127176
*/
128177
public static String indexOf(String s, String c) {
129178
return "instr(" + s + "," + c + ")";
130179
}
131-
180+
132181
/**
133182
* @param s
134183
* @param c1
@@ -138,35 +187,35 @@ public static String indexOf(String s, String c) {
138187
public static String replace(String s, String c1, String c2) {
139188
return "replace(" + s + "," + c1 + "," + c2 + ")";
140189
}
141-
190+
142191
/**
143192
* @param s1
144193
* @param s2
145-
* @return
194+
* @return "strcmp(" + s1 + "," + s2 + ")"
146195
*/
147196
public static String equals(String s1, String s2) {
148197
return "strcmp(" + s1 + "," + s2 + ")";
149198
}
150-
199+
151200
/**
152201
* @param s
153-
* @return
202+
* @return "upper(" + s + ")"
154203
*/
155204
public static String toUpperCase(String s) {
156205
return "upper(" + s + ")";
157206
}
158207
/**
159208
* @param s
160-
* @return
209+
* @return "lower(" + s + ")"
161210
*/
162211
public static String toLowerCase(String s) {
163212
return "lower(" + s + ")";
164213
}
165-
166-
167-
168-
169-
214+
215+
216+
217+
218+
170219
public static final int SEARCH_TYPE_CONTAIN_FULL = 0;
171220
public static final int SEARCH_TYPE_CONTAIN_ORDER = 1;
172221
public static final int SEARCH_TYPE_CONTAIN_SINGLE = 2;
@@ -237,5 +286,5 @@ public static String search(String s, int type, boolean ignoreCase) {
237286
return "%" + s + "%";
238287
}
239288
}
240-
289+
241290
}
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+
}

0 commit comments

Comments
 (0)