HHH-17460 - Ongoing JPA 32 work
This commit is contained in:
parent
b63af21c77
commit
04b8ea5657
|
@ -12,6 +12,7 @@ import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
@ -20,6 +21,7 @@ import java.util.function.Consumer;
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.annotations.AnyDiscriminatorValue;
|
import org.hibernate.annotations.AnyDiscriminatorValue;
|
||||||
import org.hibernate.annotations.AnyDiscriminatorValues;
|
import org.hibernate.annotations.AnyDiscriminatorValues;
|
||||||
|
|
|
@ -46,13 +46,10 @@ import org.hibernate.annotations.QueryCacheLayout;
|
||||||
import org.hibernate.annotations.RowId;
|
import org.hibernate.annotations.RowId;
|
||||||
import org.hibernate.annotations.SQLDelete;
|
import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.SQLDeleteAll;
|
import org.hibernate.annotations.SQLDeleteAll;
|
||||||
import org.hibernate.annotations.SQLDeletes;
|
|
||||||
import org.hibernate.annotations.SQLInsert;
|
import org.hibernate.annotations.SQLInsert;
|
||||||
import org.hibernate.annotations.SQLInserts;
|
|
||||||
import org.hibernate.annotations.SQLRestriction;
|
import org.hibernate.annotations.SQLRestriction;
|
||||||
import org.hibernate.annotations.SQLSelect;
|
import org.hibernate.annotations.SQLSelect;
|
||||||
import org.hibernate.annotations.SQLUpdate;
|
import org.hibernate.annotations.SQLUpdate;
|
||||||
import org.hibernate.annotations.SQLUpdates;
|
|
||||||
import org.hibernate.annotations.SecondaryRow;
|
import org.hibernate.annotations.SecondaryRow;
|
||||||
import org.hibernate.annotations.SecondaryRows;
|
import org.hibernate.annotations.SecondaryRows;
|
||||||
import org.hibernate.annotations.SelectBeforeUpdate;
|
import org.hibernate.annotations.SelectBeforeUpdate;
|
||||||
|
@ -147,7 +144,9 @@ import static org.hibernate.boot.model.internal.AnnotatedJoinColumn.buildInherit
|
||||||
import static org.hibernate.boot.model.internal.BinderHelper.extractFromPackage;
|
import static org.hibernate.boot.model.internal.BinderHelper.extractFromPackage;
|
||||||
import static org.hibernate.boot.model.internal.BinderHelper.getMappedSuperclassOrNull;
|
import static org.hibernate.boot.model.internal.BinderHelper.getMappedSuperclassOrNull;
|
||||||
import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation;
|
import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation;
|
||||||
|
import static org.hibernate.boot.model.internal.BinderHelper.getOverrideAnnotation;
|
||||||
import static org.hibernate.boot.model.internal.BinderHelper.hasToOneAnnotation;
|
import static org.hibernate.boot.model.internal.BinderHelper.hasToOneAnnotation;
|
||||||
|
import static org.hibernate.boot.model.internal.BinderHelper.overrideMatchesDialect;
|
||||||
import static org.hibernate.boot.model.internal.BinderHelper.noConstraint;
|
import static org.hibernate.boot.model.internal.BinderHelper.noConstraint;
|
||||||
import static org.hibernate.boot.model.internal.BinderHelper.toAliasEntityMap;
|
import static org.hibernate.boot.model.internal.BinderHelper.toAliasEntityMap;
|
||||||
import static org.hibernate.boot.model.internal.BinderHelper.toAliasTableMap;
|
import static org.hibernate.boot.model.internal.BinderHelper.toAliasTableMap;
|
||||||
|
@ -167,6 +166,7 @@ import static org.hibernate.internal.util.StringHelper.isEmpty;
|
||||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
||||||
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
|
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
|
||||||
import static org.hibernate.internal.util.StringHelper.unqualify;
|
import static org.hibernate.internal.util.StringHelper.unqualify;
|
||||||
|
import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;
|
||||||
import static org.hibernate.mapping.SimpleValue.DEFAULT_ID_GEN_STRATEGY;
|
import static org.hibernate.mapping.SimpleValue.DEFAULT_ID_GEN_STRATEGY;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1410,9 +1410,9 @@ public class EntityBinder {
|
||||||
private void bindCustomSql() {
|
private void bindCustomSql() {
|
||||||
final String primaryTableName = persistentClass.getTable().getName();
|
final String primaryTableName = persistentClass.getTable().getName();
|
||||||
|
|
||||||
AnnotationUsage<SQLInsert> sqlInsert = findMatchingSqlAnnotation( primaryTableName, SQLInsert.class, SQLInserts.class );
|
AnnotationUsage<SQLInsert> sqlInsert = resolveCustomSqlAnnotation( annotatedClass, SQLInsert.class, primaryTableName );
|
||||||
if ( sqlInsert == null ) {
|
if ( sqlInsert == null ) {
|
||||||
sqlInsert = findMatchingSqlAnnotation( "", SQLInsert.class, SQLInserts.class );
|
sqlInsert = resolveCustomSqlAnnotation( annotatedClass, SQLInsert.class, "" );
|
||||||
}
|
}
|
||||||
if ( sqlInsert != null ) {
|
if ( sqlInsert != null ) {
|
||||||
persistentClass.setCustomSQLInsert(
|
persistentClass.setCustomSQLInsert(
|
||||||
|
@ -1426,9 +1426,9 @@ public class EntityBinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnotationUsage<SQLUpdate> sqlUpdate = findMatchingSqlAnnotation( primaryTableName, SQLUpdate.class, SQLUpdates.class );
|
AnnotationUsage<SQLUpdate> sqlUpdate = resolveCustomSqlAnnotation( annotatedClass, SQLUpdate.class, primaryTableName );
|
||||||
if ( sqlUpdate == null ) {
|
if ( sqlUpdate == null ) {
|
||||||
sqlUpdate = findMatchingSqlAnnotation( "", SQLUpdate.class, SQLUpdates.class );
|
sqlUpdate = resolveCustomSqlAnnotation( annotatedClass, SQLUpdate.class, "" );
|
||||||
}
|
}
|
||||||
if ( sqlUpdate != null ) {
|
if ( sqlUpdate != null ) {
|
||||||
persistentClass.setCustomSQLUpdate(
|
persistentClass.setCustomSQLUpdate(
|
||||||
|
@ -1442,9 +1442,9 @@ public class EntityBinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnotationUsage<SQLDelete> sqlDelete = findMatchingSqlAnnotation( primaryTableName, SQLDelete.class, SQLDeletes.class );
|
AnnotationUsage<SQLDelete> sqlDelete = resolveCustomSqlAnnotation( annotatedClass, SQLDelete.class, primaryTableName );
|
||||||
if ( sqlDelete == null ) {
|
if ( sqlDelete == null ) {
|
||||||
sqlDelete = findMatchingSqlAnnotation( "", SQLDelete.class, SQLDeletes.class );
|
sqlDelete = resolveCustomSqlAnnotation( annotatedClass, SQLDelete.class, "" );
|
||||||
}
|
}
|
||||||
if ( sqlDelete != null ) {
|
if ( sqlDelete != null ) {
|
||||||
persistentClass.setCustomSQLDelete(
|
persistentClass.setCustomSQLDelete(
|
||||||
|
@ -1458,7 +1458,7 @@ public class EntityBinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final AnnotationUsage<SQLDeleteAll> sqlDeleteAll = annotatedClass.getAnnotationUsage( SQLDeleteAll.class );
|
final AnnotationUsage<SQLDeleteAll> sqlDeleteAll = resolveCustomSqlAnnotation( annotatedClass, SQLDeleteAll.class, "" );
|
||||||
if ( sqlDeleteAll != null ) {
|
if ( sqlDeleteAll != null ) {
|
||||||
throw new AnnotationException("@SQLDeleteAll does not apply to entities: "
|
throw new AnnotationException("@SQLDeleteAll does not apply to entities: "
|
||||||
+ persistentClass.getEntityName());
|
+ persistentClass.getEntityName());
|
||||||
|
@ -1493,6 +1493,33 @@ public class EntityBinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <A extends Annotation> AnnotationUsage<A> resolveCustomSqlAnnotation(
|
||||||
|
ClassDetails annotatedClass,
|
||||||
|
Class<A> annotationType,
|
||||||
|
String tableName) {
|
||||||
|
final Class<Annotation> overrideAnnotation = getOverrideAnnotation( annotationType );
|
||||||
|
final List<AnnotationUsage<Annotation>> dialectOverrides = annotatedClass.getRepeatedAnnotationUsages( overrideAnnotation );
|
||||||
|
if ( isNotEmpty( dialectOverrides ) ) {
|
||||||
|
for ( AnnotationUsage<Annotation> dialectOverride : dialectOverrides ) {
|
||||||
|
if ( !overrideMatchesDialect( dialectOverride, context.getMetadataCollector().getDatabase().getDialect() ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final AnnotationUsage<A> override = dialectOverride.getNestedUsage( "override" );
|
||||||
|
if ( isEmpty( tableName )
|
||||||
|
&& isEmpty( override.getString( "table" ) ) ) {
|
||||||
|
return override;
|
||||||
|
}
|
||||||
|
else if ( isNotEmpty( tableName )
|
||||||
|
&& tableName.equals( override.getString( "table" ) ) ) {
|
||||||
|
return override;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return annotatedClass.getNamedAnnotationUsage( annotationType, tableName, "table" );
|
||||||
|
}
|
||||||
|
|
||||||
private void bindFilters() {
|
private void bindFilters() {
|
||||||
for ( AnnotationUsage<Filter> filter : filters ) {
|
for ( AnnotationUsage<Filter> filter : filters ) {
|
||||||
final String filterName = filter.getString( "name" );
|
final String filterName = filter.getString( "name" );
|
||||||
|
@ -2249,8 +2276,9 @@ public class EntityBinder {
|
||||||
final String tableName = join.getTable().getQuotedName();
|
final String tableName = join.getTable().getQuotedName();
|
||||||
final AnnotationUsage<org.hibernate.annotations.Table> matchingTable =
|
final AnnotationUsage<org.hibernate.annotations.Table> matchingTable =
|
||||||
findMatchingComplementaryTableAnnotation( tableName );
|
findMatchingComplementaryTableAnnotation( tableName );
|
||||||
|
|
||||||
final AnnotationUsage<SQLInsert> sqlInsert =
|
final AnnotationUsage<SQLInsert> sqlInsert =
|
||||||
findMatchingSqlAnnotation( tableName, SQLInsert.class, SQLInserts.class );
|
resolveCustomSqlAnnotation( annotatedClass, SQLInsert.class, tableName );
|
||||||
if ( sqlInsert != null ) {
|
if ( sqlInsert != null ) {
|
||||||
join.setCustomSQLInsert(
|
join.setCustomSQLInsert(
|
||||||
sqlInsert.getString( "sql" ).trim(),
|
sqlInsert.getString( "sql" ).trim(),
|
||||||
|
@ -2275,7 +2303,7 @@ public class EntityBinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
final AnnotationUsage<SQLUpdate> sqlUpdate =
|
final AnnotationUsage<SQLUpdate> sqlUpdate =
|
||||||
findMatchingSqlAnnotation( tableName, SQLUpdate.class, SQLUpdates.class );
|
resolveCustomSqlAnnotation( annotatedClass, SQLUpdate.class, tableName );
|
||||||
if ( sqlUpdate != null ) {
|
if ( sqlUpdate != null ) {
|
||||||
join.setCustomSQLUpdate(
|
join.setCustomSQLUpdate(
|
||||||
sqlUpdate.getString( "sql" ).trim(),
|
sqlUpdate.getString( "sql" ).trim(),
|
||||||
|
@ -2300,7 +2328,7 @@ public class EntityBinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
final AnnotationUsage<SQLDelete> sqlDelete =
|
final AnnotationUsage<SQLDelete> sqlDelete =
|
||||||
findMatchingSqlAnnotation( tableName, SQLDelete.class, SQLDeletes.class );
|
resolveCustomSqlAnnotation( annotatedClass, SQLDelete.class, tableName );
|
||||||
if ( sqlDelete != null ) {
|
if ( sqlDelete != null ) {
|
||||||
join.setCustomSQLDelete(
|
join.setCustomSQLDelete(
|
||||||
sqlDelete.getString( "sql" ).trim(),
|
sqlDelete.getString( "sql" ).trim(),
|
||||||
|
|
|
@ -203,6 +203,14 @@ public interface HibernateAnnotations {
|
||||||
AnnotationDescriptor<DialectOverride.FilterDefs> DIALECT_OVERRIDE_FILTER_DEFS = createOrmDescriptor( DialectOverride.FilterDefs.class, DIALECT_OVERRIDE_FILTER_DEF_OVERRIDES );
|
AnnotationDescriptor<DialectOverride.FilterDefs> DIALECT_OVERRIDE_FILTER_DEFS = createOrmDescriptor( DialectOverride.FilterDefs.class, DIALECT_OVERRIDE_FILTER_DEF_OVERRIDES );
|
||||||
AnnotationDescriptor<DialectOverride.Version> DIALECT_OVERRIDE_VERSION = createOrmDescriptor( DialectOverride.Version.class );
|
AnnotationDescriptor<DialectOverride.Version> DIALECT_OVERRIDE_VERSION = createOrmDescriptor( DialectOverride.Version.class );
|
||||||
|
|
||||||
|
AnnotationDescriptor<DialectOverride.SQLInserts> DIALECT_OVERRIDE_SQL_INSERTS = createOrmDescriptor( DialectOverride.SQLInserts.class );
|
||||||
|
AnnotationDescriptor<DialectOverride.SQLInsert> DIALECT_OVERRIDE_SQL_INSERT = createOrmDescriptor( DialectOverride.SQLInsert.class, DIALECT_OVERRIDE_SQL_INSERTS );
|
||||||
|
AnnotationDescriptor<DialectOverride.SQLUpdates> DIALECT_OVERRIDE_SQL_UPDATES = createOrmDescriptor( DialectOverride.SQLUpdates.class );
|
||||||
|
AnnotationDescriptor<DialectOverride.SQLUpdate> DIALECT_OVERRIDE_SQL_UPDATE = createOrmDescriptor( DialectOverride.SQLUpdate.class, DIALECT_OVERRIDE_SQL_UPDATES );
|
||||||
|
AnnotationDescriptor<DialectOverride.SQLDeletes> DIALECT_OVERRIDE_SQL_DELETES = createOrmDescriptor( DialectOverride.SQLDeletes.class );
|
||||||
|
AnnotationDescriptor<DialectOverride.SQLDelete> DIALECT_OVERRIDE_SQL_DELETE = createOrmDescriptor( DialectOverride.SQLDelete.class, DIALECT_OVERRIDE_SQL_DELETES );
|
||||||
|
AnnotationDescriptor<DialectOverride.SQLDeleteAlls> DIALECT_OVERRIDE_SQL_DELETE_ALLS = createOrmDescriptor( DialectOverride.SQLDeleteAlls.class );
|
||||||
|
AnnotationDescriptor<DialectOverride.SQLDeleteAll> DIALECT_OVERRIDE_SQL_DELETE_ALL = createOrmDescriptor( DialectOverride.SQLDeleteAll.class, DIALECT_OVERRIDE_SQL_DELETE_ALLS );
|
||||||
|
|
||||||
static void forEachAnnotation(Consumer<AnnotationDescriptor<? extends Annotation>> consumer) {
|
static void forEachAnnotation(Consumer<AnnotationDescriptor<? extends Annotation>> consumer) {
|
||||||
OrmAnnotationHelper.forEachOrmAnnotation( HibernateAnnotations.class, consumer );
|
OrmAnnotationHelper.forEachOrmAnnotation( HibernateAnnotations.class, consumer );
|
||||||
|
|
Loading…
Reference in New Issue