@@ -105,7 +105,7 @@ public abstract class AbstractSQLConfig implements SQLConfig {
105105 private int position ; //Table在[]中的位置
106106 private int query ; //JSONRequest.query
107107 private int type ; //ObjectParser.type
108- private List <Map < String , Object >> join ; //join
108+ private List <Join > joinList ; //joinList
109109 //array item >>>>>>>>>>
110110 private boolean test ; //测试
111111 private boolean cacheStatic ; //静态缓存
@@ -215,7 +215,7 @@ public String getTable() {
215215 @ Override
216216 public String getSQLTable () {
217217 return (TABLE_KEY_MAP .containsKey (table ) ? TABLE_KEY_MAP .get (table ) : table )
218- + ( join != null && join .isEmpty () == false //副表已经在 parseJoin 里加了 AS
218+ + ( joinList != null && joinList .isEmpty () == false //副表已经在 parseJoin 里加了 AS
219219 && isMain () && RequestMethod .isQueryMethod (method ) ? " AS " + getAlias () : "" );
220220 }
221221 @ JSONField (serialize = false )
@@ -394,10 +394,10 @@ public String getColumnString() throws Exception {
394394 case GETS :
395395 boolean isQuery = RequestMethod .isQueryMethod (method );
396396 String joinColumn = "" ;
397- if (isQuery && join != null ) {
397+ if (isQuery && joinList != null ) {
398398 SQLConfig c ;
399- for (Map < String , Object > map : join ) {
400- c = ( SQLConfig ) map . get ( "config" );
399+ for (Join j : joinList ) {
400+ c = j . getJoinConfig ( );
401401 c .setAlias (c .getTable ());
402402 joinColumn += ((AbstractSQLConfig ) c ).getColumnString ();
403403 }
@@ -541,12 +541,12 @@ public AbstractSQLConfig setType(int type) {
541541 return this ;
542542 }
543543 @ Override
544- public List <Map < String , Object >> getJoin () {
545- return join ;
544+ public List <Join > getJoinList () {
545+ return joinList ;
546546 }
547547 @ Override
548- public SQLConfig setJoin (List <Map < String , Object >> join ) {
549- this .join = join ;
548+ public SQLConfig setJoinList (List <Join > joinList ) {
549+ this .joinList = joinList ;
550550 return this ;
551551 }
552552
@@ -1301,13 +1301,13 @@ private static String getConditionString(String column, String table, AbstractSQ
13011301
13021302 public String getJoinString () {
13031303 String joinOns = "" ;
1304- if (join != null ) {
1305- String j ;
1304+ if (joinList != null ) {
1305+ String sql ;
13061306 boolean first = true ;
1307- for (Map < String , Object > map : join ) {
1308- j = ( String ) map . get ( "join" );
1309- if (j != null ) {
1310- joinOns += (first ? "" : AND ) + j ;
1307+ for (Join j : joinList ) {
1308+ sql = j . getJoinSQL ( );
1309+ if (sql != null ) {
1310+ joinOns += (first ? "" : AND ) + sql ;
13111311 first = false ;
13121312 }
13131313 }
@@ -1321,7 +1321,7 @@ public String getJoinString() {
13211321 * @return
13221322 * @throws Exception
13231323 */
1324- public static AbstractSQLConfig newSQLConfig (RequestMethod method , String table , JSONObject request , List <Map < String , Object >> join , Callback callback ) throws Exception {
1324+ public static AbstractSQLConfig newSQLConfig (RequestMethod method , String table , JSONObject request , List <Join > joinList , Callback callback ) throws Exception {
13251325 if (request == null ) { // User:{} 这种空内容在查询时也有效
13261326 throw new NullPointerException (TAG + ": newSQLConfig request == null!" );
13271327 }
@@ -1545,7 +1545,7 @@ else if (whereList != null && whereList.contains(key)) {
15451545 config .setGroup (group );
15461546 config .setHaving (having );
15471547 config .setOrder (order );
1548- config .setJoin (parseJoin (method , join , callback ));
1548+ config .setJoinList (parseJoin (method , joinList , callback ));
15491549
15501550 //TODO 解析JOIN,包括 @column,@group 等要合并
15511551
@@ -1565,49 +1565,35 @@ else if (whereList != null && whereList.contains(key)) {
15651565 return config ;
15661566 }
15671567
1568- public static List <Map < String , Object >> parseJoin (RequestMethod method , List <Map < String , Object >> join , Callback callback ) throws Exception {
1568+ public static List <Join > parseJoin (RequestMethod method , List <Join > joinList , Callback callback ) throws Exception {
15691569
15701570 //TODO 解析出 SQLConfig 再合并 column, order, group 等
1571- if (join == null || join .isEmpty ()) {
1571+ if (joinList == null || joinList .isEmpty ()) {
15721572 return null ;
15731573 }
15741574
15751575
15761576 String name ;
1577- for (Map <String , Object > map : join ) {
1578- name = (String ) map .get ("name" );
1579- SQLConfig childConfig = newSQLConfig (method , name , (JSONObject ) map .get ("table" ), null , callback );
1580- SQLConfig childConfig2 = newSQLConfig (method , name , (JSONObject ) map .get ("table" ), null , callback );
1581- childConfig .setMain (false ).setCount (1 ).setPage (0 ).setPosition (0 );
1582- childConfig2 .setCount (1 ).setPage (0 ).setPosition (0 );
1583-
1584- // <"INNER JOIN User ON User.id = Moment.userId", UserConfig>
1585- map .put ("join" , getJoinType ((String ) map .get ("type" )) + " " + childConfig .getTablePath () + " AS "
1586- + name + " ON " + childConfig .getTable () + "." + (String ) map .get ("key" ) + " = "
1587- + (String ) map .get ("targetTable" ) + "." + (String ) map .get ("targetKey" ));
1588- map .put ("config" , childConfig );
1589- map .put ("config2" , childConfig2 );
1590- }
1591-
1592- return join ;
1593- }
1594-
1595- private static String getJoinType (String type ) {
1596- switch (type ) {
1597- case "&" :
1598- return " INNER JOIN " ;
1599- case "<" :
1600- return " LEFT JOIN " ;
1601- case ">" :
1602- return " RIGIHT JOIN " ;
1603- default :
1604- return " FULL JOIN " ;
1577+ for (Join j : joinList ) {
1578+ name = j .getName ();
1579+ SQLConfig joinConfig = newSQLConfig (method , name , j .getTable (), null , callback ).setMain (false );
1580+ SQLConfig cacheConfig = newSQLConfig (method , name , j .getTable (), null , callback ).setCount (1 );
1581+
1582+ j .setJoinConfig (joinConfig );
1583+ j .setCacheConfig (cacheConfig );
1584+ // <"INNER JOIN User ON User.id = Moment.userId", UserConfig> TODO AS 放 getSQLTable 内
1585+ j .setJoinSQL (j .getJoinTypeName () + " " + joinConfig .getTablePath () + " AS "
1586+ + name + " ON " + joinConfig .getTable () + "." + j .getKey () + " = "
1587+ + j .getTargetName () + "." + j .getTargetKey ());
16051588 }
1589+
1590+ return joinList ;
16061591 }
16071592
16081593
16091594
16101595
1596+
16111597 /**获取客户端实际需要的key
16121598 * verifyName = true
16131599 * @param method
0 commit comments