-
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: support current timestamp function
- Loading branch information
1 parent
f27809b
commit 470de34
Showing
9 changed files
with
139 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
25 changes: 25 additions & 0 deletions
25
dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CurrentTimestampTest.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.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.WithAssertions | ||
import org.junit.jupiter.api.Test | ||
import java.sql.Timestamp | ||
|
||
class CurrentTimestampTest : WithAssertions { | ||
@Test | ||
fun currentTimestamp() { | ||
// when | ||
val expression = queryPart { | ||
currentTimestamp() | ||
}.toExpression() | ||
|
||
val actual: Expression<Timestamp> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.currentTimestamp() | ||
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
...jdsl/dsl/jpql/JpqlLocalDateTimeDslTest.kt → ...l/jpql/expression/LocalDateTimeDslTest.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
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
...in/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCurrentTimestamp.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.sql.Timestamp | ||
|
||
@Internal | ||
object JpqlCurrentTimestamp : Expression<Timestamp> |
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
19 changes: 19 additions & 0 deletions
19
...lin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimestampSerializer.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,19 @@ | ||
package com.linecorp.kotlinjdsl.render.jpql.serializer.impl | ||
|
||
import com.linecorp.kotlinjdsl.Internal | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCurrentTimestamp | ||
import com.linecorp.kotlinjdsl.render.RenderContext | ||
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer | ||
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter | ||
import kotlin.reflect.KClass | ||
|
||
@Internal | ||
class JpqlCurrentTimestampSerializer : JpqlSerializer<JpqlCurrentTimestamp> { | ||
override fun handledType(): KClass<JpqlCurrentTimestamp> { | ||
return JpqlCurrentTimestamp::class | ||
} | ||
|
||
override fun serialize(part: JpqlCurrentTimestamp, writer: JpqlWriter, context: RenderContext) { | ||
writer.write("CURRENT_TIMESTAMP") | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimestampSerializerTest.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,47 @@ | ||
package com.linecorp.kotlinjdsl.render.jpql.serializer.impl | ||
|
||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCurrentTimestamp | ||
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.impl.annotations.MockK | ||
import io.mockk.verifySequence | ||
import org.assertj.core.api.WithAssertions | ||
import org.junit.jupiter.api.Test | ||
|
||
@JpqlSerializerTest | ||
class JpqlCurrentTimestampSerializerTest : WithAssertions { | ||
private val sut = JpqlCurrentTimestampSerializer() | ||
|
||
@MockK | ||
private lateinit var writer: JpqlWriter | ||
|
||
@MockK | ||
private lateinit var serializer: JpqlRenderSerializer | ||
|
||
@Test | ||
fun handledType() { | ||
// when | ||
val actual = sut.handledType() | ||
|
||
// then | ||
assertThat(actual).isEqualTo(JpqlCurrentTimestamp::class) | ||
} | ||
|
||
@Test | ||
fun serialize() { | ||
// given | ||
val part = Expressions.currentTimestamp() | ||
val context = TestRenderContext(serializer) | ||
|
||
// when | ||
sut.serialize(part as JpqlCurrentTimestamp, writer, context) | ||
|
||
// then | ||
verifySequence { | ||
writer.write("CURRENT_TIMESTAMP") | ||
} | ||
} | ||
} |