Skip to content

Commit

Permalink
HHH-15671 remove long-deleted interface RelationalModel
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Nov 4, 2022
1 parent ba3d5b4 commit 0d2aa57
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 291 deletions.
42 changes: 2 additions & 40 deletions hibernate-core/src/main/java/org/hibernate/mapping/Constraint.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.boot.model.relational.Exportable;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.Mapping;

import static org.hibernate.internal.util.StringHelper.isEmpty;

/**
* A mapping model object representing a constraint on a relational database table.
*
* @author Gavin King
* @author Brett Meyer
*/
public abstract class Constraint implements RelationalModel, Exportable, Serializable {
public abstract class Constraint implements Exportable, Serializable {

private String name;
private final ArrayList<Column> columns = new ArrayList<>();
Expand Down Expand Up @@ -175,45 +171,11 @@ public boolean isGenerated(Dialect dialect) {
return true;
}

@Override
public String sqlDropString(SqlStringGenerationContext context,
String defaultCatalog, String defaultSchema) {
final Dialect dialect = context.getDialect();
if ( isGenerated( dialect ) ) {
final String tableName = getTable().getQualifiedName( context );
return String.format(
Locale.ROOT,
"%s evictData constraint %s",
dialect.getAlterTableString( tableName ),
dialect.quote( getName() )
);
}
else {
return null;
}
}

@Override
public String sqlCreateString(Mapping p, SqlStringGenerationContext context, String defaultCatalog,
String defaultSchema) {
final Dialect dialect = context.getDialect();
if ( isGenerated( dialect ) ) {
// Certain dialects (ex: HANA) don't support FKs as expected, but other constraints can still be created.
// If that's the case, hasAlterTable() will be true, but getAddForeignKeyConstraintString will return
// empty string. Prevent blank "alter table" statements.
String constraintString = sqlConstraintString( context, getName(), defaultCatalog, defaultSchema );
if ( !isEmpty( constraintString ) ) {
final String tableName = getTable().getQualifiedName( context );
return dialect.getAlterTableString( tableName ) + " " + constraintString;
}
}
return null;
}

public List<Column> getColumns() {
return columns;
}

@Deprecated(since="6.2")
public abstract String sqlConstraintString(
SqlStringGenerationContext context,
String constraintName,
Expand Down
21 changes: 2 additions & 19 deletions hibernate-core/src/main/java/org/hibernate/mapping/ForeignKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setName(String name) {
}
}

@Override
@Override @Deprecated(since="6.2")
public String sqlConstraintString(
SqlStringGenerationContext context,
String constraintName,
Expand Down Expand Up @@ -89,7 +89,7 @@ public String sqlConstraintString(
referencedColumnNames,
isReferenceToPrimaryKey()
);

return cascadeDeleteEnabled && dialect.supportsCascadeDelete()
? result + " on delete cascade"
: result;
Expand Down Expand Up @@ -165,23 +165,6 @@ public String getKeyDefinition() {
public void setKeyDefinition(String keyDefinition) {
this.keyDefinition = keyDefinition;
}

@Override
public String sqlDropString(SqlStringGenerationContext context,
String defaultCatalog, String defaultSchema) {
Dialect dialect = context.getDialect();
String tableName = getTable().getQualifiedName( context );
final StringBuilder buf = new StringBuilder( dialect.getAlterTableString( tableName ) );
buf.append( dialect.getDropForeignKeyString() );
if ( dialect.supportsIfExistsBeforeConstraintName() ) {
buf.append( "if exists " );
}
buf.append( dialect.quote( getName() ) );
if ( dialect.supportsIfExistsAfterConstraintName() ) {
buf.append( " if exists" );
}
return buf.toString();
}

public boolean isCascadeDeleteEnabled() {
return cascadeDeleteEnabled;
Expand Down
73 changes: 2 additions & 71 deletions hibernate-core/src/main/java/org/hibernate/mapping/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,63 +30,18 @@
*
* @author Gavin King
*/
public class Index implements RelationalModel, Exportable, Serializable {
public class Index implements Exportable, Serializable {
private Identifier name;
private Table table;
private final java.util.List<Column> columns = new ArrayList<>();
private final java.util.Map<Column, String> columnOrderMap = new HashMap<>( );

@Override
public String sqlCreateString(Mapping mapping, SqlStringGenerationContext context, String defaultCatalog,
String defaultSchema)
throws HibernateException {
Dialect dialect = context.getDialect();
return buildSqlCreateIndexString(
context,
getQuotedName( dialect ),
getTable(),
columns,
columnOrderMap,
false,
defaultCatalog,
defaultSchema
);
}

public static String buildSqlDropIndexString(
SqlStringGenerationContext context,
Table table,
String name,
String defaultCatalog,
String defaultSchema) {
return buildSqlDropIndexString( name, table.getQualifiedName( context ) );
}

public static String buildSqlDropIndexString(
String name,
String tableName) {
return "drop index " + qualify( tableName, name );
}

public static String buildSqlCreateIndexString(
SqlStringGenerationContext context,
String name,
Table table,
java.util.List<Column> columns,
java.util.Map<Column, String> columnOrderMap,
boolean unique,
String defaultCatalog,
String defaultSchema) {
return buildSqlCreateIndexString(
context.getDialect(),
name,
table.getQualifiedName( context ),
columns,
columnOrderMap,
unique
);
}

public static String buildSqlCreateIndexString(
Dialect dialect,
String name,
Expand Down Expand Up @@ -126,40 +81,16 @@ public static String buildSqlCreateIndexString(
java.util.Map<Column, String> columnOrderMap,
boolean unique,
Metadata metadata) {
final String tableName = context.format( table.getQualifiedTableName() );

return buildSqlCreateIndexString(
context.getDialect(),
name,
tableName,
context.format( table.getQualifiedTableName() ),
columns,
columnOrderMap,
unique
);
}


// Used only in Table for sqlCreateString (but commented out at the moment)
public String sqlConstraintString(Dialect dialect) {
StringBuilder buf = new StringBuilder( " index (" );
boolean first = true;
for ( Column column : getColumns() ) {
if ( first ) {
first = false;
}
else {
buf.append(", ");
}
buf.append( column.getQuotedName( dialect ) );
}
return buf.append( ')' ).toString();
}

@Override
public String sqlDropString(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) {
return "drop index " + qualify( table.getQualifiedName( context ), getQuotedName( context.getDialect() ) );
}

public Table getTable() {
return table;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public String sqlConstraintString(Dialect dialect) {
return buf.append(')').toString();
}

@Override
@Override @Deprecated(since="6.2")
public String sqlConstraintString(SqlStringGenerationContext context, String constraintName, String defaultCatalog, String defaultSchema) {
Dialect dialect = context.getDialect();
StringBuilder buf = new StringBuilder();
Expand Down

This file was deleted.

115 changes: 1 addition & 114 deletions hibernate-core/src/main/java/org/hibernate/mapping/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.tool.schema.extract.spi.ColumnInformation;
import org.hibernate.tool.schema.extract.spi.TableInformation;

Expand All @@ -42,7 +41,7 @@
*
* @author Gavin King
*/
public class Table implements RelationalModel, Serializable, ContributableDatabaseObject {
public class Table implements Serializable, ContributableDatabaseObject {
private static final Logger log = Logger.getLogger( Table.class );
private static final Column[] EMPTY_COLUMN_ARRAY = new Column[0];

Expand Down Expand Up @@ -505,118 +504,6 @@ public boolean hasPrimaryKey() {
return getPrimaryKey() != null;
}

@Override
public String sqlCreateString(
Mapping p,
SqlStringGenerationContext context,
String defaultCatalog,
String defaultSchema) {
throw new UnsupportedOperationException();
}
// Dialect dialect = context.getDialect();
// StringBuilder buf = new StringBuilder( hasPrimaryKey() ? dialect.getCreateTableString() : dialect.getCreateMultisetTableString() )
// .append( ' ' )
// .append( getQualifiedName( context ) )
// .append( " (" );
//
// boolean identityColumn = idValue != null && idValue.isIdentityColumn( p.getIdentifierGeneratorFactory(), dialect );
//
// // Try to find out the name of the primary key to create it as identity if the IdentityGenerator is used
// String pkname = null;
// if ( hasPrimaryKey() && identityColumn ) {
// pkname = getPrimaryKey().getColumnIterator().next().getQuotedName( dialect );
// }
//
// Iterator<Column> iter = getColumnIterator();
// while ( iter.hasNext() ) {
// Column col = (Column) iter.next();
//
// buf.append( col.getQuotedName( dialect ) )
// .append( ' ' );
//
// if ( identityColumn && col.getQuotedName( dialect ).equals( pkname ) ) {
// // to support dialects that have their own identity data type
// if ( dialect.getIdentityColumnSupport().hasDataTypeInIdentityColumn() ) {
// buf.append( col.getSqlType( dialect, p ) );
// }
// buf.append( ' ' )
// .append( dialect.getIdentityColumnSupport().getIdentityColumnString( col.getSqlTypeCode( p ) ) );
// }
// else {
// final String columnType = col.getSqlType( dialect, p );
// buf.append( columnType );
//
// String defaultValue = col.getDefaultValue();
// if ( defaultValue != null ) {
// buf.append( " default " ).append( defaultValue );
// }
//
// String generatedAs = col.getGeneratedAs();
// if ( generatedAs != null) {
// buf.append( dialect.generatedAs( generatedAs ) );
// }
//
// if ( col.isNullable() ) {
// buf.append( dialect.getNullColumnString( columnType ) );
// }
// else {
// buf.append( " not null" );
// }
//
// }
//
// if ( col.isUnique() ) {
// String keyName = Constraint.generateName( "UK_", this, col );
// UniqueKey uk = getOrCreateUniqueKey( keyName );
// uk.addColumn( col );
// buf.append( dialect.getUniqueDelegate()
// .getColumnDefinitionUniquenessFragment( col, context ) );
// }
//
// String checkConstraint = col.checkConstraint();
// if ( checkConstraint!=null && dialect.supportsColumnCheck() ) {
// buf.append( checkConstraint );
// }
//
// String columnComment = col.getComment();
// if ( columnComment != null ) {
// buf.append( dialect.getColumnComment( columnComment ) );
// }
//
// if ( iter.hasNext() ) {
// buf.append( ", " );
// }
//
// }
// if ( hasPrimaryKey() ) {
// buf.append( ", " )
// .append( getPrimaryKey().sqlConstraintString( dialect ) );
// }
//
// buf.append( dialect.getUniqueDelegate().getTableCreationUniqueConstraintsFragment( this, context ) );
//
// if ( dialect.supportsTableCheck() ) {
// for ( String checkConstraint : checkConstraints ) {
// buf.append( ", check (" )
// .append( checkConstraint )
// .append( ')' );
// }
// }
//
// buf.append( ')' );
//
// if ( comment != null ) {
// buf.append( dialect.getTableComment( comment ) );
// }
//
// return buf.append( dialect.getTableTypeString() ).toString();

@Override
public String sqlDropString(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) {
Dialect dialect = context.getDialect();
return dialect.getDropTableString( getQualifiedName( context ) );
}

public PrimaryKey getPrimaryKey() {
return primaryKey;
}
Expand Down

0 comments on commit 0d2aa57

Please sign in to comment.