| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fa79888 commit f59a653
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,6 +120,15 @@ public JSONObject setUserIdIn(List<Object> list) { | |||
| 120 | 120 | } | |
| 121 | 121 | ||
| 122 | 122 | ||
| 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 | + | ||
| 123 | 132 | //@key关键字都放这个类 <<<<<<<<<<<<<<<<<<<<<< | |
| 124 | 133 | public static final String KEY_TRY = "@try"; //尝试,忽略异常 | |
| 125 | 134 | public static final String KEY_DROP = "@drop"; //丢弃,不返回 | |
@@ -196,7 +205,33 @@ public JSONObject setCorrect(Map<String, String> correct) { | |||
| 196 | 205 | */ | |
| 197 | 206 | public JSONObject setDatabase(String database) { | |
| 198 | 207 | 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); | ||
| 200 | 235 | } | |
| 201 | 236 | /**set schema where table was puts | |
| 202 | 237 | * @param schema | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,41 +87,28 @@ public JSONRequest setFormat(Boolean format) { | |||
| 87 | 87 | public static final int QUERY_TABLE = 0; | |
| 88 | 88 | public static final int QUERY_TOTAL = 1; | |
| 89 | 89 | public static final int QUERY_ALL = 2; | |
| 90 | - | ||
| 90 | + | ||
| 91 | 91 | public static final String QUERY_TABLE_STRING = "TABLE"; | |
| 92 | 92 | public static final String QUERY_TOTAL_STRING = "TOTAL"; | |
| 93 | 93 | 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"; | ||
| 102 | 94 | ||
| 103 | 95 | public static final String SUBQUERY_RANGE_ALL = "ALL"; | |
| 104 | 96 | public static final String SUBQUERY_RANGE_ANY = "ANY"; | |
| 105 | 97 | ||
| 106 | - public static final String KEY_QUERY = "query"; // 0- | ||
| 98 | + public static final String KEY_QUERY = "query"; | ||
| 107 | 99 | public static final String KEY_COUNT = "count"; | |
| 108 | 100 | public static final String KEY_PAGE = "page"; | |
| 109 | 101 | 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 里加一个值了 | ||
| 112 | 102 | public static final String KEY_SUBQUERY_RANGE = "range"; | |
| 113 | 103 | public static final String KEY_SUBQUERY_FROM = "from"; | |
| 114 | - | ||
| 115 | - | ||
| 104 | + | ||
| 116 | 105 | public static final List<String> ARRAY_KEY_LIST; | |
| 117 | 106 | static { | |
| 118 | 107 | ARRAY_KEY_LIST = new ArrayList<String>(); | |
| 119 | 108 | ARRAY_KEY_LIST.add(KEY_QUERY); | |
| 120 | 109 | ARRAY_KEY_LIST.add(KEY_COUNT); | |
| 121 | 110 | ARRAY_KEY_LIST.add(KEY_PAGE); | |
| 122 | 111 | ARRAY_KEY_LIST.add(KEY_JOIN); | |
| 123 | - ARRAY_KEY_LIST.add(KEY_CACHE); | ||
| 124 | - ARRAY_KEY_LIST.add(KEY_EXPLAIN); | ||
| 125 | 112 | ARRAY_KEY_LIST.add(KEY_SUBQUERY_RANGE); | |
| 126 | 113 | ARRAY_KEY_LIST.add(KEY_SUBQUERY_FROM); | |
| 127 | 114 | } | |
@@ -159,36 +146,6 @@ public JSONRequest setJoin(String... joins) { | |||
| 159 | 146 | return puts(KEY_JOIN, StringUtil.getString(joins)); | |
| 160 | 147 | } | |
| 161 | 148 | ||
| 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 | - | ||
| 192 | 149 | /**set range for Subquery | |
| 193 | 150 | * @param range | |
| 194 | 151 | * @return | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -291,8 +291,6 @@ public AbstractObjectParser parse() throws Exception { | |||
| 291 | 291 | } | |
| 292 | 292 | else {//直接解析并替换原来的,[]:{} 内必须直接解析,否则会因为丢掉count等属性,并且total@:"/[]/total"必须在[]:{} 后! | |
| 293 | 293 | 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)); | ||
| 296 | 294 | index ++; | |
| 297 | 295 | } | |
| 298 | 296 | } | |
@@ -626,7 +624,7 @@ public AbstractObjectParser setSQLConfig(int count, int page, int position) thro | |||
| 626 | 624 | ||
| 627 | 625 | if (sqlConfig == null) { | |
| 628 | 626 | try { | |
| 629 | - sqlConfig = newSQLConfig(arrayConfig, false); | ||
| 627 | + sqlConfig = newSQLConfig(false); | ||
| 630 | 628 | } | |
| 631 | 629 | catch (NotExistException e) { | |
| 632 | 630 | e.printStackTrace(); | |
@@ -740,7 +738,7 @@ public void onFunctionResponse(String type) throws Exception { | |||
| 740 | 738 | public void parseFunction(JSONObject json, String key, String value) throws Exception { | |
| 741 | 739 | Object result; | |
| 742 | 740 | if (key.startsWith("@")) { | |
| 743 | - SQLConfig config = newSQLConfig(arrayConfig, true); | ||
| 741 | + SQLConfig config = newSQLConfig(true); | ||
| 744 | 742 | config.setProcedure(value); | |
| 745 | 743 | ||
| 746 | 744 | SQLExecutor executor = null; | |
@@ -764,14 +762,6 @@ public void parseFunction(JSONObject json, String key, String value) throws Exce | |||
| 764 | 762 | } | |
| 765 | 763 | } | |
| 766 | 764 | ||
| 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 | - | ||
| 775 | 765 | @Override | |
| 776 | 766 | public void onChildResponse() throws Exception { | |
| 777 | 767 | //把isTable时取出去child解析后重新添加回来 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -752,8 +752,6 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name | |||
| 752 | 752 | final Integer count = request.getInteger(JSONRequest.KEY_COUNT); //TODO 如果不想用默认数量可以改成 getIntValue(JSONRequest.KEY_COUNT); | |
| 753 | 753 | final int page = request.getIntValue(JSONRequest.KEY_PAGE); | |
| 754 | 754 | 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); | ||
| 757 | 755 | ||
| 758 | 756 | int query2; | |
| 759 | 757 | if (query == null) { | |
@@ -778,33 +776,6 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name | |||
| 778 | 776 | } | |
| 779 | 777 | } | |
| 780 | 778 | ||
| 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 | - | ||
| 808 | 779 | int maxPage = getMaxQueryPage(); | |
| 809 | 780 | if (page < 0 || page > maxPage) { | |
| 810 | 781 | throw new IllegalArgumentException(path + "/" + JSONRequest.KEY_PAGE + ":value 中 value 的值不合法!必须在 0-" + maxPage + " 内 !"); | |
@@ -822,9 +793,7 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name | |||
| 822 | 793 | request.remove(JSONRequest.KEY_COUNT); | |
| 823 | 794 | request.remove(JSONRequest.KEY_PAGE); | |
| 824 | 795 | 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); | ||
| 828 | 797 | ||
| 829 | 798 | if (request.isEmpty()) {//如果条件成立,说明所有的 parentPath/name:request 中request都无效!!! | |
| 830 | 799 | Log.e(TAG, "onArrayParse request.isEmpty() >> return null;"); | |
@@ -854,20 +823,15 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name | |||
| 854 | 823 | .setCount(size) | |
| 855 | 824 | .setPage(page) | |
| 856 | 825 | .setQuery(query2) | |
| 857 | - .setCache(cache2) | ||
| 858 | - .setExplain(explain) | ||
| 859 | 826 | .setJoinList(onJoinParse(join, request)); | |
| 860 | 827 | ||
| 861 | - int len = explain || isSubquery ? 1 : size; | ||
| 862 | 828 | 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++) { | ||
| 864 | 831 | parent = onObjectParse(request, path, "" + i, config.setType(SQLConfig.TYPE_ITEM).setPosition(i), isSubquery); | |
| 865 | 832 | if (parent == null || parent.isEmpty()) { | |
| 866 | 833 | break; | |
| 867 | 834 | } | |
| 868 | - if (explain) { | ||
| 869 | - parent.put(JSONRequest.KEY_EXPLAIN, explain); | ||
| 870 | - } | ||
| 871 | 835 | //key[]:{Table:{}}中key equals Table时 提取Table | |
| 872 | 836 | response.add(getValue(parent, childKeys)); //null有意义 | |
| 873 | 837 | } | |
@@ -900,8 +864,6 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name | |||
| 900 | 864 | request.put(JSONRequest.KEY_COUNT, count); | |
| 901 | 865 | request.put(JSONRequest.KEY_PAGE, page); | |
| 902 | 866 | request.put(JSONRequest.KEY_JOIN, join); | |
| 903 | - request.put(JSONRequest.KEY_CACHE, cache); | ||
| 904 | - request.put(JSONRequest.KEY_EXPLAIN, explain); | ||
| 905 | 867 | ||
| 906 | 868 | if (Log.DEBUG) { | |
| 907 | 869 | Log.i(TAG, "onArrayParse return response = \n" + JSON.toJSONString(response) + "\n>>>>>>>>>>>>>>>\n\n\n"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1942,7 +1942,7 @@ public static String getSQL(AbstractSQLConfig config) throws Exception { | |||
| 1942 | 1942 | String sch = config.getSQLSchema(config.getSQLTable()); | |
| 1943 | 1943 | if (StringUtil.isNotEmpty(config.getProcedure(), true)) { | |
| 1944 | 1944 | String q = config.getQuote(); | |
| 1945 | - return "CALL " + q + sch + q + "."+ config.getProcedure(); // EXPLIAN 不能用于存储过程,和 CALL 语法冲突 | ||
| 1945 | + return "CALL " + q + sch + q + "."+ config.getProcedure(); | ||
| 1946 | 1946 | } | |
| 1947 | 1947 | ||
| 1948 | 1948 | String tablePath = config.getTablePath(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments