Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-19183 Remove LGPL-only contributions - Batch 5 #9794

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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 @@ -4,17 +4,10 @@
*/
package org.hibernate.boot.model.source.internal.hbm;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.hibernate.AssertionFailure;
import org.hibernate.boot.MappingException;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmColumnType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmManyToOneType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSynchronizeType;
import org.hibernate.boot.jaxb.hbm.spi.PluralAttributeInfo;
import org.hibernate.boot.model.source.spi.Caching;
Expand Down Expand Up @@ -72,75 +65,11 @@ protected AbstractPluralAttributeSourceImpl(
this.attributeRole = container.getAttributeRoleBase().append( pluralAttributeJaxbMapping.getName() );
this.attributePath = container.getAttributePathBase().append( pluralAttributeJaxbMapping.getName() );

Optional<JaxbHbmManyToOneType> jaxbHbmManyToOneTypeOptional = Optional.empty();

// Our goal here is to find the inverse side of a one to many to figure out against what to join
if ( pluralAttributeJaxbMapping.isInverse() && pluralAttributeJaxbMapping.getOneToMany() != null && pluralAttributeJaxbMapping.getKey().getPropertyRef() == null ) {
String childClass = pluralAttributeJaxbMapping.getOneToMany().getClazz();

if ( childClass != null ) {
// We match by columns as defined in the key
final List<String> keyColumnNames;
if ( pluralAttributeJaxbMapping.getKey().getColumnAttribute() == null ) {
keyColumnNames = new ArrayList<>( pluralAttributeJaxbMapping.getKey().getColumn().size() );
for ( JaxbHbmColumnType jaxbHbmColumnType : pluralAttributeJaxbMapping.getKey().getColumn() ) {
keyColumnNames.add( jaxbHbmColumnType.getName() );
}
}
else {
keyColumnNames = new ArrayList<>( 1 );
keyColumnNames.add( pluralAttributeJaxbMapping.getKey().getColumnAttribute() );
}
jaxbHbmManyToOneTypeOptional = mappingDocument.getDocumentRoot().getClazz()
.stream()
.filter( (JaxbHbmRootEntityType entityType) -> childClass.equals( entityType.getName() ) )
.flatMap( jaxbHbmRootEntityType -> jaxbHbmRootEntityType.getAttributes().stream() )
.filter( attribute -> {
if ( attribute instanceof JaxbHbmManyToOneType manyToOneType ) {
String manyToOneTypeClass = manyToOneType.getClazz();
String containerClass = container.getAttributeRoleBase().getFullPath();
// Consider many to ones that have no class defined or equal the owner class of the one to many
if ( manyToOneTypeClass == null || manyToOneTypeClass.equals( containerClass ) ) {
if ( manyToOneType.getColumnAttribute() == null ) {
List<Serializable> columns = manyToOneType.getColumnOrFormula();
if ( columns.size() != keyColumnNames.size() ) {
return false;
}
for ( int i = 0; i < columns.size(); i++ ) {
Serializable column = columns.get( i );
String keyColumn = keyColumnNames.get( i );
if ( !( column instanceof JaxbHbmColumnType ) || !( (JaxbHbmColumnType) column )
.getName()
.equals( keyColumn ) ) {
return false;
}
}
}
else {
return keyColumnNames.size() == 1 && keyColumnNames.get( 0 )
.equals( manyToOneType.getColumnAttribute() );
}
return true;
}
}
return false;
})
.map( JaxbHbmManyToOneType.class::cast )
.findFirst();
}
}

this.keySource = jaxbHbmManyToOneTypeOptional
.map( jaxbHbmManyToOneType -> new PluralAttributeKeySourceImpl(
sourceMappingDocument(),
pluralAttributeJaxbMapping.getKey(),
jaxbHbmManyToOneType,
container
) ).orElseGet( () -> new PluralAttributeKeySourceImpl(
sourceMappingDocument(),
pluralAttributeJaxbMapping.getKey(),
container
) );
this.keySource = new PluralAttributeKeySourceImpl(
sourceMappingDocument(),
pluralAttributeJaxbMapping.getKey(),
container
);

this.typeInformation = new HibernateTypeSourceImpl( pluralAttributeJaxbMapping.getCollectionType() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;

import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmKeyType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmManyToOneType;
import org.hibernate.boot.model.source.spi.AttributeSourceContainer;
import org.hibernate.boot.model.source.spi.PluralAttributeKeySource;
import org.hibernate.boot.model.source.spi.RelationalValueSource;
Expand Down Expand Up @@ -70,62 +69,6 @@ public List getColumnOrFormulaElements() {
);
}

public PluralAttributeKeySourceImpl(
MappingDocument mappingDocument,
final JaxbHbmKeyType jaxbKey,
final JaxbHbmManyToOneType jaxbManyToOne,
final AttributeSourceContainer container) {
super( mappingDocument );

this.explicitFkName = StringHelper.nullIfEmpty( jaxbManyToOne.getForeignKey() );
this.referencedPropertyName = StringHelper.nullIfEmpty( jaxbManyToOne.getPropertyRef() );
if ( jaxbKey.getOnDelete() == null ) {
this.cascadeDeletesAtFkLevel = jaxbManyToOne.getOnDelete() != null && "cascade".equals( jaxbManyToOne.getOnDelete().value() );
}
else {
this.cascadeDeletesAtFkLevel = "cascade".equals( jaxbKey.getOnDelete().value() );
}
if ( jaxbKey.isNotNull() == null ) {
this.nullable = jaxbManyToOne.isNotNull() == null || !jaxbManyToOne.isNotNull();
}
else {
this.nullable = !jaxbKey.isNotNull();
}
if ( jaxbKey.isUpdate() == null ) {
this.updateable = jaxbManyToOne.isUpdate();
}
else {
this.updateable = jaxbKey.isUpdate();
}

this.valueSources = RelationalValueSourceHelper.buildValueSources(
sourceMappingDocument(),
null, // todo : collection table name
new RelationalValueSourceHelper.AbstractColumnsAndFormulasSource() {
@Override
public XmlElementMetadata getSourceType() {
return XmlElementMetadata.KEY;
}

@Override
public String getSourceName() {
return null;
}

@Override
public String getColumnAttribute() {
return StringHelper.nullIfEmpty( jaxbKey.getColumnAttribute() );
}

@Override
public List getColumnOrFormulaElements() {
return jaxbKey.getColumn();
}

}
);
}

@Override
public String getExplicitForeignKeyName() {
return explicitFkName;
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.

Loading
Loading