GeezerVison is showing github.com — 对 SQLConfig 传入 Parser, ObjectParser, version, tag 等,拿到上下文信息来实现某些需求 · cloudAndMonkey/APIJSON@d0130bc
File treeExpand file treeCollapse file tree Open diff view settings APIJSONORM/src/main/java/apijson/orm
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java +10-6Lines changed: 10 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -799,7 +799,9 @@ public void onTableArrayParse(String key, JSONArray valueArray) throws Exception | 799 | 799 | @Override | 800 | 800 | public JSONObject parseResponse(RequestMethod method, String table, String alias | 801 | 801 | , JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception { | 802 | | - SQLConfig config = newSQLConfig(method, table, alias, request, joinList, isProcedure); | | 802 | + SQLConfig config = newSQLConfig(method, table, alias, request, joinList, isProcedure) | | 803 | + .setParser(parser) | | 804 | + .setObjectParser(this); | 803 | 805 | return parseResponse(config, isProcedure); | 804 | 806 | } | 805 | 807 | @Override | @@ -813,7 +815,9 @@ public JSONObject parseResponse(SQLConfig config, boolean isProcedure) throws Ex | 813 | 815 |
| 814 | 816 | @Override | 815 | 817 | public SQLConfig newSQLConfig(boolean isProcedure) throws Exception { | 816 | | - return newSQLConfig(method, table, alias, sqlRequest, joinList, isProcedure); | | 818 | + return newSQLConfig(method, table, alias, sqlRequest, joinList, isProcedure) | | 819 | + .setParser(parser) | | 820 | + .setObjectParser(this); | 817 | 821 | } | 818 | 822 |
| 819 | 823 | /**SQL 配置,for single object | @@ -836,10 +840,10 @@ public AbstractObjectParser setSQLConfig(int count, int page, int position) thro | 836 | 840 | sqlConfig = newSQLConfig(false); | 837 | 841 | } | 838 | 842 | catch (Exception e) { | 839 | | - if (e instanceof NotExistException || (e instanceof CommonException && e.getCause() instanceof NotExistException)) { | 840 | | - return this; | 841 | | - } | 842 | | - throw e; | | 843 | + if (e instanceof NotExistException || (e instanceof CommonException && e.getCause() instanceof NotExistException)) { | | 844 | + return this; | | 845 | + } | | 846 | + throw e; | 843 | 847 | } | 844 | 848 | } | 845 | 849 | sqlConfig.setCount(sqlConfig.getCount() <= 0 ? count : sqlConfig.getCount()).setPage(page).setPosition(position); | |
Collapse file Copy file name to clipboardExpand all lines: APIJSONORM/src/main/java/apijson/orm/AbstractParser.java +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1895,6 +1895,10 @@ public JSONObject executeSQL(SQLConfig config, boolean isSubquery) throws Except | 1895 | 1895 | return null; | 1896 | 1896 | } | 1897 | 1897 |
| | 1898 | + config.setParser(this); | | 1899 | + config.setVersion(getVersion()); | | 1900 | + config.setTag(getTag()); | | 1901 | + | 1898 | 1902 | if (isSubquery) { | 1899 | 1903 | JSONObject sqlObj = new JSONObject(true); | 1900 | 1904 | sqlObj.put(KEY_CONFIG, config); | @@ -1940,7 +1944,7 @@ public JSONObject executeSQL(SQLConfig config, boolean isSubquery) throws Except | 1940 | 1944 | return result; | 1941 | 1945 | } | 1942 | 1946 | catch (Exception e) { | 1943 | | - throw CommonException.wrap(e, config); | | 1947 | + throw CommonException.wrap(e, config); | 1944 | 1948 | } | 1945 | 1949 | finally { | 1946 | 1950 | if (config.getPosition() == 0 && config.limitSQLCount()) { | |
Collapse file Copy file name to clipboardExpand all lines: APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java +52-1Lines changed: 52 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -771,6 +771,56 @@ public abstract class AbstractSQLConfig implements SQLConfig { | 771 | 771 |
| 772 | 772 | } | 773 | 773 |
| | 774 | + private Parser<?> parser; | | 775 | + @Override | | 776 | + public Parser<?> getParser() { | | 777 | + return parser; | | 778 | + } | | 779 | + @Override | | 780 | + public AbstractSQLConfig setParser(Parser<?> parser) { | | 781 | + this.parser = parser; | | 782 | + return this; | | 783 | + } | | 784 | + | | 785 | + private ObjectParser objectParser; | | 786 | + @Override | | 787 | + public ObjectParser getObjectParser() { | | 788 | + return objectParser; | | 789 | + } | | 790 | + @Override | | 791 | + public AbstractSQLConfig setObjectParser(ObjectParser objectParser) { | | 792 | + this.objectParser = objectParser; | | 793 | + return this; | | 794 | + } | | 795 | + | | 796 | + private int version; | | 797 | + @Override | | 798 | + public int getVersion() { | | 799 | + if (version <= 0 && parser != null) { | | 800 | + version = parser.getVersion(); | | 801 | + } | | 802 | + return version; | | 803 | + } | | 804 | + @Override | | 805 | + public AbstractSQLConfig setVersion(int version) { | | 806 | + this.version = version; | | 807 | + return this; | | 808 | + } | | 809 | + | | 810 | + private String tag; | | 811 | + @Override | | 812 | + public String getTag() { | | 813 | + if (StringUtil.isEmpty(tag) && parser != null) { | | 814 | + tag = parser.getTag(); | | 815 | + } | | 816 | + return tag; | | 817 | + } | | 818 | + @Override | | 819 | + public AbstractSQLConfig setTag(String tag) { | | 820 | + this.tag = tag; | | 821 | + return this; | | 822 | + } | | 823 | + | 774 | 824 | // mysql8版本以上,子查询支持with as表达式 | 775 | 825 | private List<String> withAsExprSqlList = null; | 776 | 826 | protected List<Object> withAsExprPreparedValueList = new ArrayList<>(); | @@ -4734,7 +4784,8 @@ protected void onGetCrossJoinString(Join j) throws UnsupportedOperationException | 4734 | 4784 | * @return | 4735 | 4785 | * @throws Exception | 4736 | 4786 | */ | 4737 | | - public static <T extends Object> SQLConfig newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List<Join> joinList, boolean isProcedure, Callback<T> callback) throws Exception { | | 4787 | + public static <T extends Object> SQLConfig newSQLConfig(RequestMethod method, String table, String alias | | 4788 | + , JSONObject request, List<Join> joinList, boolean isProcedure, Callback<T> callback) throws Exception { | 4738 | 4789 | if (request == null) { // User:{} 这种空内容在查询时也有效 | 4739 | 4790 | throw new NullPointerException(TAG + ": newSQLConfig request == null!"); | 4740 | 4791 | } | |
Collapse file Copy file name to clipboardExpand all lines: APIJSONORM/src/main/java/apijson/orm/SQLConfig.java +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,6 +48,22 @@ public interface SQLConfig { | 48 | 48 | int TYPE_ITEM = 1; | 49 | 49 | int TYPE_ITEM_CHILD_0 = 2; | 50 | 50 |
| | 51 | + Parser<?> getParser(); | | 52 | + | | 53 | + AbstractSQLConfig setParser(Parser<?> parser); | | 54 | + | | 55 | + ObjectParser getObjectParser(); | | 56 | + | | 57 | + AbstractSQLConfig setObjectParser(ObjectParser objectParser); | | 58 | + | | 59 | + int getVersion(); | | 60 | + | | 61 | + AbstractSQLConfig setVersion(int version); | | 62 | + | | 63 | + String getTag(); | | 64 | + | | 65 | + AbstractSQLConfig setTag(String tag); | | 66 | + | 51 | 67 | boolean isMySQL(); | 52 | 68 | boolean isPostgreSQL(); | 53 | 69 | boolean isSQLServer(); | |
|