Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
shouwn committed Dec 18, 2024
2 parents 20f10e6 + 5f0dfba commit 20d8613
Show file tree
Hide file tree
Showing 20 changed files with 995 additions and 65 deletions.
20 changes: 10 additions & 10 deletions docs/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

* [Kotlin JDSL](README.md)
* [JPQL with Kotlin JDSL](jpql-with-kotlin-jdsl/README.md)
* [Statements](jpql-with-kotlin-jdsl/statements.md)
* [Entities](jpql-with-kotlin-jdsl/entities.md)
* [Paths](jpql-with-kotlin-jdsl/paths.md)
* [Expressions](jpql-with-kotlin-jdsl/expressions.md)
* [Predicates](jpql-with-kotlin-jdsl/predicates.md)
* [Sorts](jpql-with-kotlin-jdsl/sorts.md)
* [Subqueries](jpql-with-kotlin-jdsl/subqueries.md)
* [Custom DSL](jpql-with-kotlin-jdsl/custom-dsl.md)
* [Spring supports](jpql-with-kotlin-jdsl/spring-supports.md)
* [Migration 2.X to 3.X](jpql-with-kotlin-jdsl/migration-2.x-to-3.x.md)
* [Statements](jpql-with-kotlin-jdsl/statements.md)
* [Entities](jpql-with-kotlin-jdsl/entities.md)
* [Paths](jpql-with-kotlin-jdsl/paths.md)
* [Expressions](jpql-with-kotlin-jdsl/expressions.md)
* [Predicates](jpql-with-kotlin-jdsl/predicates.md)
* [Sorts](jpql-with-kotlin-jdsl/sorts.md)
* [Subqueries](jpql-with-kotlin-jdsl/subqueries.md)
* [Custom DSL](jpql-with-kotlin-jdsl/custom-dsl.md)
* [Spring supports](jpql-with-kotlin-jdsl/spring-supports.md)
* [Migration 2.X to 3.X](jpql-with-kotlin-jdsl/migration-2.x-to-3.x.md)
* [Kotlin JDSL Roadmap](kotlin-jdsl-roadmap.md)

## FAQ
Expand Down
30 changes: 20 additions & 10 deletions docs/en/jpql-with-kotlin-jdsl/spring-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,33 @@ If you declare your `JpqlSerializer` or `JpqlIntrospector` as a bean, it will be
If your `JpaRepository` extends `KotlinJdslJpqlExecutor`, you can use the extension provided by Kotlin JDSL.

```kotlin
interface AuthorRepository : JpaRepository<Author, Long>, KotlinJdslJpqlExecutor
interface BookRepository : JpaRepository<Book, Isbn>, KotlinJdslJpqlExecutor

authorRepository.findAll {
val result: List<Isbn?> = bookRepository.findAll {
select(
path(Author::authorId),
path(Book::isbn),
).from(
entity(Book::class),
)
}

val result: Page<Isbn?> = bookRepository.findPage(pageable) {
select(
path(Book::isbn),
).from(
entity(Author::class),
join(BookAuthor::class).on(path(Author::authorId).equal(path(BookAuthor::authorId))),
).groupBy(
path(Author::authorId),
).orderBy(
count(Author::authorId).desc(),
entity(Book::class),
)
}

val result: Slice<Isbn?> = bookRepository.findSlice(pageable) {
select(
path(Book::isbn),
).from(
entity(Book::class),
)
}

bookRepository.findPage(pageable) {
val result: Stream<Isbn?> = bookRepository.findStream {
select(
path(Book::isbn),
).from(
Expand Down
20 changes: 10 additions & 10 deletions docs/ko/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

* [Kotlin JDSL](README.md)
* [JPQL with Kotlin JDSL](jpql-with-kotlin-jdsl/README.md)
* [Statements](jpql-with-kotlin-jdsl/statements.md)
* [Entities](jpql-with-kotlin-jdsl/entities.md)
* [Paths](jpql-with-kotlin-jdsl/paths.md)
* [Expressions](jpql-with-kotlin-jdsl/expressions.md)
* [Predicates](jpql-with-kotlin-jdsl/predicates.md)
* [Sorts](jpql-with-kotlin-jdsl/sorts.md)
* [Subqueries](jpql-with-kotlin-jdsl/subqueries.md)
* [Custom DSL](jpql-with-kotlin-jdsl/custom-dsl.md)
* [Spring supports](jpql-with-kotlin-jdsl/spring-supports.md)
* [Migration 2.X to 3.X](jpql-with-kotlin-jdsl/migration-2.x-to-3.x.md)
* [Statements](jpql-with-kotlin-jdsl/statements.md)
* [Entities](jpql-with-kotlin-jdsl/entities.md)
* [Paths](jpql-with-kotlin-jdsl/paths.md)
* [Expressions](jpql-with-kotlin-jdsl/expressions.md)
* [Predicates](jpql-with-kotlin-jdsl/predicates.md)
* [Sorts](jpql-with-kotlin-jdsl/sorts.md)
* [Subqueries](jpql-with-kotlin-jdsl/subqueries.md)
* [Custom DSL](jpql-with-kotlin-jdsl/custom-dsl.md)
* [Spring supports](jpql-with-kotlin-jdsl/spring-supports.md)
* [Migration 2.X to 3.X](jpql-with-kotlin-jdsl/migration-2.x-to-3.x.md)
* [Kotlin JDSL Roadmap](kotlin-jdsl-roadmap.md)

## FAQ
Expand Down
3 changes: 2 additions & 1 deletion docs/ko/jpql-with-kotlin-jdsl/migration-2.x-to-3.x.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Migration 2.X to 3.X

Kotlin JDSL 2.X와 3.X는 둘 사이에 패키지 충돌이 없기 때문에 하나의 어플리케이션에서 같이 사용할 수 있습니다. 그래서 신규로 작성하는 쿼리는 Kotlin JDSL 3.X로 작성하고 점진적으로 Kotlin JDSL 2.X로 작성된 쿼리를 Kotlin JDSL 3.X로 옮겨가면 됩니다.&#x20;
Kotlin JDSL 2.X와 3.X는 둘 사이에 패키지 충돌이 없기 때문에 하나의 어플리케이션에서 같이 사용할 수 있습니다.
그래서 신규로 작성하는 쿼리는 Kotlin JDSL 3.X로 작성하고 점진적으로 Kotlin JDSL 2.X로 작성된 쿼리를 Kotlin JDSL 3.X로 옮겨가면 됩니다.
7 changes: 4 additions & 3 deletions docs/ko/jpql-with-kotlin-jdsl/predicates.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Kotlin JDSL은 JPQL의 conditional expression을 표현하기 위해 `Predicate`

{% hint style="info" %}
만약 `and()``or()`로 넘어온 `Predicate`가 모두 null 이거나 비어 있으면, `and()`의 경우에는 `1 = 1``or()`의 경우에는 `0 = 1`로 해석됩니다.
그렇기 떄문에 다이나믹 쿼리를 만들 때 조심해야 합니다.
그렇기 때문에 다이나믹 쿼리를 만들 때 조심해야 합니다.
{% endhint %}

```kotlin
Expand Down Expand Up @@ -168,8 +168,9 @@ function(Boolean::class, "myFunction", path(Book::isbn))
```

{% hint style="info" %}
사용할 함수의 정보를 JPA 제공자에 등록할 필요가 있을 수 있습니다.
예를 들어 Hibernate를 사용하고 있다면 `FunctionContributor`를 반드시 등록해야 합니다.
사용하려는 함수에 대한 정보를 JPA Provider에 등록해야 할 수도 있습니다.

예를 들어, Hibernate를 사용하고 있다면 `FunctionContributor`를 반드시 등록해야 합니다.
{% endhint %}

## Custom predicate
Expand Down
30 changes: 20 additions & 10 deletions docs/ko/jpql-with-kotlin-jdsl/spring-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,33 @@ Kotlin JDSL은 Spring Boot AutoConfigure를 지원합니다.
만약 사용하고 있는 `JpaRepository``KotlinJdslJpqlExecutor`를 상속하면, Kotlin JDSL이 제공하는 확장 기능을 사용할 수 있습니다.

```kotlin
interface AuthorRepository : JpaRepository<Author, Long>, KotlinJdslJpqlExecutor
interface BookRepository : JpaRepository<Book, Isbn>, KotlinJdslJpqlExecutor

authorRepository.findAll {
val result: List<Isbn?> = bookRepository.findAll {
select(
path(Author::authorId),
path(Book::isbn),
).from(
entity(Book::class),
)
}

val result: Page<Isbn?> = bookRepository.findPage(pageable) {
select(
path(Book::isbn),
).from(
entity(Author::class),
join(BookAuthor::class).on(path(Author::authorId).equal(path(BookAuthor::authorId))),
).groupBy(
path(Author::authorId),
).orderBy(
count(Author::authorId).desc(),
entity(Book::class),
)
}

val result: Slice<Isbn?> = bookRepository.findSlice(pageable) {
select(
path(Book::isbn),
).from(
entity(Book::class),
)
}

bookRepository.findPage(pageable) {
val result: Stream<Isbn?> = bookRepository.findStream {
select(
path(Book::isbn),
).from(
Expand Down
18 changes: 13 additions & 5 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 @@ -1287,7 +1287,7 @@ open class Jpql : JpqlDsl {
*/
@SinceJdsl("3.0.0")
fun <T : Any> new(type: KClass<T>, vararg args: Any): Expression<T> {
return Expressions.new(type, args.map { Expressions.value(it) })
return Expressions.new(type, args.map { valueOrExpression(it) })
}

/**
Expand Down Expand Up @@ -1708,7 +1708,7 @@ open class Jpql : JpqlDsl {
@LowPriorityInOverloadResolution
@SinceJdsl("3.0.0")
fun <T : Any> function(type: KClass<T>, name: String, vararg args: Any): Expression<T> {
return Expressions.function(type, name, args.map { Expressions.value(it) })
return Expressions.function(type, name, args.map { valueOrExpression(it) })
}

/**
Expand Down Expand Up @@ -1737,7 +1737,7 @@ open class Jpql : JpqlDsl {
@LowPriorityInOverloadResolution
@SinceJdsl("3.0.0")
fun <T : Any> customExpression(type: KClass<T>, template: String, vararg args: Any): Expression<T> {
return Expressions.customExpression(type, template, args.map { Expressions.value(it) })
return Expressions.customExpression(type, template, args.map { valueOrExpression(it) })
}

/**
Expand Down Expand Up @@ -3036,7 +3036,7 @@ open class Jpql : JpqlDsl {
@LowPriorityInOverloadResolution
@SinceJdsl("3.0.0")
fun function(type: KClass<Boolean>, name: String, vararg args: Any): Predicate {
return Predicates.function(name, args.map { Expressions.value(it) })
return Predicates.function(name, args.map { valueOrExpression(it) })
}

/**
Expand Down Expand Up @@ -3066,7 +3066,7 @@ open class Jpql : JpqlDsl {
@LowPriorityInOverloadResolution
@SinceJdsl("3.3.0")
fun customPredicate(template: String, vararg args: Any): Predicate {
return Predicates.customPredicate(template, args.map { Expressions.value(it) })
return Predicates.customPredicate(template, args.map { valueOrExpression(it) })
}

/**
Expand Down Expand Up @@ -3218,4 +3218,12 @@ open class Jpql : JpqlDsl {
fun <T : Any> deleteFrom(entity: Entityable<T>): DeleteQueryWhereStep<T> {
return DeleteQueryDsl(entity.toEntity())
}

private fun valueOrExpression(value: Any): Expression<*> {
return if (value is Expression<*>) {
value
} else {
Expressions.value(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,26 @@ class CustomExpressionDslTest : WithAssertions {

assertThat(actual).isEqualTo(expected)
}

@Test
fun `customExpression() with a string and a string expression`() {
// when
val expression = queryPart {
customExpression(Int::class, template1, string1, stringExpression2)
}.toExpression()

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

// then
val expected = Expressions.customExpression(
Int::class,
template1,
listOf(
Expressions.value(string1),
stringExpression2,
),
)

assertThat(actual).isEqualTo(expected)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,26 @@ class FunctionDslTest : WithAssertions {

assertThat(actual).isEqualTo(expected)
}

@Test
fun `function() with a string and a string expression`() {
// when
val expression = queryPart {
function(Int::class, name1, string1, stringExpression2)
}.toExpression()

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

// then
val expected = Expressions.function(
Int::class,
name1,
listOf(
Expressions.value(string1),
stringExpression2,
),
)

assertThat(actual).isEqualTo(expected)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,25 @@ class NewDslTest : WithAssertions {

assertThat(actual).isEqualTo(expected)
}

@Test
fun `new() with a string and a string expression`() {
// when
val expression = queryPart {
new(Row::class, string1, stringExpression2)
}.toExpression()

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

// then
val expected = Expressions.new(
type = Row::class,
args = listOf(
Expressions.value(string1),
stringExpression2,
),
)

assertThat(actual).isEqualTo(expected)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,25 @@ class CustomPredicateDslTest : WithAssertions {

assertThat(actual).isEqualTo(expected)
}

@Test
fun `customPredicate() with a string and a string expression`() {
// when
val predicate = queryPart {
customPredicate(template1, string1, stringExpression2)
}

val actual: Predicate = predicate // for type check

// then
val expected = Predicates.customPredicate(
template1,
listOf(
Expressions.value(string1),
stringExpression2,
),
)

assertThat(actual).isEqualTo(expected)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,25 @@ class FunctionDslTest : WithAssertions {

assertThat(actual).isEqualTo(expected)
}

@Test
fun `function() with a string and a string expression`() {
// when
val predicate = queryPart {
function(Boolean::class, name1, string1, stringExpression2)
}

val actual: Predicate = predicate // for type check

// then
val expected = Predicates.function(
name1,
listOf(
Expressions.value(string1),
stringExpression2,
),
)

assertThat(actual).isEqualTo(expected)
}
}
Loading

0 comments on commit 20d8613

Please sign in to comment.