HHH-18561 Fix for Informix primary key constraint syntax error

This commit is contained in:
Vladimír Kuruc 2024-09-04 10:00:51 +02:00 committed by Marco Belladelli
parent eacbd78956
commit dfe6a09f31
1 changed files with 34 additions and 0 deletions

View File

@ -42,7 +42,11 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor; import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor; import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.ForeignKey; import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.PrimaryKey;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.UniqueKey;
import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.query.spi.QueryOptions; import org.hibernate.query.spi.QueryOptions;
@ -70,6 +74,7 @@ import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.tool.schema.internal.StandardForeignKeyExporter; import org.hibernate.tool.schema.internal.StandardForeignKeyExporter;
import org.hibernate.tool.schema.internal.StandardTableExporter;
import org.hibernate.tool.schema.spi.Exporter; import org.hibernate.tool.schema.spi.Exporter;
import org.hibernate.type.descriptor.jdbc.ClobJdbcType; import org.hibernate.type.descriptor.jdbc.ClobJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
@ -137,6 +142,30 @@ public class InformixDialect extends Dialect {
return results; return results;
} }
}; };
private final StandardTableExporter informixTableExporter = new StandardTableExporter( this ) {
@Override
protected String primaryKeyString(PrimaryKey key) {
final StringBuilder constraint = new StringBuilder();
constraint.append( "primary key (" );
boolean first = true;
for ( Column column : key.getColumns() ) {
if ( first ) {
first = false;
}
else {
constraint.append(", ");
}
constraint.append( column.getQuotedName( dialect ) );
}
constraint.append(')');
final UniqueKey orderingUniqueKey = key.getOrderingUniqueKey();
if ( orderingUniqueKey != null && orderingUniqueKey.isNameExplicit() ) {
constraint.append( " constraint " )
.append( orderingUniqueKey.getName() ).append( ' ' );
}
return constraint.toString();
}
};
public InformixDialect(DialectResolutionInfo info) { public InformixDialect(DialectResolutionInfo info) {
this( info.makeCopyOrDefault( DEFAULT_VERSION ) ); this( info.makeCopyOrDefault( DEFAULT_VERSION ) );
@ -662,6 +691,11 @@ public class InformixDialect extends Dialect {
return InformixIdentityColumnSupport.INSTANCE; return InformixIdentityColumnSupport.INSTANCE;
} }
@Override
public Exporter<Table> getTableExporter() {
return this.informixTableExporter;
}
@Override @Override
public void appendBooleanValueString(SqlAppender appender, boolean bool) { public void appendBooleanValueString(SqlAppender appender, boolean bool) {
appender.appendSql( bool ? "'t'" : "'f'" ); appender.appendSql( bool ? "'t'" : "'f'" );