Skip to content

Commit

Permalink
Merge pull request alibaba#5796 from lizongbo/master
Browse files Browse the repository at this point in the history
加个兼容来规避JavaBeanBinder获取属性信息的问题 alibaba#5785
  • Loading branch information
lizongbo authored Mar 24, 2024
2 parents fa195c0 + a29d95c commit 1a9f216
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,10 @@ public DruidPooledConnection getConnection() throws SQLException {
}

public DruidPooledConnection getConnection(long maxWaitMillis) throws SQLException {
if (jdbcUrl == null || jdbcUrl.isEmpty()) {
LOG.warn("getConnection but jdbcUrl is not set,jdbcUrl=" + jdbcUrl + ",username=" + username);
return null;
}
init();

final int filtersSize = filters.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class SQLSelectQueryBlock extends SQLSelectQueryBase implements SQLReplac
protected final List<SQLSelectItem> selectList = new ArrayList<SQLSelectItem>();

protected SQLTableSource from;
protected List<String> commentsAfaterFrom;

protected SQLExprTableSource into;
protected SQLExpr where;

Expand Down Expand Up @@ -486,7 +488,6 @@ public void setFrom(SQLTableSource from) {
}
this.from = from;
}

public void setFrom(SQLSelectQueryBlock queryBlock, String alias) {
if (queryBlock == null) {
this.from = null;
Expand All @@ -496,6 +497,14 @@ public void setFrom(SQLSelectQueryBlock queryBlock, String alias) {
this.setFrom(new SQLSelect(queryBlock), alias);
}

public List<String> getCommentsAfaterFrom() {
return commentsAfaterFrom;
}

public void setCommentsAfaterFrom(List<String> commentsAfaterFrom) {
this.commentsAfaterFrom = commentsAfaterFrom;
}

public void setFrom(SQLSelect select, String alias) {
if (select == null) {
this.from = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public void parseFrom(SQLSelectQueryBlock queryBlock) {

lexer.nextTokenIdent();

if (lexer.hasComment()) {
queryBlock.setCommentsAfaterFrom(lexer.readAndResetComments());
}
while (lexer.token() == Token.HINT) {
lexer.nextToken();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ public boolean visit(MySqlSelectQueryBlock x) {
if (from != null) {
println();
print0(ucase ? "FROM " : "from ");

if (x.getCommentsAfaterFrom() != null) {
printAfterComments(x.getCommentsAfaterFrom());
println();
}
printTableSource(from);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ public boolean visit(SQLJoinTableSource x) {
this.indentCount++;
x.getCondition().accept(this);
this.indentCount--;
if (x.getAfterCommentsDirect() != null) {
printAfterComments(x.getAfterCommentsDirect());
println();
}
}

if (x.getUsing().size() > 0) {
Expand Down Expand Up @@ -450,9 +454,12 @@ public boolean visit(OdpsSelectQueryBlock x) {
if (from != null) {
println();
print0(ucase ? "FROM " : "from ");
if (x.getCommentsAfaterFrom() != null) {
printAfterComments(x.getCommentsAfaterFrom());
println();
}
from.accept(this);
}

SQLExpr where = x.getWhere();
if (where != null) {
printWhere(where);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,9 @@ protected SQLTableSource parseTableSourceRest(OracleSelectTableSource tableSourc
this.exprParser.exprList(join.getUsing(), join);
accept(Token.RPAREN);
}

if (lexer.hasComment() && lexer.isKeepComments()) {
join.addAfterComment(lexer.readAndResetComments());
}
parsePivot(join);

return parseTableSourceRest(join);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ public boolean visit(OracleSelectJoin x) {
x.getCondition().accept(this);
decrementIndent();
print(' ');
if (x.getAfterCommentsDirect() != null) {
printAfterComments(x.getAfterCommentsDirect());
println();
}
}

if (x.getUsing().size() > 0) {
Expand Down Expand Up @@ -369,6 +373,10 @@ public boolean visit(OracleSelectQueryBlock x) {

println();
print0(ucase ? "FROM " : "from ");
if (x.getCommentsAfaterFrom() != null) {
printAfterComments(x.getCommentsAfaterFrom());
println();
}
if (x.getFrom() == null) {
print0(ucase ? "DUAL" : "dual");
} else {
Expand Down Expand Up @@ -499,7 +507,10 @@ public boolean visit(OracleSelectTableReference x) {
print(' ');
x.getSampleClause().accept(this);
}

if (x.getAfterCommentsDirect() != null) {
printAfterComments(x.getAfterCommentsDirect());
println();
}
if (x.getPivot() != null) {
println();
x.getPivot().accept(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,10 @@ public boolean visit(OracleSelectJoin x) {
print0(ucase ? " ON " : " on ");
x.getCondition().accept(this);
print(' ');
if (x.getAfterCommentsDirect() != null) {
printAfterComments(x.getAfterCommentsDirect());
println();
}
}

if (x.getUsing().size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public boolean visit(PGSelectQueryBlock x) {
if (x.getFrom() != null) {
println();
print0(ucase ? "FROM " : "from ");
if (x.getCommentsAfaterFrom() != null) {
printAfterComments(x.getCommentsAfaterFrom());
println();
}
x.getFrom().accept(this);
}

Expand Down Expand Up @@ -1347,6 +1351,10 @@ public boolean visit(OracleSelectQueryBlock x) {
println();
print0(ucase ? "FROM " : "from ");
if (x.getFrom() != null) {
if (x.getCommentsAfaterFrom() != null) {
printAfterComments(x.getCommentsAfaterFrom());
println();
}
x.getFrom().accept(this);
}

Expand Down Expand Up @@ -2245,6 +2253,10 @@ public boolean visit(OracleSelectJoin x) {
print0(ucase ? " ON " : " on ");
x.getCondition().accept(this);
print(' ');
if (x.getAfterCommentsDirect() != null) {
printAfterComments(x.getAfterCommentsDirect());
println();
}
}

if (x.getUsing().size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public boolean visit(SQLServerSelectQueryBlock x) {
if (from != null) {
println();
print0(ucase ? "FROM " : "from ");
if (x.getCommentsAfaterFrom() != null) {
printAfterComments(x.getCommentsAfaterFrom());
println();
}
printTableSource(from);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,7 @@ public void parseWhere(SQLSelectQueryBlock queryBlock) {
if (lexer.token != Token.WHERE) {
return;
}

lexer.nextTokenIdent();

List<String> beforeComments = null;
if (lexer.hasComment() && lexer.isKeepComments()) {
beforeComments = lexer.readAndResetComments();
Expand Down Expand Up @@ -1105,9 +1103,12 @@ public void parseFrom(SQLSelectQueryBlock queryBlock) {
}

lexer.nextToken();

if (lexer.hasComment()) {
queryBlock.setCommentsAfaterFrom(lexer.readAndResetComments());
}
queryBlock.setFrom(
parseTableSource());

}

public SQLTableSource parseTableSource() {
Expand Down Expand Up @@ -1871,7 +1872,6 @@ public SQLTableSource parseTableSourceRest(SQLTableSource tableSource) {
lexer.reset(savePoint);
}
}

SQLTableSource tableSourceReturn = parseTableSourceRest(join);

if (isBrace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2535,10 +2535,13 @@ public boolean visit(SQLSelectQueryBlock x) {
&& ((SQLLateralViewTableSource) from).getTableSource() == null;
if (!printFrom) {
print0(ucase ? "FROM " : "from ");
if (x.getCommentsAfaterFrom() != null) {
printAfterComments(x.getCommentsAfaterFrom());
println();
}
}
printTableSource(from);
}

SQLExpr where = x.getWhere();
if (where != null) {
printWhere(where);
Expand Down Expand Up @@ -4230,6 +4233,10 @@ public boolean visit(SQLJoinTableSource x) {
this.indentCount++;
print0(ucase ? "ON " : "on ");
printExpr(condition, parameterized);
if (x.getAfterCommentsDirect() != null) {
printAfterComments(x.getAfterCommentsDirect());
println();
}
this.indentCount--;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public void test_wait() throws Exception {
Exception error = null;
try {
DruidPooledConnection conn = dataSource.getConnection();
conn.close();
assertNull(conn);
//conn.close();
} catch (SQLException ex) {
error = ex;
}
assertEquals("url not set", error.getMessage());
//assertEquals("url not set", error.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void test_0() throws Exception {
Assert.assertEquals("DELETE FROM t1\n" +
"WHERE s11 > ANY (\n" +
"\t\tSELECT COUNT(*)\n" +
"\t\tFROM t2\n" +
"\t\tFROM /* no hint */\n\t\tt2\n" +
"\t\tWHERE NOT EXISTS (\n" +
"\t\t\tSELECT *\n" +
"\t\t\tFROM t3\n" +
Expand All @@ -63,7 +63,7 @@ public void test_0() throws Exception {
assertEquals("delete from t1\n" +
"where s11 > any (\n" +
"\t\tselect count(*)\n" +
"\t\tfrom t2\n" +
"\t\tfrom /* no hint */\n\t\tt2\n" +
"\t\twhere not exists (\n" +
"\t\t\tselect *\n" +
"\t\t\tfrom t3\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void test_5() throws Exception {
"FROM customer\n" +
"\tINNER JOIN orders\n" +
"\tON customer.custkey = orders.custkey/*+ wefwe=true*/\n" +
"\t\tAND customer.nationkey = orders.orderkey", //
"\t\tAND customer.nationkey = orders.orderkey /* wef=false */\n\t\t", //
output);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void test_0() throws Exception {
" WHEN (IFNULL(tc.transaction_source ,'') NOT LIKE '%智美分销%' AND IFNULL(tc.transaction_source,'') NOT LIKE '%智美置家%') AND tc.sort='1' THEN 3\n" +
" END transaction_source_px,\n" +
" DATE_FORMAT(tc.create_date,'%Y-%m-%d %H:%i') create_date /*/*创建日期 */\n" +
" FROM midea_sd_transaction_customer tc \n" +
" FROM /*/*创建日期 */\n\t\tmidea_sd_transaction_customer tc \n" +
" LEFT JOIN( \n" +
" /*/*粒度区分到分钟(只可能有一条,也肯定有一条)*/ \n" +
" select tc1.id,tc1.transaction_id,DATE_FORMAT(MIN(tc1.create_date),'%Y-%m-%d %H:%i') create_date FROM midea_sd_transaction_customer tc1\n" +
Expand Down Expand Up @@ -422,7 +422,7 @@ public void test_0() throws Exception {
"\t\t\t\t\t\t\tAND tc.sort = '1'\n" +
"\t\t\t\t\t\tTHEN 3\n" +
"\t\t\t\t\tEND AS transaction_source_px, DATE_FORMAT(tc.create_date, '%Y-%m-%d %H:%i') AS create_date\n" +
"\t\t\t\tFROM midea_sd_transaction_customer tc\n" +
"\t\t\t\tFROM /*/*创建日期 */\n\t\t\t\tmidea_sd_transaction_customer tc\n" +
"\t\t\t\t\tLEFT JOIN (\n" +
"\t\t\t\t\t\t/* /*粒度区分到分钟(只可能有一条,也肯定有一条) */\n" +
"\t\t\t\t\t\tSELECT tc1.id, tc1.transaction_id\n" +
Expand Down Expand Up @@ -452,7 +452,7 @@ public void test_0() throws Exception {
"\t\t\t\t\t\t\t\tAND tc.sort = '1'\n" +
"\t\t\t\t\t\t\tTHEN 3\n" +
"\t\t\t\t\t\tEND AS transaction_source_px, DATE_FORMAT(tc.create_date, '%Y-%m-%d %H:%i') AS create_date\n" +
"\t\t\t\t\tFROM midea_sd_transaction_customer tc\n" +
"\t\t\t\t\tFROM /*/*创建日期 */\n\t\t\t\t\tmidea_sd_transaction_customer tc\n" +
"\t\t\t\t\t\tLEFT JOIN (\n" +
"\t\t\t\t\t\t\t/*/*粒度区分到分钟(只可能有一条,也肯定有一条)*/\n" +
"\t\t\t\t\t\t\tSELECT tc1.id, tc1.transaction_id\n" +
Expand All @@ -474,18 +474,18 @@ public void test_0() throws Exception {
"\tLEFT JOIN midea_sd_project_head projectHead ON tran.project_id = projectHead.id\n" +
"\tLEFT JOIN midea_sd_orgnazation org ON org.id = projectHead.orgnazation_id\n" +
"\tLEFT JOIN midea_sd_house_info houseInfo ON tran.house_id = houseInfo.id\n" +
"\tLEFT JOIN midea_sd_unit_info ui ON ui.id = houseInfo.unit_id\n" +
"\tLEFT JOIN midea_sd_floor_info fi ON fi.id = houseInfo.floor_id\n" +
"\tLEFT JOIN midea_sd_unit_info ui ON ui.id = houseInfo.unit_id /*/*add by zhangxiaojin 2019-05-21*/\n\t\t\n" +
"\tLEFT JOIN midea_sd_floor_info fi ON fi.id = houseInfo.floor_id /*/*add by zhangxiaojin 2019-05-21 */\n\t\t\n" +
"\tLEFT JOIN midea_sd_house_item hitem ON hitem.id = houseInfo.id\n" +
"\tLEFT JOIN midea_sd_wbs_item build ON build.id = houseInfo.building_id\n" +
"\tLEFT JOIN midea_sd_mdm_wbs_item mdmwbsitem ON mdmwbsitem.wbs_head_id = build.wbs_head_id\n" +
"\tLEFT JOIN midea_sd_mdm_bid_package mdmbidpck ON mdmbidpck.id = mdmwbsitem.bd_id\n" +
"\tLEFT JOIN midea_sd_mdm_bid_package mdmbidpck ON mdmbidpck.id = mdmwbsitem.bd_id /* LEFT JOIN midea_sd_product_type AS productType ON houseInfo.product_type_id = productType.id */\n\t\t\n" +
"\tLEFT JOIN midea_sd_mdm_product mp ON mp.id = hitem.product_id\n" +
"\tLEFT JOIN midea_sd_wbs_attribute_parameter_item pi ON pi.code = mp.decoration_type_code\n" +
"\tLEFT JOIN midea_sd_product_type productType ON mp.product_type_id = productType.id\n" +
"\tLEFT JOIN midea_sd_product_type ptt ON ptt.id = productType.parent_id\n" +
"\tLEFT JOIN midea_sd_wbs_item ON tran.wbs_id = midea_sd_wbs_item.wbs_head_id\n" +
"\tLEFT JOIN midea_sd_house_type houseType ON houseType.id = houseInfo.house_type_id\n" +
"\tLEFT JOIN midea_sd_house_type houseType ON houseType.id = houseInfo.house_type_id /*LEFT JOIN midea_sd_decoration_standard_config decoration ON tran.decoration_standard_config_id = decoration.id */\n\t\t\n" +
"\tLEFT JOIN midea_sd_after_sales aftersales ON contract.transaction_id = aftersales.transaction_id\n" +
"\tLEFT JOIN midea_sd_order_info orderinfo ON tran.id = orderinfo.transaction_id\n" +
"\tLEFT JOIN (\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void test_2() throws Exception {
assertEquals("DELETE FROM t1\n" +
"WHERE s11 > ANY (\n" +
"\t\tSELECT COUNT(*) AS `COUNT(*)`\n" +
"\t\tFROM t2\n" +
"\t\tFROM /* no hint */\n\t\tt2\n" +
"\t\tWHERE NOT EXISTS (\n" +
"\t\t\tSELECT *\n" +
"\t\t\tFROM t3\n" +
Expand Down
Loading

0 comments on commit 1a9f216

Please sign in to comment.