Skip to content
Permalink
Browse files

Make UserType function parameters nullable in BoxedStringType (#990)

  • Loading branch information...
hamdanjaveed authored and adrw committed May 16, 2019
1 parent f382938 commit c96f59ee14edd4c7759adbca572e8367dc5b0b7b
@@ -38,11 +38,11 @@ internal class BoxedStringType<T : Any> private constructor(
) : UserType {
override fun hashCode(x: Any) = x.hashCode()

override fun deepCopy(value: Any) = value
override fun deepCopy(value: Any?) = value

override fun replace(original: Any, target: Any, owner: Any?) = original

override fun equals(x: Any, y: Any) = x == y
override fun equals(x: Any?, y: Any?) = x == y

override fun returnedClass() = constructor.returnType.javaClass

@@ -29,17 +29,37 @@ class BoxedStringColumnTest {
@Test
fun happyPath() {
val abcToken = GoodLuckToken("abc")
val abcOptionalToken = GoodLuckToken("abc optional")

val defToken = GoodLuckToken("def")
val defOptionalToken = GoodLuckToken("def optional")
transacter.transaction { session ->
session.save(DbTextToken("abc", abcToken))
session.save(DbTextToken("def", defToken))
session.save(DbTextToken("abc", abcToken, abcOptionalToken))
session.save(DbTextToken("def", defToken, defOptionalToken))
}
transacter.transaction { session ->
val textHash = queryFactory.newQuery(TextTokenQuery::class)
.token(abcToken)
.uniqueResult(session)!!
assertThat(textHash.text).isEqualTo("abc")
assertThat(textHash.token).isEqualTo(abcToken)
assertThat(textHash.optional_token).isEqualTo(abcOptionalToken)
}
}

@Test
fun nullOptionalToken() {
val abcToken = GoodLuckToken("abc")
transacter.transaction { session ->
session.save(DbTextToken("abc", abcToken))
}
transacter.transaction { session ->
val textHash = queryFactory.newQuery(TextTokenQuery::class)
.token(abcToken)
.uniqueResult(session)!!
assertThat(textHash.text).isEqualTo("abc")
assertThat(textHash.token).isEqualTo(abcToken)
assertThat(textHash.optional_token).isNull()
}
}

@@ -120,9 +140,13 @@ class BoxedStringColumnTest {
@Column(nullable = false)
lateinit var token: GoodLuckToken

constructor(text: String, token: GoodLuckToken) : this() {
@Column
var optional_token: GoodLuckToken? = null

constructor(text: String, token: GoodLuckToken, optionalToken: GoodLuckToken? = null) : this() {
this.text = text
this.token = token
this.optional_token = optionalToken
}
}

@@ -2,5 +2,6 @@ CREATE TABLE text_tokens(
id bigint NOT NULL PRIMARY KEY AUTO_INCREMENT,
text varchar(255) NOT NULL,
token varchar(32) NOT NULL COLLATE utf8_bin,
optional_token varchar(32) NULL DEFAULT NULL COLLATE utf8_bin,
UNIQUE KEY `unq_token` (`token`)
);

0 comments on commit c96f59e

Please sign in to comment.
You can’t perform that action at this time.