roll back a change, to make @sebersole's rebase easier

move IndexOrUniqueKeyNameSource back inside IndexBinder
This commit is contained in:
Gavin King 2024-03-12 15:03:24 +01:00
parent da9d2c2bf7
commit 6c5daedfd3
3 changed files with 64 additions and 76 deletions

View File

@ -16,21 +16,22 @@ import org.hibernate.mapping.Table;
import java.util.List;
import static java.util.Collections.emptyList;
import static org.hibernate.boot.model.naming.Identifier.toIdentifier;
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
public class ForeignKeyNameSource implements ImplicitForeignKeyNameSource {
final List<Identifier> columnNames;
private final List<Identifier> columnNames;
private final ForeignKey foreignKey;
private final Table table;
private final MetadataBuildingContext buildingContext;
List<Identifier> referencedColumnNames;
private List<Identifier> referencedColumnNames;
public ForeignKeyNameSource(ForeignKey foreignKey, Table table, MetadataBuildingContext buildingContext) {
this.foreignKey = foreignKey;
this.table = table;
this.buildingContext = buildingContext;
columnNames = extractColumnNames(foreignKey.getColumns());
columnNames = extractColumnNames( foreignKey.getColumns() );
referencedColumnNames = null;
}
@ -59,7 +60,8 @@ public class ForeignKeyNameSource implements ImplicitForeignKeyNameSource {
@Override
public Identifier getUserProvidedIdentifier() {
return foreignKey.getName() != null ? Identifier.toIdentifier(foreignKey.getName()) : null;
String name = foreignKey.getName();
return name != null ? toIdentifier(name) : null;
}
@Override

View File

@ -8,7 +8,10 @@ package org.hibernate.boot.model.internal;
import jakarta.persistence.UniqueConstraint;
import org.hibernate.AnnotationException;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.ImplicitIndexNameSource;
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
import org.hibernate.boot.model.naming.ImplicitUniqueKeyNameSource;
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.spi.MetadataBuildingContext;
@ -25,7 +28,10 @@ import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import static java.util.Collections.emptyList;
import static org.hibernate.boot.model.naming.Identifier.toIdentifier;
import static org.hibernate.internal.util.StringHelper.isEmpty;
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
/**
* Responsible for interpreting {@link jakarta.persistence.Index} and
@ -228,4 +234,56 @@ class IndexBinder {
}
}
}
private class IndexOrUniqueKeyNameSource implements ImplicitIndexNameSource, ImplicitUniqueKeyNameSource {
private final MetadataBuildingContext buildingContext;
private final Table table;
private final String[] columnNames;
private final String originalKeyName;
public IndexOrUniqueKeyNameSource(MetadataBuildingContext buildingContext, Table table, String[] columnNames, String originalKeyName) {
this.buildingContext = buildingContext;
this.table = table;
this.columnNames = columnNames;
this.originalKeyName = originalKeyName;
}
@Override
public MetadataBuildingContext getBuildingContext() {
return buildingContext;
}
@Override
public Identifier getTableName() {
return table.getNameIdentifier();
}
private List<Identifier> columnNameIdentifiers;
@Override
public List<Identifier> getColumnNames() {
// be lazy about building these
if ( columnNameIdentifiers == null ) {
columnNameIdentifiers = toIdentifiers( columnNames );
}
return columnNameIdentifiers;
}
@Override
public Identifier getUserProvidedIdentifier() {
return originalKeyName != null ? toIdentifier( originalKeyName ) : null;
}
}
private List<Identifier> toIdentifiers(String[] names) {
if ( names == null ) {
return emptyList();
}
final List<Identifier> columnNames = arrayList( names.length );
for ( String name : names ) {
columnNames.add( getDatabase().toIdentifier( name ) );
}
return columnNames;
}
}

View File

@ -1,72 +0,0 @@
/*
* 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.boot.model.internal;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.ImplicitIndexNameSource;
import org.hibernate.boot.model.naming.ImplicitUniqueKeyNameSource;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.Table;
import java.util.List;
import static java.util.Collections.emptyList;
import static org.hibernate.boot.model.naming.Identifier.toIdentifier;
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
class IndexOrUniqueKeyNameSource implements ImplicitIndexNameSource, ImplicitUniqueKeyNameSource {
private final MetadataBuildingContext buildingContext;
private final Table table;
private final String[] columnNames;
private final String originalKeyName;
public IndexOrUniqueKeyNameSource(
MetadataBuildingContext buildingContext, Table table, String[] columnNames, String originalKeyName) {
this.buildingContext = buildingContext;
this.table = table;
this.columnNames = columnNames;
this.originalKeyName = originalKeyName;
}
@Override
public MetadataBuildingContext getBuildingContext() {
return buildingContext;
}
@Override
public Identifier getTableName() {
return table.getNameIdentifier();
}
private List<Identifier> columnNameIdentifiers;
@Override
public List<Identifier> getColumnNames() {
// be lazy about building these
if ( columnNameIdentifiers == null ) {
columnNameIdentifiers = toIdentifiers( columnNames );
}
return columnNameIdentifiers;
}
@Override
public Identifier getUserProvidedIdentifier() {
return originalKeyName != null ? toIdentifier( originalKeyName ) : null;
}
private List<Identifier> toIdentifiers(String[] names) {
if ( names == null ) {
return emptyList();
}
final List<Identifier> columnNames = arrayList( names.length );
for ( String name : names ) {
columnNames.add( buildingContext.getMetadataCollector().getDatabase().toIdentifier( name ) );
}
return columnNames;
}
}