-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: supporting localDateTime function for datetime function
- Loading branch information
Showing
10 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/LocalDateTimeExpressionDslTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.linecorp.kotlinjdsl.dsl.jpql | ||
|
||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import java.time.LocalDateTime | ||
|
||
class LocalDateTimeExpressionDslTest { | ||
|
||
@Test | ||
fun `localDateTime to support LOCAL DATETIME in jpql`() { | ||
// when | ||
val expression = queryPart { | ||
localDateTime() | ||
}.toExpression() | ||
|
||
val actual: Expression<LocalDateTime> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.localDateTime() | ||
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/LocalDateTimeExpression.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl | ||
|
||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression | ||
import java.time.LocalDateTime | ||
|
||
object LocalDateTimeExpression : Expression<LocalDateTime> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLocalDateTimeSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.linecorp.kotlinjdsl.render.jpql.serializer.impl | ||
|
||
import com.linecorp.kotlinjdsl.Internal | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.LocalDateTimeExpression | ||
import com.linecorp.kotlinjdsl.render.RenderContext | ||
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer | ||
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer | ||
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter | ||
import kotlin.reflect.KClass | ||
|
||
@Internal | ||
class JpqlLocalDateTimeSerializer : JpqlSerializer<LocalDateTimeExpression> { | ||
|
||
override fun handledType(): KClass<LocalDateTimeExpression> { | ||
return LocalDateTimeExpression::class | ||
} | ||
|
||
override fun serialize(part: LocalDateTimeExpression, writer: JpqlWriter, context: RenderContext) { | ||
val delegate = context.getValue(JpqlRenderSerializer) | ||
|
||
writer.write("LOCAL DATETIME") | ||
|
||
writer.writeParentheses { | ||
delegate.serialize(part, writer, context) | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLocalDateTimeExpressionSerializerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.linecorp.kotlinjdsl.render.jpql.serializer.impl | ||
|
||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.LocalDateTimeExpression | ||
import com.linecorp.kotlinjdsl.render.TestRenderContext | ||
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer | ||
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializerTest | ||
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.just | ||
import io.mockk.runs | ||
import io.mockk.verifySequence | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
@JpqlSerializerTest | ||
class JpqlLocalDateTimeExpressionSerializerTest { | ||
private val sut = JpqlLocalDateTimeSerializer() | ||
|
||
@MockK | ||
private lateinit var writer: JpqlWriter | ||
|
||
@MockK | ||
private lateinit var serializer: JpqlRenderSerializer | ||
|
||
@Test | ||
fun `handle type only JpqlLocalDateTime`() { | ||
// when | ||
val actual = sut.handledType() | ||
|
||
// then | ||
assertThat(actual).isEqualTo(LocalDateTimeExpression::class) | ||
} | ||
|
||
@Test | ||
fun `serialize LOCAL DATETIME function in Jpql`() { | ||
// given | ||
every { writer.write(any<String>()) } just runs | ||
|
||
val part = Expressions.localDateTime() as LocalDateTimeExpression | ||
val context = TestRenderContext(serializer) | ||
|
||
// when | ||
sut.serialize(part, writer, context) | ||
|
||
// then | ||
verifySequence { | ||
writer.write("LOCAL DATETIME") | ||
writer.writeParentheses(any()) | ||
serializer.serialize(part, writer, context) | ||
} | ||
} | ||
} |