Skip to content

Commit 40aaaa9

Browse files
committed
HHH-8149 Revert HHH-7797 in 4.1.x
1 parent 5dd2203 commit 40aaaa9

File tree

23 files changed

+283
-632
lines changed

23 files changed

+283
-632
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import java.util.TreeMap;
5151
import java.util.jar.JarFile;
5252
import java.util.zip.ZipEntry;
53-
5453
import javax.persistence.Embeddable;
5554
import javax.persistence.Entity;
5655
import javax.persistence.MapsId;
@@ -59,6 +58,10 @@
5958
import org.dom4j.Document;
6059
import org.dom4j.DocumentException;
6160
import org.dom4j.Element;
61+
import org.jboss.logging.Logger;
62+
import org.xml.sax.EntityResolver;
63+
import org.xml.sax.InputSource;
64+
6265
import org.hibernate.AnnotationException;
6366
import org.hibernate.DuplicateMappingException;
6467
import org.hibernate.EmptyInterceptor;
@@ -142,9 +145,6 @@
142145
import org.hibernate.type.TypeResolver;
143146
import org.hibernate.usertype.CompositeUserType;
144147
import org.hibernate.usertype.UserType;
145-
import org.jboss.logging.Logger;
146-
import org.xml.sax.EntityResolver;
147-
import org.xml.sax.InputSource;
148148

149149
/**
150150
* An instance of <tt>Configuration</tt> allows the application
@@ -1045,15 +1045,17 @@ public String[] generateSchemaCreationScript(Dialect dialect) throws HibernateEx
10451045
Table table = (Table) iter.next();
10461046
if ( table.isPhysicalTable() ) {
10471047

1048-
Iterator subIter = table.getUniqueKeyIterator();
1049-
while ( subIter.hasNext() ) {
1050-
UniqueKey uk = (UniqueKey) subIter.next();
1051-
String constraintString = uk.sqlCreateString( dialect, mapping, defaultCatalog, defaultSchema );
1052-
if (constraintString != null) script.add( constraintString );
1048+
if ( !dialect.supportsUniqueConstraintInCreateAlterTable() ) {
1049+
Iterator subIter = table.getUniqueKeyIterator();
1050+
while ( subIter.hasNext() ) {
1051+
UniqueKey uk = (UniqueKey) subIter.next();
1052+
String constraintString = uk.sqlCreateString( dialect, mapping, defaultCatalog, defaultSchema );
1053+
if (constraintString != null) script.add( constraintString );
1054+
}
10531055
}
10541056

10551057

1056-
subIter = table.getIndexIterator();
1058+
Iterator subIter = table.getIndexIterator();
10571059
while ( subIter.hasNext() ) {
10581060
Index index = (Index) subIter.next();
10591061
script.add(
@@ -1224,6 +1226,15 @@ public String[] generateSchemaUpdateScript(Dialect dialect, DatabaseMetadata dat
12241226
)
12251227
);
12261228
}
1229+
1230+
//broken, 'cos we don't generate these with names in SchemaExport
1231+
// subIter = table.getUniqueKeyIterator();
1232+
// while ( subIter.hasNext() ) {
1233+
// UniqueKey uk = (UniqueKey) subIter.next();
1234+
// if ( tableInfo==null || tableInfo.getIndexMetadata( uk.getFilterName() ) == null ) {
1235+
// script.add( uk.sqlCreateString(dialect, mapping) );
1236+
// }
1237+
// }
12271238
}
12281239
}
12291240

@@ -1531,6 +1542,7 @@ private void processEndOfQueue(List<FkSecondPass> endOfQueueFkSecondPasses) {
15311542
private void buildUniqueKeyFromColumnNames(Table table, String keyName, String[] columnNames) {
15321543
keyName = normalizer.normalizeIdentifierQuoting( keyName );
15331544

1545+
UniqueKey uc;
15341546
int size = columnNames.length;
15351547
Column[] columns = new Column[size];
15361548
Set<Column> unbound = new HashSet<Column>();
@@ -1547,10 +1559,10 @@ private void buildUniqueKeyFromColumnNames(Table table, String keyName, String[]
15471559
unboundNoLogical.add( new Column( column ) );
15481560
}
15491561
}
1550-
UniqueKey uk = table.getOrCreateUniqueKey( keyName );
15511562
for ( Column column : columns ) {
15521563
if ( table.containsColumn( column ) ) {
1553-
uk.addColumn( column );
1564+
uc = table.getOrCreateUniqueKey( keyName );
1565+
uc.addColumn( table.getColumn( column ) );
15541566
unbound.remove( column );
15551567
}
15561568
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ public boolean qualifyIndexName() {
401401
return false;
402402
}
403403

404+
public boolean supportsUnique() {
405+
// Does this dialect support the UNIQUE column syntax?
406+
return true;
407+
}
408+
404409
/**
405410
* The syntax used to add a foreign key constraint to a table.
406411
*

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@
3030

3131
import org.hibernate.JDBCException;
3232
import org.hibernate.cfg.Environment;
33+
import org.hibernate.dialect.function.AnsiTrimEmulationFunction;
3334
import org.hibernate.dialect.function.AvgWithArgumentCastFunction;
3435
import org.hibernate.dialect.function.NoArgSQLFunction;
3536
import org.hibernate.dialect.function.SQLFunctionTemplate;
3637
import org.hibernate.dialect.function.StandardSQLFunction;
3738
import org.hibernate.dialect.function.VarArgsSQLFunction;
38-
import org.hibernate.dialect.unique.DB2UniqueDelegate;
39-
import org.hibernate.dialect.unique.UniqueDelegate;
4039
import org.hibernate.exception.LockTimeoutException;
4140
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
4241
import org.hibernate.internal.util.JdbcExceptionHelper;
@@ -50,8 +49,6 @@
5049
* @author Gavin King
5150
*/
5251
public class DB2Dialect extends Dialect {
53-
54-
private final UniqueDelegate uniqueDelegate;
5552

5653
public DB2Dialect() {
5754
super();
@@ -178,8 +175,6 @@ public DB2Dialect() {
178175
registerKeyword( "only" );
179176

180177
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
181-
182-
uniqueDelegate = new DB2UniqueDelegate( this );
183178
}
184179
@Override
185180
public String getLowercaseFunction() {
@@ -284,6 +279,10 @@ public boolean supportsOuterJoinForUpdate() {
284279
return false;
285280
}
286281
@Override
282+
public boolean supportsNotNullUnique() {
283+
return false;
284+
}
285+
@Override
287286
public boolean supportsExistsInSelect() {
288287
return false;
289288
}
@@ -458,11 +457,6 @@ public JDBCException convert(SQLException sqlException, String message, String s
458457
};
459458
}
460459

461-
@Override
462-
public UniqueDelegate getUniqueDelegate() {
463-
return uniqueDelegate;
464-
}
465-
466460
@Override
467461
public String getNotExpression( String expression ) {
468462
return "not (" + expression + ")";

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

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858
import org.hibernate.dialect.lock.SelectLockingStrategy;
5959
import org.hibernate.dialect.pagination.LegacyLimitHandler;
6060
import org.hibernate.dialect.pagination.LimitHandler;
61-
import org.hibernate.dialect.unique.DefaultUniqueDelegate;
62-
import org.hibernate.dialect.unique.UniqueDelegate;
6361
import org.hibernate.engine.jdbc.LobCreator;
6462
import org.hibernate.engine.spi.RowSelection;
6563
import org.hibernate.engine.spi.SessionImplementor;
@@ -117,8 +115,6 @@ public abstract class Dialect implements ConversionContext {
117115
private final Properties properties = new Properties();
118116
private final Map<String, SQLFunction> sqlFunctions = new HashMap<String, SQLFunction>();
119117
private final Set<String> sqlKeywords = new HashSet<String>();
120-
121-
private final UniqueDelegate uniqueDelegate;
122118

123119

124120
// constructors and factory methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -207,8 +203,6 @@ protected Dialect() {
207203
registerHibernateType( Types.BLOB, StandardBasicTypes.BLOB.getName() );
208204
registerHibernateType( Types.CLOB, StandardBasicTypes.CLOB.getName() );
209205
registerHibernateType( Types.REAL, StandardBasicTypes.FLOAT.getName() );
210-
211-
uniqueDelegate = new DefaultUniqueDelegate( this );
212206
}
213207

214208
/**
@@ -1834,6 +1828,23 @@ public boolean qualifyIndexName() {
18341828
return true;
18351829
}
18361830

1831+
/**
1832+
* Does this dialect support the <tt>UNIQUE</tt> column syntax?
1833+
*
1834+
* @return boolean
1835+
*/
1836+
public boolean supportsUnique() {
1837+
return true;
1838+
}
1839+
1840+
/**
1841+
* Does this dialect support adding Unique constraints via create and alter table ?
1842+
* @return boolean
1843+
*/
1844+
public boolean supportsUniqueConstraintInCreateAlterTable() {
1845+
return true;
1846+
}
1847+
18371848
/**
18381849
* The syntax used to add a column to a table (optional).
18391850
*
@@ -1899,6 +1910,16 @@ public String getAddPrimaryKeyConstraintString(String constraintName) {
18991910
return " add constraint " + constraintName + " primary key ";
19001911
}
19011912

1913+
/**
1914+
* The syntax used to add a unique constraint to a table.
1915+
*
1916+
* @param constraintName The name of the unique constraint.
1917+
* @return The "add unique" fragment
1918+
*/
1919+
public String getAddUniqueConstraintString(String constraintName) {
1920+
return " add constraint " + constraintName + " unique ";
1921+
}
1922+
19021923
public boolean hasSelfReferentialForeignKeyBug() {
19031924
return false;
19041925
}
@@ -1968,6 +1989,10 @@ public boolean supportsCascadeDelete() {
19681989
return true;
19691990
}
19701991

1992+
public boolean supportsNotNullUnique() {
1993+
return true;
1994+
}
1995+
19711996
/**
19721997
* Completely optional cascading drop clause
19731998
*
@@ -2320,56 +2345,7 @@ public boolean useFollowOnLocking() {
23202345
return false;
23212346
}
23222347

2323-
public UniqueDelegate getUniqueDelegate() {
2324-
return uniqueDelegate;
2325-
}
2326-
23272348
public String getNotExpression( String expression ) {
23282349
return "not " + expression;
23292350
}
2330-
2331-
/**
2332-
* Does this dialect support the <tt>UNIQUE</tt> column syntax?
2333-
*
2334-
* @return boolean
2335-
*
2336-
* @deprecated {@link #getUniqueDelegate()} should be overridden instead.
2337-
*/
2338-
@Deprecated
2339-
public boolean supportsUnique() {
2340-
return true;
2341-
}
2342-
2343-
/**
2344-
* Does this dialect support adding Unique constraints via create and alter table ?
2345-
*
2346-
* @return boolean
2347-
*
2348-
* @deprecated {@link #getUniqueDelegate()} should be overridden instead.
2349-
*/
2350-
@Deprecated
2351-
public boolean supportsUniqueConstraintInCreateAlterTable() {
2352-
return true;
2353-
}
2354-
2355-
/**
2356-
* The syntax used to add a unique constraint to a table.
2357-
*
2358-
* @param constraintName The name of the unique constraint.
2359-
* @return The "add unique" fragment
2360-
*
2361-
* @deprecated {@link #getUniqueDelegate()} should be overridden instead.
2362-
*/
2363-
@Deprecated
2364-
public String getAddUniqueConstraintString(String constraintName) {
2365-
return " add constraint " + constraintName + " unique ";
2366-
}
2367-
2368-
/**
2369-
* @deprecated {@link #getUniqueDelegate()} should be overridden instead.
2370-
*/
2371-
@Deprecated
2372-
public boolean supportsNotNullUnique() {
2373-
return true;
2374-
}
23752351
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ public String getForUpdateString() {
216216
return " for update";
217217
}
218218

219+
public boolean supportsUnique() {
220+
return true;
221+
}
222+
219223
public boolean supportsLimit() {
220224
return true;
221225
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ public String getForUpdateString() {
246246
return "";
247247
}
248248

249+
public boolean supportsUnique() {
250+
return false;
251+
}
252+
249253
public boolean supportsLimit() {
250254
return true;
251255
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ public boolean useMaxForLimit() {
306306
return true;
307307
}
308308

309+
/**
310+
* Ingres explicitly needs "unique not null", because "with null" is default
311+
*/
312+
public boolean supportsNotNullUnique() {
313+
return false;
314+
}
315+
309316
/**
310317
* Does this dialect support temporary tables?
311318
*/

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ public String getForUpdateString() {
240240
return ""; // Original Dialect.java returns " for update";
241241
}
242242

243+
/**
244+
* RDMS does not support adding Unique constraints via create and alter table.
245+
*/
246+
public boolean supportsUniqueConstraintInCreateAlterTable() {
247+
return true;
248+
}
249+
243250
// Verify the state of this new method in Hibernate 3.0 Dialect.java
244251
/**
245252
* RDMS does not support Cascade Deletes.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ public boolean supportsExpectedLobUsagePattern() {
422422
return false;
423423
}
424424

425+
public boolean supportsUniqueConstraintInCreateAlterTable() {
426+
return false;
427+
}
428+
425429
public String getCrossJoinSeparator() {
426430
return ", ";
427431
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ public boolean dropConstraints() {
102102
public boolean qualifyIndexName() {
103103
return false;
104104
}
105+
106+
public boolean supportsUnique() {
107+
return false;
108+
}
109+
110+
public boolean supportsUniqueConstraintInCreateAlterTable() {
111+
return false;
112+
}
105113

106114
public String getAddColumnString() {
107115
return "add";

0 commit comments

Comments
 (0)