/
UniqueDelegate.java
151 lines (139 loc) · 4.97 KB
/
UniqueDelegate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.dialect.unique;
import org.hibernate.metamodel.relational.Column;
import org.hibernate.metamodel.relational.Table;
import org.hibernate.metamodel.relational.UniqueKey;
/**
* Dialect-level delegate in charge of applying "uniqueness" to a column.
* Uniqueness can be defined in 1 of 3 ways:
*
* 1.) Add a unique constraint via separate alter table statements.
* 2.) Add a unique constraint via dialect-specific syntax in table create statement.
* 3.) Add "unique" syntax to the column itself.
*
* #1 & #2 are preferred, if possible -- #3 should be solely a fall-back.
*
* TODO: This could eventually be simplified. With AST, 1 "applyUniqueness"
* method might be possible. But due to .cfg and .mapping still resolving
* around StringBuilders, separate methods were needed.
*
* See HHH-7797.
*
* @author Brett Meyer
*/
public interface UniqueDelegate {
/**
* If the delegate supports unique constraints, this method should simply
* create the UniqueKey on the Table. Otherwise, the constraint isn't
* supported and "unique" should be returned in order to add it
* to the column definition.
*
* @param table
* @param column
* @return String
*/
public String applyUniqueToColumn( org.hibernate.mapping.Table table,
org.hibernate.mapping.Column column );
/**
* If the delegate supports unique constraints, this method should simply
* create the UniqueKey on the Table. Otherwise, the constraint isn't
* supported and "unique" should be returned in order to add it
* to the column definition.
*
* @param table
* @param column
* @return String
*/
public String applyUniqueToColumn( Table table, Column column );
/**
* If constraints are supported, but not in seperate alter statements,
* return uniqueConstraintSql in order to add the constraint to the
* original table definition.
*
* @param table
* @return String
*/
public String applyUniquesToTable( org.hibernate.mapping.Table table );
/**
* If constraints are supported, but not in seperate alter statements,
* return uniqueConstraintSql in order to add the constraint to the
* original table definition.
*
* @param table
* @return String
*/
public String applyUniquesToTable( Table table );
/**
* If creating unique constraints in separate alter statements is
* supported, generate the necessary "alter" syntax for the given key.
*
* @param uniqueKey
* @param defaultCatalog
* @param defaultSchema
* @return String
*/
public String applyUniquesOnAlter( org.hibernate.mapping.UniqueKey uniqueKey,
String defaultCatalog, String defaultSchema );
/**
* If creating unique constraints in separate alter statements is
* supported, generate the necessary "alter" syntax for the given key.
*
* @param uniqueKey
* @return String
*/
public String applyUniquesOnAlter( UniqueKey uniqueKey );
/**
* If dropping unique constraints in separate alter statements is
* supported, generate the necessary "alter" syntax for the given key.
*
* @param uniqueKey
* @param defaultCatalog
* @param defaultSchema
* @return String
*/
public String dropUniquesOnAlter( org.hibernate.mapping.UniqueKey uniqueKey,
String defaultCatalog, String defaultSchema );
/**
* If dropping unique constraints in separate alter statements is
* supported, generate the necessary "alter" syntax for the given key.
*
* @param uniqueKey
* @return String
*/
public String dropUniquesOnAlter( UniqueKey uniqueKey );
/**
* Generates the syntax necessary to create the unique constraint (reused
* by all methods). Ex: "unique (column1, column2, ...)"
*
* @param uniqueKey
* @return String
*/
public String uniqueConstraintSql( org.hibernate.mapping.UniqueKey uniqueKey );
/**
* Generates the syntax necessary to create the unique constraint (reused
* by all methods). Ex: "unique (column1, column2, ...)"
*
* @param uniqueKey
* @return String
*/
public String uniqueConstraintSql( UniqueKey uniqueKey );
}