Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shouwn committed Oct 24, 2023
2 parents 6077c3f + 3b01d08 commit 5d32709
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16.x
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion docs/en/jpql-with-kotlin-jdsl/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Kotlin JDSL provides functions to support built-in functions in JPA.
| SUBSTRING | not yet |
| TRIM | not yet |
| LOWER | support |
| UPPER | not yet |
| UPPER | support |
| LENGTH | support |
| LOCATE | support |

Expand Down
2 changes: 1 addition & 1 deletion docs/ko/jpql-with-kotlin-jdsl/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함
| SUBSTRING | not yet |
| TRIM | not yet |
| LOWER | support |
| UPPER | not yet |
| UPPER | support |
| LENGTH | support |
| LOCATE | support |

Expand Down
16 changes: 16 additions & 0 deletions dsl/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,22 @@ open class Jpql : JpqlDsl {
return Expressions.type(path.toPath())
}

/**
* Creates an expression that represents the string in uppercase.
*/
@SinceJdsl("3.0.0")
fun upper(value: String): Expression<String> {
return Expressions.upper(Expressions.value(value))
}

/**
* Creates an expression that represents the string in uppercase.
*/
@SinceJdsl("3.0.0")
fun upper(value: Expressionable<String>): Expression<String> {
return Expressions.upper(value.toExpression())
}

/**
* Creates an expression that represents the string in lowercase.
*/
Expand Down
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.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

class UpperDslTest : WithAssertions {
private val string1 = "string1"

private val stringExpression1 = Expressions.value("string1")

@Test
fun `upper() with a string`() {
// when
val expression = queryPart {
upper(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.upper(
Expressions.value(string1),
)

assertThat(actual).isEqualTo(expected)
}

@Test
fun `upper() with a string expression`() {
// when
val expression = queryPart {
upper(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.upper(
stringExpression1,
)

assertThat(actual).isEqualTo(expected)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPlus
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubquery
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSum
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlTimes
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlUpper
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlValue
import com.linecorp.kotlinjdsl.querymodel.jpql.path.Path
import com.linecorp.kotlinjdsl.querymodel.jpql.predicate.Predicate
Expand Down Expand Up @@ -415,6 +416,14 @@ object Expressions {
return JpqlPathType(path)
}

/**
* Creates an expression that represents the string in uppercase.
*/
@SinceJdsl("3.0.0")
fun upper(value: Expression<String>): Expression<String> {
return JpqlUpper(value)
}

/**
* Creates an expression that represents the string in lowercase.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl

import com.linecorp.kotlinjdsl.Internal
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression

@Internal
data class JpqlUpper internal constructor(
val value: Expression<String>,
) : Expression<String>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPlus
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubquery
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSum
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlTimes
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlUpper
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlValue
import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths
import com.linecorp.kotlinjdsl.querymodel.jpql.predicate.Predicates
Expand Down Expand Up @@ -599,6 +600,19 @@ class ExpressionsTest : WithAssertions {
assertThat(actual).isEqualTo(expected)
}

@Test
fun upper() {
// when
val actual = Expressions.upper(stringExpression1)

// then
val expected = JpqlUpper(
stringExpression1,
)

assertThat(actual).isEqualTo(expected)
}

@Test
fun lower() {
// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSubquerySerialize
import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSumSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlTimesSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlUpdateQuerySerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlUpperSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlValueSerializer

/**
Expand Down Expand Up @@ -329,6 +330,7 @@ private class DefaultModule : JpqlRenderModule {
JpqlSumSerializer(),
JpqlTimesSerializer(),
JpqlUpdateQuerySerializer(),
JpqlUpperSerializer(),
JpqlValueSerializer(),
)
}
Expand Down
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.JpqlUpper
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 JpqlUpperSerializer : JpqlSerializer<JpqlUpper> {
override fun handledType(): KClass<JpqlUpper> {
return JpqlUpper::class
}

override fun serialize(part: JpqlUpper, writer: JpqlWriter, context: RenderContext) {
val delegate = context.getValue(JpqlRenderSerializer)

writer.write("UPPER")

writer.writeParentheses {
delegate.serialize(part.value, writer, context)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.linecorp.kotlinjdsl.render.jpql.serializer.impl

import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlUpper
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 JpqlUpperSerializerTest : WithAssertions {
private val sut = JpqlUpperSerializer()

@MockK
private lateinit var writer: JpqlWriter

@MockK
private lateinit var serializer: JpqlRenderSerializer

private val stringExpression1 = Expressions.value("string1")

@Test
fun handledType() {
// when
val actual = sut.handledType()

// then
assertThat(actual).isEqualTo(JpqlUpper::class)
}

@Test
fun serialize() {
// given
val part = Expressions.upper(
stringExpression1,
)
val context = TestRenderContext(serializer)

// when
sut.serialize(part as JpqlUpper, writer, context)

// then
verifySequence {
writer.write("UPPER")
writer.writeParentheses(any())
serializer.serialize(stringExpression1, writer, context)
}
}
}

0 comments on commit 5d32709

Please sign in to comment.