mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 06:45:21 +00:00
DB2. Support for unique indices with null columns
(cherry picked from commit 23a5d577a6)
This commit is contained in:
1 parent
94ae513d85
commit
f2e04d9fbf
1 file changed
+15
-3
+15
-3
@@ -24,10 +24,22 @@ public class DB2Ddl extends PlatformDdl {
|
|||||||
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) {
|
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) {
|
||||||
if (nullableColumns == null || nullableColumns.length == 0) {
|
if (nullableColumns == null || nullableColumns.length == 0) {
|
||||||
return super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
|
return super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
|
||||||
} else {
|
}
|
||||||
// Hmm: Complex workaround: https://www.ibm.com/developerworks/mydeveloperworks/blogs/SQLTips4DB2LUW/entry/unique_where_not_null_indexes26?lang=en
|
|
||||||
return "-- NOT SUPPORTED " + super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
|
if (uqName == null) {
|
||||||
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
|
StringBuilder sb = new StringBuilder("create unique index ");
|
||||||
|
sb.append(uqName).append(" on ").append(tableName).append('(');
|
||||||
|
|
||||||
|
for (int i = 0; i < columns.length; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
sb.append(",");
|
||||||
|
}
|
||||||
|
sb.append(columns[i]);
|
||||||
|
}
|
||||||
|
sb.append(") exclude null keys");
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user