1515package zuo .biao .apijson .server ;
1616
1717import static zuo .biao .apijson .JSONObject .KEY_COMBINE ;
18+ import static zuo .biao .apijson .JSONObject .KEY_SQL ;
1819import static zuo .biao .apijson .JSONObject .KEY_CORRECT ;
1920import static zuo .biao .apijson .JSONObject .KEY_DROP ;
2021import static zuo .biao .apijson .JSONObject .KEY_TRY ;
4950 * @author Lemon
5051 */
5152public abstract class AbstractObjectParser implements ObjectParser {
52- private static final String TAG = "ObjectParser " ;
53+ private static final String TAG = "AbstractObjectParser " ;
5354
5455 @ NotNull
5556 protected Parser <?> parser ;
@@ -75,7 +76,8 @@ public AbstractObjectParser setParser(Parser<?> parser) {
7576 * TODO Parser内要不因为 非 TYPE_ITEM_CHILD_0 的Table 为空导致后续中断。
7677 */
7778 protected final boolean drop ;
78- protected JSONObject correct ;
79+ protected final JSONObject correct ;
80+ protected final JSONObject sql ;
7981
8082 /**for single object
8183 * @param parentPath
@@ -101,14 +103,19 @@ public AbstractObjectParser(@NotNull JSONObject request, String parentPath, Stri
101103 if (isEmpty ) {
102104 this .tri = false ;
103105 this .drop = false ;
104- } else {
106+ this .correct = null ;
107+ this .sql = null ;
108+ }
109+ else {
105110 this .tri = request .getBooleanValue (KEY_TRY );
106111 this .drop = request .getBooleanValue (KEY_DROP );
107112 this .correct = request .getJSONObject (KEY_CORRECT );
113+ this .sql = request .getJSONObject (KEY_SQL );
108114
109115 request .remove (KEY_TRY );
110116 request .remove (KEY_DROP );
111117 request .remove (KEY_CORRECT );
118+ request .remove (KEY_SQL );
112119
113120 try {
114121 parseCorrect ();
@@ -121,8 +128,8 @@ public AbstractObjectParser(@NotNull JSONObject request, String parentPath, Stri
121128 }
122129
123130
124- Log .d (TAG , "ObjectParser table = " + table + "; isTable = " + isTable );
125- Log .d (TAG , "ObjectParser isEmpty = " + isEmpty + "; tri = " + tri + "; drop = " + drop );
131+ Log .d (TAG , "AbstractObjectParser table = " + table + "; isTable = " + isTable );
132+ Log .d (TAG , "AbstractObjectParser isEmpty = " + isEmpty + "; tri = " + tri + "; drop = " + drop );
126133 }
127134
128135 public static final Map <String , Pattern > COMPILE_MAP ;
@@ -162,8 +169,7 @@ public AbstractObjectParser parseCorrect() throws Exception {
162169 }
163170
164171 if (rk == null ) {
165- throw new IllegalArgumentException (
166- "格式错误!找不到 " + k + ":" + value + " 对应[" + v + "]内的任何一项!" );
172+ throw new IllegalArgumentException ("格式错误!找不到 " + k + ":" + value + " 对应[" + v + "]内的任何一项!" );
167173 }
168174 request .put (rk , request .remove (k ));
169175 corrected .put (k , rk );
@@ -523,16 +529,32 @@ public void onPUTArrayParse(@NotNull String key, @NotNull JSONArray array) throw
523529
524530 }
525531
526-
527- /**SQL查询,for single object
528- * @return {@link #executeSQL(int, int, int)}
532+ /**SQL 配置,for single object
533+ * @return {@link #setSQLConfig(int, int, int)}
529534 * @throws Exception
530535 */
531536 @ Override
532- public AbstractObjectParser executeSQL () throws Exception {
533- return executeSQL (1 , 0 , 0 );
537+ public AbstractObjectParser setSQLConfig () throws Exception {
538+ return setSQLConfig (1 , 0 , 0 );
539+ }
540+
541+ @ Override
542+ public AbstractObjectParser setSQLConfig (int count , int page , int position ) throws Exception {
543+ if (isTable == false ) {
544+ return this ;
545+ }
546+
547+ if (sqlConfig == null ) {
548+ sqlConfig = newSQLConfig ();
549+ }
550+ sqlConfig .setCount (count ).setPage (page ).setPosition (position );
551+
552+ parser .onVerifyRole (sqlConfig );
553+
554+ return this ;
534555 }
535556
557+
536558 protected SQLConfig sqlConfig = null ;//array item复用
537559 /**SQL查询,for array item
538560 * @param count
@@ -542,17 +564,12 @@ public AbstractObjectParser executeSQL() throws Exception {
542564 * @throws Exception
543565 */
544566 @ Override
545- public AbstractObjectParser executeSQL (int count , int page , int position ) throws Exception {
567+ public AbstractObjectParser executeSQL () throws Exception {
546568 //执行SQL操作数据库
547569 if (isTable == false ) {//提高性能
548570 sqlReponse = new JSONObject (sqlRequest );
549571 } else {
550-
551572 try {
552- if (sqlConfig == null ) {
553- sqlConfig = newSQLConfig ();
554- }
555- sqlConfig .setCount (count ).setPage (page ).setPosition (position );
556573 sqlReponse = onSQLExecute ();
557574 } catch (Exception e ) {
558575 Log .e (TAG , "getObject try { response = getSQLObject(config2); } catch (Exception e) {" );
@@ -621,11 +638,11 @@ public void onFunctionResponse(String type) throws Exception {
621638 //解析函数function
622639 Set <Entry <String , String >> functionSet = map == null ? null : map .entrySet ();
623640 if (functionSet != null && functionSet .isEmpty () == false ) {
624- // JSONObject json = "-".equals(type) ? request : response; // key-():function 是实时执行,而不是在这里批量执行
641+ // JSONObject json = "-".equals(type) ? request : response; // key-():function 是实时执行,而不是在这里批量执行
625642
626643 for (Entry <String , String > entry : functionSet ) {
627644
628- // parseFunction(json, entry.getKey(), entry.getValue());
645+ // parseFunction(json, entry.getKey(), entry.getValue());
629646 parseFunction (response , entry .getKey (), entry .getValue ());
630647 }
631648 }
@@ -696,9 +713,11 @@ public void recycle() {
696713 if (correct != null ) {
697714 request .put (KEY_CORRECT , correct );
698715 }
716+ if (sql != null ) {
717+ request .put (KEY_SQL , sql );
718+ }
699719
700720
701- correct = null ;
702721 corrected = null ;
703722 method = null ;
704723 parentPath = null ;
0 commit comments