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 @@ -465,7 +465,7 @@ public Boolean getFollowOnLocking() {
* @return {@code this} for method chaining
*
* @see org.hibernate.jpa.HibernateHints#HINT_FOLLOW_ON_LOCKING
* @see org.hibernate.dialect.Dialect#useFollowOnLocking(String, QueryOptions)
* @see org.hibernate.dialect.Dialect#useFollowOnLocking(String, org.hibernate.query.spi.QueryOptions)
*/
public LockOptions setFollowOnLocking(Boolean followOnLocking) {
if ( immutable ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4156,7 +4156,7 @@ public boolean isEmptyStringTreatedAsNull() {
* {@code false} (the default) indicates that locking
* should be applied to the main SQL statement.
*
* @since 5.2
* @since 6.0
*/
public boolean useFollowOnLocking(String sql, QueryOptions queryOptions) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,86 @@

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.NamingHelper;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class NamingHelperTest extends BaseUnitTestCase {
class NamingHelperTest {

@Test
@JiraKey(value = "HHH-12357")
public void generateHashedFkName() {
Identifier booksDe = new Identifier( "Bücher", false );
Identifier authorsDe = new Identifier( "Autoren", false );
Identifier authorId = new Identifier( "autor_id", false );
@ParameterizedTest
@MethodSource("args")
void smoke(String charset, String prefix, String tableName, String referencedTableName, List<String> columnNames, String expectedFkName, String expectedConstraintName) {
assertThat( NamingHelper.withCharset( charset )
.generateHashedFkName(
prefix,
Identifier.toIdentifier( tableName ),
Identifier.toIdentifier( referencedTableName ),
columnNames.stream().map( Identifier::toIdentifier )
.collect( Collectors.toUnmodifiableList() ) ) )
.isEqualTo( expectedFkName );

String fkNameLatin1 = NamingHelper.withCharset( "ISO-8859-1" ).generateHashedFkName( "FK", booksDe, authorsDe, authorId );
assertThat( NamingHelper.withCharset( charset )
.generateHashedFkName(
prefix,
Identifier.toIdentifier( tableName ),
Identifier.toIdentifier( referencedTableName ),
columnNames.stream().map( Identifier::toIdentifier )
.toArray( Identifier[]::new ) ) )
.isEqualTo( expectedFkName );

assertEquals( "FKpvm24wh1qwbmx6xjcbc7uv5f7", fkNameLatin1 );
assertThat( NamingHelper.withCharset( charset )
.generateHashedConstraintName(
prefix,
Identifier.toIdentifier( tableName ),
columnNames.stream().map( Identifier::toIdentifier )
.collect( Collectors.toUnmodifiableList() ) ) )
.isEqualTo( expectedConstraintName );

String fkNameUtf8 = NamingHelper.withCharset( "UTF8" ).generateHashedFkName( "FK", booksDe, authorsDe, authorId );

assertEquals( "FKdgopp1hqnm8c1o6sfbb3tbeh", fkNameUtf8 );
assertThat( NamingHelper.withCharset( charset )
.generateHashedConstraintName(
prefix,
Identifier.toIdentifier( tableName ),
columnNames.stream().map( Identifier::toIdentifier )
.toArray( Identifier[]::new ) ) )
.isEqualTo( expectedConstraintName );
}

@Test
@JiraKey(value = "HHH-12357")
public void generateHashedFkNameUSingUtf8() {
Identifier booksDe = new Identifier( "Bücher", false );
Identifier authorsDe = new Identifier( "Autoren", false );
Identifier authorId = new Identifier( "autor_id", false );

String fkNameLatin1 = NamingHelper.withCharset( "UTF8" ).generateHashedFkName( "FK", booksDe, authorsDe, authorId );

assertEquals( "FKdgopp1hqnm8c1o6sfbb3tbeh", fkNameLatin1 );

String fkNameUtf8 = NamingHelper.withCharset( "UTF8" ).generateHashedFkName( "FK", booksDe, authorsDe, authorId );

assertEquals( "FKdgopp1hqnm8c1o6sfbb3tbeh", fkNameUtf8 );
private static Stream<Arguments> args() {
// String charset, String prefix, String tableName, String referencedTableName,
// List<String> columnNames, String expectedFkName, String expectedConstraintName
return Stream.of(
Arguments.of(
StandardCharsets.UTF_8.name(),
"fk_", "table_name", "other_table_name", List.of( "col1", "col2", "col3" ),
"fk_f4u43ook9b825fxbm3exb18q6", "fk_1o8k3sa4q2a2wb596v4htt8qf" ),
Arguments.of(
StandardCharsets.ISO_8859_1.name(),
"fk_", "table_name", "other_table_name", List.of( "col1", "col2", "col3" ),
"fk_f4u43ook9b825fxbm3exb18q6", "fk_1o8k3sa4q2a2wb596v4htt8qf" ),
Arguments.of(
StandardCharsets.UTF_8.name(),
"fk_", "café", "le_déjeuner", List.of( "col1", "col2", "col3" ),
"fk_jdvsrk14lxab6a829ok160vyj", "fk_h34kugb2bguwmcn1g5h1q3snf" ),
Arguments.of(
StandardCharsets.ISO_8859_1.name(),
"fk_", "café", "le_déjeuner", List.of( "col1", "col2", "col3" ),
"fk_g1py0mkjd1tu46tr8c2e1vm2l", "fk_1pitt5gtytwpy6ea02o7l5men" ),
Arguments.of(
StandardCharsets.UTF_8.name(),
"fk_", "abcdefghijklmnopqrstuvwxyzäöüß", "stuvwxyzäöüß", List.of( "col1" ),
"fk_q11mlivmrc3sdfnncd2hwkpqp", "fk_gm8xsqu7ayucv5w5w2gj2dfly" ),
Arguments.of(
StandardCharsets.ISO_8859_1.name(),
"fk_", "abcdefghijklmnopqrstuvwxyzäöüß", "stuvwxyzäöüß", List.of( "col1" )
, "fk_fua9hgc6dn6eno8hlqt58j72o", "fk_3iig3yrgsf5bjlbdo05d7mp2" )
);
}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading