-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: supporting localDateTime function for datetime function #628
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 26 additions & 0 deletions
26
...l/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/JpqlLocalDateTimeDslTest.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,26 @@ | ||
package com.linecorp.kotlinjdsl.dsl.jpql.expression | ||
|
||
import com.linecorp.kotlinjdsl.dsl.jpql.queryPart | ||
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 JpqlLocalDateTimeDslTest { | ||
|
||
@Test | ||
fun localDateTime() { | ||
// 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
8 changes: 8 additions & 0 deletions
8
.../main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlLocalDateTime.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,8 @@ | ||
package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl | ||
|
||
import com.linecorp.kotlinjdsl.Internal | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression | ||
import java.time.LocalDateTime | ||
|
||
@Internal | ||
object JpqlLocalDateTime : 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpressionPar | |
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFunctionExpression | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLength | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLiteral | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLocalDateTime | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLocate | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLower | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlMax | ||
|
@@ -887,4 +888,15 @@ class ExpressionsTest : WithAssertions { | |
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `localDateTime to support LOCAL DATETIME in jpql`() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As with the DSL test, please simplify the test name. |
||
// when | ||
val actual = Expressions.localDateTime() | ||
|
||
// then | ||
val expected = JpqlLocalDateTime.toExpression() | ||
|
||
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
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.JpqlLocalDateTime | ||
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<JpqlLocalDateTime> { | ||
|
||
override fun handledType(): KClass<JpqlLocalDateTime> { | ||
return JpqlLocalDateTime::class | ||
} | ||
|
||
override fun serialize(part: JpqlLocalDateTime, writer: JpqlWriter, context: RenderContext) { | ||
val delegate = context.getValue(JpqlRenderSerializer) | ||
|
||
writer.write("LOCAL DATETIME") | ||
|
||
writer.writeParentheses { | ||
delegate.serialize(part, writer, context) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked that |
||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...om/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlJpqlLocalDateTimeSerializerTest.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.JpqlLocalDateTime | ||
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 JpqlJpqlLocalDateTimeSerializerTest { | ||
private val sut = JpqlLocalDateTimeSerializer() | ||
|
||
@MockK | ||
private lateinit var writer: JpqlWriter | ||
|
||
@MockK | ||
private lateinit var serializer: JpqlRenderSerializer | ||
|
||
@Test | ||
fun handle() { | ||
// when | ||
val actual = sut.handledType() | ||
|
||
// then | ||
assertThat(actual).isEqualTo(JpqlLocalDateTime::class) | ||
} | ||
|
||
@Test | ||
fun serialize() { | ||
// given | ||
every { writer.write(any<String>()) } just runs | ||
|
||
val part = Expressions.localDateTime() as JpqlLocalDateTime | ||
val context = TestRenderContext(serializer) | ||
|
||
// when | ||
sut.serialize(part, writer, context) | ||
|
||
// then | ||
verifySequence { | ||
writer.write("LOCAL DATETIME") | ||
writer.writeParentheses(any()) | ||
serializer.serialize(part, writer, context) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please align the comment with DSL.