Skip to content

Commit 5d1ebed

Browse files
committed
HHH-8362 InformixUniqueDelegate
Conflicts: hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java
1 parent d596ea1 commit 5d1ebed

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
import org.hibernate.MappingException;
2929
import org.hibernate.dialect.function.VarArgsSQLFunction;
30+
import org.hibernate.dialect.unique.InformixUniqueDelegate;
31+
import org.hibernate.dialect.unique.UniqueDelegate;
3032
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
3133
import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
3234
import org.hibernate.internal.util.JdbcExceptionHelper;
@@ -41,6 +43,8 @@
4143
* @author Steve Molitor
4244
*/
4345
public class InformixDialect extends Dialect {
46+
47+
private final UniqueDelegate uniqueDelegate;
4448

4549
/**
4650
* Creates new <code>InformixDialect</code> instance. Sets up the JDBC /
@@ -72,6 +76,8 @@ public InformixDialect() {
7276
registerColumnType(Types.VARCHAR, 32739, "lvarchar($l)");
7377

7478
registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "(", "||", ")" ) );
79+
80+
uniqueDelegate = new InformixUniqueDelegate( this );
7581
}
7682

7783
public String getAddColumnString() {
@@ -270,5 +276,9 @@ public String getCreateTemporaryTableString() {
270276
public String getCreateTemporaryTablePostfix() {
271277
return "with no log";
272278
}
273-
279+
280+
@Override
281+
public UniqueDelegate getUniqueDelegate() {
282+
return uniqueDelegate;
283+
}
274284
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* JBoss, Home of Professional Open Source
5+
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
6+
* as indicated by the @authors tag. All rights reserved.
7+
* See the copyright.txt in the distribution for a
8+
* full listing of individual contributors.
9+
*
10+
* This copyrighted material is made available to anyone wishing to use,
11+
* modify, copy, or redistribute it subject to the terms and conditions
12+
* of the GNU Lesser General Public License, v. 2.1.
13+
* This program is distributed in the hope that it will be useful, but WITHOUT A
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
* You should have received a copy of the GNU Lesser General Public License,
17+
* v.2.1 along with this distribution; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*/
21+
package org.hibernate.dialect.unique;
22+
23+
import org.hibernate.dialect.Dialect;
24+
import org.hibernate.metamodel.relational.UniqueKey;
25+
26+
/**
27+
* Informix requires the constraint name to come last on the alter table.
28+
*
29+
* @author Brett Meyer
30+
*/
31+
public class InformixUniqueDelegate extends DefaultUniqueDelegate {
32+
33+
public InformixUniqueDelegate( Dialect dialect ) {
34+
super( dialect );
35+
}
36+
37+
@Override
38+
public String applyUniquesOnAlter( org.hibernate.mapping.UniqueKey uniqueKey,
39+
String defaultCatalog, String defaultSchema ) {
40+
return new StringBuilder( "alter table " )
41+
.append( uniqueKey.getTable().getQualifiedName(
42+
dialect, defaultCatalog, defaultSchema ) )
43+
.append( " add constraint " )
44+
.append( uniqueConstraintSql( uniqueKey ) )
45+
.append( " constraint " )
46+
.append( uniqueKey.getName() )
47+
.toString();
48+
}
49+
50+
@Override
51+
public String applyUniquesOnAlter( UniqueKey uniqueKey ) {
52+
return new StringBuilder( "alter table " )
53+
.append( uniqueKey.getTable().getQualifiedName( dialect ) )
54+
.append( " add constraint " )
55+
.append( uniqueConstraintSql( uniqueKey ) )
56+
.append( " constraint " )
57+
.append( uniqueKey.getName() )
58+
.toString();
59+
}
60+
}

0 commit comments

Comments
 (0)