From 5780ef76c2ea2f50df076bf6aad2a6bc2a70caa1 Mon Sep 17 00:00:00 2001 From: "jonghyon.s" Date: Sat, 30 Mar 2024 13:56:51 +0900 Subject: [PATCH] refactor: remove duplicated code in support modules --- .../javax/JpqlEntityManagerUtils.kt | 67 +++------ .../extension/EntityManagerExtensions.kt | 16 +-- .../javax/JpqlEntityManagerUtilsTest.kt | 91 +++--------- .../extension/EntityManagerExtensionsTest.kt | 13 +- .../eclipselink/JpqlEntityManagerUtils.kt | 67 +++------ .../extension/EntityManagerExtensions.kt | 16 +-- .../eclipselink/JpqlEntityManagerUtilsTest.kt | 87 ++---------- .../extension/EntityManagerExtensionsTest.kt | 13 +- .../hibernate/JpqlEntityManagerUtils.kt | 67 +++------ .../extension/EntityManagerExtensions.kt | 22 ++- .../hibernate/JpqlEntityManagerUtilsTest.kt | 91 +++--------- .../extension/EntityManagerExtensionsTest.kt | 13 +- .../reactive/JpqlMutinySessionUtils.kt | 63 +++------ .../JpqlMutinyStatelessSessionUtils.kt | 63 +++------ .../reactive/JpqlStageSessionUtils.kt | 63 +++------ .../JpqlStageStatelessSessionUtils.kt | 63 +++------ .../extension/MutinySessionExtensions.kt | 16 +-- .../MutinyStatelessSessionExtensions.kt | 16 +-- .../extension/StageSessionExtensions.kt | 16 +-- .../StageStatelessSessionExtensions.kt | 16 +-- .../reactive/JpqlMutinySessionUtilsTest.kt | 131 +++++------------- .../JpqlMutinyStatelessSessionUtilsTest.kt | 131 +++++------------- .../reactive/JpqlStageSessionUtilsTest.kt | 131 +++++------------- .../JpqlStageStatelessSessionUtilsTest.kt | 131 +++++------------- .../extension/MutinySessionExtensionsTest.kt | 33 +++-- .../MutinyStatelessSessionExtensionsTest.kt | 34 +++-- .../extension/StageSessionExtensionsTest.kt | 33 +++-- .../StageStatelessSessionExtensionsTest.kt | 34 +++-- .../reactive/JpqlMutinySessionUtils.kt | 69 ++++----- .../JpqlMutinyStatelessSessionUtils.kt | 67 +++------ .../reactive/JpqlStageSessionUtils.kt | 69 ++++----- .../JpqlStageStatelessSessionUtils.kt | 67 +++------ .../extension/MutinySessionExtensions.kt | 16 +-- .../MutinyStatelessSessionExtensions.kt | 17 +-- .../extension/StageSessionExtensions.kt | 16 +-- .../StageStatelessSessionExtensions.kt | 17 +-- .../reactive/JpqlMutinySessionUtilsTest.kt | 87 ++---------- .../JpqlMutinyStatelessSessionUtilsTest.kt | 131 +++++------------- .../reactive/JpqlStageSessionUtilsTest.kt | 87 ++---------- .../JpqlStageStatelessSessionUtilsTest.kt | 129 +++++------------ .../extension/MutinySessionExtensionsTest.kt | 21 ++- .../MutinyStatelessSessionExtensionsTest.kt | 34 +++-- .../extension/StageSessionExtensionsTest.kt | 21 ++- .../StageStatelessSessionExtensionsTest.kt | 34 +++-- .../hibernate/JpqlEntityManagerUtils.kt | 67 +++------ .../extension/EntityManagerExtensions.kt | 22 ++- .../hibernate/JpqlEntityManagerUtilsTest.kt | 87 ++---------- .../extension/EntityManagerExtensionsTest.kt | 13 +- .../extension/EntityManagerExtensions.kt | 2 +- .../jpa/extension/EntityManagerExtensions.kt | 14 +- 50 files changed, 899 insertions(+), 1725 deletions(-) diff --git a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt index a8b83226f..b01e863d5 100644 --- a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt +++ b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtils.kt @@ -1,11 +1,7 @@ package com.linecorp.kotlinjdsl.support.eclipselink.javax -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import javax.persistence.EntityManager import javax.persistence.Query import javax.persistence.TypedQuery @@ -14,87 +10,70 @@ import kotlin.reflect.KClass internal object JpqlEntityManagerUtils { fun createQuery( entityManager: EntityManager, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): TypedQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(entityManager, rendered, query.returnType) + return createQuery(entityManager, rendered.query, rendered.params, returnType.java) } fun createQuery( entityManager: EntityManager, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): TypedQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(entityManager, rendered, query.returnType) + return createQuery(entityManager, rendered.query, rendered.params, returnType.java) } - fun createQuery( + fun createQuery( entityManager: EntityManager, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(entityManager, rendered) + return createQuery(entityManager, rendered.query, rendered.params) } - fun createQuery( + fun createQuery( entityManager: EntityManager, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(entityManager, rendered) - } - - fun createQuery( - entityManager: EntityManager, - query: DeleteQuery, - context: RenderContext, - ): Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(entityManager, rendered) - } - - fun createQuery( - entityManager: EntityManager, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(entityManager, rendered) + return createQuery(entityManager, rendered.query, rendered.params) } private fun createQuery( entityManager: EntityManager, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): TypedQuery { - return entityManager.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return entityManager.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createQuery( entityManager: EntityManager, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Query { - return entityManager.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return entityManager.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Query, params: JpqlRenderedParams) { + private fun setParams(query: Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/extension/EntityManagerExtensions.kt b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/extension/EntityManagerExtensions.kt index 525272254..8a4cfdc68 100644 --- a/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/extension/EntityManagerExtensions.kt +++ b/support/eclipselink-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/extension/EntityManagerExtensions.kt @@ -11,26 +11,26 @@ import javax.persistence.Query import javax.persistence.TypedQuery /** - * Creates [javax.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [javax.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: SelectQuery, context: RenderContext, -): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, query.returnType, context) /** - * Creates [javax.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [javax.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [javax.persistence.Query] from the [UpdateQuery] and [RenderContext]. + * Creates a [javax.persistence.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -39,7 +39,7 @@ fun EntityManager.createQuery( ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) /** - * Creates [javax.persistence.Query] from the [UpdateQuery] and [RenderContext]. + * Creates a [javax.persistence.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -49,7 +49,7 @@ fun EntityManager.createQuery( ): Query = JpqlEntityManagerUtils.createQuery(this, query, queryParams, context) /** - * Creates [javax.persistence.Query] from the [DeleteQuery] and [RenderContext]. + * Creates a [javax.persistence.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -58,7 +58,7 @@ fun EntityManager.createQuery( ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) /** - * Creates [javax.persistence.Query] from the [DeleteQuery] and [RenderContext]. + * Creates a [javax.persistence.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( diff --git a/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtilsTest.kt b/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtilsTest.kt index d81395a13..0bc3a241f 100644 --- a/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtilsTest.kt +++ b/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/JpqlEntityManagerUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.eclipselink.javax -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -32,13 +30,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery - - @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery + private lateinit var query1: JpqlQuery<*> @MockK private lateinit var stringTypedQuery1: TypedQuery @@ -62,24 +54,22 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, context) + val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -87,25 +77,23 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, mapOf(queryParam1, queryParam2), context) + val actual = JpqlEntityManagerUtils + .createQuery(entityManager, query1, mapOf(queryParam1, queryParam2), String::class, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -113,54 +101,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { entityManager.createQuery(any()) } returns stringTypedQuery1 - every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 - - // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(stringTypedQuery1) - - verifySequence { - renderer.render(updateQuery1, context) - entityManager.createQuery(rendered1.query) - stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) - stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { entityManager.createQuery(any()) } returns stringTypedQuery1 - every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 - - // when - val actual = - JpqlEntityManagerUtils.createQuery(entityManager, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(stringTypedQuery1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - entityManager.createQuery(rendered1.query) - stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) - stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -169,13 +110,13 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery1, context) + val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) entityManager.createQuery(rendered1.query) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -183,7 +124,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -192,14 +133,14 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = - JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery1, mapOf(queryParam1, queryParam2), context) + val actual = JpqlEntityManagerUtils + .createQuery(entityManager, query1, mapOf(queryParam1, queryParam2), context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) diff --git a/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/extension/EntityManagerExtensionsTest.kt b/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/extension/EntityManagerExtensionsTest.kt index 07a84072d..f002c2157 100644 --- a/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/extension/EntityManagerExtensionsTest.kt +++ b/support/eclipselink-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/javax/extension/EntityManagerExtensionsTest.kt @@ -17,6 +17,7 @@ import org.junit.jupiter.api.extension.ExtendWith import javax.persistence.EntityManager import javax.persistence.Query import javax.persistence.TypedQuery +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class EntityManagerExtensionsTest : WithAssertions { @@ -53,8 +54,9 @@ class EntityManagerExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlEntityManagerUtils.createQuery(any(), any>(), any()) + JpqlEntityManagerUtils.createQuery(any(), any>(), any>(), any()) } returns typedQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = entityManager.createQuery(selectQuery1, context) @@ -63,7 +65,8 @@ class EntityManagerExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(typedQuery1) verifySequence { - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, context) + selectQuery1.returnType + JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, String::class, context) } } @@ -71,8 +74,9 @@ class EntityManagerExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlEntityManagerUtils.createQuery(any(), any>(), any(), any()) + JpqlEntityManagerUtils.createQuery(any(), any>(), any(), any>(), any()) } returns typedQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = entityManager.createQuery(selectQuery1, queryParams1, context) @@ -81,7 +85,8 @@ class EntityManagerExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(typedQuery1) verifySequence { - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, queryParams1, String::class, context) } } diff --git a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt index cea0efd0d..ab93bdbbc 100644 --- a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt +++ b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtils.kt @@ -1,11 +1,7 @@ package com.linecorp.kotlinjdsl.support.eclipselink -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import jakarta.persistence.EntityManager import jakarta.persistence.Query import jakarta.persistence.TypedQuery @@ -14,87 +10,70 @@ import kotlin.reflect.KClass internal object JpqlEntityManagerUtils { fun createQuery( entityManager: EntityManager, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): TypedQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(entityManager, rendered, query.returnType) + return createQuery(entityManager, rendered.query, rendered.params, returnType.java) } fun createQuery( entityManager: EntityManager, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): TypedQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(entityManager, rendered, query.returnType) + return createQuery(entityManager, rendered.query, rendered.params, returnType.java) } - fun createQuery( + fun createQuery( entityManager: EntityManager, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(entityManager, rendered) + return createQuery(entityManager, rendered.query, rendered.params) } - fun createQuery( + fun createQuery( entityManager: EntityManager, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(entityManager, rendered) - } - - fun createQuery( - entityManager: EntityManager, - query: DeleteQuery, - context: RenderContext, - ): Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(entityManager, rendered) - } - - fun createQuery( - entityManager: EntityManager, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(entityManager, rendered) + return createQuery(entityManager, rendered.query, rendered.params) } private fun createQuery( entityManager: EntityManager, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): TypedQuery { - return entityManager.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return entityManager.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createQuery( entityManager: EntityManager, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Query { - return entityManager.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return entityManager.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Query, params: JpqlRenderedParams) { + private fun setParams(query: Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/extension/EntityManagerExtensions.kt b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/extension/EntityManagerExtensions.kt index e85805c13..6b8518a22 100644 --- a/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/extension/EntityManagerExtensions.kt +++ b/support/eclipselink/src/main/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/extension/EntityManagerExtensions.kt @@ -11,26 +11,26 @@ import jakarta.persistence.Query import jakarta.persistence.TypedQuery /** - * Creates [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: SelectQuery, context: RenderContext, -): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, query.returnType, context) /** - * Creates [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [jakarta.persistence.Query] from the [UpdateQuery] and [RenderContext]. + * Creates a [jakarta.persistence.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -39,7 +39,7 @@ fun EntityManager.createQuery( ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) /** - * Creates [jakarta.persistence.Query] from the [UpdateQuery] and [RenderContext]. + * Creates a [jakarta.persistence.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -49,7 +49,7 @@ fun EntityManager.createQuery( ): Query = JpqlEntityManagerUtils.createQuery(this, query, queryParams, context) /** - * Creates [jakarta.persistence.Query] from the [DeleteQuery] and [RenderContext]. + * Creates a [jakarta.persistence.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -58,7 +58,7 @@ fun EntityManager.createQuery( ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) /** - * Creates [jakarta.persistence.Query] from the [DeleteQuery] and [RenderContext]. + * Creates a [jakarta.persistence.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( diff --git a/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtilsTest.kt b/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtilsTest.kt index 5c383befe..8f07778fc 100644 --- a/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtilsTest.kt +++ b/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/JpqlEntityManagerUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.eclipselink -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -32,13 +30,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery - - @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery + private lateinit var query1: JpqlQuery<*> @MockK private lateinit var stringTypedQuery1: TypedQuery @@ -62,24 +54,22 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, context) + val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -87,25 +77,23 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when val actual = JpqlEntityManagerUtils - .createQuery(entityManager, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(entityManager, query1, mapOf(queryParam1, queryParam2), String::class, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -113,54 +101,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { entityManager.createQuery(any()) } returns stringTypedQuery1 - every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 - - // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(stringTypedQuery1) - - verifySequence { - renderer.render(updateQuery1, context) - entityManager.createQuery(rendered1.query) - stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) - stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { entityManager.createQuery(any()) } returns stringTypedQuery1 - every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 - - // when - val actual = JpqlEntityManagerUtils - .createQuery(entityManager, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(stringTypedQuery1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - entityManager.createQuery(rendered1.query) - stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) - stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -169,13 +110,13 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery1, context) + val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) entityManager.createQuery(rendered1.query) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -183,7 +124,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -193,13 +134,13 @@ class JpqlEntityManagerUtilsTest : WithAssertions { // when val actual = JpqlEntityManagerUtils - .createQuery(entityManager, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(entityManager, query1, mapOf(queryParam1, queryParam2), context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) diff --git a/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/extension/EntityManagerExtensionsTest.kt b/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/extension/EntityManagerExtensionsTest.kt index 088d1fe60..a39bd8f87 100644 --- a/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/extension/EntityManagerExtensionsTest.kt +++ b/support/eclipselink/src/test/kotlin/com/linecorp/kotlinjdsl/support/eclipselink/extension/EntityManagerExtensionsTest.kt @@ -17,6 +17,7 @@ import org.assertj.core.api.WithAssertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class EntityManagerExtensionsTest : WithAssertions { @@ -53,8 +54,9 @@ class EntityManagerExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlEntityManagerUtils.createQuery(any(), any>(), any()) + JpqlEntityManagerUtils.createQuery(any(), any>(), any>(), any()) } returns typedQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = entityManager.createQuery(selectQuery1, context) @@ -63,7 +65,8 @@ class EntityManagerExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(typedQuery1) verifySequence { - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, context) + selectQuery1.returnType + JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, String::class, context) } } @@ -71,8 +74,9 @@ class EntityManagerExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlEntityManagerUtils.createQuery(any(), any>(), any(), any()) + JpqlEntityManagerUtils.createQuery(any(), any>(), any(), any>(), any()) } returns typedQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = entityManager.createQuery(selectQuery1, queryParams1, context) @@ -81,7 +85,8 @@ class EntityManagerExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(typedQuery1) verifySequence { - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, queryParams1, String::class, context) } } diff --git a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt index 74ab9149c..651b18f5a 100644 --- a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt +++ b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt @@ -2,12 +2,8 @@ package com.linecorp.kotlinjdsl.support.hibernate -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import javax.persistence.EntityManager import javax.persistence.Query import javax.persistence.TypedQuery @@ -16,87 +12,70 @@ import kotlin.reflect.KClass internal object JpqlEntityManagerUtils { fun createQuery( entityManager: EntityManager, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): TypedQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(entityManager, rendered, query.returnType) + return createQuery(entityManager, rendered.query, rendered.params, returnType.java) } fun createQuery( entityManager: EntityManager, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): TypedQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(entityManager, rendered, query.returnType) + return createQuery(entityManager, rendered.query, rendered.params, returnType.java) } - fun createQuery( + fun createQuery( entityManager: EntityManager, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(entityManager, rendered) + return createQuery(entityManager, rendered.query, rendered.params) } - fun createQuery( + fun createQuery( entityManager: EntityManager, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(entityManager, rendered) - } - - fun createQuery( - entityManager: EntityManager, - query: DeleteQuery, - context: RenderContext, - ): Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(entityManager, rendered) - } - - fun createQuery( - entityManager: EntityManager, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(entityManager, rendered) + return createQuery(entityManager, rendered.query, rendered.params) } private fun createQuery( entityManager: EntityManager, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): TypedQuery { - return entityManager.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return entityManager.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createQuery( entityManager: EntityManager, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Query { - return entityManager.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return entityManager.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Query, params: JpqlRenderedParams) { + private fun setParams(query: Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensions.kt b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensions.kt index 6082938a3..4bbe7dc93 100644 --- a/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensions.kt +++ b/support/hibernate-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensions.kt @@ -10,25 +10,37 @@ import javax.persistence.EntityManager import javax.persistence.Query import javax.persistence.TypedQuery +/** + * Creates a [javax.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: SelectQuery, context: RenderContext, -): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, query.returnType, context) +/** + * Creates a [javax.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, query.returnType, context) +/** + * Creates a [javax.persistence.Query] from the [UpdateQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: UpdateQuery, context: RenderContext, ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) +/** + * Creates a [javax.persistence.Query] from the [UpdateQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: UpdateQuery, @@ -36,12 +48,18 @@ fun EntityManager.createQuery( context: RenderContext, ): Query = JpqlEntityManagerUtils.createQuery(this, query, queryParams, context) +/** + * Creates a [javax.persistence.Query] from the [DeleteQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: DeleteQuery, context: RenderContext, ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) +/** + * Creates a [javax.persistence.Query] from the [DeleteQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: DeleteQuery, diff --git a/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt b/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt index 7b6dbf8e9..b67494ffe 100644 --- a/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt +++ b/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -32,13 +30,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery - - @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery + private lateinit var query1: JpqlQuery<*> @MockK private lateinit var stringTypedQuery1: TypedQuery @@ -62,24 +54,22 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, context) + val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -87,25 +77,23 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, mapOf(queryParam1, queryParam2), context) + val actual = JpqlEntityManagerUtils + .createQuery(entityManager, query1, mapOf(queryParam1, queryParam2), String::class, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -113,54 +101,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { entityManager.createQuery(any()) } returns stringTypedQuery1 - every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 - - // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(stringTypedQuery1) - - verifySequence { - renderer.render(updateQuery1, context) - entityManager.createQuery(rendered1.query) - stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) - stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { entityManager.createQuery(any()) } returns stringTypedQuery1 - every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 - - // when - val actual = - JpqlEntityManagerUtils.createQuery(entityManager, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(stringTypedQuery1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - entityManager.createQuery(rendered1.query) - stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) - stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -169,13 +110,13 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery1, context) + val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) entityManager.createQuery(rendered1.query) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -183,7 +124,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -192,14 +133,14 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = - JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery1, mapOf(queryParam1, queryParam2), context) + val actual = JpqlEntityManagerUtils + .createQuery(entityManager, query1, mapOf(queryParam1, queryParam2), context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) diff --git a/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensionsTest.kt b/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensionsTest.kt index 6d055bb44..582ef8a94 100644 --- a/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensionsTest.kt +++ b/support/hibernate-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensionsTest.kt @@ -17,6 +17,7 @@ import org.junit.jupiter.api.extension.ExtendWith import javax.persistence.EntityManager import javax.persistence.Query import javax.persistence.TypedQuery +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class EntityManagerExtensionsTest : WithAssertions { @@ -53,8 +54,9 @@ class EntityManagerExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlEntityManagerUtils.createQuery(any(), any>(), any()) + JpqlEntityManagerUtils.createQuery(any(), any>(), any>(), any()) } returns typedQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = entityManager.createQuery(selectQuery1, context) @@ -63,7 +65,8 @@ class EntityManagerExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(typedQuery1) verifySequence { - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, context) + selectQuery1.returnType + JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, String::class, context) } } @@ -71,8 +74,9 @@ class EntityManagerExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlEntityManagerUtils.createQuery(any(), any>(), any(), any()) + JpqlEntityManagerUtils.createQuery(any(), any>(), any(), any>(), any()) } returns typedQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = entityManager.createQuery(selectQuery1, queryParams1, context) @@ -81,7 +85,8 @@ class EntityManagerExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(typedQuery1) verifySequence { - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, queryParams1, String::class, context) } } diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt index 0c0e52bf3..6bc81ce75 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt @@ -1,98 +1,77 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import org.hibernate.reactive.mutiny.Mutiny import kotlin.reflect.KClass internal object JpqlMutinySessionUtils { fun createQuery( session: Mutiny.Session, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Mutiny.Session, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Mutiny.Session, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } fun createQuery( session: Mutiny.Session, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered) - } - - fun createQuery( - session: Mutiny.Session, - query: DeleteQuery, - context: RenderContext, - ): Mutiny.Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(session, rendered) - } - - fun createQuery( - session: Mutiny.Session, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Mutiny.Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } private fun createQuery( session: Mutiny.Session, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): Mutiny.Query { - return session.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return session.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createQuery( session: Mutiny.Session, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Mutiny.Query { - return session.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return session.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Mutiny.Query, params: JpqlRenderedParams) { + private fun setParams(query: Mutiny.Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt index 52025a1f5..0e63c7070 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt @@ -1,98 +1,77 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import org.hibernate.reactive.mutiny.Mutiny import kotlin.reflect.KClass internal object JpqlMutinyStatelessSessionUtils { fun createQuery( session: Mutiny.StatelessSession, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Mutiny.StatelessSession, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Mutiny.StatelessSession, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } fun createQuery( session: Mutiny.StatelessSession, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered) - } - - fun createQuery( - session: Mutiny.StatelessSession, - query: DeleteQuery, - context: RenderContext, - ): Mutiny.Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(session, rendered) - } - - fun createQuery( - session: Mutiny.StatelessSession, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Mutiny.Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } private fun createQuery( session: Mutiny.StatelessSession, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): Mutiny.Query { - return session.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return session.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createQuery( session: Mutiny.StatelessSession, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Mutiny.Query { - return session.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return session.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Mutiny.Query, params: JpqlRenderedParams) { + private fun setParams(query: Mutiny.Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt index 6b273cc11..e6d3b2db2 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt @@ -1,98 +1,77 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import org.hibernate.reactive.stage.Stage import kotlin.reflect.KClass internal object JpqlStageSessionUtils { fun createQuery( session: Stage.Session, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Stage.Session, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Stage.Session, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } fun createQuery( session: Stage.Session, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered) - } - - fun createQuery( - session: Stage.Session, - query: DeleteQuery, - context: RenderContext, - ): Stage.Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(session, rendered) - } - - fun createQuery( - session: Stage.Session, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Stage.Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } private fun createQuery( session: Stage.Session, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): Stage.Query { - return session.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return session.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createQuery( session: Stage.Session, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Stage.Query { - return session.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return session.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Stage.Query, params: JpqlRenderedParams) { + private fun setParams(query: Stage.Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt index c5fdac0c9..cb8f5e5dc 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt @@ -1,98 +1,77 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import org.hibernate.reactive.stage.Stage import kotlin.reflect.KClass internal object JpqlStageStatelessSessionUtils { fun createQuery( session: Stage.StatelessSession, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Stage.StatelessSession, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Stage.StatelessSession, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } fun createQuery( session: Stage.StatelessSession, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered) - } - - fun createQuery( - session: Stage.StatelessSession, - query: DeleteQuery, - context: RenderContext, - ): Stage.Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(session, rendered) - } - - fun createQuery( - session: Stage.StatelessSession, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Stage.Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } private fun createQuery( session: Stage.StatelessSession, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): Stage.Query { - return session.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return session.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createQuery( session: Stage.StatelessSession, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Stage.Query { - return session.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return session.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Stage.Query, params: JpqlRenderedParams) { + private fun setParams(query: Stage.Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensions.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensions.kt index db95246ba..4e7a1ab8a 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensions.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensions.kt @@ -9,26 +9,26 @@ import com.linecorp.kotlinjdsl.support.hibernate.reactive.JpqlMutinySessionUtils import org.hibernate.reactive.mutiny.Mutiny /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createQuery( query: SelectQuery, context: RenderContext, -): Mutiny.Query = JpqlMutinySessionUtils.createQuery(this, query, context) +): Mutiny.Query = JpqlMutinySessionUtils.createQuery(this, query, query.returnType, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Mutiny.Query = JpqlMutinySessionUtils.createQuery(this, query, queryParams, context) +): Mutiny.Query = JpqlMutinySessionUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createQuery( @@ -37,7 +37,7 @@ fun Mutiny.Session.createQuery( ): Mutiny.Query = JpqlMutinySessionUtils.createQuery(this, query, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createQuery( @@ -47,7 +47,7 @@ fun Mutiny.Session.createQuery( ): Mutiny.Query = JpqlMutinySessionUtils.createQuery(this, query, queryParams, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createQuery( @@ -56,7 +56,7 @@ fun Mutiny.Session.createQuery( ): Mutiny.Query = JpqlMutinySessionUtils.createQuery(this, query, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createQuery( diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensions.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensions.kt index 05a8bc93a..07e7f5337 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensions.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensions.kt @@ -9,26 +9,26 @@ import com.linecorp.kotlinjdsl.support.hibernate.reactive.JpqlMutinyStatelessSes import org.hibernate.reactive.mutiny.Mutiny /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( query: SelectQuery, context: RenderContext, -): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, context) +): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, query.returnType, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, queryParams, context) +): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( @@ -37,7 +37,7 @@ fun Mutiny.StatelessSession.createQuery( ): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( @@ -47,7 +47,7 @@ fun Mutiny.StatelessSession.createQuery( ): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, queryParams, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( @@ -56,7 +56,7 @@ fun Mutiny.StatelessSession.createQuery( ): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensions.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensions.kt index ecb673309..51307a4e4 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensions.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensions.kt @@ -9,26 +9,26 @@ import com.linecorp.kotlinjdsl.support.hibernate.reactive.JpqlStageSessionUtils import org.hibernate.reactive.stage.Stage /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createQuery( query: SelectQuery, context: RenderContext, -): Stage.Query = JpqlStageSessionUtils.createQuery(this, query, context) +): Stage.Query = JpqlStageSessionUtils.createQuery(this, query, query.returnType, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Stage.Query = JpqlStageSessionUtils.createQuery(this, query, queryParams, context) +): Stage.Query = JpqlStageSessionUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createQuery( @@ -37,7 +37,7 @@ fun Stage.Session.createQuery( ): Stage.Query = JpqlStageSessionUtils.createQuery(this, query, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createQuery( @@ -47,7 +47,7 @@ fun Stage.Session.createQuery( ): Stage.Query = JpqlStageSessionUtils.createQuery(this, query, queryParams, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createQuery( @@ -56,7 +56,7 @@ fun Stage.Session.createQuery( ): Stage.Query = JpqlStageSessionUtils.createQuery(this, query, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createQuery( diff --git a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensions.kt b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensions.kt index 93c8cc187..e2a3a325a 100644 --- a/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensions.kt +++ b/support/hibernate-reactive-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensions.kt @@ -9,26 +9,26 @@ import com.linecorp.kotlinjdsl.support.hibernate.reactive.JpqlStageStatelessSess import org.hibernate.reactive.stage.Stage /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( query: SelectQuery, context: RenderContext, -): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, context) +): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, query.returnType, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, queryParams, context) +): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( @@ -37,7 +37,7 @@ fun Stage.StatelessSession.createQuery( ): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( @@ -47,7 +47,7 @@ fun Stage.StatelessSession.createQuery( ): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, queryParams, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( @@ -56,7 +56,7 @@ fun Stage.StatelessSession.createQuery( ): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( diff --git a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtilsTest.kt b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtilsTest.kt index 7b9be708e..6f845870b 100644 --- a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtilsTest.kt +++ b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -31,16 +29,10 @@ class JpqlMutinySessionUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery + private lateinit var query1: JpqlQuery<*> @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery - - @MockK - private lateinit var query1: Mutiny.Query + private lateinit var mutinyQuery1: Mutiny.Query private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" @@ -57,151 +49,100 @@ class JpqlMutinySessionUtilsTest : WithAssertions { every { JpqlRendererHolder.get() } returns renderer excludeRecords { JpqlRendererHolder.get() } - excludeRecords { query1.equals(any()) } + excludeRecords { mutinyQuery1.equals(any()) } } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when - val actual = JpqlMutinySessionUtils.createQuery(session, selectQuery1, context) + val actual = JpqlMutinySessionUtils.createQuery(session, query1, String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when val actual = JpqlMutinySessionUtils - .createQuery(session, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlMutinySessionUtils.createQuery(session, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlMutinySessionUtils - .createQuery(session, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when - val actual = JpqlMutinySessionUtils.createQuery(session, deleteQuery1, context) + val actual = JpqlMutinySessionUtils.createQuery(session, query1, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when val actual = JpqlMutinySessionUtils - .createQuery(session, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } } diff --git a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtilsTest.kt b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtilsTest.kt index d8dab4ce3..a7b34423a 100644 --- a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtilsTest.kt +++ b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -31,16 +29,10 @@ class JpqlMutinyStatelessSessionUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery + private lateinit var query1: JpqlQuery<*> @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery - - @MockK - private lateinit var query1: Mutiny.Query + private lateinit var mutinyQuery1: Mutiny.Query private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" @@ -57,151 +49,100 @@ class JpqlMutinyStatelessSessionUtilsTest : WithAssertions { every { JpqlRendererHolder.get() } returns renderer excludeRecords { JpqlRendererHolder.get() } - excludeRecords { query1.equals(any()) } + excludeRecords { mutinyQuery1.equals(any()) } } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when - val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, context) + val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, query1, String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when val actual = JpqlMutinyStatelessSessionUtils - .createQuery(session, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlMutinyStatelessSessionUtils - .createQuery(session, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when - val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, context) + val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, query1, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when val actual = JpqlMutinyStatelessSessionUtils - .createQuery(session, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } } diff --git a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtilsTest.kt b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtilsTest.kt index 39be575f4..268fc6727 100644 --- a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtilsTest.kt +++ b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -31,16 +29,10 @@ class JpqlStageSessionUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery + private lateinit var query1: JpqlQuery<*> @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery - - @MockK - private lateinit var query1: Stage.Query + private lateinit var stageQuery1: Stage.Query private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" @@ -57,151 +49,100 @@ class JpqlStageSessionUtilsTest : WithAssertions { every { JpqlRendererHolder.get() } returns renderer excludeRecords { JpqlRendererHolder.get() } - excludeRecords { query1.equals(any()) } + excludeRecords { stageQuery1.equals(any()) } } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when - val actual = JpqlStageSessionUtils.createQuery(session, selectQuery1, context) + val actual = JpqlStageSessionUtils.createQuery(session, query1, String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when val actual = JpqlStageSessionUtils - .createQuery(session, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlStageSessionUtils.createQuery(session, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlStageSessionUtils - .createQuery(session, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when - val actual = JpqlStageSessionUtils.createQuery(session, deleteQuery1, context) + val actual = JpqlStageSessionUtils.createQuery(session, query1, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when val actual = JpqlStageSessionUtils - .createQuery(session, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } } diff --git a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtilsTest.kt b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtilsTest.kt index e24e0d491..61bcf4002 100644 --- a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtilsTest.kt +++ b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -31,16 +29,10 @@ class JpqlStageStatelessSessionUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery + private lateinit var query1: JpqlQuery<*> @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery - - @MockK - private lateinit var query1: Stage.Query + private lateinit var stageQuery1: Stage.Query private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" @@ -57,151 +49,100 @@ class JpqlStageStatelessSessionUtilsTest : WithAssertions { every { JpqlRendererHolder.get() } returns renderer excludeRecords { JpqlRendererHolder.get() } - excludeRecords { query1.equals(any()) } + excludeRecords { stageQuery1.equals(any()) } } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when - val actual = JpqlStageStatelessSessionUtils.createQuery(session, selectQuery1, context) + val actual = JpqlStageStatelessSessionUtils.createQuery(session, query1, String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when val actual = JpqlStageStatelessSessionUtils - .createQuery(session, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with a update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with a update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlStageStatelessSessionUtils - .createQuery(session, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when - val actual = JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, context) + val actual = JpqlStageStatelessSessionUtils.createQuery(session, query1, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when val actual = JpqlStageStatelessSessionUtils - .createQuery(session, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } } diff --git a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensionsTest.kt b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensionsTest.kt index f704f8a91..4753b7513 100644 --- a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensionsTest.kt +++ b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensionsTest.kt @@ -15,6 +15,7 @@ import org.hibernate.reactive.mutiny.Mutiny import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class MutinySessionExtensionsTest : WithAssertions { @@ -48,8 +49,9 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlMutinySessionUtils.createQuery(any(), any>(), any()) + JpqlMutinySessionUtils.createQuery(any(), any>(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, context) @@ -58,7 +60,8 @@ class MutinySessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinySessionUtils.createQuery(session, selectQuery1, context) + selectQuery1.returnType + JpqlMutinySessionUtils.createQuery(session, selectQuery1, String::class, context) } } @@ -66,8 +69,9 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlMutinySessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinySessionUtils.createQuery(any(), any>(), any(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, queryParams1, context) @@ -76,7 +80,8 @@ class MutinySessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinySessionUtils.createQuery(session, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlMutinySessionUtils.createQuery(session, selectQuery1, queryParams1, String::class, context) } } @@ -84,7 +89,7 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createQuery() with an update query`() { // given every { - JpqlMutinySessionUtils.createQuery(any(), any>(), any()) + JpqlMutinySessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -94,7 +99,7 @@ class MutinySessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinySessionUtils.createQuery(session, updateQuery1, context) + JpqlMutinySessionUtils.createQuery(session, updateQuery1, context) } } @@ -102,7 +107,9 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createQuery() with an update query and query params`() { // given every { - JpqlMutinySessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinySessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -112,7 +119,7 @@ class MutinySessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinySessionUtils.createQuery(session, updateQuery1, queryParams1, context) + JpqlMutinySessionUtils.createQuery(session, updateQuery1, queryParams1, context) } } @@ -120,7 +127,7 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query`() { // given every { - JpqlMutinySessionUtils.createQuery(any(), any>(), any()) + JpqlMutinySessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -130,7 +137,7 @@ class MutinySessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinySessionUtils.createQuery(session, deleteQuery1, context) + JpqlMutinySessionUtils.createQuery(session, deleteQuery1, context) } } @@ -138,7 +145,9 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query and query params`() { // given every { - JpqlMutinySessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinySessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -148,7 +157,7 @@ class MutinySessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinySessionUtils.createQuery(session, deleteQuery1, queryParams1, context) + JpqlMutinySessionUtils.createQuery(session, deleteQuery1, queryParams1, context) } } } diff --git a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensionsTest.kt b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensionsTest.kt index bbde5e4b0..b01031c04 100644 --- a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensionsTest.kt +++ b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensionsTest.kt @@ -15,6 +15,7 @@ import org.hibernate.reactive.mutiny.Mutiny import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class MutinyStatelessSessionExtensionsTest : WithAssertions { @@ -48,8 +49,9 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, context) @@ -58,7 +60,8 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, context) + selectQuery1.returnType + JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, String::class, context) } } @@ -66,8 +69,10 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinyStatelessSessionUtils + .createQuery(any(), any>(), any(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, queryParams1, context) @@ -76,7 +81,8 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, queryParams1, String::class, context) } } @@ -84,7 +90,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -94,7 +100,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, context) + JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, context) } } @@ -102,7 +108,9 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query and query params`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinyStatelessSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -112,7 +120,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, queryParams1, context) + JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, queryParams1, context) } } @@ -120,7 +128,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -130,7 +138,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, context) + JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, context) } } @@ -138,7 +146,9 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query and query params`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinyStatelessSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -148,7 +158,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) + JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) } } } diff --git a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensionsTest.kt b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensionsTest.kt index e0c1c9bf9..6b1f55937 100644 --- a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensionsTest.kt +++ b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensionsTest.kt @@ -15,6 +15,7 @@ import org.hibernate.reactive.stage.Stage import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class StageSessionExtensionsTest : WithAssertions { @@ -48,8 +49,9 @@ class StageSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlStageSessionUtils.createQuery(any(), any>(), any()) + JpqlStageSessionUtils.createQuery(any(), any>(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, context) @@ -58,7 +60,8 @@ class StageSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageSessionUtils.createQuery(session, selectQuery1, context) + selectQuery1.returnType + JpqlStageSessionUtils.createQuery(session, selectQuery1, String::class, context) } } @@ -66,8 +69,9 @@ class StageSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlStageSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageSessionUtils.createQuery(any(), any>(), any(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, queryParams1, context) @@ -76,7 +80,8 @@ class StageSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageSessionUtils.createQuery(session, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlStageSessionUtils.createQuery(session, selectQuery1, queryParams1, String::class, context) } } @@ -84,7 +89,7 @@ class StageSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query`() { // given every { - JpqlStageSessionUtils.createQuery(any(), any>(), any()) + JpqlStageSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -94,7 +99,7 @@ class StageSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageSessionUtils.createQuery(session, updateQuery1, context) + JpqlStageSessionUtils.createQuery(session, updateQuery1, context) } } @@ -102,7 +107,9 @@ class StageSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query and query params`() { // given every { - JpqlStageSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -112,7 +119,7 @@ class StageSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageSessionUtils.createQuery(session, updateQuery1, queryParams1, context) + JpqlStageSessionUtils.createQuery(session, updateQuery1, queryParams1, context) } } @@ -120,7 +127,7 @@ class StageSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query`() { // given every { - JpqlStageSessionUtils.createQuery(any(), any>(), any()) + JpqlStageSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -130,7 +137,7 @@ class StageSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageSessionUtils.createQuery(session, deleteQuery1, context) + JpqlStageSessionUtils.createQuery(session, deleteQuery1, context) } } @@ -138,7 +145,9 @@ class StageSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query and query params`() { // given every { - JpqlStageSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -148,7 +157,7 @@ class StageSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) + JpqlStageSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) } } } diff --git a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensionsTest.kt b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensionsTest.kt index bc7a5f0ff..63161063f 100644 --- a/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensionsTest.kt +++ b/support/hibernate-reactive-javax/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensionsTest.kt @@ -15,6 +15,7 @@ import org.hibernate.reactive.stage.Stage import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class StageStatelessSessionExtensionsTest : WithAssertions { @@ -48,8 +49,9 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, context) @@ -58,7 +60,8 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, selectQuery1, context) + selectQuery1.returnType + JpqlStageStatelessSessionUtils.createQuery(session, selectQuery1, String::class, context) } } @@ -66,8 +69,10 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageStatelessSessionUtils + .createQuery(any(), any>(), any(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, queryParams1, context) @@ -76,7 +81,8 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlStageStatelessSessionUtils.createQuery(session, selectQuery1, queryParams1, String::class, context) } } @@ -84,7 +90,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -94,7 +100,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, context) + JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, context) } } @@ -102,7 +108,9 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query and query params`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageStatelessSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -112,7 +120,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, queryParams1, context) + JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, queryParams1, context) } } @@ -120,7 +128,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -130,7 +138,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, context) + JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, context) } } @@ -138,7 +146,9 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query and query params`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageStatelessSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -148,7 +158,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) + JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) } } } diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt index 1c495334b..340ed988f 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtils.kt @@ -1,104 +1,83 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import org.hibernate.reactive.mutiny.Mutiny import kotlin.reflect.KClass internal object JpqlMutinySessionUtils { fun createQuery( session: Mutiny.Session, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): Mutiny.SelectionQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Mutiny.Session, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): Mutiny.SelectionQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } - fun createMutationQuery( + fun createMutationQuery( session: Mutiny.Session, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Mutiny.MutationQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createMutationQuery(session, rendered) + return createMutationQuery(session, rendered.query, rendered.params) } - fun createMutationQuery( + fun createMutationQuery( session: Mutiny.Session, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Mutiny.MutationQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createMutationQuery(session, rendered) - } - - fun createMutationQuery( - session: Mutiny.Session, - query: DeleteQuery, - context: RenderContext, - ): Mutiny.MutationQuery { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createMutationQuery(session, rendered) - } - - fun createMutationQuery( - session: Mutiny.Session, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Mutiny.MutationQuery { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createMutationQuery(session, rendered) + return createMutationQuery(session, rendered.query, rendered.params) } private fun createQuery( session: Mutiny.Session, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): Mutiny.SelectionQuery { - return session.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return session.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createMutationQuery( session: Mutiny.Session, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Mutiny.MutationQuery { - return session.createMutationQuery(rendered.query).apply { - setParams(this, rendered.params) + return session.createMutationQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Mutiny.SelectionQuery, params: JpqlRenderedParams) { + private fun setParams(query: Mutiny.SelectionQuery, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } } - private fun setParams(query: Mutiny.MutationQuery, params: JpqlRenderedParams) { + private fun setParams(query: Mutiny.MutationQuery, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt index 44961517f..209055e65 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtils.kt @@ -1,104 +1,83 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import org.hibernate.reactive.mutiny.Mutiny import kotlin.reflect.KClass internal object JpqlMutinyStatelessSessionUtils { fun createQuery( session: Mutiny.StatelessSession, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): Mutiny.SelectionQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Mutiny.StatelessSession, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): Mutiny.SelectionQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Mutiny.StatelessSession, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } fun createQuery( session: Mutiny.StatelessSession, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Mutiny.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered) - } - - fun createQuery( - session: Mutiny.StatelessSession, - query: DeleteQuery, - context: RenderContext, - ): Mutiny.Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(session, rendered) - } - - fun createQuery( - session: Mutiny.StatelessSession, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Mutiny.Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } private fun createQuery( session: Mutiny.StatelessSession, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): Mutiny.SelectionQuery { - return session.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return session.createQuery(query, returnType).apply { + setParams(this, queryParams) } } - private fun createQuery( + private fun createQuery( session: Mutiny.StatelessSession, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Mutiny.Query { - return session.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return session.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Mutiny.Query, params: JpqlRenderedParams) { + private fun setParams(query: Mutiny.SelectionQuery, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } } - private fun setParams(query: Mutiny.SelectionQuery, params: JpqlRenderedParams) { + private fun setParams(query: Mutiny.Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt index 361bdac10..c8c2e32b4 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtils.kt @@ -1,104 +1,83 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import org.hibernate.reactive.stage.Stage import kotlin.reflect.KClass internal object JpqlStageSessionUtils { fun createQuery( session: Stage.Session, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): Stage.SelectionQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Stage.Session, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): Stage.SelectionQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } - fun createMutationQuery( + fun createMutationQuery( session: Stage.Session, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Stage.MutationQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createMutationQuery(session, rendered) + return createMutationQuery(session, rendered.query, rendered.params) } - fun createMutationQuery( + fun createMutationQuery( session: Stage.Session, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Stage.MutationQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createMutationQuery(session, rendered) - } - - fun createMutationQuery( - session: Stage.Session, - query: DeleteQuery, - context: RenderContext, - ): Stage.MutationQuery { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createMutationQuery(session, rendered) - } - - fun createMutationQuery( - session: Stage.Session, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Stage.MutationQuery { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createMutationQuery(session, rendered) + return createMutationQuery(session, rendered.query, rendered.params) } private fun createQuery( session: Stage.Session, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): Stage.SelectionQuery { - return session.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return session.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createMutationQuery( session: Stage.Session, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Stage.MutationQuery { - return session.createMutationQuery(rendered.query).apply { - setParams(this, rendered.params) + return session.createMutationQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Stage.SelectionQuery, params: JpqlRenderedParams) { + private fun setParams(query: Stage.SelectionQuery, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } } - private fun setParams(query: Stage.MutationQuery, params: JpqlRenderedParams) { + private fun setParams(query: Stage.MutationQuery, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt index b3ad19f1d..6810a1959 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtils.kt @@ -1,104 +1,83 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import org.hibernate.reactive.stage.Stage import kotlin.reflect.KClass internal object JpqlStageStatelessSessionUtils { fun createQuery( session: Stage.StatelessSession, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): Stage.SelectionQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Stage.StatelessSession, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): Stage.SelectionQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered, query.returnType) + return createQuery(session, rendered.query, rendered.params, returnType.java) } fun createQuery( session: Stage.StatelessSession, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } fun createQuery( session: Stage.StatelessSession, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Stage.Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(session, rendered) - } - - fun createQuery( - session: Stage.StatelessSession, - query: DeleteQuery, - context: RenderContext, - ): Stage.Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(session, rendered) - } - - fun createQuery( - session: Stage.StatelessSession, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Stage.Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(session, rendered) + return createQuery(session, rendered.query, rendered.params) } private fun createQuery( session: Stage.StatelessSession, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): Stage.SelectionQuery { - return session.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return session.createQuery(query, returnType).apply { + setParams(this, queryParams) } } - private fun createQuery( + private fun createQuery( session: Stage.StatelessSession, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Stage.Query { - return session.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return session.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Stage.Query, params: JpqlRenderedParams) { + private fun setParams(query: Stage.SelectionQuery, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } } - private fun setParams(query: Stage.SelectionQuery, params: JpqlRenderedParams) { + private fun setParams(query: Stage.Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensions.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensions.kt index 77fb7abce..f0bcf0ecc 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensions.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensions.kt @@ -9,26 +9,26 @@ import com.linecorp.kotlinjdsl.support.hibernate.reactive.JpqlMutinySessionUtils import org.hibernate.reactive.mutiny.Mutiny /** - * Creates [Mutiny.SelectionQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.SelectionQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createQuery( query: SelectQuery, context: RenderContext, -): Mutiny.SelectionQuery = JpqlMutinySessionUtils.createQuery(this, query, context) +): Mutiny.SelectionQuery = JpqlMutinySessionUtils.createQuery(this, query, query.returnType, context) /** - * Creates [Mutiny.SelectionQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.SelectionQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Mutiny.SelectionQuery = JpqlMutinySessionUtils.createQuery(this, query, queryParams, context) +): Mutiny.SelectionQuery = JpqlMutinySessionUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [Mutiny.MutationQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.MutationQuery] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createMutationQuery( @@ -37,7 +37,7 @@ fun Mutiny.Session.createMutationQuery( ): Mutiny.MutationQuery = JpqlMutinySessionUtils.createMutationQuery(this, query, context) /** - * Creates [Mutiny.MutationQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.MutationQuery] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createMutationQuery( @@ -47,7 +47,7 @@ fun Mutiny.Session.createMutationQuery( ): Mutiny.MutationQuery = JpqlMutinySessionUtils.createMutationQuery(this, query, queryParams, context) /** - * Creates [Mutiny.MutationQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.MutationQuery] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createMutationQuery( @@ -56,7 +56,7 @@ fun Mutiny.Session.createMutationQuery( ): Mutiny.MutationQuery = JpqlMutinySessionUtils.createMutationQuery(this, query, context) /** - * Creates [Mutiny.MutationQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.MutationQuery] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.Session.createMutationQuery( diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensions.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensions.kt index fc0392919..20b69b8fc 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensions.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensions.kt @@ -9,26 +9,27 @@ import com.linecorp.kotlinjdsl.support.hibernate.reactive.JpqlMutinyStatelessSes import org.hibernate.reactive.mutiny.Mutiny /** - * Creates [Mutiny.SelectionQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.SelectionQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( query: SelectQuery, context: RenderContext, -): Mutiny.SelectionQuery = JpqlMutinyStatelessSessionUtils.createQuery(this, query, context) +): Mutiny.SelectionQuery = JpqlMutinyStatelessSessionUtils.createQuery(this, query, query.returnType, context) /** - * Creates [Mutiny.SelectionQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.SelectionQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Mutiny.SelectionQuery = JpqlMutinyStatelessSessionUtils.createQuery(this, query, queryParams, context) +): Mutiny.SelectionQuery = + JpqlMutinyStatelessSessionUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( @@ -37,7 +38,7 @@ fun Mutiny.StatelessSession.createQuery( ): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( @@ -47,7 +48,7 @@ fun Mutiny.StatelessSession.createQuery( ): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, queryParams, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( @@ -56,7 +57,7 @@ fun Mutiny.StatelessSession.createQuery( ): Mutiny.Query = JpqlMutinyStatelessSessionUtils.createQuery(this, query, context) /** - * Creates [Mutiny.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Mutiny.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Mutiny.StatelessSession.createQuery( diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensions.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensions.kt index 92590a681..19c04928c 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensions.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensions.kt @@ -9,26 +9,26 @@ import com.linecorp.kotlinjdsl.support.hibernate.reactive.JpqlStageSessionUtils import org.hibernate.reactive.stage.Stage /** - * Creates [Stage.SelectionQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.SelectionQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createQuery( query: SelectQuery, context: RenderContext, -): Stage.SelectionQuery = JpqlStageSessionUtils.createQuery(this, query, context) +): Stage.SelectionQuery = JpqlStageSessionUtils.createQuery(this, query, query.returnType, context) /** - * Creates [Stage.SelectionQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.SelectionQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Stage.SelectionQuery = JpqlStageSessionUtils.createQuery(this, query, queryParams, context) +): Stage.SelectionQuery = JpqlStageSessionUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [Stage.MutationQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.MutationQuery] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createMutationQuery( @@ -37,7 +37,7 @@ fun Stage.Session.createMutationQuery( ): Stage.MutationQuery = JpqlStageSessionUtils.createMutationQuery(this, query, context) /** - * Creates [Stage.MutationQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.MutationQuery] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createMutationQuery( @@ -47,7 +47,7 @@ fun Stage.Session.createMutationQuery( ): Stage.MutationQuery = JpqlStageSessionUtils.createMutationQuery(this, query, queryParams, context) /** - * Creates [Stage.MutationQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.MutationQuery] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createMutationQuery( @@ -56,7 +56,7 @@ fun Stage.Session.createMutationQuery( ): Stage.MutationQuery = JpqlStageSessionUtils.createMutationQuery(this, query, context) /** - * Creates [Stage.MutationQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.MutationQuery] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.Session.createMutationQuery( diff --git a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensions.kt b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensions.kt index 664457871..7b7a3b725 100644 --- a/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensions.kt +++ b/support/hibernate-reactive/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensions.kt @@ -9,26 +9,27 @@ import com.linecorp.kotlinjdsl.support.hibernate.reactive.JpqlStageStatelessSess import org.hibernate.reactive.stage.Stage /** - * Creates [Stage.SelectionQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.SelectionQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( query: SelectQuery, context: RenderContext, -): Stage.SelectionQuery = JpqlStageStatelessSessionUtils.createQuery(this, query, context) +): Stage.SelectionQuery = JpqlStageStatelessSessionUtils.createQuery(this, query, query.returnType, context) /** - * Creates [Stage.SelectionQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.SelectionQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Stage.SelectionQuery = JpqlStageStatelessSessionUtils.createQuery(this, query, queryParams, context) +): Stage.SelectionQuery = + JpqlStageStatelessSessionUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( @@ -37,7 +38,7 @@ fun Stage.StatelessSession.createQuery( ): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( @@ -47,7 +48,7 @@ fun Stage.StatelessSession.createQuery( ): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, queryParams, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( @@ -56,7 +57,7 @@ fun Stage.StatelessSession.createQuery( ): Stage.Query = JpqlStageStatelessSessionUtils.createQuery(this, query, context) /** - * Creates [Stage.Query] from the [SelectQuery] and [RenderContext]. + * Creates a [Stage.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun Stage.StatelessSession.createQuery( diff --git a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtilsTest.kt b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtilsTest.kt index 34cedeeb7..eace09138 100644 --- a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtilsTest.kt +++ b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinySessionUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -31,13 +29,7 @@ class JpqlMutinySessionUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery - - @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery + private lateinit var query1: JpqlQuery<*> @MockK private lateinit var selectionQuery1: Mutiny.SelectionQuery @@ -65,24 +57,22 @@ class JpqlMutinySessionUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { session.createQuery(any(), any>()) } returns selectionQuery1 every { selectionQuery1.setParameter(any(), any()) } returns selectionQuery1 // when - val actual = JpqlMutinySessionUtils.createQuery(session, selectQuery1, context) + val actual = JpqlMutinySessionUtils.createQuery(session, query1, String::class, context) // then assertThat(actual).isEqualTo(selectionQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) session.createQuery(rendered1.query, String::class.java) selectionQuery1.setParameter(renderedParam1.first, renderedParam1.second) selectionQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -90,25 +80,23 @@ class JpqlMutinySessionUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { session.createQuery(any(), any>()) } returns selectionQuery1 every { selectionQuery1.setParameter(any(), any()) } returns selectionQuery1 // when val actual = JpqlMutinySessionUtils - .createQuery(session, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), String::class, context) // then assertThat(actual).isEqualTo(selectionQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query, String::class.java) selectionQuery1.setParameter(renderedParam1.first, renderedParam1.second) selectionQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -116,54 +104,7 @@ class JpqlMutinySessionUtilsTest : WithAssertions { } @Test - fun `createMutationQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { session.createMutationQuery(any()) } returns mutationQuery1 - every { mutationQuery1.setParameter(any(), any()) } returns mutationQuery1 - - // when - val actual = JpqlMutinySessionUtils.createMutationQuery(session, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(mutationQuery1) - - verifySequence { - renderer.render(updateQuery1, context) - session.createMutationQuery(rendered1.query) - mutationQuery1.setParameter(renderedParam1.first, renderedParam1.second) - mutationQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createMutationQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createMutationQuery(any()) } returns mutationQuery1 - every { mutationQuery1.setParameter(any(), any()) } returns mutationQuery1 - - // when - val actual = JpqlMutinySessionUtils - .createMutationQuery(session, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(mutationQuery1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - session.createMutationQuery(rendered1.query) - mutationQuery1.setParameter(renderedParam1.first, renderedParam1.second) - mutationQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createMutationQuery() with a delete query`() { + fun `createMutationQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -172,13 +113,13 @@ class JpqlMutinySessionUtilsTest : WithAssertions { every { mutationQuery1.setParameter(any(), any()) } returns mutationQuery1 // when - val actual = JpqlMutinySessionUtils.createMutationQuery(session, deleteQuery1, context) + val actual = JpqlMutinySessionUtils.createMutationQuery(session, query1, context) // then assertThat(actual).isEqualTo(mutationQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) session.createMutationQuery(rendered1.query) mutationQuery1.setParameter(renderedParam1.first, renderedParam1.second) mutationQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -186,7 +127,7 @@ class JpqlMutinySessionUtilsTest : WithAssertions { } @Test - fun `createMutationQuery() with a delete query and query params`() { + fun `createMutationQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -196,13 +137,13 @@ class JpqlMutinySessionUtilsTest : WithAssertions { // when val actual = JpqlMutinySessionUtils - .createMutationQuery(session, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createMutationQuery(session, query1, mapOf(queryParam1, queryParam2), context) // then assertThat(actual).isEqualTo(mutationQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createMutationQuery(rendered1.query) mutationQuery1.setParameter(renderedParam1.first, renderedParam1.second) mutationQuery1.setParameter(renderedParam2.first, renderedParam2.second) diff --git a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtilsTest.kt b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtilsTest.kt index d8dab4ce3..a7b34423a 100644 --- a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtilsTest.kt +++ b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlMutinyStatelessSessionUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -31,16 +29,10 @@ class JpqlMutinyStatelessSessionUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery + private lateinit var query1: JpqlQuery<*> @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery - - @MockK - private lateinit var query1: Mutiny.Query + private lateinit var mutinyQuery1: Mutiny.Query private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" @@ -57,151 +49,100 @@ class JpqlMutinyStatelessSessionUtilsTest : WithAssertions { every { JpqlRendererHolder.get() } returns renderer excludeRecords { JpqlRendererHolder.get() } - excludeRecords { query1.equals(any()) } + excludeRecords { mutinyQuery1.equals(any()) } } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when - val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, context) + val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, query1, String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when val actual = JpqlMutinyStatelessSessionUtils - .createQuery(session, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlMutinyStatelessSessionUtils - .createQuery(session, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when - val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, context) + val actual = JpqlMutinyStatelessSessionUtils.createQuery(session, query1, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns mutinyQuery1 + every { mutinyQuery1.setParameter(any(), any()) } returns mutinyQuery1 // when val actual = JpqlMutinyStatelessSessionUtils - .createQuery(session, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(mutinyQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + mutinyQuery1.setParameter(renderedParam1.first, renderedParam1.second) + mutinyQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } } diff --git a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtilsTest.kt b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtilsTest.kt index d9f978b0c..22aae8d40 100644 --- a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtilsTest.kt +++ b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageSessionUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -31,13 +29,7 @@ class JpqlStageSessionUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery - - @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery + private lateinit var query1: JpqlQuery<*> @MockK private lateinit var selectionQuery1: Stage.SelectionQuery @@ -65,24 +57,22 @@ class JpqlStageSessionUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { session.createQuery(any(), any>()) } returns selectionQuery1 every { selectionQuery1.setParameter(any(), any()) } returns selectionQuery1 // when - val actual = JpqlStageSessionUtils.createQuery(session, selectQuery1, context) + val actual = JpqlStageSessionUtils.createQuery(session, query1, String::class, context) // then assertThat(actual).isEqualTo(selectionQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) session.createQuery(rendered1.query, String::class.java) selectionQuery1.setParameter(renderedParam1.first, renderedParam1.second) selectionQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -90,25 +80,23 @@ class JpqlStageSessionUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { session.createQuery(any(), any>()) } returns selectionQuery1 every { selectionQuery1.setParameter(any(), any()) } returns selectionQuery1 // when val actual = JpqlStageSessionUtils - .createQuery(session, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), String::class, context) // then assertThat(actual).isEqualTo(selectionQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query, String::class.java) selectionQuery1.setParameter(renderedParam1.first, renderedParam1.second) selectionQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -116,54 +104,7 @@ class JpqlStageSessionUtilsTest : WithAssertions { } @Test - fun `createMutationQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { session.createMutationQuery(any()) } returns mutationQuery1 - every { mutationQuery1.setParameter(any(), any()) } returns mutationQuery1 - - // when - val actual = JpqlStageSessionUtils.createMutationQuery(session, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(mutationQuery1) - - verifySequence { - renderer.render(updateQuery1, context) - session.createMutationQuery(rendered1.query) - mutationQuery1.setParameter(renderedParam1.first, renderedParam1.second) - mutationQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createMutationQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createMutationQuery(any()) } returns mutationQuery1 - every { mutationQuery1.setParameter(any(), any()) } returns mutationQuery1 - - // when - val actual = JpqlStageSessionUtils - .createMutationQuery(session, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(mutationQuery1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - session.createMutationQuery(rendered1.query) - mutationQuery1.setParameter(renderedParam1.first, renderedParam1.second) - mutationQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createMutationQuery() with a delete query`() { + fun `createMutationQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -172,13 +113,13 @@ class JpqlStageSessionUtilsTest : WithAssertions { every { mutationQuery1.setParameter(any(), any()) } returns mutationQuery1 // when - val actual = JpqlStageSessionUtils.createMutationQuery(session, deleteQuery1, context) + val actual = JpqlStageSessionUtils.createMutationQuery(session, query1, context) // then assertThat(actual).isEqualTo(mutationQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) session.createMutationQuery(rendered1.query) mutationQuery1.setParameter(renderedParam1.first, renderedParam1.second) mutationQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -186,7 +127,7 @@ class JpqlStageSessionUtilsTest : WithAssertions { } @Test - fun `createMutationQuery() with a delete query and query params`() { + fun `createMutationQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -196,13 +137,13 @@ class JpqlStageSessionUtilsTest : WithAssertions { // when val actual = JpqlStageSessionUtils - .createMutationQuery(session, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createMutationQuery(session, query1, mapOf(queryParam1, queryParam2), context) // then assertThat(actual).isEqualTo(mutationQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createMutationQuery(rendered1.query) mutationQuery1.setParameter(renderedParam1.first, renderedParam1.second) mutationQuery1.setParameter(renderedParam2.first, renderedParam2.second) diff --git a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtilsTest.kt b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtilsTest.kt index e24e0d491..2486ee853 100644 --- a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtilsTest.kt +++ b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/JpqlStageStatelessSessionUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate.reactive -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -31,16 +29,10 @@ class JpqlStageStatelessSessionUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery + private lateinit var query1: SelectQuery @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery - - @MockK - private lateinit var query1: Stage.Query + private lateinit var stageQuery1: Stage.Query private val renderedQuery1 = "query" private val renderedParam1 = "queryParam1" to "queryParamValue1" @@ -57,151 +49,100 @@ class JpqlStageStatelessSessionUtilsTest : WithAssertions { every { JpqlRendererHolder.get() } returns renderer excludeRecords { JpqlRendererHolder.get() } - excludeRecords { query1.equals(any()) } + excludeRecords { stageQuery1.equals(any()) } } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when - val actual = JpqlStageStatelessSessionUtils.createQuery(session, selectQuery1, context) + val actual = JpqlStageStatelessSessionUtils.createQuery(session, query1, String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class - every { session.createQuery(any(), any>()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any(), any>()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when val actual = JpqlStageStatelessSessionUtils - .createQuery(session, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), String::class, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query, String::class.java) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with a update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with a update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 - - // when - val actual = JpqlStageStatelessSessionUtils - .createQuery(session, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(query1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when - val actual = JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, context) + val actual = JpqlStageStatelessSessionUtils.createQuery(session, query1, context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { session.createQuery(any()) } returns query1 - every { query1.setParameter(any(), any()) } returns query1 + every { session.createQuery(any()) } returns stageQuery1 + every { stageQuery1.setParameter(any(), any()) } returns stageQuery1 // when val actual = JpqlStageStatelessSessionUtils - .createQuery(session, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(session, query1, mapOf(queryParam1, queryParam2), context) // then - assertThat(actual).isEqualTo(query1) + assertThat(actual).isEqualTo(stageQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) session.createQuery(rendered1.query) - query1.setParameter(renderedParam1.first, renderedParam1.second) - query1.setParameter(renderedParam2.first, renderedParam2.second) + stageQuery1.setParameter(renderedParam1.first, renderedParam1.second) + stageQuery1.setParameter(renderedParam2.first, renderedParam2.second) } } } diff --git a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensionsTest.kt b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensionsTest.kt index 012be13df..835ad6333 100644 --- a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensionsTest.kt +++ b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinySessionExtensionsTest.kt @@ -15,6 +15,7 @@ import org.hibernate.reactive.mutiny.Mutiny import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class MutinySessionExtensionsTest : WithAssertions { @@ -51,8 +52,9 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlMutinySessionUtils.createQuery(any(), any>(), any()) + JpqlMutinySessionUtils.createQuery(any(), any>(), any>(), any()) } returns selectionQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, context) @@ -61,7 +63,8 @@ class MutinySessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(selectionQuery1) verifySequence { - JpqlMutinySessionUtils.createQuery(session, selectQuery1, context) + selectQuery1.returnType + JpqlMutinySessionUtils.createQuery(session, selectQuery1, String::class, context) } } @@ -69,8 +72,9 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlMutinySessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinySessionUtils.createQuery(any(), any>(), any(), any>(), any()) } returns selectionQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, queryParams1, context) @@ -79,7 +83,8 @@ class MutinySessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(selectionQuery1) verifySequence { - JpqlMutinySessionUtils.createQuery(session, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlMutinySessionUtils.createQuery(session, selectQuery1, queryParams1, String::class, context) } } @@ -105,7 +110,9 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createMutationQuery() with an update query and query params`() { // given every { - JpqlMutinySessionUtils.createMutationQuery(any(), any>(), any(), any()) + JpqlMutinySessionUtils.createMutationQuery( + any(), any>(), any>(), any(), + ) } returns mutationQuery1 // when @@ -141,7 +148,9 @@ class MutinySessionExtensionsTest : WithAssertions { fun `createMutationQuery() with a delete query and query params`() { // given every { - JpqlMutinySessionUtils.createMutationQuery(any(), any>(), any(), any()) + JpqlMutinySessionUtils.createMutationQuery( + any(), any>(), any>(), any(), + ) } returns mutationQuery1 // when diff --git a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensionsTest.kt b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensionsTest.kt index bbde5e4b0..b01031c04 100644 --- a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensionsTest.kt +++ b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/MutinyStatelessSessionExtensionsTest.kt @@ -15,6 +15,7 @@ import org.hibernate.reactive.mutiny.Mutiny import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class MutinyStatelessSessionExtensionsTest : WithAssertions { @@ -48,8 +49,9 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, context) @@ -58,7 +60,8 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, context) + selectQuery1.returnType + JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, String::class, context) } } @@ -66,8 +69,10 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinyStatelessSessionUtils + .createQuery(any(), any>(), any(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, queryParams1, context) @@ -76,7 +81,8 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlMutinyStatelessSessionUtils.createQuery(session, selectQuery1, queryParams1, String::class, context) } } @@ -84,7 +90,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -94,7 +100,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, context) + JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, context) } } @@ -102,7 +108,9 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query and query params`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinyStatelessSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -112,7 +120,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, queryParams1, context) + JpqlMutinyStatelessSessionUtils.createQuery(session, updateQuery1, queryParams1, context) } } @@ -120,7 +128,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -130,7 +138,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, context) + JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, context) } } @@ -138,7 +146,9 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query and query params`() { // given every { - JpqlMutinyStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlMutinyStatelessSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -148,7 +158,7 @@ class MutinyStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) + JpqlMutinyStatelessSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) } } } diff --git a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensionsTest.kt b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensionsTest.kt index 23247d4b7..5764464fb 100644 --- a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensionsTest.kt +++ b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageSessionExtensionsTest.kt @@ -15,6 +15,7 @@ import org.hibernate.reactive.stage.Stage import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class StageSessionExtensionsTest : WithAssertions { @@ -51,8 +52,9 @@ class StageSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlStageSessionUtils.createQuery(any(), any>(), any()) + JpqlStageSessionUtils.createQuery(any(), any>(), any>(), any()) } returns selectionQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, context) @@ -61,7 +63,8 @@ class StageSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(selectionQuery1) verifySequence { - JpqlStageSessionUtils.createQuery(session, selectQuery1, context) + selectQuery1.returnType + JpqlStageSessionUtils.createQuery(session, selectQuery1, String::class, context) } } @@ -69,8 +72,9 @@ class StageSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlStageSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageSessionUtils.createQuery(any(), any>(), any(), any>(), any()) } returns selectionQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, queryParams1, context) @@ -79,7 +83,8 @@ class StageSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(selectionQuery1) verifySequence { - JpqlStageSessionUtils.createQuery(session, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlStageSessionUtils.createQuery(session, selectQuery1, queryParams1, String::class, context) } } @@ -105,7 +110,9 @@ class StageSessionExtensionsTest : WithAssertions { fun `createMutationQuery() with an update query and query params`() { // given every { - JpqlStageSessionUtils.createMutationQuery(any(), any>(), any(), any()) + JpqlStageSessionUtils.createMutationQuery( + any(), any>(), any>(), any(), + ) } returns mutationQuery1 // when @@ -141,7 +148,9 @@ class StageSessionExtensionsTest : WithAssertions { fun `createMutationQuery() with a delete query and query params`() { // given every { - JpqlStageSessionUtils.createMutationQuery(any(), any>(), any(), any()) + JpqlStageSessionUtils.createMutationQuery( + any(), any>(), any>(), any(), + ) } returns mutationQuery1 // when diff --git a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensionsTest.kt b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensionsTest.kt index 7f0c0c544..63161063f 100644 --- a/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensionsTest.kt +++ b/support/hibernate-reactive/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/reactive/extension/StageStatelessSessionExtensionsTest.kt @@ -15,6 +15,7 @@ import org.hibernate.reactive.stage.Stage import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class StageStatelessSessionExtensionsTest : WithAssertions { @@ -48,8 +49,9 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, context) @@ -58,7 +60,8 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, selectQuery1, context) + selectQuery1.returnType + JpqlStageStatelessSessionUtils.createQuery(session, selectQuery1, String::class, context) } } @@ -66,8 +69,10 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageStatelessSessionUtils + .createQuery(any(), any>(), any(), any>(), any()) } returns query1 + every { selectQuery1.returnType } returns String::class // when val actual = session.createQuery(selectQuery1, queryParams1, context) @@ -76,7 +81,8 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(any(), selectQuery1, any(), any()) + selectQuery1.returnType + JpqlStageStatelessSessionUtils.createQuery(session, selectQuery1, queryParams1, String::class, context) } } @@ -84,7 +90,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -94,7 +100,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, context) + JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, context) } } @@ -102,7 +108,9 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with an update query and query params`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageStatelessSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -112,7 +120,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, queryParams1, context) + JpqlStageStatelessSessionUtils.createQuery(session, updateQuery1, queryParams1, context) } } @@ -120,7 +128,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) + JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any()) } returns query1 // when @@ -130,7 +138,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, context) + JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, context) } } @@ -138,7 +146,9 @@ class StageStatelessSessionExtensionsTest : WithAssertions { fun `createQuery() with a delete query and query params`() { // given every { - JpqlStageStatelessSessionUtils.createQuery(any(), any>(), any(), any()) + JpqlStageStatelessSessionUtils.createQuery( + any(), any>(), any>(), any(), + ) } returns query1 // when @@ -148,7 +158,7 @@ class StageStatelessSessionExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(query1) verifySequence { - JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) + JpqlStageStatelessSessionUtils.createQuery(session, deleteQuery1, queryParams1, context) } } } diff --git a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt index 14654944c..93acccd8d 100644 --- a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt +++ b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtils.kt @@ -2,12 +2,8 @@ package com.linecorp.kotlinjdsl.support.hibernate -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext -import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered -import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams import jakarta.persistence.EntityManager import jakarta.persistence.Query import jakarta.persistence.TypedQuery @@ -16,87 +12,70 @@ import kotlin.reflect.KClass internal object JpqlEntityManagerUtils { fun createQuery( entityManager: EntityManager, - query: SelectQuery, + query: JpqlQuery<*>, + returnType: KClass, context: RenderContext, ): TypedQuery { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(entityManager, rendered, query.returnType) + return createQuery(entityManager, rendered.query, rendered.params, returnType.java) } fun createQuery( entityManager: EntityManager, - query: SelectQuery, + query: JpqlQuery<*>, queryParams: Map, + returnType: KClass, context: RenderContext, ): TypedQuery { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(entityManager, rendered, query.returnType) + return createQuery(entityManager, rendered.query, rendered.params, returnType.java) } - fun createQuery( + fun createQuery( entityManager: EntityManager, - query: UpdateQuery, + query: JpqlQuery<*>, context: RenderContext, ): Query { val rendered = JpqlRendererHolder.get().render(query, context) - return createQuery(entityManager, rendered) + return createQuery(entityManager, rendered.query, rendered.params) } - fun createQuery( + fun createQuery( entityManager: EntityManager, - query: UpdateQuery, + query: JpqlQuery<*>, queryParams: Map, context: RenderContext, ): Query { val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - return createQuery(entityManager, rendered) - } - - fun createQuery( - entityManager: EntityManager, - query: DeleteQuery, - context: RenderContext, - ): Query { - val rendered = JpqlRendererHolder.get().render(query, context) - - return createQuery(entityManager, rendered) - } - - fun createQuery( - entityManager: EntityManager, - query: DeleteQuery, - queryParams: Map, - context: RenderContext, - ): Query { - val rendered = JpqlRendererHolder.get().render(query, queryParams, context) - - return createQuery(entityManager, rendered) + return createQuery(entityManager, rendered.query, rendered.params) } private fun createQuery( entityManager: EntityManager, - rendered: JpqlRendered, - resultClass: KClass, + query: String, + queryParams: Map, + returnType: Class, ): TypedQuery { - return entityManager.createQuery(rendered.query, resultClass.java).apply { - setParams(this, rendered.params) + return entityManager.createQuery(query, returnType).apply { + setParams(this, queryParams) } } private fun createQuery( entityManager: EntityManager, - rendered: JpqlRendered, + query: String, + queryParams: Map, ): Query { - return entityManager.createQuery(rendered.query).apply { - setParams(this, rendered.params) + return entityManager.createQuery(query).apply { + setParams(this, queryParams) } } - private fun setParams(query: Query, params: JpqlRenderedParams) { + private fun setParams(query: Query, params: Map) { params.forEach { (name, value) -> query.setParameter(name, value) } diff --git a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensions.kt b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensions.kt index d101b6bb7..3ec1964c2 100644 --- a/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensions.kt +++ b/support/hibernate/src/main/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensions.kt @@ -10,25 +10,37 @@ import jakarta.persistence.EntityManager import jakarta.persistence.Query import jakarta.persistence.TypedQuery +/** + * Creates a [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: SelectQuery, context: RenderContext, -): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, query.returnType, context) +/** + * Creates a [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, query.returnType, context) +/** + * Creates a [jakarta.persistence.Query] from the [UpdateQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: UpdateQuery, context: RenderContext, ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) +/** + * Creates a [jakarta.persistence.Query] from the [UpdateQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: UpdateQuery, @@ -36,12 +48,18 @@ fun EntityManager.createQuery( context: RenderContext, ): Query = JpqlEntityManagerUtils.createQuery(this, query, queryParams, context) +/** + * Creates a [jakarta.persistence.Query] from the [DeleteQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: DeleteQuery, context: RenderContext, ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) +/** + * Creates a [jakarta.persistence.Query] from the [DeleteQuery] and [RenderContext]. + */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: DeleteQuery, diff --git a/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt b/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt index ab313bd81..34635291b 100644 --- a/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt +++ b/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/JpqlEntityManagerUtilsTest.kt @@ -1,8 +1,6 @@ package com.linecorp.kotlinjdsl.support.hibernate -import com.linecorp.kotlinjdsl.querymodel.jpql.delete.DeleteQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery -import com.linecorp.kotlinjdsl.querymodel.jpql.update.UpdateQuery +import com.linecorp.kotlinjdsl.querymodel.jpql.JpqlQuery import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRendered import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderedParams @@ -32,13 +30,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { private lateinit var context: RenderContext @MockK - private lateinit var selectQuery1: SelectQuery - - @MockK - private lateinit var updateQuery1: UpdateQuery - - @MockK - private lateinit var deleteQuery1: DeleteQuery + private lateinit var query1: JpqlQuery<*> @MockK private lateinit var stringTypedQuery1: TypedQuery @@ -62,24 +54,22 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query`() { + fun `createQuery() with a query and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, context) + val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, String::class, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(selectQuery1, context) - selectQuery1.returnType + renderer.render(query1, context) entityManager.createQuery(rendered1.query, String::class.java) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -87,25 +77,23 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a select query and query params`() { + fun `createQuery() with a query and query params and a return type`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) every { renderer.render(any(), any(), any()) } returns rendered1 - every { selectQuery1.returnType } returns String::class every { entityManager.createQuery(any(), any>()) } returns stringTypedQuery1 every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when val actual = JpqlEntityManagerUtils - .createQuery(entityManager, selectQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(entityManager, query1, mapOf(queryParam1, queryParam2), String::class, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context) - selectQuery1.returnType + renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query, String::class.java) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -113,54 +101,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with an update query`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any()) } returns rendered1 - every { entityManager.createQuery(any()) } returns stringTypedQuery1 - every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 - - // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, updateQuery1, context) - - // then - assertThat(actual).isEqualTo(stringTypedQuery1) - - verifySequence { - renderer.render(updateQuery1, context) - entityManager.createQuery(rendered1.query) - stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) - stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with an update query and query params`() { - // given - val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) - - every { renderer.render(any(), any(), any()) } returns rendered1 - every { entityManager.createQuery(any()) } returns stringTypedQuery1 - every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 - - // when - val actual = JpqlEntityManagerUtils - .createQuery(entityManager, updateQuery1, mapOf(queryParam1, queryParam2), context) - - // then - assertThat(actual).isEqualTo(stringTypedQuery1) - - verifySequence { - renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context) - entityManager.createQuery(rendered1.query) - stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) - stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) - } - } - - @Test - fun `createQuery() with a delete query`() { + fun `createQuery() with a query`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -169,13 +110,13 @@ class JpqlEntityManagerUtilsTest : WithAssertions { every { stringTypedQuery1.setParameter(any(), any()) } returns stringTypedQuery1 // when - val actual = JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery1, context) + val actual = JpqlEntityManagerUtils.createQuery(entityManager, query1, context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(deleteQuery1, context) + renderer.render(query1, context) entityManager.createQuery(rendered1.query) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) @@ -183,7 +124,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions { } @Test - fun `createQuery() with a delete query and query params`() { + fun `createQuery() with a query and query params`() { // given val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2))) @@ -193,13 +134,13 @@ class JpqlEntityManagerUtilsTest : WithAssertions { // when val actual = JpqlEntityManagerUtils - .createQuery(entityManager, deleteQuery1, mapOf(queryParam1, queryParam2), context) + .createQuery(entityManager, query1, mapOf(queryParam1, queryParam2), context) // then assertThat(actual).isEqualTo(stringTypedQuery1) verifySequence { - renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context) + renderer.render(query1, mapOf(queryParam1, queryParam2), context) entityManager.createQuery(rendered1.query) stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second) stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second) diff --git a/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensionsTest.kt b/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensionsTest.kt index 7422ee9b0..3ebdb2d97 100644 --- a/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensionsTest.kt +++ b/support/hibernate/src/test/kotlin/com/linecorp/kotlinjdsl/support/hibernate/extension/EntityManagerExtensionsTest.kt @@ -17,6 +17,7 @@ import org.assertj.core.api.WithAssertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.reflect.KClass @ExtendWith(MockKExtension::class) class EntityManagerExtensionsTest : WithAssertions { @@ -53,8 +54,9 @@ class EntityManagerExtensionsTest : WithAssertions { fun `createQuery() with a select query`() { // given every { - JpqlEntityManagerUtils.createQuery(any(), any>(), any()) + JpqlEntityManagerUtils.createQuery(any(), any>(), any>(), any()) } returns typedQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = entityManager.createQuery(selectQuery1, context) @@ -63,7 +65,8 @@ class EntityManagerExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(typedQuery1) verifySequence { - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, context) + selectQuery1.returnType + JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, String::class, context) } } @@ -71,8 +74,9 @@ class EntityManagerExtensionsTest : WithAssertions { fun `createQuery() with a select query and query params`() { // given every { - JpqlEntityManagerUtils.createQuery(any(), any>(), any(), any()) + JpqlEntityManagerUtils.createQuery(any(), any>(), any(), any>(), any()) } returns typedQuery1 + every { selectQuery1.returnType } returns String::class // when val actual = entityManager.createQuery(selectQuery1, queryParams1, context) @@ -81,7 +85,8 @@ class EntityManagerExtensionsTest : WithAssertions { assertThat(actual).isEqualTo(typedQuery1) verifySequence { - JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, queryParams1, context) + selectQuery1.returnType + JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, queryParams1, String::class, context) } } diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/extension/EntityManagerExtensions.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/extension/EntityManagerExtensions.kt index ceffd09eb..40d2d696c 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/extension/EntityManagerExtensions.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/extension/EntityManagerExtensions.kt @@ -27,7 +27,7 @@ fun EntityManager.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Query = JpqlEntityManagerUtils.createQuery(this, query, queryParams, query.returnType, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, query.returnType, context) /** * Creates a [javax.persistence.Query] from the [UpdateQuery] and [RenderContext]. diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/extension/EntityManagerExtensions.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/extension/EntityManagerExtensions.kt index 53ca0d726..35050ea28 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/extension/EntityManagerExtensions.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/extension/EntityManagerExtensions.kt @@ -11,7 +11,7 @@ import jakarta.persistence.Query import jakarta.persistence.TypedQuery /** - * Creates [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -20,17 +20,17 @@ fun EntityManager.createQuery( ): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, query.returnType, context) /** - * Creates [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. + * Creates a [jakarta.persistence.TypedQuery] from the [SelectQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( query: SelectQuery, queryParams: Map, context: RenderContext, -): Query = JpqlEntityManagerUtils.createQuery(this, query, queryParams, query.returnType, context) +): TypedQuery = JpqlEntityManagerUtils.createQuery(this, query, queryParams, query.returnType, context) /** - * Creates [jakarta.persistence.TypedQuery] from the [UpdateQuery] and [RenderContext]. + * Creates a [jakarta.persistence.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -39,7 +39,7 @@ fun EntityManager.createQuery( ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) /** - * Creates [jakarta.persistence.TypedQuery] from the [UpdateQuery] and [RenderContext]. + * Creates a [jakarta.persistence.Query] from the [UpdateQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -49,7 +49,7 @@ fun EntityManager.createQuery( ): Query = JpqlEntityManagerUtils.createQuery(this, query, queryParams, context) /** - * Creates [jakarta.persistence.TypedQuery] from the [DeleteQuery] and [RenderContext]. + * Creates a [jakarta.persistence.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery( @@ -58,7 +58,7 @@ fun EntityManager.createQuery( ): Query = JpqlEntityManagerUtils.createQuery(this, query, context) /** - * Creates [jakarta.persistence.TypedQuery] from the [DeleteQuery] and [RenderContext]. + * Creates a [jakarta.persistence.Query] from the [DeleteQuery] and [RenderContext]. */ @SinceJdsl("3.0.0") fun EntityManager.createQuery(