Skip to content
Closed
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<mysql-connector-java.version>8.0.33</mysql-connector-java.version>
<postgresql.version>42.7.4</postgresql.version>
<oracle.version>23.7.0.25.01</oracle.version>
<gaussdb.version>506.0.0.b058</gaussdb.version>

<!-- R2DBC driver dependencies-->
<r2dbc-postgresql.version>1.0.7.RELEASE</r2dbc-postgresql.version>
Expand Down
38 changes: 38 additions & 0 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.huaweicloud.gaussdb</groupId>
<artifactId>gaussdbjdbc</artifactId>
<version>${gaussdb.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
Expand Down Expand Up @@ -318,6 +325,37 @@
</plugins>
</build>
</profile>
<profile>
<id>gaussdb</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>gaussdb-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude/>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>gaussdb</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>all-dbs</id>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2021-2025 the original author or authors.
*
* 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
*
* https://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 org.springframework.data.jdbc.core.dialect;

import org.springframework.data.relational.core.dialect.GaussDBDialect;
import org.springframework.util.ClassUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;

/**
* JDBC specific GaussDBDialect Dialect.
*
* Notes: this file is token from JdbcPostgresDialect and add specific changes for GaussDB
*
* @author liubao
*/
public class JdbcGaussDBDialect extends GaussDBDialect {

public static final JdbcGaussDBDialect INSTANCE = new JdbcGaussDBDialect();

private static final Set<Class<?>> SIMPLE_TYPES;

static {

Set<Class<?>> simpleTypes = new HashSet<>(GaussDBDialect.INSTANCE.simpleTypes());
List<String> simpleTypeNames = Arrays.asList( //
"com.huawei.gaussdb.jdbc.util.PGobject", //
"com.huawei.gaussdb.jdbc.geometric.PGpoint", //
"com.huawei.gaussdb.jdbc.geometric.PGbox", //
"com.huawei.gaussdb.jdbc.geometric.PGcircle", //
"com.huawei.gaussdb.jdbc.geometric.PGline", //
"com.huawei.gaussdb.jdbc.geometric.PGpath", //
"com.huawei.gaussdb.jdbc.geometric.PGpolygon", //
"com.huawei.gaussdb.jdbc.geometric.PGlseg" //
);
simpleTypeNames.forEach(name -> ifClassPresent(name, simpleTypes::add));
SIMPLE_TYPES = Collections.unmodifiableSet(simpleTypes);
}

@Override
public Set<Class<?>> simpleTypes() {
return SIMPLE_TYPES;
}

/**
* If the class is present on the class path, invoke the specified consumer {@code action} with the class object,
* otherwise do nothing.
*
* @param action block to be executed if a value is present.
*/
private static void ifClassPresent(String className, Consumer<Class<?>> action) {
if (ClassUtils.isPresent(className, GaussDBDialect.class.getClassLoader())) {
action.accept(ClassUtils.resolveClassName(className, GaussDBDialect.class.getClassLoader()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,12 @@
*/
package org.springframework.data.jdbc.repository.config;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.dao.NonTransientDataAccessException;
import org.springframework.data.jdbc.core.dialect.JdbcDb2Dialect;
import org.springframework.data.jdbc.core.dialect.JdbcGaussDBDialect;
import org.springframework.data.jdbc.core.dialect.JdbcMySqlDialect;
import org.springframework.data.jdbc.core.dialect.JdbcPostgresDialect;
import org.springframework.data.jdbc.core.dialect.JdbcSqlServerDialect;
Expand All @@ -44,6 +36,14 @@
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

/**
* Resolves a {@link Dialect}. Resolution typically uses {@link JdbcOperations} to obtain and inspect a
* {@link Connection}. Dialect resolution uses Spring's {@link SpringFactoriesLoader spring.factories} to determine
Expand Down Expand Up @@ -139,7 +139,9 @@ private static Dialect getDialect(Connection connection) throws SQLException {
if (name.contains("oracle")) {
return OracleDialect.INSTANCE;
}

if (name.contains("gaussdb")) {
return JdbcGaussDBDialect.INSTANCE;
}
LOG.info(String.format("Couldn't determine Dialect for \"%s\"", name));
return null;
}
Expand Down
Loading