-
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.
Merge pull request #621 from jbl428/feat/ln
Support Arithmetic function LN
- Loading branch information
Showing
10 changed files
with
187 additions
and
4 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
47 changes: 47 additions & 0 deletions
47
dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/LnDslTest.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.dsl.jpql.expression | ||
|
||
import com.linecorp.kotlinjdsl.dsl.jpql.entity.book.Book | ||
import com.linecorp.kotlinjdsl.dsl.jpql.queryPart | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths | ||
import org.assertj.core.api.WithAssertions | ||
import org.junit.jupiter.api.Test | ||
|
||
class LnDslTest : WithAssertions { | ||
private val expression1 = Paths.path(Book::salePrice) | ||
|
||
@Test | ||
fun `ln() with a property`() { | ||
// when | ||
val expression = queryPart { | ||
ln(Book::price) | ||
}.toExpression() | ||
|
||
val actual: Expression<Double> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.ln( | ||
value = Paths.path(Book::price), | ||
) | ||
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `ln() with a expression`() { | ||
// when | ||
val expression = queryPart { | ||
ln(expression1) | ||
}.toExpression() | ||
|
||
val actual: Expression<Double> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.ln( | ||
value = expression1, | ||
) | ||
|
||
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
12 changes: 12 additions & 0 deletions
12
...el/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlLn.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,12 @@ | ||
package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl | ||
|
||
import com.linecorp.kotlinjdsl.Internal | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression | ||
|
||
/** | ||
* Expression that applies natural logarithm function to [value]. | ||
*/ | ||
@Internal | ||
data class JpqlLn<T : Number> internal constructor( | ||
val value: Expression<T>, | ||
) : Expression<Double> |
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
26 changes: 26 additions & 0 deletions
26
...l/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializer.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.render.jpql.serializer.impl | ||
|
||
import com.linecorp.kotlinjdsl.Internal | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLn | ||
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 JpqlLnSerializer : JpqlSerializer<JpqlLn<*>> { | ||
override fun handledType(): KClass<JpqlLn<*>> { | ||
return JpqlLn::class | ||
} | ||
|
||
override fun serialize(part: JpqlLn<*>, writer: JpqlWriter, context: RenderContext) { | ||
val delegate = context.getValue(JpqlRenderSerializer) | ||
|
||
writer.write("LN") | ||
|
||
writer.writeParentheses { | ||
delegate.serialize(part.value, writer, context) | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...c/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializerTest.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,55 @@ | ||
package com.linecorp.kotlinjdsl.render.jpql.serializer.impl | ||
|
||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLn | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths | ||
import com.linecorp.kotlinjdsl.render.TestRenderContext | ||
import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book | ||
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 JpqlLnSerializerTest : WithAssertions { | ||
private val sut = JpqlLnSerializer() | ||
|
||
@MockK | ||
private lateinit var writer: JpqlWriter | ||
|
||
@MockK | ||
private lateinit var serializer: JpqlRenderSerializer | ||
|
||
private val expression1 = Paths.path(Book::price) | ||
|
||
@Test | ||
fun handledType() { | ||
// when | ||
val actual = sut.handledType() | ||
|
||
// then | ||
assertThat(actual).isEqualTo(JpqlLn::class) | ||
} | ||
|
||
@Test | ||
fun serialize() { | ||
// given | ||
val part = Expressions.ln( | ||
value = expression1, | ||
) | ||
val context = TestRenderContext(serializer) | ||
|
||
// when | ||
sut.serialize(part as JpqlLn<*>, writer, context) | ||
|
||
// then | ||
verifySequence { | ||
writer.write("LN") | ||
writer.writeParentheses(any()) | ||
serializer.serialize(expression1, writer, context) | ||
} | ||
} | ||
} |