Skip to content

Commit 02ab7f4

Browse files
committed
support @view on Informix
1 parent 64f3b7f commit 02ab7f4

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,4 +1014,8 @@ public boolean supportsRowValueConstructorSyntaxInInList() {
10141014
return false;
10151015
}
10161016

1017+
@Override
1018+
public boolean requiresColumnListInCreateView() {
1019+
return true;
1020+
}
10171021
}

hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2927,12 +2927,23 @@ public String getCrossReferenceParentTableFilter(){
29272927
* The syntax used to add a primary key constraint to a table.
29282928
*
29292929
* @param constraintName The name of the PK constraint.
2930-
* @return The "add PK" fragment
2930+
*
2931+
* @apiNote Currently unused, since we never use {@code alter table}
2932+
* to add a primary key constraint.
29312933
*/
29322934
public String getAddPrimaryKeyConstraintString(String constraintName) {
29332935
return " add constraint " + constraintName + " primary key ";
29342936
}
29352937

2938+
/**
2939+
* Is a list of column names required in the {@code create view} statement?
2940+
*
2941+
* @since 7.1
2942+
*/
2943+
public boolean requiresColumnListInCreateView() {
2944+
return false;
2945+
}
2946+
29362947
/**
29372948
* The {@link SqmMultiTableMutationStrategy} to use when not specified by
29382949
* {@link org.hibernate.query.spi.QueryEngineOptions#getCustomSqmMultiTableMutationStrategy}.

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardTableExporter.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.hibernate.type.SqlTypes;
3434

3535
import static java.util.Collections.addAll;
36+
import static java.util.Comparator.comparing;
3637
import static org.hibernate.internal.util.StringHelper.EMPTY_STRINGS;
3738
import static org.hibernate.tool.schema.internal.ColumnDefinitions.appendColumn;
3839

@@ -64,8 +65,26 @@ public String[] getSqlCreateStrings(
6465
final String viewQuery = table.getViewQuery();
6566
if ( viewQuery != null ) {
6667
createTable.append("create view ")
67-
.append( formattedTableName )
68-
.append(" as ")
68+
.append( formattedTableName );
69+
if ( dialect.requiresColumnListInCreateView() ) {
70+
createTable.append(" (");
71+
var sortedColumns =
72+
table.getColumns().stream()
73+
.sorted( comparing( c -> viewQuery.indexOf( c.getQuotedName( dialect ) ) ) )
74+
.toList();
75+
boolean isFirst = true;
76+
for ( Column column : sortedColumns ) {
77+
if ( isFirst ) {
78+
isFirst = false;
79+
}
80+
else {
81+
createTable.append( ", " );
82+
}
83+
createTable.append( column.getQuotedName( dialect ) );
84+
}
85+
createTable.append(")");
86+
}
87+
createTable.append(" as ")
6988
.append( viewQuery );
7089
}
7190
else {

0 commit comments

Comments
 (0)