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 @@ -481,7 +481,6 @@ public LockOptions setTimeOut(int timeout) {
return setTimeout( Timeouts.interpretMilliSeconds( timeout ) );
}


/**
* The current lock scope:
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package org.hibernate.engine.profile;

import org.hibernate.metamodel.RuntimeMetamodels;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMappingsList;
import org.hibernate.metamodel.mapping.EntityMappingType;
Expand All @@ -27,9 +27,9 @@ public class DefaultFetchProfile extends FetchProfile {
* The name of an implicit fetch profile which includes all eager to-one associations.
*/
public static final String HIBERNATE_DEFAULT_PROFILE = "org.hibernate.defaultProfile";
private final RuntimeMetamodels metamodels;
private final MappingMetamodel metamodels;

public DefaultFetchProfile(RuntimeMetamodels metamodels) {
public DefaultFetchProfile(MappingMetamodel metamodels) {
super(HIBERNATE_DEFAULT_PROFILE);
this.metamodels = metamodels;
}
Expand All @@ -39,7 +39,7 @@ public DefaultFetchProfile(RuntimeMetamodels metamodels) {
final int last = role.lastIndexOf('.');
final String entityName = role.substring( 0, last );
final String property = role.substring( last + 1 );
final EntityMappingType entity = metamodels.getEntityMappingType( entityName );
final EntityMappingType entity = metamodels.getEntityDescriptor( entityName );
if ( entity != null ) {
final AttributeMapping attributeMapping = entity.findAttributeMapping( property );
if ( attributeMapping != null && !attributeMapping.isPluralAttributeMapping() ) {
Expand All @@ -54,8 +54,7 @@ public DefaultFetchProfile(RuntimeMetamodels metamodels) {

@Override
public boolean hasSubselectLoadableCollectionsEnabled(EntityPersister persister) {
final EntityMappingType entity = metamodels.getEntityMappingType( persister.getEntityName() );
final AttributeMappingsList attributeMappings = entity.getAttributeMappings();
final AttributeMappingsList attributeMappings = persister.getAttributeMappings();
for ( int i = 0; i < attributeMappings.size(); i++ ) {
AttributeMapping attributeMapping = attributeMappings.get( i );
if ( attributeMapping.getMappedFetchOptions().getStyle() == SUBSELECT ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ private boolean copyState(Object entity, Type[] types, Object[] state, SessionFa
}

private static Object[] currentState(Object entity, SessionFactoryImplementor factory) {
return factory.getRuntimeMetamodels()
.getEntityMappingType( entity.getClass() )
return factory.getMappingMetamodel()
.getEntityDescriptor( entity.getClass() )
.getEntityPersister()
.getValues( entity );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ static void addFetchProfiles(
MetadataImplementor bootMetamodel,
RuntimeMetamodels runtimeMetamodels,
Map<String, FetchProfile> fetchProfiles) {
for ( org.hibernate.mapping.FetchProfile mappingProfile : bootMetamodel.getFetchProfiles() ) {
final FetchProfile fetchProfile = createFetchProfile( runtimeMetamodels.getMappingMetamodel(), mappingProfile );
final MappingMetamodel mappingMetamodel = runtimeMetamodels.getMappingMetamodel();
for ( var mappingProfile : bootMetamodel.getFetchProfiles() ) {
final FetchProfile fetchProfile = createFetchProfile( mappingMetamodel, mappingProfile );
fetchProfiles.put( fetchProfile.getName(), fetchProfile );
}
fetchProfiles.put( HIBERNATE_DEFAULT_PROFILE, new DefaultFetchProfile( runtimeMetamodels ) );
fetchProfiles.put( HIBERNATE_DEFAULT_PROFILE, new DefaultFetchProfile( mappingMetamodel ) );
}

private static FetchProfile createFetchProfile(
MappingMetamodel mappingMetamodel,
org.hibernate.mapping.FetchProfile mappingProfile) {
final String profileName = mappingProfile.getName();
final FetchProfile fetchProfile = new FetchProfile( profileName );
for ( org.hibernate.mapping.FetchProfile.Fetch mappingFetch : mappingProfile.getFetches() ) {
for ( var mappingFetch : mappingProfile.getFetches() ) {
// resolve the persister owning the fetch
final EntityPersister owner = getEntityPersister( mappingMetamodel, fetchProfile, mappingFetch );
if ( owner instanceof FetchProfileAffectee fetchProfileAffectee ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
import org.hibernate.query.TupleTransformer;

import java.lang.reflect.Constructor;
import java.util.List;

/**
* A {@link TupleTransformer} for handling {@link List} results from native queries.
* A {@link TupleTransformer} which packages each native query result in
* an instance of the result class by calling an appropriate constructor.
*
* @implNote The result type must have exactly one constructor with the
* correct number of parameters. Constructors cannot be disambiguated by
* parameter type.
*
* @since 6.3
*
* @author Gavin King
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
/**
* A {@link TupleTransformer} for handling {@link List} results from native queries.
*
* @since 6.3
*
* @author Gavin King
*/
public class NativeQueryListTransformer implements TupleTransformer<List<Object>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
/**
* A {@link TupleTransformer} for handling {@link Map} results from native queries.
*
* @since 6.3
*
* @author Gavin King
*/
public class NativeQueryMapTransformer implements TupleTransformer<Map<String,Object>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,64 @@
*
* @since 6.0
*
* @see PersistentAttributeType
*/
@Incubating
public enum AttributeClassification {
/**
* @see jakarta.persistence.Basic
*/
BASIC( PersistentAttributeType.BASIC ),
BASIC,

/**
* @see jakarta.persistence.Embedded
*/

EMBEDDED( PersistentAttributeType.EMBEDDED ),
EMBEDDED,

/**
* @see org.hibernate.annotations.Any
*/
ANY( null ),
ANY,

/**
* @see jakarta.persistence.OneToOne
*/
ONE_TO_ONE( PersistentAttributeType.ONE_TO_ONE ),
ONE_TO_ONE,

/**
* @see jakarta.persistence.ManyToOne
*/
MANY_TO_ONE( PersistentAttributeType.MANY_TO_ONE ),
MANY_TO_ONE,

/**
* @see jakarta.persistence.ElementCollection
*/
ELEMENT_COLLECTION( PersistentAttributeType.ELEMENT_COLLECTION ),
ELEMENT_COLLECTION,

/**
* @see jakarta.persistence.OneToMany
*/
ONE_TO_MANY( PersistentAttributeType.ONE_TO_MANY ),
ONE_TO_MANY,

/**
* @see jakarta.persistence.ManyToMany
*/
MANY_TO_MANY( PersistentAttributeType.MANY_TO_MANY );

private final PersistentAttributeType jpaClassification;

AttributeClassification(PersistentAttributeType jpaClassification) {
this.jpaClassification = jpaClassification;
}
MANY_TO_MANY;

/**
* The associated {@link PersistentAttributeType}, if one
*/
public PersistentAttributeType getJpaClassification() {
return jpaClassification;
return switch ( this ) {
case BASIC -> PersistentAttributeType.BASIC;
case EMBEDDED -> PersistentAttributeType.EMBEDDED;
case ONE_TO_ONE -> PersistentAttributeType.ONE_TO_ONE;
case MANY_TO_ONE -> PersistentAttributeType.MANY_TO_ONE;
case ELEMENT_COLLECTION -> PersistentAttributeType.ELEMENT_COLLECTION;
case ONE_TO_MANY -> PersistentAttributeType.ONE_TO_MANY;
case MANY_TO_MANY -> PersistentAttributeType.MANY_TO_MANY;
case ANY -> null;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ public enum CollectionClassification {
* An Object or primitive array. Roughly follows the semantics
* of {@link #LIST}
*/
ARRAY( PluralAttribute.CollectionType.COLLECTION, true ),
ARRAY,

/**
* A non-unique, unordered collection. Represented
* as {@link java.util.Collection} or {@link java.util.List}
*/
BAG( PluralAttribute.CollectionType.COLLECTION, false ),
BAG,

/**
* A {@link #BAG} with a generated id for each element
*/
ID_BAG( PluralAttribute.CollectionType.COLLECTION, false ),
ID_BAG,

/**
* A non-unique, ordered collection following the requirements of {@link java.util.List}
*
* @see org.hibernate.cfg.AvailableSettings#DEFAULT_LIST_SEMANTICS
*/
LIST( PluralAttribute.CollectionType.LIST, true ),
LIST,

/**
* A unique, unordered collection following the requirements of {@link java.util.Set}
*/
SET( PluralAttribute.CollectionType.SET, false ),
SET,

/**
* A sorted {@link #SET} using either natural sorting of the elements or a
Expand All @@ -58,7 +58,7 @@ public enum CollectionClassification {
* @see org.hibernate.annotations.SortNatural
* @see org.hibernate.annotations.SortComparator
*/
SORTED_SET( PluralAttribute.CollectionType.SET, false ),
SORTED_SET,

/**
* A {@link #SET} that is ordered using an order-by fragment
Expand All @@ -69,12 +69,12 @@ public enum CollectionClassification {
* @see jakarta.persistence.OrderBy
* @see org.hibernate.annotations.SQLOrder
*/
ORDERED_SET( PluralAttribute.CollectionType.SET, false ),
ORDERED_SET,

/**
* A collection following the semantics of {@link java.util.Map}
*/
MAP( PluralAttribute.CollectionType.MAP, true ),
MAP,

/**
* A sorted {@link #MAP} using either natural sorting of the keys or a
Expand All @@ -84,7 +84,7 @@ public enum CollectionClassification {
* @see org.hibernate.annotations.SortNatural
* @see org.hibernate.annotations.SortComparator
*/
SORTED_MAP( PluralAttribute.CollectionType.MAP, true ),
SORTED_MAP,

/**
* A {@link #MAP} that is ordered using an order-by fragment
Expand All @@ -95,22 +95,22 @@ public enum CollectionClassification {
* @see jakarta.persistence.OrderBy
* @see org.hibernate.annotations.SQLOrder
*/
ORDERED_MAP( PluralAttribute.CollectionType.MAP, true );

private final PluralAttribute.CollectionType jpaClassification;
private final boolean isIndexed;

CollectionClassification(PluralAttribute.CollectionType jpaClassification, boolean isIndexed) {
this.jpaClassification = jpaClassification;
this.isIndexed = isIndexed;
}
ORDERED_MAP;

public PluralAttribute.CollectionType toJpaClassification() {
return jpaClassification;
return switch ( this ) {
case ARRAY, BAG, ID_BAG -> PluralAttribute.CollectionType.COLLECTION;
case LIST -> PluralAttribute.CollectionType.LIST;
case SET, SORTED_SET, ORDERED_SET -> PluralAttribute.CollectionType.SET;
case MAP, SORTED_MAP, ORDERED_MAP -> PluralAttribute.CollectionType.MAP;
};
}

public boolean isIndexed() {
return isIndexed;
return switch ( this ) {
case ARRAY, LIST, MAP, SORTED_MAP, ORDERED_MAP -> true;
default -> false;
};
}

public boolean isRowUpdatePossible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,34 @@ public interface RuntimeMetamodels {

// some convenience methods...

/**
* @deprecated Only called from tests
*/
@Deprecated(since = "7.0", forRemoval = true)
default EntityMappingType getEntityMappingType(String entityName) {
return getMappingMetamodel().getEntityDescriptor( entityName );
}

/**
* @deprecated Only called from tests
*/
@Deprecated(since = "7.0", forRemoval = true)
default EntityMappingType getEntityMappingType(Class<?> entityType) {
return getMappingMetamodel().getEntityDescriptor( entityType );
}

/**
* @deprecated No longer called
*/
@Deprecated(since = "7.0", forRemoval = true)
default PluralAttributeMapping getPluralAttributeMapping(String role) {
return getMappingMetamodel().findCollectionDescriptor( role ).getAttributeMapping();
}

/**
* @deprecated No longer called
*/
@Deprecated(since = "7.0", forRemoval = true)
default String getImportedName(String name) {
return getMappingMetamodel().getImportedName( name );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
package org.hibernate.metamodel;

/**
* At the end of the day, any "value mapping" (id, version, attribute, collection element, etc.)
* can be one of a few classifications. This defines an enumeration of those classifications.
* Any "value mapping" (id, version, attribute, collection element, etc.)
* belongs to one of several broad categories. This enumeration is quite
* similar to {@link jakarta.persistence.metamodel.Type.PersistenceType}.
*
* @author Steve Ebersole
*
* @see jakarta.persistence.metamodel.Type.PersistenceType
*/
public enum ValueClassification {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,8 @@ private EntityMappingType determineConcreteType(Object entity, SharedSessionCont
final String entityName = session == null
? sessionFactory.bestGuessEntityName( entity )
: session.bestGuessEntityName( entity );
return sessionFactory
.getRuntimeMetamodels()
.getEntityMappingType( entityName );
return sessionFactory.getMappingMetamodel()
.getEntityDescriptor( entityName );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,8 @@ private EntityMappingType determineConcreteType(Object entity, SharedSessionCont
final String entityName = session == null
? sessionFactory.bestGuessEntityName( entity )
: session.bestGuessEntityName( entity );
return sessionFactory
.getRuntimeMetamodels()
.getEntityMappingType( entityName );
return sessionFactory.getMappingMetamodel()
.getEntityDescriptor( entityName );
}

public ModelPart findSubPart(String name, EntityMappingType treatTarget) {
Expand Down
Loading
Loading