-
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-17884 Fix the enum value sorting for EnumeratedType.STRING enums
- Loading branch information
Showing
8 changed files
with
121 additions
and
76 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
95 changes: 95 additions & 0 deletions
95
hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/EnumJdbcType.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,95 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.type.descriptor.jdbc; | ||
|
||
import java.sql.CallableStatement; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import org.hibernate.dialect.MySQLDialect; | ||
import org.hibernate.type.descriptor.ValueBinder; | ||
import org.hibernate.type.descriptor.ValueExtractor; | ||
import org.hibernate.type.descriptor.WrapperOptions; | ||
import org.hibernate.type.descriptor.java.JavaType; | ||
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterCharacterData; | ||
|
||
import static org.hibernate.type.SqlTypes.ENUM; | ||
import static org.hibernate.type.SqlTypes.VARCHAR; | ||
|
||
/** | ||
* Represents an {@code enum} type for databases like MySQL and H2. | ||
* <p> | ||
* Hibernate will automatically use this for enums mapped | ||
* as {@link jakarta.persistence.EnumType#STRING}. | ||
* | ||
* @see org.hibernate.type.SqlTypes#ENUM | ||
* @see MySQLDialect#getEnumTypeDeclaration(String, String[]) | ||
* | ||
* @author Gavin King | ||
*/ | ||
public class EnumJdbcType implements JdbcType { | ||
|
||
public static final EnumJdbcType INSTANCE = new EnumJdbcType(); | ||
|
||
@Override | ||
public int getJdbcTypeCode() { | ||
return VARCHAR; | ||
} | ||
|
||
@Override | ||
public int getDefaultSqlTypeCode() { | ||
return ENUM; | ||
} | ||
|
||
@Override | ||
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) { | ||
return new JdbcLiteralFormatterCharacterData<>( javaType ); | ||
} | ||
|
||
@Override | ||
public String getFriendlyName() { | ||
return "ENUM"; | ||
} | ||
|
||
@Override | ||
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) { | ||
return new BasicBinder<>( javaType, this ) { | ||
@Override | ||
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) | ||
throws SQLException { | ||
st.setString( index, getJavaType().unwrap( value, String.class, options ) ); | ||
} | ||
|
||
@Override | ||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) | ||
throws SQLException { | ||
st.setString( name, getJavaType().unwrap( value, String.class, options ) ); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) { | ||
return new BasicExtractor<>( javaType, this ) { | ||
@Override | ||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException { | ||
return getJavaType().wrap( rs.getString( paramIndex ), options ); | ||
} | ||
|
||
@Override | ||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException { | ||
return getJavaType().wrap( statement.getString( index ), options ); | ||
} | ||
|
||
@Override | ||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException { | ||
return getJavaType().wrap( statement.getString( name ), options ); | ||
} | ||
}; | ||
} | ||
} |
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