|
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 { |
|
0 commit comments