diff --git a/APIJSON-Java-Server/APIJSONFinal/.gitignore b/APIJSON-Java-Server/APIJSONFinal/.gitignore index f8bca96f3..25a3c93a5 100755 --- a/APIJSON-Java-Server/APIJSONFinal/.gitignore +++ b/APIJSON-Java-Server/APIJSONFinal/.gitignore @@ -27,8 +27,6 @@ plan.txt *.class -# Package Files # -*.jar *.bak diff --git a/APIJSON-Java-Server/APIJSONFinal/libs/apijson-orm-3.7.0.jar b/APIJSON-Java-Server/APIJSONFinal/libs/apijson-orm-3.7.0.jar new file mode 100644 index 000000000..5a5b020a4 Binary files /dev/null and b/APIJSON-Java-Server/APIJSONFinal/libs/apijson-orm-3.7.0.jar differ diff --git a/APIJSON-Java-Server/APIJSONFinal/libs/postgresql-42.2.4.jar b/APIJSON-Java-Server/APIJSONFinal/libs/postgresql-42.2.4.jar new file mode 100644 index 000000000..4f747bea0 Binary files /dev/null and b/APIJSON-Java-Server/APIJSONFinal/libs/postgresql-42.2.4.jar differ diff --git a/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoFunction.java b/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoFunction.java index 5f3256cf6..2d1a31213 100755 --- a/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoFunction.java +++ b/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoFunction.java @@ -45,10 +45,9 @@ public class DemoFunction extends RemoteFunction { private static final String TAG = "DemoFunction"; - private final RequestMethod method; private final HttpSession session; - public DemoFunction(RequestMethod method, HttpSession session) { - this.method = method; + public DemoFunction(RequestMethod method, String tag, int version, HttpSession session) { + super(method, tag, version); this.session = session; } @@ -78,11 +77,11 @@ public static void test() throws Exception { request.put("object", object); - Log.i(TAG, "plus(1,-2) = " + new DemoFunction(null, null).invoke("plus(i0,i1)", request)); - Log.i(TAG, "count([1,2,4,10]) = " + new DemoFunction(null, null).invoke("countArray(array)", request)); - Log.i(TAG, "isContain([1,2,4,10], 10) = " + new DemoFunction(null, null).invoke("isContain(array,id)", request)); - Log.i(TAG, "getFromArray([1,2,4,10], 0) = " + new DemoFunction(null, null).invoke("getFromArray(array,@position)", request)); - Log.i(TAG, "getFromObject({key:true}, key) = " + new DemoFunction(null, null).invoke("getFromObject(object,key)", request)); + Log.i(TAG, "plus(1,-2) = " + new DemoFunction(null, null, 1, null).invoke("plus(i0,i1)", request)); + Log.i(TAG, "count([1,2,4,10]) = " + new DemoFunction(null, null, 1, null).invoke("countArray(array)", request)); + Log.i(TAG, "isContain([1,2,4,10], 10) = " + new DemoFunction(null, null, 1, null).invoke("isContain(array,id)", request)); + Log.i(TAG, "getFromArray([1,2,4,10], 0) = " + new DemoFunction(null, null, 1, null).invoke("getFromArray(array,@position)", request)); + Log.i(TAG, "getFromObject({key:true}, key) = " + new DemoFunction(null, null, 1, null).invoke("getFromObject(object,key)", request)); } @@ -112,7 +111,7 @@ public static JSONObject init(boolean shutdownWhenServerError) throws ServerExce request.putAll(functionItem.toArray(0, 0, FUNCTION_)); } //Function[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - + JSONObject response = new DemoParser(RequestMethod.GET, true).parseResponse(request); if (JSONResponse.isSuccess(response) == false) { onServerError("\n\n\n\n\n !!!! 查询远程函数异常 !!!\n" + response.getString(JSONResponse.KEY_MSG) + "\n\n\n\n\n", shutdownWhenServerError); @@ -135,15 +134,28 @@ public static JSONObject init(boolean shutdownWhenServerError) throws ServerExce if (demo == null) { onServerError("字段 demo 的值必须为合法且非 null 的 JSONObejct 字符串!", shutdownWhenServerError); } + String name = item.getString("name"); if (demo.containsKey("result()") == false) { - demo.put("result()", getFunctionCall(item.getString("name"), item.getString("arguments"))); + demo.put("result()", getFunctionCall(name, item.getString("arguments"))); } - demo.put(JSONRequest.KEY_COLUMN, "id,name,arguments,demo"); + // demo.put(JSONRequest.KEY_TAG, item.getString(JSONRequest.KEY_TAG)); + // demo.put(JSONRequest.KEY_VERSION, item.getInteger(JSONRequest.KEY_VERSION)); + + FUNCTION_MAP.put(name, item); //必须在测试 invoke 前! + + String[] methods = StringUtil.split(item.getString("methods")); + JSONObject r = new DemoParser( + methods == null || methods.length <= 0 ? RequestMethod.GET : RequestMethod.valueOf(methods[0]) + , true + ) + .setTag(item.getString(JSONRequest.KEY_TAG)) + .setVersion(item.getIntValue(JSONRequest.KEY_VERSION)) + .parseResponse(demo); - JSONObject r = new DemoParser(RequestMethod.GET, true).parseResponse(demo); if (JSONResponse.isSuccess(r) == false) { onServerError(JSONResponse.getMsg(r), shutdownWhenServerError); } + } return response; @@ -223,10 +235,6 @@ public Object verifyURLList(@NotNull JSONObject request, @NotNull String urlList * @throws Exception */ public int deleteCommentOfMoment(@NotNull JSONObject rq, @NotNull String momentId) throws Exception { - if (method != RequestMethod.DELETE) { - throw new UnsupportedOperationException("远程函数 deleteCommentOfMoment 只支持 DELETE 方法!"); - } - long mid = rq.getLongValue(momentId); if (mid <= 0 || rq.getIntValue(JSONResponse.KEY_COUNT) <= 0) { return 0; @@ -254,10 +262,6 @@ public int deleteCommentOfMoment(@NotNull JSONObject rq, @NotNull String momentI * @return */ public int deleteChildComment(@NotNull JSONObject rq, @NotNull String toId) throws Exception { - if (method != RequestMethod.DELETE) { //TODO 如果这样的判断太多,可以把 DemoFunction 分成对应不同 RequestMethod 的 GetFunciton 等,创建时根据 method 判断用哪个 - throw new UnsupportedOperationException("远程函数 deleteChildComment 只支持 DELETE 方法!"); - } - long tid = rq.getLongValue(toId); if (tid <= 0 || rq.getIntValue(JSONResponse.KEY_COUNT) <= 0) { return 0; @@ -324,10 +328,10 @@ private JSONArray getChildCommentIdList(long tid) { * @return * @throws ServerException */ - public JSONObject getFunctionDemo(@NotNull JSONObject request) throws ServerException { + public JSONObject getFunctionDemo(@NotNull JSONObject request) { JSONObject demo = JSON.parseObject(request.getString("demo")); if (demo == null) { - throw new ServerException("服务器内部错误,字段 demo 的值必须为合法且非 null 的 JSONObejct 字符串!"); + demo = new JSONObject(); } if (demo.containsKey("result()") == false) { demo.put("result()", getFunctionCall(request.getString("name"), request.getString("arguments"))); @@ -349,7 +353,7 @@ public String getFunctionDetail(@NotNull JSONObject request) { * @return */ private static String getFunctionCall(String name, String arguments) { - return name + "(" + arguments + ")"; + return name + "(" + StringUtil.getTrimedString(arguments) + ")"; } /**TODO 仅用来测试 "key-()":"getIdList()" 和 "key()":"getIdList()" @@ -357,7 +361,7 @@ private static String getFunctionCall(String name, String arguments) { * @return JSONArray 只能用JSONArray,用long[]会在SQLConfig解析崩溃 * @throws Exception */ - public JSONArray getIdList(@NotNull JSONObject request) throws Exception { + public JSONArray getIdList(@NotNull JSONObject request) { return new JSONArray(new ArrayList(Arrays.asList(12, 15, 301, 82001, 82002, 38710))); } diff --git a/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoObjectParser.java b/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoObjectParser.java index 1878b31f7..7b6e5f1c0 100755 --- a/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoObjectParser.java +++ b/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoObjectParser.java @@ -14,6 +14,8 @@ package apijson.demo.server; +import java.util.List; + import javax.servlet.http.HttpSession; import com.alibaba.fastjson.JSONObject; @@ -22,6 +24,7 @@ import zuo.biao.apijson.RequestMethod; import zuo.biao.apijson.StringUtil; import zuo.biao.apijson.server.AbstractObjectParser; +import zuo.biao.apijson.server.Join; import zuo.biao.apijson.server.Parser; import zuo.biao.apijson.server.SQLConfig; @@ -29,7 +32,7 @@ /**简化Parser,getObject和getArray(getArrayConfig)都能用 * @author Lemon */ -public abstract class DemoObjectParser extends AbstractObjectParser { +public class DemoObjectParser extends AbstractObjectParser { static { COMPILE_MAP.put("phone", StringUtil.PATTERN_PHONE); @@ -38,7 +41,7 @@ public abstract class DemoObjectParser extends AbstractObjectParser { } - + /**for single object * @param parentPath * @param request @@ -48,7 +51,7 @@ public abstract class DemoObjectParser extends AbstractObjectParser { public DemoObjectParser(HttpSession session, @NotNull JSONObject request, String parentPath, String name, SQLConfig arrayConfig, boolean isSubquery) throws Exception { super(request, parentPath, name, arrayConfig, isSubquery); } - + @Override public DemoObjectParser setMethod(RequestMethod method) { super.setMethod(method); @@ -61,9 +64,10 @@ public DemoObjectParser setParser(Parser parser) { return this; } + @Override - public SQLConfig newSQLConfig(boolean isProcedure) throws Exception { - return DemoSQLConfig.newSQLConfig(method, table, alias, sqlRequest, joinList, isProcedure); + public SQLConfig newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List joinList, boolean isProcedure) throws Exception { + return DemoSQLConfig.newSQLConfig(method, table, alias, request, joinList, isProcedure); } diff --git a/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoParser.java b/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoParser.java index adc1ddc49..248c36091 100755 --- a/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoParser.java +++ b/APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoParser.java @@ -94,7 +94,7 @@ public JSONObject parseResponse(JSONObject request) { @Override public Object onFunctionParse(JSONObject json, String fun) throws Exception { if (function == null) { - function = new DemoFunction(requestMethod, session); + function = new DemoFunction(requestMethod, tag, version, session); } return function.invoke(fun, json); } @@ -106,15 +106,7 @@ public DemoObjectParser createObjectParser(JSONObject request, String parentPath return new DemoObjectParser(session, request, parentPath, name, arrayConfig, isSubquery) { //TODO 删除,onPUTArrayParse改用MySQL函数JSON_ADD, JSON_REMOVE等 - @Override - public JSONObject parseResponse(JSONRequest request) throws Exception { - DemoParser demoParser = new DemoParser(RequestMethod.GET); - demoParser.setSession(session); - // parser.setNoVerifyRequest(noVerifyRequest) - demoParser.setNoVerifyLogin(noVerifyLogin); - demoParser.setNoVerifyRole(noVerifyRole); - return demoParser.parseResponse(request); - } + // @Override