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
3 changes: 0 additions & 3 deletions hibernate-core/src/main/java/org/hibernate/LockOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public class LockOptions implements Serializable {
private PessimisticLockScope pessimisticLockScope;
private Boolean followOnLocking;


private Map<String, LockMode> aliasSpecificLockModes;

/**
Expand Down Expand Up @@ -510,8 +509,6 @@ public int hashCode() {
return Objects.hash( lockMode, timeout, aliasSpecificLockModes, followOnLocking, pessimisticLockScope );
}



/**
* Set of {@link Map.Entry}s, each associating an alias with its
* specified {@linkplain #setAliasSpecificLockMode alias-specific}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
* Defines the possible values for {@value AvailableSettings#HBM2DDL_AUTO}.
*
* @deprecated This enumeration is currently unused and will be removed.
* Use {@link org.hibernate.tool.schema.Action} instead.
*
* @author Steve Ebersole
*
* @see org.hibernate.tool.schema.Action
*/
@Deprecated(since = "7.0", forRemoval = true)
public enum SchemaAutoTooling {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -62,10 +61,11 @@
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tool.schema.Action;
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.ActionGrouping;
import org.hibernate.type.spi.TypeConfiguration;

import static java.lang.String.join;
import static java.util.Collections.emptySet;
import static org.hibernate.cfg.AvailableSettings.EVENT_LISTENER_PREFIX;
import static org.hibernate.internal.util.StringHelper.splitAtCommas;
import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize;
Expand Down Expand Up @@ -164,10 +164,10 @@ public SqmFunctionRegistry getFunctionRegistry() {

@Override
public SessionFactoryBuilder getSessionFactoryBuilder() {
final SessionFactoryBuilderImplementor defaultBuilder = getFactoryBuilder();
final var defaultBuilder = getFactoryBuilder();
SessionFactoryBuilder builder = null;
List<String> activeFactoryNames = null;
for ( SessionFactoryBuilderFactory discoveredBuilderFactory : getSessionFactoryBuilderFactories() ) {
for ( var discoveredBuilderFactory : getSessionFactoryBuilderFactories() ) {
final SessionFactoryBuilder returnedBuilder =
discoveredBuilderFactory.getSessionFactoryBuilder( this, defaultBuilder );
if ( returnedBuilder != null ) {
Expand Down Expand Up @@ -371,85 +371,90 @@ public NamedObjectRepository buildNamedQueryRepository() {
@Override
public void orderColumns(boolean forceOrdering) {
final ColumnOrderingStrategy columnOrderingStrategy = metadataBuildingOptions.getColumnOrderingStrategy();
if ( columnOrderingStrategy == ColumnOrderingStrategyLegacy.INSTANCE ) {
// No need to order columns when using the no-op strategy
return;
// No need to order columns when using the no-op strategy
if ( columnOrderingStrategy != ColumnOrderingStrategyLegacy.INSTANCE ) {
final boolean shouldOrderTableColumns = forceOrdering || shouldOrderTableColumns();
for ( Namespace namespace : database.getNamespaces() ) {
if ( shouldOrderTableColumns ) {
for ( Table table : namespace.getTables() ) {
handleTable( table, columnOrderingStrategy );
handlePrimaryKey( table, columnOrderingStrategy );
handleForeignKeys( table, columnOrderingStrategy );
}
}
for ( UserDefinedType userDefinedType : namespace.getUserDefinedTypes() ) {
handleUDT( userDefinedType, columnOrderingStrategy );
}
}
}
}

final boolean shouldOrderTableColumns = forceOrdering || shouldOrderTableColumns();
private void handleTable(Table table, ColumnOrderingStrategy columnOrderingStrategy) {
final List<Column> tableColumns = columnOrderingStrategy.orderTableColumns( table, this );
if ( tableColumns != null ) {
table.reorderColumns( tableColumns );
}
}

for ( Namespace namespace : database.getNamespaces() ) {
if ( shouldOrderTableColumns ) {
for ( Table table : namespace.getTables() ) {
final List<Column> tableColumns = columnOrderingStrategy.orderTableColumns( table, this );
if ( tableColumns != null ) {
table.reorderColumns( tableColumns );
}
final PrimaryKey primaryKey = table.getPrimaryKey();
if ( primaryKey != null && primaryKey.getColumns()
.size() > 1 && primaryKey.getOriginalOrder() == null ) {
final List<Column> primaryKeyColumns = columnOrderingStrategy.orderConstraintColumns(
primaryKey,
this
);
private void handleUDT(UserDefinedType userDefinedType, ColumnOrderingStrategy columnOrderingStrategy) {
if ( userDefinedType instanceof UserDefinedObjectType objectType
&& objectType.getColumns().size() > 1 ) {
final List<Column> objectTypeColumns =
columnOrderingStrategy.orderUserDefinedTypeColumns( objectType, this );
if ( objectTypeColumns != null ) {
objectType.reorderColumns( objectTypeColumns );
}
}
}

private void handleForeignKeys(Table table, ColumnOrderingStrategy columnOrderingStrategy) {
for ( ForeignKey foreignKey : table.getForeignKeys().values() ) {
final List<Column> columns = foreignKey.getColumns();
if ( columns.size() > 1 ) {
if ( foreignKey.getReferencedColumns().isEmpty() ) {
final PrimaryKey targetPrimaryKey =
foreignKey.getReferencedTable().getPrimaryKey();
// Make sure we order the columns of the primary key first,
// so that foreign key ordering can rely on this
if ( targetPrimaryKey.getOriginalOrder() == null ) {
final List<Column> primaryKeyColumns =
columnOrderingStrategy.orderConstraintColumns( targetPrimaryKey, this );
if ( primaryKeyColumns != null ) {
primaryKey.reorderColumns( primaryKeyColumns );
targetPrimaryKey.reorderColumns( primaryKeyColumns );
}
}
for ( ForeignKey foreignKey : table.getForeignKeys().values() ) {
final List<Column> columns = foreignKey.getColumns();
if ( columns.size() > 1 ) {
if ( foreignKey.getReferencedColumns().isEmpty() ) {
final PrimaryKey foreignKeyTargetPrimaryKey = foreignKey.getReferencedTable()
.getPrimaryKey();
// Make sure we order the columns of the primary key first,
// so that foreign key ordering can rely on this
if ( foreignKeyTargetPrimaryKey.getOriginalOrder() == null ) {
final List<Column> primaryKeyColumns = columnOrderingStrategy.orderConstraintColumns(
foreignKeyTargetPrimaryKey,
this
);
if ( primaryKeyColumns != null ) {
foreignKeyTargetPrimaryKey.reorderColumns( primaryKeyColumns );
}
}

// Patch up the order of foreign keys based on new order of the target primary key
final int[] originalPrimaryKeyOrder = foreignKeyTargetPrimaryKey.getOriginalOrder();
if ( originalPrimaryKeyOrder != null ) {
final ArrayList<Column> foreignKeyColumnsCopy = new ArrayList<>( columns );
for ( int i = 0; i < foreignKeyColumnsCopy.size(); i++ ) {
columns.set( i, foreignKeyColumnsCopy.get( originalPrimaryKeyOrder[i] ) );
}
}
}

// Patch up the order of foreign keys based on new order of the target primary key
final int[] originalPrimaryKeyOrder = targetPrimaryKey.getOriginalOrder();
if ( originalPrimaryKeyOrder != null ) {
final ArrayList<Column> foreignKeyColumnsCopy = new ArrayList<>( columns );
for ( int i = 0; i < foreignKeyColumnsCopy.size(); i++ ) {
columns.set( i, foreignKeyColumnsCopy.get( originalPrimaryKeyOrder[i] ) );
}
}
}
}
for ( UserDefinedType userDefinedType : namespace.getUserDefinedTypes() ) {
if ( userDefinedType instanceof UserDefinedObjectType objectType
&& objectType.getColumns().size() > 1 ) {
final List<Column> objectTypeColumns =
columnOrderingStrategy.orderUserDefinedTypeColumns( objectType, this );
if ( objectTypeColumns != null ) {
objectType.reorderColumns( objectTypeColumns );
}
}
}
}

private void handlePrimaryKey(Table table, ColumnOrderingStrategy columnOrderingStrategy) {
final PrimaryKey primaryKey = table.getPrimaryKey();
if ( primaryKey != null && primaryKey.getColumns()
.size() > 1 && primaryKey.getOriginalOrder() == null ) {
final List<Column> primaryKeyColumns =
columnOrderingStrategy.orderConstraintColumns( primaryKey, this );
if ( primaryKeyColumns != null ) {
primaryKey.reorderColumns( primaryKeyColumns );
}
}
}

private boolean shouldOrderTableColumns() {
final ConfigurationService configurationService =
metadataBuildingOptions.getServiceRegistry().requireService( ConfigurationService.class );
final Set<SchemaManagementToolCoordinator.ActionGrouping> groupings =
SchemaManagementToolCoordinator.ActionGrouping.interpret( this,
configurationService.getSettings() );
if ( groupings.isEmpty() ) {
return false;
}
for ( SchemaManagementToolCoordinator.ActionGrouping grouping : groupings ) {
final var settings =
metadataBuildingOptions.getServiceRegistry()
.requireService( ConfigurationService.class )
.getSettings();
for ( ActionGrouping grouping : ActionGrouping.interpret( this, settings ) ) {
if ( isColumnOrderingRelevant( grouping.getScriptAction() )
|| isColumnOrderingRelevant( grouping.getDatabaseAction() ) ) {
return true;
Expand Down Expand Up @@ -479,30 +484,29 @@ public void validate() throws MappingException {
@Override
public Set<MappedSuperclass> getMappedSuperclassMappingsCopy() {
return mappedSuperclassMap == null
? Collections.emptySet()
? emptySet()
: new HashSet<>( mappedSuperclassMap.values() );
}

@Override
public void initSessionFactory(SessionFactoryImplementor sessionFactory) {
// must not use BootstrapContext services here
final ServiceRegistryImplementor sessionFactoryServiceRegistry = sessionFactory.getServiceRegistry();
assert sessionFactoryServiceRegistry != null;
final ServiceRegistryImplementor registry = sessionFactory.getServiceRegistry();
assert registry != null;
final ConfigurationService configurationService =
sessionFactoryServiceRegistry.requireService( ConfigurationService.class );
registry.requireService( ConfigurationService.class );
final ClassLoaderService classLoaderService =
sessionFactoryServiceRegistry.requireService( ClassLoaderService.class );
registry.requireService( ClassLoaderService.class );
final EventListenerRegistry eventListenerRegistry =
sessionFactoryServiceRegistry.requireService( EventListenerRegistry.class );
for ( Map.Entry<String,Object> entry : configurationService.getSettings().entrySet() ) {
final String propertyName = entry.getKey();
registry.requireService( EventListenerRegistry.class );
configurationService.getSettings().forEach( (propertyName, value) -> {
if ( propertyName.startsWith( EVENT_LISTENER_PREFIX ) ) {
final String eventTypeName = propertyName.substring( EVENT_LISTENER_PREFIX.length() + 1 );
final EventType<?> eventType = EventType.resolveEventTypeByName( eventTypeName );
final String listeners = (String) entry.getValue();
final String listeners = (String) value;
appendListeners( eventListenerRegistry, classLoaderService, listeners, eventType );
}
}
} );
}

private <T> void appendListeners(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
package org.hibernate.metamodel.model.domain;

import java.io.Serializable;
import java.util.Objects;

import org.hibernate.Incubating;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.spi.DotIdentifierSequence;
import org.hibernate.spi.NavigablePath;

import static org.hibernate.internal.util.StringHelper.isEmpty;

/**
* A compound path which represents a {@link org.hibernate.metamodel.mapping.ModelPart}
* and uniquely identifies it with the runtime metamodel.
Expand Down Expand Up @@ -41,29 +43,26 @@ public NavigableRole(NavigableRole parent, String localName) {
public NavigableRole(NavigableRole parent, String localName, char separator) {
this.parent = parent;
this.localName = localName;
this.fullPath = fullPath( parent, localName, separator );
}

private String fullPath(NavigableRole parent, String localName, char separator) {
// the _identifierMapper is a "hidden" property on entities with composite keys.
// concatenating it will prevent the path from correctly being used to look up
// various things such as criteria paths and fetch profile association paths
if ( IDENTIFIER_MAPPER_PROPERTY.equals( localName ) ) {
this.fullPath = parent != null ? parent.getFullPath() : "";
return parent == null ? "" : parent.getFullPath();
}
else {
final String prefix;
if ( parent != null ) {
final String resolvedParent = parent.getFullPath();
if ( StringHelper.isEmpty( resolvedParent ) ) {
prefix = "";
}
else {
prefix = resolvedParent + separator;
}
prefix = isEmpty( resolvedParent ) ? "" : resolvedParent + separator;
}
else {
prefix = "";
}

this.fullPath = prefix + localName;
return prefix + localName;
}
}

Expand All @@ -80,10 +79,10 @@ public NavigableRole append(String name) {
}

/**
* Uses `#` as the separator rather than `.`. The intention being that the incoming name is a
* {@link org.hibernate.metamodel.mapping.ModelPartContainer} of some sort
*
* todo (6.0) : better name?
* Uses {@code #} as the separator rather than a period,
* the intention being that the incoming name is a
* {@link org.hibernate.metamodel.mapping.ModelPartContainer}
* of some sort.
*/
public NavigableRole appendContainer(String name) {
return new NavigableRole( this, name, '#' );
Expand Down Expand Up @@ -112,20 +111,21 @@ public String toString() {
}

@Override
public boolean equals(final Object o) {
if ( this == o ) {
public boolean equals(final Object object) {
if ( this == object ) {
return true;
}
if ( o == null || NavigableRole.class != o.getClass() ) {
else if ( !(object instanceof NavigableRole that) ) {
return false;
}
NavigableRole that = (NavigableRole) o;
return fullPath.equals( that.fullPath );
else {
return Objects.equals( this.fullPath, that.fullPath );
}
}

@Override
public int hashCode() {
return this.fullPath.hashCode();
return fullPath.hashCode();
}

}
Loading
Loading