35
35
* @author Brett Meyer
36
36
*/
37
37
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
+
38
53
/**
39
54
* Get the fragment that can be used to make a column unique as part of its column definition.
40
55
* <p/>
@@ -45,7 +60,27 @@ public interface UniqueDelegate {
45
60
* @return The fragment (usually "unique"), empty string indicates the uniqueness will be indicated using a
46
61
* different approach
47
62
*/
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
+ }
49
84
50
85
/**
51
86
* 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 {
60
95
* @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}. NOTE: The leading
61
96
* comma is important!
62
97
*/
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
+ }
64
114
65
115
/**
66
116
* Get the SQL ALTER TABLE command to be used to create the given UniqueKey.
@@ -70,8 +120,23 @@ public interface UniqueDelegate {
70
120
* @param context A context for SQL string generation
71
121
* @return The ALTER TABLE command
72
122
*/
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
+ }
75
140
76
141
/**
77
142
* 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
81
146
* @param context A context for SQL string generation
82
147
* @return The ALTER TABLE command
83
148
*/
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
+ }
86
153
87
154
}
0 commit comments