Skip to content

Commit efe4e0d

Browse files
committed
Client:新增SQL并优化JSONObject,JSONRequest
1 parent ad69bb3 commit efe4e0d

4 files changed

Lines changed: 353 additions & 118 deletions

File tree

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/MomentListFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import zuo.biao.apijson.JSON;
2020
import zuo.biao.apijson.JSONRequest;
2121
import zuo.biao.apijson.JSONResponse;
22+
import zuo.biao.apijson.SQL;
2223
import zuo.biao.apijson.StringUtil;
2324
import zuo.biao.library.interfaces.AdapterCallBack;
2425
import zuo.biao.library.interfaces.CacheCallBack;
@@ -43,7 +44,6 @@
4344
import apijson.demo.client.application.APIJSONApplication;
4445
import apijson.demo.client.base.BaseHttpListFragment;
4546
import apijson.demo.client.interfaces.TopBarMenuCallback;
46-
import apijson.demo.client.model.CommentItem;
4747
import apijson.demo.client.model.MomentItem;
4848
import apijson.demo.client.util.CommentUtil;
4949
import apijson.demo.client.util.HttpRequest;
@@ -362,7 +362,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
362362
JSONRequest search = new JSONRequest();
363363
if (StringUtil.isNotEmpty(value, true)) {
364364
split = ":";
365-
search.putSearch("content", value, JSONRequest.SEARCH_TYPE_CONTAIN_ORDER);
365+
search.putSearch("content", value, SQL.SEARCH_TYPE_CONTAIN_ORDER);
366366
}
367367
toActivity(MomentListActivity.createIntent(context, range, id, search, false)
368368
.putExtra(INTENT_TITLE, "搜索" + split + value));

APIJSON(Android)/APIJSON(ADT)/APIJSONLibrary/src/zuo/biao/apijson/JSONObject.java

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,114 @@ public String getColumns() {
243243
}
244244

245245

246+
247+
248+
//Request,默认encode <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
249+
250+
/**
251+
* encode = true
252+
* @param key
253+
* @param isNull
254+
* @return {@link #putNull(String, boolean, boolean)}
255+
*/
256+
public JSONObject putNull(String key, boolean isNull) {
257+
return putNull(key, isNull, true);
258+
}
259+
/**
260+
* @param key
261+
* @param isNull
262+
* @param encode
263+
* @return
264+
*/
265+
public JSONObject putNull(String key, boolean isNull, boolean encode) {
266+
put(key + "{}", SQL.isNull(isNull), encode);
267+
return this;
268+
}
269+
/**
270+
* trim = false
271+
* @param key
272+
* @param isEmpty
273+
* @return {@link #putEmpty(String, boolean, boolean)}
274+
*/
275+
public JSONObject putEmpty(String key, boolean isEmpty) {
276+
return putEmpty(key, isEmpty, false);
277+
}
278+
/**
279+
* encode = true
280+
* @param key
281+
* @param isEmpty
282+
* @return {@link #putEmpty(String, boolean, boolean, boolean)}
283+
*/
284+
public JSONObject putEmpty(String key, boolean isEmpty, boolean trim) {
285+
return putEmpty(key, isEmpty, trim, true);
286+
}
287+
/**
288+
* @param key
289+
* @param isEmpty
290+
* @param encode
291+
* @return
292+
*/
293+
public JSONObject putEmpty(String key, boolean isEmpty, boolean trim, boolean encode) {
294+
put(key + "{}", SQL.isEmpty(key, isEmpty, trim), encode);
295+
return this;
296+
}
297+
/**
298+
* encode = true
299+
* @param key
300+
* @param compare <=0, >5 ...
301+
* @return {@link #putLength(String, String, boolean)}
302+
*/
303+
public JSONObject putLength(String key, String compare) {
304+
return putLength(key, compare, true);
305+
}
306+
/**
307+
* @param key
308+
* @param compare <=0, >5 ...
309+
* @param encode
310+
* @return
311+
*/
312+
public JSONObject putLength(String key, String compare, boolean encode) {
313+
put(key + "{}", SQL.length(key) + compare, encode);
314+
return this;
315+
}
316+
317+
/**设置搜索
318+
* type = SEARCH_TYPE_CONTAIN_FULL
319+
* @param key
320+
* @param value
321+
* @return {@link #putSearch(String, String, int)}
322+
*/
323+
public JSONObject putSearch(String key, String value) {
324+
return putSearch(key, value, SQL.SEARCH_TYPE_CONTAIN_FULL);
325+
}
326+
/**设置搜索
327+
* encode = true
328+
* @param key
329+
* @param value
330+
* @param type
331+
* @return {@link #putSearch(String, String, int, boolean)}
332+
*/
333+
public JSONObject putSearch(String key, String value, int type) {
334+
return putSearch(key, value, type, true);
335+
}
336+
/**设置搜索
337+
* @param key
338+
* @param value
339+
* @param type
340+
* @param encode
341+
* @return
342+
*/
343+
public JSONObject putSearch(String key, String value, int type, boolean encode) {
344+
if (key == null) {
345+
key = "";
346+
}
347+
if (key.endsWith("$") == false) {
348+
key += "$";
349+
}
350+
put(key, SQL.search(value, type), encode);
351+
return this;
352+
}
353+
354+
//Request,默认encode >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
355+
246356
}

APIJSON(Android)/APIJSON(ADT)/APIJSONLibrary/src/zuo/biao/apijson/JSONRequest.java

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -191,120 +191,4 @@ public JSONRequest toArray(int count, int page, String name, boolean encode) {
191191
return new JSONRequest(StringUtil.getString(name) + KEY_ARRAY, this.setCount(count).setPage(page), encode);
192192
}
193193

194-
195-
/**设置搜索
196-
* @param key
197-
* @param value
198-
* @see {@link #putSearch(String, String, int)}
199-
*/
200-
public void putSearch(String key, String value) {
201-
putSearch(key, value, SEARCH_TYPE_CONTAIN_FULL);
202-
}
203-
/**设置搜索
204-
* encode = true
205-
* @param key
206-
* @param value
207-
* @param type
208-
* @see {@link #putSearch(String, String, int, boolean)}
209-
*/
210-
public void putSearch(String key, String value, int type) {
211-
putSearch(key, value, type, true);
212-
}
213-
/**设置搜索
214-
* @param key
215-
* @param value
216-
* @param type
217-
* @param encode
218-
*/
219-
public void putSearch(String key, String value, int type, boolean encode) {
220-
if (key == null) {
221-
key = "";
222-
}
223-
if (key.endsWith("$") == false) {
224-
key += "$";
225-
}
226-
put(key, getSearch(value, type), encode);
227-
}
228-
229-
public static final int SEARCH_TYPE_CONTAIN_FULL = 0;
230-
public static final int SEARCH_TYPE_CONTAIN_ORDER = 1;
231-
public static final int SEARCH_TYPE_CONTAIN_SINGLE = 2;
232-
public static final int SEARCH_TYPE_CONTAIN_ANY = 3;
233-
public static final int SEARCH_TYPE_START = 4;
234-
public static final int SEARCH_TYPE_END = 5;
235-
public static final int SEARCH_TYPE_START_SINGLE = 6;
236-
public static final int SEARCH_TYPE_END_SINGLE = 7;
237-
public static final int SEARCH_TYPE_PART_MATCH = 8;
238-
/**
239-
* SQL中NOT LIKE就行??
240-
*/
241-
public static final int SEARCH_TYPE_NO_CONTAIN = 9;
242-
/**
243-
* SQL中NOT LIKE就行??
244-
*/
245-
public static final int SEARCH_TYPE_NO_PART_MATCH = 10;
246-
/**获取搜索值
247-
* @param key
248-
* @return
249-
*/
250-
public static String getSearch(String key) {
251-
return getSearch(key, SEARCH_TYPE_CONTAIN_FULL);
252-
}
253-
/**获取搜索值
254-
* @param key
255-
* @param type
256-
* @return
257-
*/
258-
public static String getSearch(String key, int type) {
259-
return getSearch(key, type, true);
260-
}
261-
/**获取搜索值
262-
* @param key
263-
* @param type
264-
* @param ignoreCase
265-
* @return
266-
*/
267-
public static String getSearch(String key, int type, boolean ignoreCase) {
268-
if (key == null) {
269-
return null;
270-
}
271-
switch (type) {
272-
case SEARCH_TYPE_CONTAIN_SINGLE:
273-
return "_" + key + "_";
274-
case SEARCH_TYPE_CONTAIN_ORDER:
275-
char[] cs = key.toCharArray();
276-
if (cs == null) {
277-
return null;
278-
}
279-
String s = "%";
280-
for (int i = 0; i < cs.length; i++) {
281-
s += cs[i] + "%";
282-
}
283-
return s;
284-
case SEARCH_TYPE_START:
285-
return key + "%";
286-
case SEARCH_TYPE_END:
287-
return "%" + key;
288-
case SEARCH_TYPE_START_SINGLE:
289-
return key + "_";
290-
case SEARCH_TYPE_END_SINGLE:
291-
return "_" + key;
292-
case SEARCH_TYPE_NO_CONTAIN:
293-
return "[^" + key + "]";
294-
case SEARCH_TYPE_NO_PART_MATCH:
295-
cs = key.toCharArray();
296-
if (cs == null) {
297-
return null;
298-
}
299-
s = "";
300-
for (int i = 0; i < cs.length; i++) {
301-
s += getSearch("" + cs[i], SEARCH_TYPE_NO_CONTAIN, ignoreCase);
302-
}
303-
return s;
304-
default:
305-
return "%" + key + "%";
306-
}
307-
}
308-
309-
310194
}

0 commit comments

Comments
 (0)