Skip to content

Commit f59a653

Browse files
committed
Server:去除数组关键词 explain 和 cache
1 parent fa79888 commit f59a653

File tree

5 files changed

+45
-101
lines changed

5 files changed

+45
-101
lines changed

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/JSONObject.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ public JSONObject setUserIdIn(List<Object> list) {
120120
}
121121

122122

123+
public static final int CACHE_ALL = 0;
124+
public static final int CACHE_ROM = 1;
125+
public static final int CACHE_RAM = 2;
126+
127+
public static final String CACHE_ALL_STRING = "ALL";
128+
public static final String CACHE_ROM_STRING = "ROM";
129+
public static final String CACHE_RAM_STRING = "RAM";
130+
131+
123132
//@key关键字都放这个类 <<<<<<<<<<<<<<<<<<<<<<
124133
public static final String KEY_TRY = "@try"; //尝试,忽略异常
125134
public static final String KEY_DROP = "@drop"; //丢弃,不返回
@@ -196,7 +205,33 @@ public JSONObject setCorrect(Map<String, String> correct) {
196205
*/
197206
public JSONObject setDatabase(String database) {
198207
return puts(KEY_DATABASE, database);
199-
208+
}
209+
/**set joins of Main Table and it's Vice Tables in Array layer
210+
* @param joins "@/User/id@", "&/User/id@,>/Comment/momentId@" ...
211+
* @return
212+
*/
213+
public JSONObject setExplain(boolean explain) {
214+
return puts(KEY_EXPLAIN, explain);
215+
}
216+
/**set cache type
217+
* @param cache
218+
* @return
219+
* @see {@link #CACHE_ALL}
220+
* @see {@link #CACHE_RAM}
221+
* @see {@link #CACHE_ROM}
222+
*/
223+
public JSONObject setCache(int cache) {
224+
return puts(KEY_CACHE, cache);
225+
}
226+
/**set cache type
227+
* @param cache
228+
* @return
229+
* @see {@link #CACHE_ALL_STRING}
230+
* @see {@link #CACHE_RAM_STRING}
231+
* @see {@link #CACHE_ROM_STRING}
232+
*/
233+
public JSONObject setCache(String cache) {
234+
return puts(KEY_CACHE, cache);
200235
}
201236
/**set schema where table was puts
202237
* @param schema

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/JSONRequest.java

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -87,41 +87,28 @@ public JSONRequest setFormat(Boolean format) {
8787
public static final int QUERY_TABLE = 0;
8888
public static final int QUERY_TOTAL = 1;
8989
public static final int QUERY_ALL = 2;
90-
90+
9191
public static final String QUERY_TABLE_STRING = "TABLE";
9292
public static final String QUERY_TOTAL_STRING = "TOTAL";
9393
public static final String QUERY_ALL_STRING = "ALL";
94-
95-
public static final int CACHE_ALL = 0;
96-
public static final int CACHE_ROM = 1;
97-
public static final int CACHE_RAM = 2;
98-
99-
public static final String CACHE_ALL_STRING = "ALL";
100-
public static final String CACHE_ROM_STRING = "ROM";
101-
public static final String CACHE_RAM_STRING = "RAM";
10294

10395
public static final String SUBQUERY_RANGE_ALL = "ALL";
10496
public static final String SUBQUERY_RANGE_ANY = "ANY";
10597

106-
public static final String KEY_QUERY = "query"; // 0-
98+
public static final String KEY_QUERY = "query";
10799
public static final String KEY_COUNT = "count";
108100
public static final String KEY_PAGE = "page";
109101
public static final String KEY_JOIN = "join";
110-
public static final String KEY_CACHE = "cache"; // RAM/ROM/ALL ?
111-
public static final String KEY_EXPLAIN = "explain"; // true explain:true/false 为了兼容,就不在 query 里加一个值了
112102
public static final String KEY_SUBQUERY_RANGE = "range";
113103
public static final String KEY_SUBQUERY_FROM = "from";
114-
115-
104+
116105
public static final List<String> ARRAY_KEY_LIST;
117106
static {
118107
ARRAY_KEY_LIST = new ArrayList<String>();
119108
ARRAY_KEY_LIST.add(KEY_QUERY);
120109
ARRAY_KEY_LIST.add(KEY_COUNT);
121110
ARRAY_KEY_LIST.add(KEY_PAGE);
122111
ARRAY_KEY_LIST.add(KEY_JOIN);
123-
ARRAY_KEY_LIST.add(KEY_CACHE);
124-
ARRAY_KEY_LIST.add(KEY_EXPLAIN);
125112
ARRAY_KEY_LIST.add(KEY_SUBQUERY_RANGE);
126113
ARRAY_KEY_LIST.add(KEY_SUBQUERY_FROM);
127114
}
@@ -159,36 +146,6 @@ public JSONRequest setJoin(String... joins) {
159146
return puts(KEY_JOIN, StringUtil.getString(joins));
160147
}
161148

162-
/**set cache type
163-
* @param cache
164-
* @return
165-
* @see {@link #CACHE_ALL}
166-
* @see {@link #CACHE_RAM}
167-
* @see {@link #CACHE_ROM}
168-
*/
169-
public JSONRequest setCache(int cache) {
170-
return puts(KEY_CACHE, cache);
171-
}
172-
173-
/**set cache type
174-
* @param cache
175-
* @return
176-
* @see {@link #CACHE_ALL_STRING}
177-
* @see {@link #CACHE_RAM_STRING}
178-
* @see {@link #CACHE_ROM_STRING}
179-
*/
180-
public JSONRequest setCache(String cache) {
181-
return puts(KEY_CACHE, cache);
182-
}
183-
184-
/**set joins of Main Table and it's Vice Tables in Array layer
185-
* @param joins "@/User/id@", "&/User/id@,>/Comment/momentId@" ...
186-
* @return
187-
*/
188-
public JSONRequest setExplain(boolean explain) {
189-
return puts(KEY_EXPLAIN, explain);
190-
}
191-
192149
/**set range for Subquery
193150
* @param range
194151
* @return

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractObjectParser.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ public AbstractObjectParser parse() throws Exception {
291291
}
292292
else {//直接解析并替换原来的,[]:{} 内必须直接解析,否则会因为丢掉count等属性,并且total@:"/[]/total"必须在[]:{} 后!
293293
response.put(key, onChildParse(index, key, (JSONObject)value));
294-
//导致不返回任何字段 response.put(isTable == false && arrayConfig != null && arrayConfig.isExplain()
295-
// ? JSONRequest.KEY_EXPLAIN : key, onChildParse(index, key, (JSONObject)value));
296294
index ++;
297295
}
298296
}
@@ -626,7 +624,7 @@ public AbstractObjectParser setSQLConfig(int count, int page, int position) thro
626624

627625
if (sqlConfig == null) {
628626
try {
629-
sqlConfig = newSQLConfig(arrayConfig, false);
627+
sqlConfig = newSQLConfig(false);
630628
}
631629
catch (NotExistException e) {
632630
e.printStackTrace();
@@ -740,7 +738,7 @@ public void onFunctionResponse(String type) throws Exception {
740738
public void parseFunction(JSONObject json, String key, String value) throws Exception {
741739
Object result;
742740
if (key.startsWith("@")) {
743-
SQLConfig config = newSQLConfig(arrayConfig, true);
741+
SQLConfig config = newSQLConfig(true);
744742
config.setProcedure(value);
745743

746744
SQLExecutor executor = null;
@@ -764,14 +762,6 @@ public void parseFunction(JSONObject json, String key, String value) throws Exce
764762
}
765763
}
766764

767-
private SQLConfig newSQLConfig(SQLConfig arrayConfig, boolean isProcedure) throws Exception {
768-
SQLConfig cfg = newSQLConfig(isProcedure);
769-
// if (arrayConfig != null) {
770-
// cfg.setCache(arrayConfig.getCache()).setExplain(arrayConfig.isExplain());
771-
// }
772-
return cfg;
773-
}
774-
775765
@Override
776766
public void onChildResponse() throws Exception {
777767
//把isTable时取出去child解析后重新添加回来

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractParser.java

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,6 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name
752752
final Integer count = request.getInteger(JSONRequest.KEY_COUNT); //TODO 如果不想用默认数量可以改成 getIntValue(JSONRequest.KEY_COUNT);
753753
final int page = request.getIntValue(JSONRequest.KEY_PAGE);
754754
final Object join = request.get(JSONRequest.KEY_JOIN);
755-
final String cache = request.getString(JSONRequest.KEY_CACHE);
756-
final boolean explain = request.getBooleanValue(JSONRequest.KEY_EXPLAIN);
757755

758756
int query2;
759757
if (query == null) {
@@ -778,33 +776,6 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name
778776
}
779777
}
780778

781-
int cache2;
782-
if (cache == null) {
783-
cache2 = JSONRequest.CACHE_ALL;
784-
}
785-
else {
786-
if (isSubquery) {
787-
throw new IllegalArgumentException("子查询内不支持传 " + JSONRequest.KEY_CACHE + "!");
788-
}
789-
790-
switch (cache) {
791-
case "0":
792-
case JSONRequest.CACHE_ALL_STRING:
793-
cache2 = JSONRequest.CACHE_ALL;
794-
break;
795-
case "1":
796-
case JSONRequest.CACHE_ROM_STRING:
797-
cache2 = JSONRequest.CACHE_ROM;
798-
break;
799-
case "2":
800-
case JSONRequest.CACHE_RAM_STRING:
801-
cache2 = JSONRequest.CACHE_RAM;
802-
break;
803-
default:
804-
throw new IllegalArgumentException(path + "/" + JSONRequest.KEY_CACHE + ":value 中 value 的值不合法!必须在 [0,1,2] 或 [ALL, ROM, RAM] 内 !");
805-
}
806-
}
807-
808779
int maxPage = getMaxQueryPage();
809780
if (page < 0 || page > maxPage) {
810781
throw new IllegalArgumentException(path + "/" + JSONRequest.KEY_PAGE + ":value 中 value 的值不合法!必须在 0-" + maxPage + " 内 !");
@@ -822,9 +793,7 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name
822793
request.remove(JSONRequest.KEY_COUNT);
823794
request.remove(JSONRequest.KEY_PAGE);
824795
request.remove(JSONRequest.KEY_JOIN);
825-
request.remove(JSONRequest.KEY_CACHE);
826-
request.remove(JSONRequest.KEY_EXPLAIN);
827-
Log.d(TAG, "onArrayParse query = " + query + "; count = " + count + "; page = " + page + "; join = " + join + "; cache = " + cache + "; explain = " + explain);
796+
Log.d(TAG, "onArrayParse query = " + query + "; count = " + count + "; page = " + page + "; join = " + join);
828797

829798
if (request.isEmpty()) {//如果条件成立,说明所有的 parentPath/name:request 中request都无效!!!
830799
Log.e(TAG, "onArrayParse request.isEmpty() >> return null;");
@@ -854,20 +823,15 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name
854823
.setCount(size)
855824
.setPage(page)
856825
.setQuery(query2)
857-
.setCache(cache2)
858-
.setExplain(explain)
859826
.setJoinList(onJoinParse(join, request));
860827

861-
int len = explain || isSubquery ? 1 : size;
862828
JSONObject parent;
863-
for (int i = 0; i < len; i++) { //生成len个, config.setType(SQLConfig.TYPE_ITEM) 每次都必要,因为内部会设置成其它值
829+
//生成size个
830+
for (int i = 0; i < (isSubquery ? 1 : size); i++) {
864831
parent = onObjectParse(request, path, "" + i, config.setType(SQLConfig.TYPE_ITEM).setPosition(i), isSubquery);
865832
if (parent == null || parent.isEmpty()) {
866833
break;
867834
}
868-
if (explain) {
869-
parent.put(JSONRequest.KEY_EXPLAIN, explain);
870-
}
871835
//key[]:{Table:{}}中key equals Table时 提取Table
872836
response.add(getValue(parent, childKeys)); //null有意义
873837
}
@@ -900,8 +864,6 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name
900864
request.put(JSONRequest.KEY_COUNT, count);
901865
request.put(JSONRequest.KEY_PAGE, page);
902866
request.put(JSONRequest.KEY_JOIN, join);
903-
request.put(JSONRequest.KEY_CACHE, cache);
904-
request.put(JSONRequest.KEY_EXPLAIN, explain);
905867

906868
if (Log.DEBUG) {
907869
Log.i(TAG, "onArrayParse return response = \n" + JSON.toJSONString(response) + "\n>>>>>>>>>>>>>>>\n\n\n");

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
19421942
String sch = config.getSQLSchema(config.getSQLTable());
19431943
if (StringUtil.isNotEmpty(config.getProcedure(), true)) {
19441944
String q = config.getQuote();
1945-
return "CALL " + q + sch + q + "."+ config.getProcedure(); // EXPLIAN 不能用于存储过程,和 CALL 语法冲突
1945+
return "CALL " + q + sch + q + "."+ config.getProcedure();
19461946
}
19471947

19481948
String tablePath = config.getTablePath();

0 commit comments

Comments
 (0)