@@ -37,26 +37,26 @@ public class DiscriminatorHelper {
3737 * and the {@link org.hibernate.type.descriptor.jdbc.JdbcType}.
3838 */
3939 static BasicType <?> getDiscriminatorType (PersistentClass persistentClass ) {
40- Type discriminatorType = persistentClass .getDiscriminator ().getType ();
41- if ( discriminatorType instanceof BasicType ) {
42- return ( BasicType <?>) discriminatorType ;
40+ final Type discriminatorType = persistentClass .getDiscriminator ().getType ();
41+ if ( discriminatorType instanceof BasicType <?> basicType ) {
42+ return basicType ;
4343 }
4444 else {
4545 throw new MappingException ( "Illegal discriminator type: " + discriminatorType .getName () );
4646 }
4747 }
4848
4949 public static BasicType <?> getDiscriminatorType (Component component ) {
50- Type discriminatorType = component .getDiscriminator ().getType ();
51- if ( discriminatorType instanceof BasicType ) {
52- return ( BasicType <?>) discriminatorType ;
50+ final Type discriminatorType = component .getDiscriminator ().getType ();
51+ if ( discriminatorType instanceof BasicType <?> basicType ) {
52+ return basicType ;
5353 }
5454 else {
5555 throw new MappingException ( "Illegal discriminator type: " + discriminatorType .getName () );
5656 }
5757 }
5858
59- static String getDiscriminatorSQLValue (PersistentClass persistentClass , Dialect dialect ) {
59+ public static String getDiscriminatorSQLValue (PersistentClass persistentClass , Dialect dialect ) {
6060 if ( persistentClass .isDiscriminatorValueNull () ) {
6161 return InFragment .NULL ;
6262 }
@@ -69,16 +69,18 @@ else if ( persistentClass.isDiscriminatorValueNotNull() ) {
6969 }
7070
7171 private static Object parseDiscriminatorValue (PersistentClass persistentClass ) {
72- BasicType <?> discriminatorType = getDiscriminatorType ( persistentClass );
72+ final BasicType <?> discriminatorType = getDiscriminatorType ( persistentClass );
73+ final String discriminatorValue = persistentClass .getDiscriminatorValue ();
7374 try {
74- return discriminatorType .getJavaTypeDescriptor ().fromString ( persistentClass . getDiscriminatorValue () );
75+ return discriminatorType .getJavaTypeDescriptor ().fromString ( discriminatorValue );
7576 }
7677 catch ( Exception e ) {
77- throw new MappingException ( "Could not parse discriminator value" , e );
78+ throw new MappingException ( "Could not parse discriminator value '" + discriminatorValue
79+ + "' as discriminator type '" + discriminatorType .getName () + "'" , e );
7880 }
7981 }
8082
81- static Object getDiscriminatorValue (PersistentClass persistentClass ) {
83+ public static Object getDiscriminatorValue (PersistentClass persistentClass ) {
8284 if ( persistentClass .isDiscriminatorValueNull () ) {
8385 return NULL_DISCRIMINATOR ;
8486 }
@@ -101,10 +103,7 @@ private static <T> String discriminatorSqlLiteral(
101103 );
102104 }
103105
104- public static <T > String jdbcLiteral (
105- T value ,
106- JdbcLiteralFormatter <T > formatter ,
107- Dialect dialect ) {
106+ public static <T > String jdbcLiteral (T value , JdbcLiteralFormatter <T > formatter , Dialect dialect ) {
108107 try {
109108 return formatter .toJdbcLiteral ( value , dialect , null );
110109 }
@@ -119,26 +118,12 @@ public static <T> String jdbcLiteral(
119118 * domain types, or to {@link StandardBasicTypes#CLASS Class} for non-inherited ones.
120119 */
121120 public static <T > SqmExpressible <? super T > getDiscriminatorType (
122- SqmPathSource <T > domainType ,
123- NodeBuilder nodeBuilder ) {
121+ SqmPathSource <T > domainType , NodeBuilder nodeBuilder ) {
124122 final SqmPathSource <?> subPathSource = domainType .findSubPathSource ( DISCRIMINATOR_ROLE_NAME );
125- final SqmExpressible <?> type ;
126- if ( subPathSource != null ) {
127- type = subPathSource .getSqmPathType ();
128- }
129- else {
130- type = nodeBuilder .getTypeConfiguration ()
131- .getBasicTypeRegistry ()
132- .resolve ( StandardBasicTypes .CLASS );
133- }
123+ final SqmExpressible <?> type = subPathSource != null
124+ ? subPathSource .getSqmPathType ()
125+ : nodeBuilder .getTypeConfiguration ().getBasicTypeRegistry ().resolve ( StandardBasicTypes .CLASS );
134126 //noinspection unchecked
135127 return (SqmExpressible <? super T >) type ;
136128 }
137-
138- static String discriminatorLiteral (JdbcLiteralFormatter <Object > formatter , Dialect dialect , Object value ) {
139- return value == NULL_DISCRIMINATOR || value == NOT_NULL_DISCRIMINATOR
140- ? null
141- : jdbcLiteral ( value , formatter , dialect );
142- }
143-
144129}
0 commit comments