add @DialectOverride.SQLSelect

This commit is contained in:
Gavin 2023-04-08 11:52:45 +02:00 committed by Gavin King
parent adffa890b1
commit 559c325759
3 changed files with 28 additions and 2 deletions

View File

@ -362,6 +362,30 @@ public interface DialectOverride {
FilterDefs[] value();
}
/**
* Specializes a {@link org.hibernate.annotations.SQLSelect}
* in a certain dialect.
*/
@Target({METHOD, FIELD, TYPE})
@Retention(RUNTIME)
@Repeatable(SQLSelects.class)
@OverridesAnnotation(org.hibernate.annotations.SQLSelect.class)
@interface SQLSelect {
/**
* The {@link Dialect} in which this override applies.
*/
Class<? extends Dialect> dialect();
Version before() default @Version(major = MAX_VALUE);
Version sameOrAfter() default @Version(major = MIN_VALUE);
org.hibernate.annotations.SQLSelect override();
}
@Target({METHOD, FIELD})
@Retention(RUNTIME)
@interface SQLSelects {
SQLSelect[] value();
}
/**
* Marks an annotation type as a dialect-specific override for
* some other annotation type.

View File

@ -51,6 +51,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* </ol>
*
* @see HQLSelect
* @see DialectOverride.SQLSelect
*
* @author Gavin King
*

View File

@ -1251,8 +1251,9 @@ public class EntityBinder {
}
private void bindCustomSql() {
//SQL overriding
//TODO: tolerate non-empty table() member here if it explicitly names the main table
//TODO: would be nice to add these guys to @DialectOverride, but getOverridableAnnotation()
// does not yet handle repeatable annotations
final SQLInsert sqlInsert = findMatchingSqlAnnotation( "", SQLInsert.class, SQLInserts.class );
if ( sqlInsert != null ) {
@ -1288,7 +1289,7 @@ public class EntityBinder {
+ persistentClass.getEntityName());
}
final SQLSelect sqlSelect = annotatedClass.getAnnotation( SQLSelect.class );
final SQLSelect sqlSelect = getOverridableAnnotation( annotatedClass, SQLSelect.class, context );
if ( sqlSelect != null ) {
final String loaderName = persistentClass.getEntityName() + "$SQLSelect";
persistentClass.setLoaderName( loaderName );