Skip to content

Commit b11ab6a

Browse files
committed
Server:优化Parser#getObject的依赖解析,解决0:{{},"praiseCount":"/User[]/total"}解析问题;删除QueryHelper内被注释的getCount方法
1 parent 7adb4e3 commit b11ab6a

2 files changed

Lines changed: 42 additions & 49 deletions

File tree

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

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -578,31 +578,37 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
578578
throw new IllegalArgumentException("\"key@\": 后面必须为依赖路径String!");
579579
}
580580
// System.out.println("getObject key.endsWith(@) >> parseRelation = " + parseRelation);
581+
// System.out.println("getObject key.endsWith(@) >> parseRelation = " + parseRelation);
581582
String replaceKey = key.substring(0, key.length() - 1);//key{}@ getRealKey
582-
583-
String valuePath = new String((String) value);//改用实时替换[] -> []/i
584-
585-
if (valuePath.startsWith(SEPARATOR)) {
586-
valuePath = getAbsPath(parentPath, valuePath);
587-
} else {//处理[] -> []/i
588-
valuePath = replaceArrayChildPath(parentPath, valuePath);
589-
value = new String(valuePath);//避免后续重新转换
590-
}
583+
String targetPath = getValuePath(parentPath, new String((String) value));
584+
591585
//先尝试获取,尽量保留缺省依赖路径,这样就不需要担心路径改变
592-
Object target = getValueByPath(valuePath);
593-
Log.i(TAG, "getObject valuePath = " + valuePath + "; target = " + target);
594-
595-
if (valuePath.equals(target)) {//必须valuePath和保证getValueByPath传进去的一致!
596-
Log.i(TAG, "getObject target != null && target instanceof String"
597-
+ " && ((String) target).startsWith(valuePath) >> ");
598-
Log.i(TAG, "getObject parseRelation == false"
599-
+ " >> containRelation = true; putRelation(keyPath, valuePath);");
600-
containRelation = true;
601-
} else {//直接替换原来的key@:path为key:target
602-
Log.i(TAG, "getObject >> key = replaceKey; value = target;");
603-
key = replaceKey;
604-
value = target;
586+
Object target = getValueByPath(targetPath);
587+
Log.i(TAG, "getObject targetPath = " + targetPath + "; target = " + target);
588+
589+
if (target == null) {//String#equals(null)会出错
590+
Log.d(TAG, "getObject target == null >> continue;");
591+
continue;
605592
}
593+
if (targetPath.equals(target)) {//必须valuePath和保证getValueByPath传进去的一致!
594+
Log.d(TAG, "getObject targetPath.equals(target) >>");
595+
596+
//非查询关键词 @key 不影响查询,直接跳过
597+
if (isTableKey && (key.startsWith("@") == false || QueryConfig.TABLE_KEY_LIST.contains(key))) {
598+
Log.e(TAG, "getObject isTableKey && (key.startsWith(@) == false"
599+
+ " || QueryConfig.TABLE_KEY_LIST.contains(key)) >> return null;");
600+
return null;//获取不到就不用再做无效的query了。不考虑 Table:{Table:{}}嵌套
601+
} else {
602+
Log.d(TAG, "getObject isTableKey(table) == false >> continue;");
603+
continue;//舍去,对Table无影响
604+
}
605+
}
606+
607+
608+
//直接替换原来的key@:path为key:target
609+
Log.i(TAG, "getObject >> key = replaceKey; value = target;");
610+
key = replaceKey;
611+
value = target;
606612
Log.d(TAG, "getObject key = " + key + "; value = " + value);
607613
}
608614

@@ -828,6 +834,20 @@ public int estimateMaxCount(String path, String table, JSONObject value) throws
828834
return response == null ? 0 : response.getIntValue(JSONResponse.KEY_COUNT);
829835
}
830836

837+
838+
/**获取被依赖引用的key的路径, 实时替换[] -> []/i
839+
* @param parentPath
840+
* @param valuePath
841+
* @return
842+
*/
843+
private String getValuePath(String parentPath, String valuePath) {
844+
if (valuePath.startsWith(SEPARATOR)) {
845+
valuePath = getAbsPath(parentPath, valuePath);
846+
} else {//处理[] -> []/i
847+
valuePath = replaceArrayChildPath(parentPath, valuePath);
848+
}
849+
return valuePath;
850+
}
831851

832852
/**获取绝对路径
833853
* @param path

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/sql/QueryHelper.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -257,31 +257,4 @@ private String[] getColumnArray(QueryConfig config) throws SQLException {
257257
}
258258

259259

260-
// /**
261-
// * @param table
262-
// * @param schema
263-
// * @return
264-
// * @throws Exception
265-
// */
266-
// public int getCount(String table) throws Exception {
267-
// if (connection == null || connection.isClosed()) {
268-
// Log.i(TAG, "getCount connection " + (connection == null ? " = null" : ("isClosed = " + connection.isClosed()))) ;
269-
// connection = getConnection();
270-
// statement = connection.createStatement(); //创建Statement对象
271-
// metaData = connection.getMetaData();
272-
// }
273-
//
274-
// ResultSet rs = statement.executeQuery("SELECT Count(*) FROM " + table);//创建数据对象
275-
//
276-
// int count = 0;
277-
// if (rs.next()) {
278-
// count = rs.getInt(1);
279-
// }
280-
// Log.i(TAG, "getCount count = " + count) ;
281-
//
282-
// rs.close();
283-
//
284-
// return count;
285-
// }
286-
287260
}

0 commit comments

Comments
 (0)