提交 859576ee authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add enum UniqueIndexNullsHandling and fix a typo

上级 cd69a288
...@@ -22,6 +22,29 @@ public class Mode { ...@@ -22,6 +22,29 @@ public class Mode {
REGULAR, DB2, Derby, MSSQLServer, HSQLDB, MySQL, Oracle, PostgreSQL, Ignite, REGULAR, DB2, Derby, MSSQLServer, HSQLDB, MySQL, Oracle, PostgreSQL, Ignite,
} }
/**
* Determines how rows with {@code NULL} values in indexed columns are handled
* in unique indexes.
*/
public enum UniqueIndexNullsHandling {
/**
* Multiple identical indexed columns with at least one {@code NULL} value are
* allowed in unique index.
*/
ALLOW_DUPLICATES_WITH_ANY_NULL,
/**
* Multiple identical indexed columns with all {@code NULL} values are allowed
* in unique index.
*/
ALLOW_DUPLICATES_WITH_ALL_NULLS,
/**
* Multiple identical indexed columns are not allowed in unique index.
*/
FORBID_ANY_DUPLICATES;
}
private static final HashMap<String, Mode> MODES = New.hashMap(); private static final HashMap<String, Mode> MODES = New.hashMap();
// Modes are also documented in the features section // Modes are also documented in the features section
...@@ -87,16 +110,10 @@ public class Mode { ...@@ -87,16 +110,10 @@ public class Mode {
public boolean systemColumns; public boolean systemColumns;
/** /**
* <ul> * Determines how rows with {@code NULL} values in indexed columns are handled
* <li>If {@code 0}, multiple identical indexed columns with at least one * in unique indexes.
* {@code NULL} value are allowed in unique index.</li>
* <li>If {@code 1}, multiple identical indexed columns with all {@code NULL}
* values are allowed in unique index.</li>
* <li>If {@code 2}, multiple identical indexed columns are not allowed in
* unique index.</li>
* </ul>
*/ */
public byte uniquieIndexNullsHandling; public UniqueIndexNullsHandling uniqueIndexNullsHandling = UniqueIndexNullsHandling.ALLOW_DUPLICATES_WITH_ANY_NULL;
/** /**
* Empty strings are treated like NULL values. Useful for Oracle emulation. * Empty strings are treated like NULL values. Useful for Oracle emulation.
...@@ -207,7 +224,7 @@ public class Mode { ...@@ -207,7 +224,7 @@ public class Mode {
mode = new Mode(ModeEnum.Derby.name()); mode = new Mode(ModeEnum.Derby.name());
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.uniquieIndexNullsHandling = 2; mode.uniqueIndexNullsHandling = UniqueIndexNullsHandling.FORBID_ANY_DUPLICATES;
mode.supportOffsetFetch = true; mode.supportOffsetFetch = true;
mode.sysDummy1 = true; mode.sysDummy1 = true;
mode.isolationLevelInSelectOrInsertStatement = true; mode.isolationLevelInSelectOrInsertStatement = true;
...@@ -219,7 +236,7 @@ public class Mode { ...@@ -219,7 +236,7 @@ public class Mode {
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.convertOnlyToSmallerScale = true; mode.convertOnlyToSmallerScale = true;
mode.nullConcatIsNull = true; mode.nullConcatIsNull = true;
mode.uniquieIndexNullsHandling = 2; mode.uniqueIndexNullsHandling = UniqueIndexNullsHandling.FORBID_ANY_DUPLICATES;
mode.allowPlusForStringConcat = true; mode.allowPlusForStringConcat = true;
// HSQLDB does not support client info properties. See // HSQLDB does not support client info properties. See
// http://hsqldb.org/doc/apidocs/ // http://hsqldb.org/doc/apidocs/
...@@ -231,7 +248,7 @@ public class Mode { ...@@ -231,7 +248,7 @@ public class Mode {
mode = new Mode(ModeEnum.MSSQLServer.name()); mode = new Mode(ModeEnum.MSSQLServer.name());
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.squareBracketQuotedNames = true; mode.squareBracketQuotedNames = true;
mode.uniquieIndexNullsHandling = 2; mode.uniqueIndexNullsHandling = UniqueIndexNullsHandling.FORBID_ANY_DUPLICATES;
mode.allowPlusForStringConcat = true; mode.allowPlusForStringConcat = true;
mode.swapConvertFunctionParameters = true; mode.swapConvertFunctionParameters = true;
mode.supportPoundSymbolForColumnNames = true; mode.supportPoundSymbolForColumnNames = true;
...@@ -259,7 +276,7 @@ public class Mode { ...@@ -259,7 +276,7 @@ public class Mode {
mode = new Mode(ModeEnum.Oracle.name()); mode = new Mode(ModeEnum.Oracle.name());
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.convertOnlyToSmallerScale = true; mode.convertOnlyToSmallerScale = true;
mode.uniquieIndexNullsHandling = 1; mode.uniqueIndexNullsHandling = UniqueIndexNullsHandling.ALLOW_DUPLICATES_WITH_ALL_NULLS;
mode.treatEmptyStringsAsNull = true; mode.treatEmptyStringsAsNull = true;
mode.regexpReplaceBackslashReferences = true; mode.regexpReplaceBackslashReferences = true;
mode.supportPoundSymbolForColumnNames = true; mode.supportPoundSymbolForColumnNames = true;
......
...@@ -310,35 +310,24 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -310,35 +310,24 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
* {@code false otherwise} * {@code false otherwise}
*/ */
protected boolean mayHaveDuplicates(SearchRow searchRow) { protected boolean mayHaveDuplicates(SearchRow searchRow) {
int mode = database.getMode().uniquieIndexNullsHandling; switch (database.getMode().uniqueIndexNullsHandling) {
/* case ALLOW_DUPLICATES_WITH_ANY_NULL:
* Multiple identical indexed columns with at least one NULL value are allowed
* in unique index.
*/
if (mode == 0) {
for (int index : columnIds) { for (int index : columnIds) {
if (searchRow.getValue(index) == ValueNull.INSTANCE) { if (searchRow.getValue(index) == ValueNull.INSTANCE) {
return true; return true;
} }
} }
return false; return false;
} case ALLOW_DUPLICATES_WITH_ALL_NULLS:
/*
* Multiple identical indexed columns with all {@code NULL} values are allowed
* in unique index.
*/
if (mode == 1) {
for (int index : columnIds) { for (int index : columnIds) {
if (searchRow.getValue(index) != ValueNull.INSTANCE) { if (searchRow.getValue(index) != ValueNull.INSTANCE) {
return false; return false;
} }
} }
return true; return true;
default:
return false;
} }
/*
* Multiple identical indexed columns are not allowed in unique index.
*/
return false;
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论