Skip to content
Merged
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
39 changes: 29 additions & 10 deletions docker_db.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#! /bin/bash

if command -v podman > /dev/null; then
if command -v docker > /dev/null; then
CONTAINER_CLI=$(command -v docker)
HEALTCHECK_PATH="{{.State.Health.Status}}"
PRIVILEGED_CLI=""
else
CONTAINER_CLI=$(command -v podman)
HEALTCHECK_PATH="{{.State.Healthcheck.Status}}"
# Only use sudo for podman
Expand All @@ -9,10 +13,6 @@ if command -v podman > /dev/null; then
else
PRIVILEGED_CLI=""
fi
else
CONTAINER_CLI=$(command -v docker)
HEALTCHECK_PATH="{{.State.Health.Status}}"
PRIVILEGED_CLI=""
fi

mysql() {
Expand Down Expand Up @@ -489,7 +489,7 @@ oracle_setup() {
echo "Waiting for Oracle to start..."
sleep 5;
# On WSL, health-checks intervals don't work for Podman, so run them manually
if command -v podman > /dev/null; then
if ! command -v docker > /dev/null; then
$PRIVILEGED_CLI $CONTAINER_CLI healthcheck run oracle > /dev/null
fi
HEALTHSTATUS="`$PRIVILEGED_CLI $CONTAINER_CLI inspect -f $HEALTCHECK_PATH oracle`"
Expand Down Expand Up @@ -569,7 +569,7 @@ oracle_free_setup() {
echo "Waiting for Oracle Free to start..."
sleep 5;
# On WSL, health-checks intervals don't work for Podman, so run them manually
if command -v podman > /dev/null; then
if ! command -v docker > /dev/null; then
$PRIVILEGED_CLI $CONTAINER_CLI healthcheck run oracle > /dev/null
fi
HEALTHSTATUS="`$PRIVILEGED_CLI $CONTAINER_CLI inspect -f $HEALTCHECK_PATH oracle`"
Expand Down Expand Up @@ -658,9 +658,13 @@ disable_userland_proxy() {
echo "Stopping docker..."
sudo service docker stop
echo "Updating /etc/docker/daemon.json..."
sudo bash -c 'echo "${docker_daemon_json/\}/,}\"userland-proxy\": false}" > /etc/docker/daemon.json'
sudo bash -c "export docker_daemon_json='$docker_daemon_json'; echo \"\${docker_daemon_json/\}/,}\\\"userland-proxy\\\": false}\" > /etc/docker/daemon.json"
echo "New docker daemon config:"
cat /etc/docker/daemon.json
echo "Starting docker..."
sudo service docker start
echo "Service status:"
sudo journalctl -xeu docker.service
echo "Docker successfully started with userland proxies disabled"
fi
fi
Expand Down Expand Up @@ -733,6 +737,21 @@ oracle() {
oracle_23
}

oracle_18() {
$PRIVILEGED_CLI $CONTAINER_CLI rm -f oracle || true
disable_userland_proxy
# We need to use the defaults
# SYSTEM/Oracle18
$PRIVILEGED_CLI $CONTAINER_CLI run --name oracle -d -p 1521:1521 -e ORACLE_PASSWORD=Oracle18 \
--cap-add cap_net_raw \
--health-cmd healthcheck.sh \
--health-interval 5s \
--health-timeout 5s \
--health-retries 10 \
${DB_IMAGE_ORACLE_21:-docker.io/gvenzl/oracle-xe:18.4.0}
oracle_setup
}

oracle_21() {
$PRIVILEGED_CLI $CONTAINER_CLI rm -f oracle || true
disable_userland_proxy
Expand Down Expand Up @@ -765,7 +784,7 @@ oracle_23() {
hana() {
temp_dir=$(mktemp -d)
echo '{"master_password" : "H1bernate_test"}' >$temp_dir/password.json
chmod 777 -R $temp_dir
chmod -R 777 $temp_dir
$PRIVILEGED_CLI $CONTAINER_CLI rm -f hana || true
$PRIVILEGED_CLI $CONTAINER_CLI run -d --name hana -p 39013:39013 -p 39017:39017 -p 39041-39045:39041-39045 -p 1128-1129:1128-1129 -p 59013-59014:59013-59014 \
--memory=8g \
Expand All @@ -775,7 +794,7 @@ hana() {
--sysctl kernel.shmmni=4096 \
--sysctl kernel.shmall=8388608 \
-v $temp_dir:/config:Z \
${DB_IMAGE_HANA:-docker.io/saplabs/hanaexpress:2.00.072.00.20231123.1} \
${DB_IMAGE_HANA:-docker.io/saplabs/hanaexpress:2.00.076.00.20240701.1} \
--passwords-url file:///config/password.json \
--agree-to-sap-license
# Give the container some time to start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.*;
import org.hibernate.dialect.aggregate.AggregateSupport;
import org.hibernate.dialect.aggregate.CockroachDBAggregateSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.function.FormatFunction;
import org.hibernate.dialect.function.PostgreSQLTruncFunction;
Expand Down Expand Up @@ -699,6 +701,11 @@ public NationalizationSupport getNationalizationSupport() {
return NationalizationSupport.IMPLICIT;
}

@Override
public AggregateSupport getAggregateSupport() {
return CockroachDBAggregateSupport.valueOf( this );
}

@Override
public int getMaxIdentifierLength() {
return 63;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
functionFactory.jsonArray_db2();
functionFactory.jsonArrayAgg_db2();
functionFactory.jsonObjectAgg_db2();
functionFactory.jsonTable_db2();
functionFactory.jsonTable_db2( getMaximumSeriesSize() );
}
}

Expand All @@ -459,7 +459,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
functionFactory.xmlagg();
functionFactory.xmltable_db2();

functionFactory.unnest_emulated();
functionFactory.unnest_db2( getMaximumSeriesSize() );
if ( supportsRecursiveCTE() ) {
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), false, true );
}
Expand Down Expand Up @@ -1007,7 +1007,9 @@ public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {

@Override
public AggregateSupport getAggregateSupport() {
return DB2AggregateSupport.INSTANCE;
return getDB2Version().isSameOrAfter( 11 )
? DB2AggregateSupport.JSON_INSTANCE
: DB2AggregateSupport.INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.*;
import org.hibernate.dialect.aggregate.AggregateSupport;
import org.hibernate.dialect.aggregate.H2AggregateSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.identity.H2FinalTableIdentityColumnSupport;
import org.hibernate.dialect.identity.H2IdentityColumnSupport;
Expand Down Expand Up @@ -301,6 +303,11 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
jdbcTypeRegistry.addDescriptor( OrdinalEnumJdbcType.INSTANCE );
}

@Override
public AggregateSupport getAggregateSupport() {
return H2AggregateSupport.valueOf( this );
}

@Override
public int getDefaultStatementBatchSize() {
return 15;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import org.hibernate.dialect.NullOrdering;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.RowLockStrategy;
import org.hibernate.dialect.aggregate.AggregateSupport;
import org.hibernate.dialect.aggregate.HANAAggregateSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.function.IntegralTimestampaddFunction;
import org.hibernate.dialect.identity.HANAIdentityColumnSupport;
Expand Down Expand Up @@ -534,6 +536,11 @@ protected <T extends JdbcOperation> SqlAstTranslator<T> buildTranslator(
};
}

@Override
public AggregateSupport getAggregateSupport() {
return HANAAggregateSupport.valueOf( this );
}

/**
* HANA has no extract() function, but we can emulate
* it using the appropriate named functions instead of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.*;
import org.hibernate.dialect.aggregate.AggregateSupport;
import org.hibernate.dialect.aggregate.AggregateSupportImpl;
import org.hibernate.dialect.aggregate.MySQLAggregateSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.sequence.MariaDBSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
Expand All @@ -18,6 +21,7 @@
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.sqm.CastType;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
Expand All @@ -29,8 +33,6 @@
import org.hibernate.type.SqlTypes;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JsonArrayJdbcTypeConstructor;
import org.hibernate.type.descriptor.jdbc.JsonJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl;
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
Expand Down Expand Up @@ -122,6 +124,13 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR
}
}

@Override
public AggregateSupport getAggregateSupport() {
return getVersion().isSameOrAfter( 10, 2 )
? MySQLAggregateSupport.LONGTEXT_INSTANCE
: AggregateSupportImpl.INSTANCE;
}

@Override
public JdbcType resolveSqlTypeDescriptor(
String columnTypeName,
Expand Down Expand Up @@ -150,15 +159,22 @@ public JdbcType resolveSqlTypeDescriptor(
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration().getJdbcTypeRegistry();
// Make sure we register the JSON type descriptor before calling super, because MariaDB does not need casting
jdbcTypeRegistry.addDescriptorIfAbsent( SqlTypes.JSON, JsonJdbcType.INSTANCE );
jdbcTypeRegistry.addTypeConstructorIfAbsent( JsonArrayJdbcTypeConstructor.INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( SqlTypes.JSON, MariaDBCastingJsonJdbcType.INSTANCE );
jdbcTypeRegistry.addTypeConstructorIfAbsent( MariaDBCastingJsonArrayJdbcTypeConstructor.INSTANCE );

super.contributeTypes( typeContributions, serviceRegistry );
if ( getVersion().isSameOrAfter( 10, 7 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( VarcharUUIDJdbcType.INSTANCE );
}
}

@Override
public String castPattern(CastType from, CastType to) {
return to == CastType.JSON
? "json_extract(?1,'$')"
: super.castPattern( from, to );
}

@Override
public SqlAstTranslatorFactory getSqlAstTranslatorFactory() {
return new StandardSqlAstTranslatorFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hibernate.dialect.MySQLSqlAstTranslator;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.collections.Stack;
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
Expand Down Expand Up @@ -292,7 +293,54 @@ public void visitOffsetFetchClause(QueryPart queryPart) {

@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
renderComparisonDistinctOperator( lhs, operator, rhs );
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null && lhsExpressionType.getJdbcTypeCount() == 1
&& lhsExpressionType.getSingleJdbcMapping().getJdbcType().isJson() ) {
switch ( operator ) {
case DISTINCT_FROM:
appendSql( "case when json_equals(" );
lhs.accept( this );
appendSql( ',' );
rhs.accept( this );
appendSql( ")=1 or " );
lhs.accept( this );
appendSql( " is null and " );
rhs.accept( this );
appendSql( " is null then 0 else 1 end=1" );
break;
case NOT_DISTINCT_FROM:
appendSql( "case when json_equals(" );
lhs.accept( this );
appendSql( ',' );
rhs.accept( this );
appendSql( ")=1 or " );
lhs.accept( this );
appendSql( " is null and " );
rhs.accept( this );
appendSql( " is null then 0 else 1 end=0" );
break;
case NOT_EQUAL:
appendSql( "json_equals(" );
lhs.accept( this );
appendSql( ',' );
rhs.accept( this );
appendSql( ")=0" );
break;
case EQUAL:
appendSql( "json_equals(" );
lhs.accept( this );
appendSql( ',' );
rhs.accept( this );
appendSql( ")=1" );
break;
default:
renderComparisonDistinctOperator( lhs, operator, rhs );
break;
}
}
else {
renderComparisonDistinctOperator( lhs, operator, rhs );
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.*;
import org.hibernate.dialect.aggregate.AggregateSupport;
import org.hibernate.dialect.aggregate.MySQLAggregateSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.MySQLIdentityColumnSupport;
Expand Down Expand Up @@ -263,7 +265,10 @@ protected String castType(int sqlTypeCode) {
//MySQL doesn't let you cast to DOUBLE/FLOAT
//but don't just return 'decimal' because
//the default scale is 0 (no decimal places)
return "decimal($p,$s)";
return getMySQLVersion().isSameOrAfter( 8, 0, 17 )
// In newer versions of MySQL, casting to float/double is supported
? super.castType( sqlTypeCode )
: "decimal($p,$s)";
case CHAR:
case NCHAR:
case VARCHAR:
Expand Down Expand Up @@ -385,6 +390,13 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR
ddlTypeRegistry.addDescriptor( new NativeOrdinalEnumDdlTypeImpl( this ) );
}

@Override
public AggregateSupport getAggregateSupport() {
return getMySQLVersion().isSameOrAfter( 5, 7 )
? MySQLAggregateSupport.JSON_INSTANCE
: super.getAggregateSupport();
}

@Deprecated
protected static int getCharacterSetBytesPerCharacter(DatabaseMetaData databaseMetaData) {
if ( databaseMetaData != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.hibernate.dialect.SQLServerCastingXmlArrayJdbcTypeConstructor;
import org.hibernate.dialect.SQLServerCastingXmlJdbcType;
import org.hibernate.dialect.TimeZoneSupport;
import org.hibernate.dialect.aggregate.AggregateSupport;
import org.hibernate.dialect.aggregate.SQLServerAggregateSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.function.CountFunction;
import org.hibernate.dialect.function.SQLServerFormatEmulation;
Expand Down Expand Up @@ -504,6 +506,11 @@ protected <T extends JdbcOperation> SqlAstTranslator<T> buildTranslator(
};
}

@Override
public AggregateSupport getAggregateSupport() {
return SQLServerAggregateSupport.valueOf( this );
}

@Override
public SizeStrategy getSizeStrategy() {
return sizeStrategy;
Expand Down
Loading
Loading