Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
java: [ 8, 11, 17, 21 ]
java: [ 17, 21 ]
fail-fast: false
max-parallel: 16
name: Test JDK ${{ matrix.java }}, ${{ matrix.os }}
Expand All @@ -31,9 +31,6 @@ jobs:
distribution: 'temurin'
java-version: ${{ matrix.java }}
cache: 'maven'
- name: Build with Maven if test jdk8
if: ${{ matrix.java == '8' || matrix.java == '11'}}
run: ./mvnw -Pgen-javadoc clean package -B
- name: Build with Maven if test jdk17
if: ${{ matrix.java == '17' || matrix.java == '21' }}
run: ./mvnw -Penable-for-jdk17+,gen-code-cov clean package -B
Expand Down
8 changes: 8 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@
<scope>provided</scope>
</dependency>

<!-- GaussBD Driver -->
<dependency>
<groupId>com.huaweicloud.gaussdb</groupId>
<artifactId>gaussdbjdbc</artifactId>
<version>506.0.0.b058</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
/**
* @author ljw [[email protected]]
* @author wenshao [[email protected]]
* @author Acewuye
*/
public class DruidDataSource extends DruidAbstractDataSource
implements DruidDataSourceMBean, ManagedDataSource, Referenceable, Closeable, Cloneable, ConnectionPoolDataSource, MBeanRegistration {
Expand Down Expand Up @@ -1068,6 +1069,9 @@ private void initValidConnectionChecker() {
|| realDriverClassName.equals(JdbcConstants.OPENGAUSS_DRIVER)
|| realDriverClassName.equals(JdbcConstants.POLARDB_DRIVER)) {
this.validConnectionChecker = new PGValidConnectionChecker();
} else if (realDriverClassName.equals(JdbcConstants.GAUSSDB_DRIVER)) {
DbType dbType = DbType.of(this.dbTypeName);
this.validConnectionChecker = new GaussDBValidConnectionChecker();
} else if (realDriverClassName.equals(JdbcConstants.OCEANBASE_DRIVER)
|| (realDriverClassName.equals(JdbcConstants.OCEANBASE_DRIVER2))) {
DbType dbType = DbType.of(this.dbTypeName);
Expand Down Expand Up @@ -1111,7 +1115,8 @@ private void initExceptionSorter() {
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)
|| realDriverClassName.equals(JdbcConstants.POLARDB_DRIVER)) {
this.exceptionSorter = new PGExceptionSorter();

} else if (realDriverClassName.equals(JdbcConstants.GAUSSDB_DRIVER)) {
this.exceptionSorter = new GaussDBExceptionSorter();
} else if (realDriverClassName.equals("com.alibaba.druid.mock.MockDriver")) {
this.exceptionSorter = new MockExceptionSorter();
} else if (realDriverClassName.contains("DB2")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.pool.vendor;

import com.alibaba.druid.pool.ExceptionSorter;

import java.sql.SQLException;
import java.sql.SQLRecoverableException;
import java.util.Properties;

/**
* @author Acewuye
*
* Notes: Original code of this class based on com.alibaba.druid.pool.vendor.PGExceptionSorter
*/
public class GaussDBExceptionSorter implements ExceptionSorter {
@Override
public boolean isExceptionFatal(SQLException e) {
if (e instanceof SQLRecoverableException) {
return true;
}

String sqlState = e.getSQLState();
if (sqlState == null) {
return false;
}

// com.huawei.gaussdb.jdbc.util.PSQLState
if (sqlState.startsWith("08")) {
return true;
}

return false;
}

@Override
public void configFromProperties(Properties properties) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.pool.vendor;

import com.alibaba.druid.pool.ValidConnectionChecker;
import com.alibaba.druid.pool.ValidConnectionCheckerAdapter;
import com.alibaba.druid.util.StringUtils;

import java.io.Serializable;
import java.sql.Connection;

/**
* @author Acewuye
*
* Notes: Original code of this class based on com.alibaba.druid.pool.vendor.PGValidConnectionChecker
*/
public class GaussDBValidConnectionChecker extends ValidConnectionCheckerAdapter implements ValidConnectionChecker, Serializable {
private static final long serialVersionUID = -2227528634302168877L;

private String defaultValidateQuery = "SELECT 'x'";

public GaussDBValidConnectionChecker() {
configFromProperties(System.getProperties());
}

public boolean isValidConnection(Connection conn,
String validateQuery,
int validationQueryTimeout) throws Exception {
if (conn.isClosed()) {
return false;
}

if (StringUtils.isEmpty(validateQuery)) {
validateQuery = this.defaultValidateQuery;
}

return ValidConnectionCheckerAdapter.execValidQuery(conn, validateQuery, validationQueryTimeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ private XAConnection createPhysicalXAConnection(Connection physicalConn) throws
return MySqlUtils.createXAConnection(driver, physicalConn);
case postgresql:
return PGUtils.createXAConnection(physicalConn);
case gaussdb:
return GaussDBUtils.createXAConnection(physicalConn);
case h2:
return H2Utils.createXAConnection(h2Factory, physicalConn);
case jtds:
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/com/alibaba/druid/sql/PagerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private static boolean limitQueryBlock(SQLSelect select, DbType dbType, int offs
case polardbx:
return limitMySqlQueryBlock(queryBlock, dbType, offset, count, check);
case postgresql:
case gaussdb:
case greenplum:
case edb:
case hive:
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/com/alibaba/druid/sql/SQLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,10 @@ private static String _normalize(String name, DbType dbType, boolean isForced, b
if (PGUtils.isKeyword(normalizeName)) {
return name;
}
} else if (DbType.gaussdb == dbType) {
if (GaussDBUtils.isKeyword(normalizeName)) {
return name;
}
}
}

Expand Down Expand Up @@ -2295,6 +2299,14 @@ public static List<SQLInsertStatement> splitInsertValues(DbType dbType, String i
return insertLists;
}

public static boolean isQuoteChar(char c) {
return c == '`' || c == '\'' || c == '"';
}

public static String removeQuote(String str) {
return str.replace("`", "").replace("'", "").replace("\"", "");
}

static class TimeZoneVisitor extends SQLASTVisitorAdapter {
private TimeZone from;
private TimeZone to;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public void addBeforeComment(String comment) {

@SuppressWarnings("unchecked")
public void addBeforeComment(List<String> comments) {
if (comments == null) {
return;
}
if (attributes == null) {
attributes = new HashMap<String, Object>(1);
}
Expand All @@ -193,6 +196,9 @@ public List<String> getBeforeCommentsDirect() {

@SuppressWarnings("unchecked")
public void addAfterComment(String comment) {
if (comment == null) {
return;
}
if (attributes == null) {
attributes = new HashMap<String, Object>(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.alibaba.druid.sql.ast.expr;

import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.MySqlUtils;

import java.text.ParseException;
Expand All @@ -36,6 +37,13 @@ public SQLDateExpr clone() {
return x;
}

@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.dataType);
}
visitor.endVisit(this);
}
public SQLDateExpr(String literal) {
this();
this.setValue(literal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -54,6 +55,13 @@ public SQLDateTimeExpr(String literal) {
public void setValue(String literal) {
value = literal;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.dataType);
}
visitor.endVisit(this);
}

@Override
public String getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

import java.text.SimpleDateFormat;
import java.util.Collections;
Expand Down Expand Up @@ -60,6 +61,13 @@ public SQLTimeExpr(String literal) {
public void setValue(String value) {
this.value = value;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.dataType);
}
visitor.endVisit(this);
}

public SQLTimeExpr clone() {
SQLTimeExpr x = new SQLTimeExpr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ public boolean equals(Object obj) {

@Override
protected void accept0(SQLASTVisitor visitor) {
visitor.visit(this);

if (visitor.visit(this)) {
acceptChild(visitor, this.dataType);
}
visitor.endVisit(this);
}

Expand Down
30 changes: 26 additions & 4 deletions core/src/main/java/com/alibaba/druid/sql/ast/expr/SQLTypeExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@ public abstract class SQLTypeExpr extends SQLExprImpl implements SQLLiteralExpr,
protected Object value;

public SQLTypeExpr(SQLDataType sqlDataType) {
if (sqlDataType != null) {
sqlDataType.setParent(this);
}
this.dataType = sqlDataType;
}

public void setValue(SQLExpr value) {
public void setValue(Object value) {
this.value = value;
if (value != null) {
value.setParent(this);
if (value instanceof SQLExpr) {
((SQLExpr) value).setParent(this);
}
}

public void setDataType(SQLDataType dataType) {
if (dataType != null) {
dataType.setParent(this);
}
this.dataType = dataType;
}
public SQLDataType getDataType() {
return dataType;
}
Expand All @@ -42,12 +51,25 @@ public SQLDataType computeDataType() {
}
@Override
protected void accept0(SQLASTVisitor visitor) {
visitor.visit(this);
if (visitor.visit(this)) {
acceptChild(visitor, this.dataType);
if (this.value instanceof SQLExpr) {
acceptChild(visitor, (SQLExpr) this.value);
}
}
visitor.endVisit(this);
}

@Override
public boolean replace(SQLExpr expr, SQLExpr target) {
if (expr == this.dataType && target instanceof SQLDataType) {
setDataType((SQLDataType) target);
return true;
}
if (this.value instanceof SQLExpr && expr == this.value) {
this.setValue(target);
return true;
}
return false;
}
@Override
Expand Down
Loading