From e7f0a039fb66378af6f1edae2b48b1a00feccac5 Mon Sep 17 00:00:00 2001 From: Ali Lozano Date: Sun, 5 Apr 2020 13:30:21 -0500 Subject: [PATCH 1/3] Implement Equals in ColumnTypes. --- .../org/jetbrains/exposed/sql/ColumnType.kt | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt index f1a38b371f..7d6a15ea69 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt @@ -70,6 +70,11 @@ interface IColumnType { */ abstract class ColumnType(override var nullable: Boolean = false) : IColumnType { override fun toString(): String = sqlType() + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + return true + } } /** @@ -99,6 +104,17 @@ class AutoIncColumnType( } override fun sqlType(): String = resolveAutoIncType(delegate) + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as AutoIncColumnType + + if (delegate != other.delegate) return false + + return true + } } /** Returns `true` if this is an auto-increment column, `false` otherwise. */ @@ -137,6 +153,18 @@ class EntityIDColumnType>(val idColumn: Column) : ColumnTyp }, idColumn.table as IdTable ) + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as EntityIDColumnType<*> + + if (idColumn != other.idColumn) return false + + return true + } + } // Numeric columns @@ -224,6 +252,19 @@ class DecimalColumnType( is Int -> value.toBigDecimal() else -> error("Unexpected value of type Double: $value of ${value::class.qualifiedName}") }.setScale(scale, RoundingMode.HALF_EVEN) + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as DecimalColumnType + + if (precision != other.precision) return false + if (scale != other.scale) return false + + return true + } } // Character columns @@ -266,6 +307,17 @@ abstract class StringColumnType( append('\'') } + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as StringColumnType + + if (collate != other.collate) return false + + return true + } + companion object { private val charactersToEscape = mapOf( '\'' to "\'\'", @@ -274,6 +326,9 @@ abstract class StringColumnType( '\n' to "\\n" ) } + + + } /** @@ -290,6 +345,18 @@ open class VarCharColumnType( append(" COLLATE ${escape(collate)}") } } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as VarCharColumnType + + if (colLength != other.colLength) return false + + return true + } } /** @@ -332,6 +399,23 @@ class BinaryColumnType( val length: Int ) : BasicBinaryColumnType() { override fun sqlType(): String = currentDialect.dataTypeProvider.binaryType(length) + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as BinaryColumnType + + if (length != other.length) return false + + return true + } + + override fun hashCode(): Int { + return length + } + } /** @@ -446,6 +530,18 @@ class EnumerationColumnType>( is Enum<*> -> value.ordinal else -> error("$value of ${value::class.qualifiedName} is not valid for enum ${klass.simpleName}") } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as EnumerationColumnType<*> + + if (klass != other.klass) return false + + return true + } } /** @@ -467,6 +563,18 @@ class EnumerationNameColumnType>( is Enum<*> -> value.name else -> error("$value of ${value::class.qualifiedName} is not valid for enum ${klass.qualifiedName}") } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as EnumerationNameColumnType<*> + + if (klass != other.klass) return false + + return true + } } // Date/Time columns From 5fb7467ff8da4be5f9abe5fe6436fb2d00ae0918 Mon Sep 17 00:00:00 2001 From: Ali Lozano Date: Tue, 7 Apr 2020 14:38:56 -0500 Subject: [PATCH 2/3] Add nullable field to equals method of ColumnType --- .../src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt index 7d6a15ea69..5efc456357 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt @@ -73,6 +73,10 @@ abstract class ColumnType(override var nullable: Boolean = false) : IColumnType override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false + + other as ColumnType + + if (nullable != other.nullable) return false return true } } From dbf7a992f696cd42a88d7fae66ccdcb3a29ff538 Mon Sep 17 00:00:00 2001 From: Ali Lozano Date: Mon, 13 Apr 2020 12:57:11 -0500 Subject: [PATCH 3/3] Added super.equals in StringColumnType --- .../src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt index 5efc456357..00a56b0ed7 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt @@ -314,6 +314,7 @@ abstract class StringColumnType( override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false other as StringColumnType