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
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,10 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), false, true );

functionFactory.hex( "hex(?1)" );
functionFactory.sha( "hash(?1, 2)" );
functionFactory.md5( "hash(?1, 0)" );
if ( getDB2Version().isSameOrAfter( 11 ) ) {
functionFactory.sha( "hash(?1, 2)" );
functionFactory.md5( "hash(?1, 0)" );
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
// functionFactory.xmlextract();
functionFactory.generateSeries_hana( getMaximumSeriesSize() );

functionFactory.hex( "to_hex(?1)" );
functionFactory.sha( "hash_sha256(?1)" );
functionFactory.md5( "hash_md5(?1)" );
functionFactory.hex( "bintohex(?1)" );
functionFactory.sha( "hash_sha256(to_binary(?1))" );
functionFactory.md5( "hash_md5(to_binary(?1))" );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public String aggregateComponentCustomReadExpression(
case TIMESTAMP_UTC:
return template.replace(
placeholder,
"cast(trim(trailing 'Z' from xmlcast(xmlquery(" + xmlExtractArguments( aggregateParentReadExpression, columnExpression ) + ") as varchar(35))) as " + column.getColumnDefinition() + ")"
"cast(replace(trim(trailing 'Z' from xmlcast(xmlquery(" + xmlExtractArguments( aggregateParentReadExpression, columnExpression ) + ") as varchar(35))),'T',' ') as " + column.getColumnDefinition() + ")"
);
case SQLXML:
return template.replace(
Expand Down Expand Up @@ -261,7 +261,8 @@ private static String xmlCustomWriteExpression(String customWriteExpression, Jdb
// We encode binary data as hex
return "hex(" + customWriteExpression + ")";
case UUID:
return "regexp_replace(lower(hex(" + customWriteExpression + ")),'^(.{8})(.{4})(.{4})(.{4})(.{12})$','$1-$2-$3-$4-$5')";
// Old DB2 didn't support regexp_replace yet
return "overlay(overlay(overlay(overlay(lower(hex(" + customWriteExpression + ")),'-',21,0,octets),'-',17,0,octets),'-',13,0,octets),'-',9,0,octets)";
// case ARRAY:
// case XML_ARRAY:
// return "(" + customWriteExpression + ") format json";
Expand Down Expand Up @@ -754,7 +755,7 @@ private static boolean needsVarcharForBitDataCast(String columnType) {
// xmlelement and xmltable don't seem to support the "varbinary", "binary" or "char for bit data" types
final String columTypeLC = columnType.toLowerCase( Locale.ROOT ).trim();
return columTypeLC.contains( "binary" )
|| columTypeLC.startsWith( "char" ) && columTypeLC.endsWith( " bit data" );
|| columTypeLC.contains( "char" ) && columTypeLC.endsWith( " bit data" );
}

interface JsonWriteExpression {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,25 @@
import jakarta.persistence.Id;

import org.hibernate.annotations.Nationalized;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;

import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;

/**
* @author Vlad Mihalcea
*/
@Jpa(annotatedClasses = NationalizedTest.Product.class)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnicodeNClob.class)
public class NationalizedTest extends BaseEntityManagerFunctionalTestCase {

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Product.class
};
}
public class NationalizedTest {

@Test
public void test() {
Integer productId = doInJPA(this::entityManagerFactory, entityManager -> {
public void test(EntityManagerFactoryScope scope) {
Integer productId = scope.fromTransaction( entityManager -> {
//tag::basic-nationalized-persist-example[]
final Product product = new Product();
product.setId(1);
Expand All @@ -44,7 +38,7 @@ public void test() {

return product.getId();
});
doInJPA(this::entityManagerFactory, entityManager -> {
scope.inTransaction( entityManager -> {
Product product = entityManager.find(Product.class, productId);

assertEquals("My product®™ warranty 😍", product.getWarranty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,7 @@ public void testCtidColumnFunction(SessionFactoryScope scope) {
@RequiresDialect(PostgreSQLDialect.class)
@RequiresDialect(MySQLDialect.class)
@RequiresDialect(OracleDialect.class)
@RequiresDialect(DB2Dialect.class)
@RequiresDialect(value = DB2Dialect.class, majorVersion = 11)
@RequiresDialect(SQLServerDialect.class)
@RequiresDialect(H2Dialect.class)
@RequiresDialect(HANADialect.class)
Expand Down
Loading