| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2a506fd commit b39dda6
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,9 +137,10 @@ public JSONObject setUserIdIn(List<Object> list) { | |||
| 137 | 137 | ||
| 138 | 138 | public static final String KEY_ROLE = "@role"; //角色,拥有对某些数据的某些操作的权限 | |
| 139 | 139 | public static final String KEY_DATABASE = "@database"; //数据库类型,默认为MySQL | |
| 140 | + public static final String KEY_SCHEMA = "@schema"; //数据库,Table在非默认schema内时需要声明 | ||
| 141 | + public static final String KEY_DATASOURCE = "@datasource"; //数据源 | ||
| 140 | 142 | public static final String KEY_EXPLAIN = "@explain"; //分析 true/false | |
| 141 | 143 | public static final String KEY_CACHE = "@cache"; //缓存 RAM/ROM/ALL | |
| 142 | - public static final String KEY_SCHEMA = "@schema"; //数据库,Table在非默认schema内时需要声明 | ||
| 143 | 144 | public static final String KEY_COLUMN = "@column"; //查询的Table字段或SQL函数 | |
| 144 | 145 | public static final String KEY_FROM = "@from"; //FROM语句 | |
| 145 | 146 | public static final String KEY_COMBINE = "@combine"; //条件组合,每个条件key前面可以放&,|,!逻辑关系 "id!{},&sex,!name&$" | |
@@ -154,9 +155,10 @@ public JSONObject setUserIdIn(List<Object> list) { | |||
| 154 | 155 | TABLE_KEY_LIST = new ArrayList<String>(); | |
| 155 | 156 | TABLE_KEY_LIST.add(KEY_ROLE); | |
| 156 | 157 | TABLE_KEY_LIST.add(KEY_DATABASE); | |
| 158 | + TABLE_KEY_LIST.add(KEY_SCHEMA); | ||
| 159 | + TABLE_KEY_LIST.add(KEY_DATASOURCE); | ||
| 157 | 160 | TABLE_KEY_LIST.add(KEY_EXPLAIN); | |
| 158 | 161 | TABLE_KEY_LIST.add(KEY_CACHE); | |
| 159 | - TABLE_KEY_LIST.add(KEY_SCHEMA); | ||
| 160 | 162 | TABLE_KEY_LIST.add(KEY_COLUMN); | |
| 161 | 163 | TABLE_KEY_LIST.add(KEY_FROM); | |
| 162 | 164 | TABLE_KEY_LIST.add(KEY_COMBINE); | |
@@ -216,6 +218,20 @@ public JSONObject setRole(String role) { | |||
| 216 | 218 | public JSONObject setDatabase(String database) { | |
| 217 | 219 | return puts(KEY_DATABASE, database); | |
| 218 | 220 | } | |
| 221 | + /**set schema where table was puts | ||
| 222 | + * @param schema | ||
| 223 | + * @return this | ||
| 224 | + */ | ||
| 225 | + public JSONObject setSchema(String schema) { | ||
| 226 | + return puts(KEY_SCHEMA, schema); | ||
| 227 | + } | ||
| 228 | + /**set datasource where table was puts | ||
| 229 | + * @param datasource | ||
| 230 | + * @return this | ||
| 231 | + */ | ||
| 232 | + public JSONObject setDatasource(String datasource) { | ||
| 233 | + return puts(KEY_DATASOURCE, datasource); | ||
| 234 | + } | ||
| 219 | 235 | /**set if return explain informations | |
| 220 | 236 | * @param explain | |
| 221 | 237 | * @return | |
@@ -243,13 +259,6 @@ public JSONObject setCache(Integer cache) { | |||
| 243 | 259 | public JSONObject setCache(String cache) { | |
| 244 | 260 | return puts(KEY_CACHE, cache); | |
| 245 | 261 | } | |
| 246 | - /**set schema where table was puts | ||
| 247 | - * @param schema | ||
| 248 | - * @return this | ||
| 249 | - */ | ||
| 250 | - public JSONObject setSchema(String schema) { | ||
| 251 | - return puts(KEY_SCHEMA, schema); | ||
| 252 | - } | ||
| 253 | 262 | ||
| 254 | 263 | /**set keys need to be returned | |
| 255 | 264 | * @param keys key0, key1, key2 ... | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -287,6 +287,10 @@ else if (method == PUT && value instanceof JSONArray | |||
| 287 | 287 | if (parser.getGlobleSchema() != null && sqlRequest.get(JSONRequest.KEY_SCHEMA) == null) { | |
| 288 | 288 | sqlRequest.put(JSONRequest.KEY_SCHEMA, parser.getGlobleSchema()); | |
| 289 | 289 | } | |
| 290 | + if (parser.getGlobleDatasource() != null && sqlRequest.get(JSONRequest.KEY_DATASOURCE) == null) { | ||
| 291 | + sqlRequest.put(JSONRequest.KEY_DATASOURCE, parser.getGlobleDatasource()); | ||
| 292 | + } | ||
| 293 | + | ||
| 290 | 294 | if (isSubquery == false) { //解决 SQL 语法报错,子查询不能 EXPLAIN | |
| 291 | 295 | if (parser.getGlobleExplain() != null && sqlRequest.get(JSONRequest.KEY_EXPLAIN) == null) { | |
| 292 | 296 | sqlRequest.put(JSONRequest.KEY_EXPLAIN, parser.getGlobleExplain()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -199,6 +199,16 @@ public AbstractParser<T> setGlobleSchema(String globleSchema) { | |||
| 199 | 199 | public String getGlobleSchema() { | |
| 200 | 200 | return globleSchema; | |
| 201 | 201 | } | |
| 202 | + protected String globleDatasource; | ||
| 203 | + @Override | ||
| 204 | + public String getGlobleDatasource() { | ||
| 205 | + return globleDatasource; | ||
| 206 | + } | ||
| 207 | + public AbstractParser<T> setGlobleDatasource(String globleDatasource) { | ||
| 208 | + this.globleDatasource = globleDatasource; | ||
| 209 | + return this; | ||
| 210 | + } | ||
| 211 | + | ||
| 202 | 212 | protected Boolean globleExplain; | |
| 203 | 213 | public AbstractParser<T> setGlobleExplain(Boolean globleExplain) { | |
| 204 | 214 | this.globleExplain = globleExplain; | |
@@ -361,12 +371,14 @@ public JSONObject parseResponse(JSONObject request) { | |||
| 361 | 371 | setGlobleFormat(requestObject.getBoolean(JSONRequest.KEY_FORMAT)); | |
| 362 | 372 | setGlobleDatabase(requestObject.getString(JSONRequest.KEY_DATABASE)); | |
| 363 | 373 | setGlobleSchema(requestObject.getString(JSONRequest.KEY_SCHEMA)); | |
| 374 | + setGlobleDatasource(requestObject.getString(JSONRequest.KEY_DATASOURCE)); | ||
| 364 | 375 | setGlobleExplain(requestObject.getBoolean(JSONRequest.KEY_EXPLAIN)); | |
| 365 | 376 | setGlobleCache(requestObject.getString(JSONRequest.KEY_CACHE)); | |
| 366 | 377 | ||
| 367 | 378 | requestObject.remove(JSONRequest.KEY_FORMAT); | |
| 368 | 379 | requestObject.remove(JSONRequest.KEY_DATABASE); | |
| 369 | 380 | requestObject.remove(JSONRequest.KEY_SCHEMA); | |
| 381 | + requestObject.remove(JSONRequest.KEY_DATASOURCE); | ||
| 370 | 382 | requestObject.remove(JSONRequest.KEY_EXPLAIN); | |
| 371 | 383 | requestObject.remove(JSONRequest.KEY_CACHE); | |
| 372 | 384 | } catch (Exception e) { | |
@@ -1245,6 +1257,7 @@ else if (join != null){ | |||
| 1245 | 1257 | JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_ROLE); | |
| 1246 | 1258 | JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_DATABASE); | |
| 1247 | 1259 | JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_SCHEMA); | |
| 1260 | + JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_DATASOURCE); | ||
| 1248 | 1261 | JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_COLUMN); | |
| 1249 | 1262 | JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_COMBINE); | |
| 1250 | 1263 | JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_GROUP); | |
@@ -1464,7 +1477,7 @@ public Object getValueByPath(String valuePath) { | |||
| 1464 | 1477 | //取出key被valuePath包含的result,再从里面获取key对应的value | |
| 1465 | 1478 | JSONObject parent = null; | |
| 1466 | 1479 | String[] keys = null; | |
| 1467 | - for (Map.Entry<String,Object> entry : queryResultMap.entrySet()){ | ||
| 1480 | + for (Entry<String,Object> entry : queryResultMap.entrySet()){ | ||
| 1468 | 1481 | String path = entry.getKey(); | |
| 1469 | 1482 | if (valuePath.startsWith(path + "/")) { | |
| 1470 | 1483 | try { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ | |||
| 9 | 9 | import static apijson.JSONObject.KEY_COLUMN; | |
| 10 | 10 | import static apijson.JSONObject.KEY_COMBINE; | |
| 11 | 11 | import static apijson.JSONObject.KEY_DATABASE; | |
| 12 | + import static apijson.JSONObject.KEY_DATASOURCE; | ||
| 12 | 13 | import static apijson.JSONObject.KEY_EXPLAIN; | |
| 13 | 14 | import static apijson.JSONObject.KEY_FROM; | |
| 14 | 15 | import static apijson.JSONObject.KEY_GROUP; | |
@@ -335,6 +336,7 @@ public String getUserIdKey() { | |||
| 335 | 336 | private boolean distinct = false; | |
| 336 | 337 | private String database; //表所在的数据库类型 | |
| 337 | 338 | private String schema; //表所在的数据库名 | |
| 339 | + private String datasource; //数据源 | ||
| 338 | 340 | private String table; //表名 | |
| 339 | 341 | private String alias; //表别名 | |
| 340 | 342 | private String group; //分组方式的字符串数组,','分隔 | |
@@ -549,6 +551,17 @@ public AbstractSQLConfig setSchema(String schema) { | |||
| 549 | 551 | this.schema = schema; | |
| 550 | 552 | return this; | |
| 551 | 553 | } | |
| 554 | + | ||
| 555 | + @Override | ||
| 556 | + public String getDatasource() { | ||
| 557 | + return datasource; | ||
| 558 | + } | ||
| 559 | + @Override | ||
| 560 | + public SQLConfig setDatasource(String datasource) { | ||
| 561 | + this.datasource = datasource; | ||
| 562 | + return this; | ||
| 563 | + } | ||
| 564 | + | ||
| 552 | 565 | /**请求传进来的Table名 | |
| 553 | 566 | * @return | |
| 554 | 567 | * @see {@link #getSQLTable()} | |
@@ -1547,7 +1560,7 @@ public Object getWhere(String key, boolean exactMatch) { | |||
| 1547 | 1560 | synchronized (where) { | |
| 1548 | 1561 | if (where != null) { | |
| 1549 | 1562 | int index; | |
| 1550 | - for (Map.Entry<String,Object> entry : where.entrySet()) { | ||
| 1563 | + for (Entry<String,Object> entry : where.entrySet()) { | ||
| 1551 | 1564 | String k = entry.getKey(); | |
| 1552 | 1565 | index = k.indexOf(key); | |
| 1553 | 1566 | if (index >= 0 && StringUtil.isName(k.substring(index)) == false) { | |
@@ -2502,7 +2515,7 @@ public String getSetString(RequestMethod method, Map<String, Object> content, bo | |||
| 2502 | 2515 | Object value; | |
| 2503 | 2516 | ||
| 2504 | 2517 | String idKey = getIdKey(); | |
| 2505 | - for (Map.Entry<String,Object> entry : content.entrySet()) { | ||
| 2518 | + for (Entry<String,Object> entry : content.entrySet()) { | ||
| 2506 | 2519 | String key = entry.getKey(); | |
| 2507 | 2520 | //避免筛选到全部 value = key == null ? null : content.get(key); | |
| 2508 | 2521 | if (key == null || idKey.equals(key)) { | |
@@ -2811,12 +2824,14 @@ public static SQLConfig newSQLConfig(RequestMethod method, String table, String | |||
| 2811 | 2824 | } | |
| 2812 | 2825 | ||
| 2813 | 2826 | String schema = request.getString(KEY_SCHEMA); | |
| 2827 | + String datasource = request.getString(KEY_DATASOURCE); | ||
| 2814 | 2828 | ||
| 2815 | 2829 | SQLConfig config = callback.getSQLConfig(method, database, schema, table); | |
| 2816 | 2830 | config.setAlias(alias); | |
| 2817 | 2831 | ||
| 2818 | 2832 | config.setDatabase(database); //不删,后面表对象还要用的,必须放在 parseJoin 前 | |
| 2819 | 2833 | config.setSchema(schema); //不删,后面表对象还要用的 | |
| 2834 | + config.setDatasource(datasource); //不删,后面表对象还要用的 | ||
| 2820 | 2835 | ||
| 2821 | 2836 | if (isProcedure) { | |
| 2822 | 2837 | return config; | |
@@ -3387,21 +3402,39 @@ public static interface IdCallback { | |||
| 3387 | 3402 | */ | |
| 3388 | 3403 | Object newId(RequestMethod method, String database, String schema, String table); | |
| 3389 | 3404 | ||
| 3390 | - /**获取主键名 | ||
| 3405 | + /**已废弃,最早 5.0.0 移除,改用 {@link #getIdKey(String, String, String, String)} | ||
| 3391 | 3406 | * @param database | |
| 3392 | 3407 | * @param schema | |
| 3393 | 3408 | * @param table | |
| 3394 | 3409 | * @return | |
| 3395 | 3410 | */ | |
| 3411 | + @Deprecated | ||
| 3396 | 3412 | String getIdKey(String database, String schema, String table); | |
| 3413 | + | ||
| 3414 | + /**获取主键名 | ||
| 3415 | + * @param database | ||
| 3416 | + * @param schema | ||
| 3417 | + * @param table | ||
| 3418 | + * @return | ||
| 3419 | + */ | ||
| 3420 | + String getIdKey(String database, String schema, String datasource, String table); | ||
| 3397 | 3421 | ||
| 3398 | - /**获取 User 的主键名 | ||
| 3422 | + /**已废弃,最早 5.0.0 移除,改用 {@link #getUserIdKey(String, String, String, String)} | ||
| 3399 | 3423 | * @param database | |
| 3400 | 3424 | * @param schema | |
| 3401 | 3425 | * @param table | |
| 3402 | 3426 | * @return | |
| 3403 | 3427 | */ | |
| 3428 | + @Deprecated | ||
| 3404 | 3429 | String getUserIdKey(String database, String schema, String table); | |
| 3430 | + | ||
| 3431 | + /**获取 User 的主键名 | ||
| 3432 | + * @param database | ||
| 3433 | + * @param schema | ||
| 3434 | + * @param table | ||
| 3435 | + * @return | ||
| 3436 | + */ | ||
| 3437 | + String getUserIdKey(String database, String schema, String datasource, String table); | ||
| 3405 | 3438 | } | |
| 3406 | 3439 | ||
| 3407 | 3440 | public static interface Callback extends IdCallback { | |
@@ -3434,11 +3467,21 @@ public Object newId(RequestMethod method, String database, String schema, String | |||
| 3434 | 3467 | public String getIdKey(String database, String schema, String table) { | |
| 3435 | 3468 | return KEY_ID; | |
| 3436 | 3469 | } | |
| 3470 | + | ||
| 3471 | + @Override | ||
| 3472 | + public String getIdKey(String database, String schema, String datasource, String table) { | ||
| 3473 | + return getIdKey(database, schema, table); | ||
| 3474 | + } | ||
| 3437 | 3475 | ||
| 3438 | 3476 | @Override | |
| 3439 | 3477 | public String getUserIdKey(String database, String schema, String table) { | |
| 3440 | 3478 | return KEY_USER_ID; | |
| 3441 | 3479 | } | |
| 3480 | + | ||
| 3481 | + @Override | ||
| 3482 | + public String getUserIdKey(String database, String schema, String datasource, String table) { | ||
| 3483 | + return getUserIdKey(database, schema, table); | ||
| 3484 | + } | ||
| 3442 | 3485 | ||
| 3443 | 3486 | @Override | |
| 3444 | 3487 | public void onMissingKey4Combine(String name, JSONObject request, String combine, String item, String key) throws Exception { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments