Skip to content
2 changes: 2 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ elif [ "$RDBMS" == "mariadb" ] || [ "$RDBMS" == "mariadb_10_6" ]; then
goal="-Pdb=mariadb_ci"
elif [ "$RDBMS" == "postgresql" ] || [ "$RDBMS" == "postgresql_13" ]; then
goal="-Pdb=pgsql_ci"
elif [ "$RDBMS" == "gaussdb" ]; then
goal="-Pdb=gaussdb -DdbHost=localhost:8000"
elif [ "$RDBMS" == "edb" ] || [ "$RDBMS" == "edb_13" ]; then
goal="-Pdb=edb_ci -DdbHost=localhost:5444"
elif [ "$RDBMS" == "oracle" ]; then
Expand Down
2 changes: 2 additions & 0 deletions ci/database-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ elif [ "$RDBMS" == 'mariadb' ]; then
bash $DIR/../docker_db.sh mariadb
elif [ "$RDBMS" == 'postgresql' ]; then
bash $DIR/../docker_db.sh postgresql
elif [ "$RDBMS" == 'gaussdb' ]; then
bash $DIR/../docker_db.sh gaussdb
elif [ "$RDBMS" == 'edb' ]; then
bash $DIR/../docker_db.sh edb
elif [ "$RDBMS" == 'db2' ]; then
Expand Down
40 changes: 40 additions & 0 deletions docker_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,45 @@ postgresql_17() {
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-17-pgvector && psql -U hibernate_orm_test -d hibernate_orm_test -c "create extension vector;"'
}

gaussdb() {
$CONTAINER_CLI rm -f opengauss || true

# config param
CONTAINER_NAME=opengauss
IMAGE=opengauss/opengauss:7.0.0-RC1.B023
PORT=8000
DB_USER=hibernate_orm_test
DB_PASSWORD=Hibernate_orm_test@1234
DB_NAME=hibernate_orm_test
PSQL_IMAGE=postgres:14

echo "start OpenGauss container..."
$CONTAINER_CLI run --name ${CONTAINER_NAME} \
--privileged=true \
-e GS_USERNAME=${DB_USER} \
-e GS_PASSWORD=${DB_PASSWORD} \
-e GS_PORT=${PORT} \
-p ${PORT}:8000 \
-d ${IMAGE}

echo "wait OpenGauss starting..."
sleep 30

echo " Initialize the database using the PostgreSQL client container..."

$CONTAINER_CLI run --rm --network=host ${PSQL_IMAGE} \
bash -c "
PGPASSWORD='${DB_PASSWORD}' psql -h localhost -p ${PORT} -U ${DB_USER} -d postgres -c \"CREATE DATABASE ${DB_NAME} OWNER ${DB_USER};\" &&
PGPASSWORD='${DB_PASSWORD}' psql -h localhost -p ${PORT} -U ${DB_USER} -d ${DB_NAME} -c \"CREATE SCHEMA test AUTHORIZATION ${DB_USER};\"
"

echo "Initialization completed"
echo "connection information"
echo " Host: localhost"
echo " Port: ${PORT}"
echo " Database: ${DB_NAME}"
}

edb() {
edb_17
}
Expand Down Expand Up @@ -1089,6 +1128,7 @@ if [ -z ${1} ]; then
echo -e "\toracle"
echo -e "\toracle_23"
echo -e "\toracle_21"
echo -e "\tgaussdb"
echo -e "\tpostgresql"
echo -e "\tpostgresql_17"
echo -e "\tpostgresql_16"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.community.dialect.TiDBDialect;
import org.hibernate.community.dialect.GaussDBDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.agroal.internal.AgroalConnectionProvider;

Expand All @@ -17,6 +18,7 @@
*/
@SkipForDialect(value = TiDBDialect.class, comment = "Doesn't support SERIALIZABLE isolation")
@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase cannot change isolation level in autocommit mode")
@SkipForDialect(value = GaussDBDialect.class, comment = "GaussDB does not support SERIALIZABLE isolation")
public class AgroalTransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest {
@Override
protected ConnectionProvider getConnectionProviderUnderTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.c3p0.internal.C3P0ConnectionProvider;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.community.dialect.GaussDBDialect;
import org.hibernate.dialect.SybaseASEDialect;
import org.hibernate.community.dialect.TiDBDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
Expand All @@ -23,6 +24,7 @@
@SkipForDialect(value = TiDBDialect.class, comment = "Doesn't support SERIALIZABLE isolation")
@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase cannot change isolation level in autocommit mode")
@SkipForDialect(value = SybaseASEDialect.class, comment = "JtdsConnection.isValid not implemented")
@SkipForDialect(value = GaussDBDialect.class, comment = "GaussDB does not support SERIALIZABLE isolation")
public class C3p0TransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest {
private StandardServiceRegistry ssr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,21 @@ public String getDriverClassName(String jdbcUrl) {
? "org.apache.derby.jdbc.ClientDriver"
: "org.apache.derby.jdbc.EmbeddedDriver";
}
},

GAUSSDB {
@Override
public Dialect createDialect(DialectResolutionInfo info) {
return new GaussDBDialect(info);
}
@Override
public boolean productNameMatches(String databaseName) {
return "GaussDB".equals( databaseName );
}
@Override
public String getDriverClassName(String jdbcUrl) {
return "com.huawei.gaussdb.jdbc.Driver";
}
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.community.dialect;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.BasicPluralJavaType;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.AggregateJdbcType;
import org.hibernate.type.descriptor.jdbc.ArrayJdbcType;
import org.hibernate.type.descriptor.jdbc.BasicBinder;
import org.hibernate.type.descriptor.jdbc.JdbcType;

/**
* Descriptor for {@link Types#ARRAY ARRAY} handling.
*
* @author liubao
*
* Notes: Original code of this class is based on PostgreSQLArrayJdbcType.
*/
public class GaussDBArrayJdbcType extends ArrayJdbcType {

public GaussDBArrayJdbcType(JdbcType elementJdbcType) {
super( elementJdbcType );
}

@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaTypeDescriptor) {
@SuppressWarnings("unchecked")
final BasicPluralJavaType<X> pluralJavaType = (BasicPluralJavaType<X>) javaTypeDescriptor;
final ValueBinder<X> elementBinder = getElementJdbcType().getBinder( pluralJavaType.getElementJavaType() );
return new BasicBinder<>( javaTypeDescriptor, this ) {

@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setArray( index, getArray( value, options ) );
}

@Override
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
throws SQLException {
final java.sql.Array arr = getArray( value, options );
try {
st.setObject( name, arr, java.sql.Types.ARRAY );
}
catch (SQLException ex) {
throw new HibernateException( "JDBC driver does not support named parameters for setArray. Use positional.", ex );
}
}

@Override
public Object getBindValue(X value, WrapperOptions options) throws SQLException {
return ( (GaussDBArrayJdbcType) getJdbcType() ).getArray( this, elementBinder, value, options );
}

private java.sql.Array getArray(X value, WrapperOptions options) throws SQLException {
final GaussDBArrayJdbcType arrayJdbcType = (GaussDBArrayJdbcType) getJdbcType();
final Object[] objects;

final JdbcType elementJdbcType = arrayJdbcType.getElementJdbcType();
if ( elementJdbcType instanceof AggregateJdbcType ) {
// The GaussDB JDBC driver does not support arrays of structs, which contain byte[]
final AggregateJdbcType aggregateJdbcType = (AggregateJdbcType) elementJdbcType;
final Object[] domainObjects = getJavaType().unwrap(
value,
Object[].class,
options
);
objects = new Object[domainObjects.length];
for ( int i = 0; i < domainObjects.length; i++ ) {
if ( domainObjects[i] != null ) {
objects[i] = aggregateJdbcType.createJdbcValue( domainObjects[i], options );
}
}
}
else {
objects = arrayJdbcType.getArray( this, elementBinder, value, options );
}

final SharedSessionContractImplementor session = options.getSession();
final String typeName = arrayJdbcType.getElementTypeName( getJavaType(), session );
return session.getJdbcCoordinator().getLogicalConnection().getPhysicalConnection()
.createArrayOf( typeName, objects );
}
};
}

@Override
public String toString() {
return "GaussDBArrayTypeDescriptor(" + getElementJdbcType().toString() + ")";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.community.dialect;

import java.sql.Types;

import org.hibernate.dialect.Dialect;
import org.hibernate.tool.schema.extract.spi.ColumnTypeInformation;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeConstructor;
import org.hibernate.type.spi.TypeConfiguration;

/**
* Factory for {@link GaussDBArrayJdbcType}.
*
* @author liubao
*
* Notes: Original code of this class is based on PostgreSQLArrayJdbcTypeConstructor.
*/
public class GaussDBArrayJdbcTypeConstructor implements JdbcTypeConstructor {

public static final GaussDBArrayJdbcTypeConstructor INSTANCE = new GaussDBArrayJdbcTypeConstructor();

@Override
public JdbcType resolveType(
TypeConfiguration typeConfiguration,
Dialect dialect,
BasicType<?> elementType,
ColumnTypeInformation columnTypeInformation) {
return resolveType( typeConfiguration, dialect, elementType.getJdbcType(), columnTypeInformation );
}

@Override
public JdbcType resolveType(
TypeConfiguration typeConfiguration,
Dialect dialect,
JdbcType elementType,
ColumnTypeInformation columnTypeInformation) {
return new GaussDBArrayJdbcType( elementType );
}

@Override
public int getDefaultSqlTypeCode() {
return Types.ARRAY;
}
}
Loading