Skip to content

Commit 97f8732

Browse files
yrodierebeikov
authored andcommitted
HHH-15069 Fix backwards-incompatible changes for implementors of UniqueDelegate
1 parent 9f4ebca commit 97f8732

File tree

1 file changed

+73
-6
lines changed

1 file changed

+73
-6
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/unique/UniqueDelegate.java

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@
3535
* @author Brett Meyer
3636
*/
3737
public interface UniqueDelegate {
38+
/**
39+
* Get the fragment that can be used to make a column unique as part of its column definition.
40+
* <p/>
41+
* This is intended for dialects which do not support unique constraints
42+
*
43+
* @param column The column to which to apply the unique
44+
* @return The fragment (usually "unique"), empty string indicates the uniqueness will be indicated using a
45+
* different approach
46+
* @deprecated Implement {@link #getColumnDefinitionUniquenessFragment(Column, SqlStringGenerationContext)} instead.
47+
*/
48+
@Deprecated
49+
default String getColumnDefinitionUniquenessFragment(Column column) {
50+
throw new IllegalStateException("getColumnDefinitionUniquenessFragment(...) was not implemented!");
51+
}
52+
3853
/**
3954
* Get the fragment that can be used to make a column unique as part of its column definition.
4055
* <p/>
@@ -45,7 +60,27 @@ public interface UniqueDelegate {
4560
* @return The fragment (usually "unique"), empty string indicates the uniqueness will be indicated using a
4661
* different approach
4762
*/
48-
public String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context);
63+
default String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context) {
64+
return getColumnDefinitionUniquenessFragment( column );
65+
}
66+
67+
/**
68+
* Get the fragment that can be used to apply unique constraints as part of table creation. The implementation
69+
* should iterate over the {@link org.hibernate.mapping.UniqueKey} instances for the given table (see
70+
* {@link org.hibernate.mapping.Table#getUniqueKeyIterator()} and generate the whole fragment for all
71+
* unique keys
72+
* <p/>
73+
* Intended for Dialects which support unique constraint definitions, but just not in separate ALTER statements.
74+
*
75+
* @param table The table for which to generate the unique constraints fragment
76+
* @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}. NOTE: The leading
77+
* comma is important!
78+
* @deprecated Implement {@link #getTableCreationUniqueConstraintsFragment(Table, SqlStringGenerationContext)} instead.
79+
*/
80+
@Deprecated
81+
default String getTableCreationUniqueConstraintsFragment(Table table) {
82+
throw new IllegalStateException("getTableCreationUniqueConstraintsFragment(...) was not implemented!");
83+
}
4984

5085
/**
5186
* Get the fragment that can be used to apply unique constraints as part of table creation. The implementation
@@ -60,7 +95,22 @@ public interface UniqueDelegate {
6095
* @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}. NOTE: The leading
6196
* comma is important!
6297
*/
63-
public String getTableCreationUniqueConstraintsFragment(Table table, SqlStringGenerationContext context);
98+
default String getTableCreationUniqueConstraintsFragment(Table table, SqlStringGenerationContext context) {
99+
return getTableCreationUniqueConstraintsFragment( table );
100+
}
101+
102+
/**
103+
* Get the SQL ALTER TABLE command to be used to create the given UniqueKey.
104+
*
105+
* @param uniqueKey The UniqueKey instance. Contains all information about the columns
106+
* @param metadata Access to the bootstrap mapping information
107+
* @return The ALTER TABLE command
108+
* @deprecated Implement {@link #getAlterTableToAddUniqueKeyCommand(UniqueKey, Metadata, SqlStringGenerationContext)} instead.
109+
*/
110+
@Deprecated
111+
default String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) {
112+
throw new IllegalStateException("getAlterTableToAddUniqueKeyCommand(...) was not implemented!");
113+
}
64114

65115
/**
66116
* Get the SQL ALTER TABLE command to be used to create the given UniqueKey.
@@ -70,8 +120,23 @@ public interface UniqueDelegate {
70120
* @param context A context for SQL string generation
71121
* @return The ALTER TABLE command
72122
*/
73-
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
74-
SqlStringGenerationContext context);
123+
default String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
124+
SqlStringGenerationContext context) {
125+
return getAlterTableToAddUniqueKeyCommand( uniqueKey, metadata );
126+
}
127+
128+
/**
129+
* Get the SQL ALTER TABLE command to be used to drop the given UniqueKey.
130+
*
131+
* @param uniqueKey The UniqueKey instance. Contains all information about the columns
132+
* @param metadata Access to the bootstrap mapping information
133+
* @return The ALTER TABLE command
134+
* @deprecated Implement {@link #getAlterTableToDropUniqueKeyCommand(UniqueKey, Metadata, SqlStringGenerationContext)} instead.
135+
*/
136+
@Deprecated
137+
default String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) {
138+
throw new IllegalStateException("getAlterTableToDropUniqueKeyCommand(...) was not implemented!");
139+
}
75140

76141
/**
77142
* Get the SQL ALTER TABLE command to be used to drop the given UniqueKey.
@@ -81,7 +146,9 @@ public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata m
81146
* @param context A context for SQL string generation
82147
* @return The ALTER TABLE command
83148
*/
84-
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
85-
SqlStringGenerationContext context);
149+
default String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
150+
SqlStringGenerationContext context) {
151+
return getAlterTableToDropUniqueKeyCommand( uniqueKey, metadata );
152+
}
86153

87154
}

0 commit comments

Comments
 (0)