|
30 | 30 | import org.hibernate.dialect.Dialect; |
31 | 31 |
|
32 | 32 | import org.hibernate.resource.transaction.spi.DdlTransactionIsolator; |
33 | | -import org.jboss.logging.Logger; |
34 | 33 |
|
35 | 34 | import static java.util.Collections.emptyList; |
36 | 35 | import static java.util.Collections.singletonList; |
|
46 | 45 | * @author Gavin King |
47 | 46 | */ |
48 | 47 | public class Table implements Serializable, ContributableDatabaseObject { |
49 | | - private static final Logger LOG = Logger.getLogger( Table.class ); |
50 | 48 | private static final Column[] EMPTY_COLUMN_ARRAY = new Column[0]; |
51 | 49 |
|
52 | 50 | private final String contributor; |
@@ -110,17 +108,19 @@ public Table( |
110 | 108 | String subselect, |
111 | 109 | boolean isAbstract) { |
112 | 110 | this.contributor = contributor; |
113 | | - this.catalog = namespace.getPhysicalName().catalog(); |
114 | | - this.schema = namespace.getPhysicalName().schema(); |
| 111 | + final var physicalName = namespace.getPhysicalName(); |
| 112 | + this.catalog = physicalName.catalog(); |
| 113 | + this.schema = physicalName.schema(); |
115 | 114 | this.name = physicalTableName; |
116 | 115 | this.subselect = subselect; |
117 | 116 | this.isAbstract = isAbstract; |
118 | 117 | } |
119 | 118 |
|
120 | 119 | public Table(String contributor, Namespace namespace, String subselect, boolean isAbstract) { |
121 | 120 | this.contributor = contributor; |
122 | | - this.catalog = namespace.getPhysicalName().catalog(); |
123 | | - this.schema = namespace.getPhysicalName().schema(); |
| 121 | + final var physicalName = namespace.getPhysicalName(); |
| 122 | + this.catalog = physicalName.catalog(); |
| 123 | + this.schema = physicalName.schema(); |
124 | 124 | this.subselect = subselect; |
125 | 125 | this.isAbstract = isAbstract; |
126 | 126 | } |
@@ -247,7 +247,7 @@ public Column getColumn(Column column) { |
247 | 247 | return null; |
248 | 248 | } |
249 | 249 | else { |
250 | | - final Column existing = columns.get( column.getCanonicalName() ); |
| 250 | + final var existing = columns.get( column.getCanonicalName() ); |
251 | 251 | return column.equals( existing ) ? existing : null; |
252 | 252 | } |
253 | 253 | } |
@@ -276,15 +276,11 @@ public void addColumn(Column column) { |
276 | 276 | if ( oldColumn == null ) { |
277 | 277 | if ( primaryKey != null ) { |
278 | 278 | for ( var primaryKeyColumn : primaryKey.getColumns() ) { |
279 | | - if ( primaryKeyColumn.getCanonicalName().equals( column.getCanonicalName() ) ) { |
| 279 | + if ( Objects.equals( column.getCanonicalName(), |
| 280 | + primaryKeyColumn.getCanonicalName() ) ) { |
| 281 | + // Force the column to be non-null |
| 282 | + // as it is part of the primary key |
280 | 283 | column.setNullable( false ); |
281 | | - if ( LOG.isTraceEnabled() ) { |
282 | | - LOG.tracef( |
283 | | - "Forcing column [%s] to be non-null as it is part of the primary key for table [%s]", |
284 | | - column.getCanonicalName(), |
285 | | - getNameIdentifier().getCanonicalName() |
286 | | - ); |
287 | | - } |
288 | 284 | } |
289 | 285 | } |
290 | 286 | } |
@@ -452,18 +448,21 @@ public void setPrimaryKey(PrimaryKey primaryKey) { |
452 | 448 | } |
453 | 449 |
|
454 | 450 | public Index getOrCreateIndex(String indexName) { |
455 | | - Index index = indexes.get( indexName ); |
456 | | - if ( index == null ) { |
457 | | - index = new Index(); |
458 | | - index.setName( indexName ); |
459 | | - index.setTable( this ); |
460 | | - indexes.put( indexName, index ); |
| 451 | + final var index = indexes.get( indexName ); |
| 452 | + if ( index != null ) { |
| 453 | + return index; |
| 454 | + } |
| 455 | + else { |
| 456 | + final var newIndex = new Index(); |
| 457 | + newIndex.setName( indexName ); |
| 458 | + newIndex.setTable( this ); |
| 459 | + indexes.put( indexName, newIndex ); |
| 460 | + return newIndex; |
461 | 461 | } |
462 | | - return index; |
463 | 462 | } |
464 | 463 |
|
465 | 464 | public Index getIndex(String indexName) { |
466 | | - return indexes.get( indexName ); |
| 465 | + return indexes.get( indexName ); |
467 | 466 | } |
468 | 467 |
|
469 | 468 | public Index addIndex(Index index) { |
|
0 commit comments