Skip to content

Commit 33f260a

Browse files
gavinkingsebersole
authored andcommitted
HHH-18197 finally remove @table (yay!)
Signed-off-by: Gavin King <gavin@hibernate.org>
1 parent 2e51ac3 commit 33f260a

File tree

16 files changed

+54
-582
lines changed

16 files changed

+54
-582
lines changed

hibernate-core/src/main/java/org/hibernate/annotations/Table.java

Lines changed: 0 additions & 127 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/annotations/Tables.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java

Lines changed: 12 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.hibernate.annotations.SoftDelete;
5656
import org.hibernate.annotations.Subselect;
5757
import org.hibernate.annotations.Synchronize;
58-
import org.hibernate.annotations.Tables;
5958
import org.hibernate.annotations.TypeBinderType;
6059
import org.hibernate.annotations.View;
6160
import org.hibernate.annotations.Where;
@@ -432,24 +431,8 @@ private void handleIdentifier(
432431
}
433432

434433
private void processComplementaryTableDefinitions() {
435-
annotatedClass.forEachAnnotationUsage( org.hibernate.annotations.Table.class, getSourceModelContext(), (usage) -> {
436-
final Table appliedTable = findTable( usage.appliesTo() );
437-
438-
final String comment = usage.comment();
439-
if ( !comment.isEmpty() ) {
440-
appliedTable.setComment( comment );
441-
}
442-
443-
final String checkConstraint = usage.checkConstraint();
444-
if ( !checkConstraint.isEmpty() ) {
445-
//noinspection deprecation
446-
appliedTable.addCheckConstraint( checkConstraint );
447-
}
448-
449-
TableBinder.addIndexes( appliedTable, usage.indexes(), context );
450-
} );
451-
452-
final jakarta.persistence.Table jpaTableUsage = annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class, getSourceModelContext() );
434+
final jakarta.persistence.Table jpaTableUsage =
435+
annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class, getSourceModelContext() );
453436
if ( jpaTableUsage != null ) {
454437
final Table table = persistentClass.getTable();
455438
TableBinder.addJpaIndexes( table, jpaTableUsage.indexes(), context );
@@ -2061,24 +2044,17 @@ private void bindJoinToPersistentClass(Join join, AnnotatedJoinColumns joinColum
20612044
}
20622045

20632046
private void setForeignKeyNameIfDefined(Join join) {
2064-
final String tableName = join.getTable().getQuotedName();
2065-
final org.hibernate.annotations.Table matchingTable = findMatchingComplementaryTableAnnotation( tableName );
20662047
final SimpleValue key = (SimpleValue) join.getKey();
2067-
if ( matchingTable != null && !matchingTable.foreignKey().name().isEmpty() ) {
2068-
key.setForeignKeyName( matchingTable.foreignKey().name() );
2069-
}
2070-
else {
2071-
final SecondaryTable jpaSecondaryTable = findMatchingSecondaryTable( join );
2072-
if ( jpaSecondaryTable != null ) {
2073-
final boolean noConstraintByDefault = context.getBuildingOptions().isNoConstraintByDefault();
2074-
if ( jpaSecondaryTable.foreignKey().value() == ConstraintMode.NO_CONSTRAINT
2075-
|| jpaSecondaryTable.foreignKey().value() == ConstraintMode.PROVIDER_DEFAULT && noConstraintByDefault ) {
2076-
key.disableForeignKey();
2077-
}
2078-
else {
2079-
key.setForeignKeyName( nullIfEmpty( jpaSecondaryTable.foreignKey().name() ) );
2080-
key.setForeignKeyDefinition( nullIfEmpty( jpaSecondaryTable.foreignKey().foreignKeyDefinition() ) );
2081-
}
2048+
final SecondaryTable jpaSecondaryTable = findMatchingSecondaryTable( join );
2049+
if ( jpaSecondaryTable != null ) {
2050+
final boolean noConstraintByDefault = context.getBuildingOptions().isNoConstraintByDefault();
2051+
if ( jpaSecondaryTable.foreignKey().value() == ConstraintMode.NO_CONSTRAINT
2052+
|| jpaSecondaryTable.foreignKey().value() == ConstraintMode.PROVIDER_DEFAULT && noConstraintByDefault ) {
2053+
key.disableForeignKey();
2054+
}
2055+
else {
2056+
key.setForeignKeyName( nullIfEmpty( jpaSecondaryTable.foreignKey().name() ) );
2057+
key.setForeignKeyDefinition( nullIfEmpty( jpaSecondaryTable.foreignKey().foreignKeyDefinition() ) );
20822058
}
20832059
}
20842060
}
@@ -2101,24 +2077,6 @@ private SecondaryTable findMatchingSecondaryTable(Join join) {
21012077
return null;
21022078
}
21032079

2104-
private org.hibernate.annotations.Table findMatchingComplementaryTableAnnotation(String tableName) {
2105-
final org.hibernate.annotations.Table table = annotatedClass.getDirectAnnotationUsage( org.hibernate.annotations.Table.class );
2106-
if ( table != null && tableName.equals( table.appliesTo() ) ) {
2107-
return table;
2108-
}
2109-
else {
2110-
final Tables tables = annotatedClass.getAnnotationUsage( Tables.class, getSourceModelContext() );
2111-
if ( tables != null ) {
2112-
for (org.hibernate.annotations.Table nested : tables.value()) {
2113-
if ( tableName.equals( nested.appliesTo() ) ) {
2114-
return nested;
2115-
}
2116-
}
2117-
}
2118-
return null;
2119-
}
2120-
}
2121-
21222080
private SecondaryRow findMatchingSecondaryRowAnnotation(String tableName) {
21232081
final SecondaryRow row = annotatedClass.getDirectAnnotationUsage( SecondaryRow.class );
21242082
if ( row != null && ( row.table().isEmpty() || tableName.equals( row.table() ) ) ) {
@@ -2263,16 +2221,11 @@ Join createJoin(
22632221

22642222
private void handleSecondaryRowManagement(Join join) {
22652223
final String tableName = join.getTable().getQuotedName();
2266-
final org.hibernate.annotations.Table matchingTable = findMatchingComplementaryTableAnnotation( tableName );
22672224
final SecondaryRow matchingRow = findMatchingSecondaryRowAnnotation( tableName );
22682225
if ( matchingRow != null ) {
22692226
join.setInverse( !matchingRow.owned() );
22702227
join.setOptional( matchingRow.optional() );
22712228
}
2272-
else if ( matchingTable != null ) {
2273-
join.setInverse( matchingTable.inverse() );
2274-
join.setOptional( matchingTable.optional() );
2275-
}
22762229
else {
22772230
//default
22782231
join.setInverse( false );
@@ -2282,8 +2235,6 @@ else if ( matchingTable != null ) {
22822235

22832236
private void processSecondaryTableCustomSql(Join join) {
22842237
final String tableName = join.getTable().getQuotedName();
2285-
final org.hibernate.annotations.Table matchingTable = findMatchingComplementaryTableAnnotation( tableName );
2286-
22872238
final SQLInsert sqlInsert = resolveCustomSqlAnnotation( annotatedClass, SQLInsert.class, tableName );
22882239
if ( sqlInsert != null ) {
22892240
join.setCustomSQLInsert(
@@ -2296,17 +2247,6 @@ private void processSecondaryTableCustomSql(Join join) {
22962247
join.setInsertExpectation( getDefaultSupplier( expectationClass ) );
22972248
}
22982249
}
2299-
else if ( matchingTable != null ) {
2300-
final SQLInsert matchingTableInsert = matchingTable.sqlInsert();
2301-
final String matchingTableInsertSql = matchingTableInsert.sql().trim();
2302-
if ( !matchingTableInsertSql.isEmpty() ) {
2303-
join.setCustomSQLInsert(
2304-
matchingTableInsertSql,
2305-
matchingTableInsert.callable(),
2306-
fromResultCheckStyle( matchingTableInsert.check() )
2307-
);
2308-
}
2309-
}
23102250

23112251
final SQLUpdate sqlUpdate = resolveCustomSqlAnnotation( annotatedClass, SQLUpdate.class, tableName );
23122252
if ( sqlUpdate != null ) {
@@ -2320,17 +2260,6 @@ else if ( matchingTable != null ) {
23202260
join.setUpdateExpectation( getDefaultSupplier( expectationClass ) );
23212261
}
23222262
}
2323-
else if ( matchingTable != null ) {
2324-
final SQLUpdate matchingTableUpdate = matchingTable.sqlUpdate();
2325-
final String matchingTableUpdateSql = matchingTableUpdate.sql().trim();
2326-
if ( !matchingTableUpdateSql.isEmpty() ) {
2327-
join.setCustomSQLUpdate(
2328-
matchingTableUpdateSql,
2329-
matchingTableUpdate.callable(),
2330-
fromResultCheckStyle( matchingTableUpdate.check() )
2331-
);
2332-
}
2333-
}
23342263

23352264
final SQLDelete sqlDelete = resolveCustomSqlAnnotation( annotatedClass, SQLDelete.class, tableName );
23362265
if ( sqlDelete != null ) {
@@ -2344,17 +2273,6 @@ else if ( matchingTable != null ) {
23442273
join.setDeleteExpectation( getDefaultSupplier( expectationClass ) );
23452274
}
23462275
}
2347-
else if ( matchingTable != null ) {
2348-
final SQLDelete matchingTableDelete = matchingTable.sqlDelete();
2349-
final String deleteSql = matchingTableDelete.sql().trim();
2350-
if ( !deleteSql.isEmpty() ) {
2351-
join.setCustomSQLDelete(
2352-
deleteSql,
2353-
matchingTableDelete.callable(),
2354-
fromResultCheckStyle( matchingTableDelete.check() )
2355-
);
2356-
}
2357-
}
23582276
}
23592277

23602278
public java.util.Map<String, Join> getSecondaryTables() {
@@ -2378,24 +2296,6 @@ public void setIgnoreIdAnnotations(boolean ignoreIdAnnotations) {
23782296
this.ignoreIdAnnotations = ignoreIdAnnotations;
23792297
}
23802298

2381-
private Table findTable(String tableName) {
2382-
for ( Table table : persistentClass.getTableClosure() ) {
2383-
if ( table.getQuotedName().equals( tableName ) ) {
2384-
//we are in the correct table to find columns
2385-
return table;
2386-
}
2387-
}
2388-
//maybe a join/secondary table
2389-
for ( Join join : secondaryTables.values() ) {
2390-
if ( join.getTable().getQuotedName().equals( tableName ) ) {
2391-
return join.getTable();
2392-
}
2393-
}
2394-
throw new AnnotationException( "Entity '" + name
2395-
+ "' has a '@org.hibernate.annotations.Table' annotation which 'appliesTo' an unknown table named '"
2396-
+ tableName + "'" );
2397-
}
2398-
23992299
public AccessType getPropertyAccessType() {
24002300
return propertyAccessType;
24012301
}

hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -624,15 +624,6 @@ public interface HibernateAnnotations {
624624
Synchronize.class,
625625
SynchronizeAnnotation.class
626626
);
627-
OrmAnnotationDescriptor<Tables,TablesAnnotation> TABLES = new OrmAnnotationDescriptor<>(
628-
Tables.class,
629-
TablesAnnotation.class
630-
);
631-
OrmAnnotationDescriptor<Table, TableAnnotation> TABLE = new OrmAnnotationDescriptor<>(
632-
Table.class,
633-
TableAnnotation.class,
634-
TABLES
635-
);
636627
OrmAnnotationDescriptor<Target,TargetLegacyAnnotation> TARGET_LEGACY = new OrmAnnotationDescriptor<>(
637628
Target.class,
638629
TargetLegacyAnnotation.class

0 commit comments

Comments
 (0)