-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-18728 - Allow mixed discriminator-value mappings for ANY
HHH-18729 - Allow custom strategy for implicit discriminator-value determination for ANY
- Loading branch information
Showing
25 changed files
with
273 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...src/main/java/org/hibernate/metamodel/internal/FullNameImplicitDiscriminatorStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.metamodel.internal; | ||
|
||
import org.hibernate.HibernateException; | ||
import org.hibernate.metamodel.mapping.EntityMappingType; | ||
import org.hibernate.metamodel.model.domain.NavigableRole; | ||
import org.hibernate.metamodel.spi.ImplicitDiscriminatorStrategy; | ||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor; | ||
import org.hibernate.persister.entity.EntityPersister; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public class FullNameImplicitDiscriminatorStrategy implements ImplicitDiscriminatorStrategy { | ||
public static final FullNameImplicitDiscriminatorStrategy FULL_NAME_STRATEGY = new FullNameImplicitDiscriminatorStrategy(); | ||
|
||
@Override | ||
public Object toDiscriminatorValue(EntityMappingType entityMapping, NavigableRole discriminatorRole, MappingMetamodelImplementor mappingModel) { | ||
return entityMapping.getEntityName(); | ||
} | ||
|
||
@Override | ||
public EntityMappingType toEntityMapping(Object discriminatorValue, NavigableRole discriminatorRole, MappingMetamodelImplementor mappingModel) { | ||
if ( discriminatorValue instanceof String assumedEntityName ) { | ||
final EntityPersister persister = mappingModel.findEntityDescriptor( assumedEntityName ); | ||
|
||
if ( persister != null ) { | ||
return persister; | ||
} | ||
} | ||
|
||
throw new HibernateException( "Cannot interpret discriminator value (" + discriminatorRole + ") : " + discriminatorValue ); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...rc/main/java/org/hibernate/metamodel/internal/ShortNameImplicitDiscriminatorStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.metamodel.internal; | ||
|
||
import org.hibernate.HibernateException; | ||
import org.hibernate.metamodel.mapping.EntityMappingType; | ||
import org.hibernate.metamodel.model.domain.NavigableRole; | ||
import org.hibernate.metamodel.spi.ImplicitDiscriminatorStrategy; | ||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public class ShortNameImplicitDiscriminatorStrategy implements ImplicitDiscriminatorStrategy { | ||
public static final ShortNameImplicitDiscriminatorStrategy SHORT_NAME_STRATEGY = new ShortNameImplicitDiscriminatorStrategy(); | ||
|
||
@Override | ||
public Object toDiscriminatorValue(EntityMappingType entityMapping, NavigableRole discriminatorRole, MappingMetamodelImplementor mappingModel) { | ||
return entityMapping.getImportedName(); | ||
} | ||
|
||
@Override | ||
public EntityMappingType toEntityMapping(Object discriminatorValue, NavigableRole discriminatorRole, MappingMetamodelImplementor mappingModel) { | ||
if ( discriminatorValue instanceof String assumedEntityName ) { | ||
final String importedName = mappingModel.getImportedName( assumedEntityName ); | ||
final EntityMappingType entityMapping = mappingModel.findEntityDescriptor( importedName ); | ||
if ( entityMapping != null ) { | ||
return entityMapping; | ||
} | ||
} | ||
|
||
throw new HibernateException( "Cannot interpret discriminator value (" + discriminatorRole + ") : " + discriminatorValue ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.