Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shouwn committed Nov 22, 2023
2 parents 2ed0795 + 1b028df commit df75609
Show file tree
Hide file tree
Showing 77 changed files with 2,296 additions and 75 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Visit [the gitbook](https://kotlin-jdsl.gitbook.io/docs/) for more information.
Visit [the gitbook](https://kotlin-jdsl.gitbook.io/snapshot-docs/) for more information.

# Kotlin JDSL

<a href="https://github.com/line/kotlin-jdsl"><img src="https://img.shields.io/github/stars/line/kotlin-jdsl.svg?style=social" /></a>
<a href="https://discord.gg/7FH8c6npmg"><img src="https://img.shields.io/badge/chat-on%20Discord-brightgreen.svg?style=social&amp;logo=discord" /></a>
<a href="https://github.com/line/kotlin-jdsl/contributors"><img src="https://img.shields.io/github/contributors/line/kotlin-jdsl.svg" /></a>
<a href="https://codecov.io/gh/line/kotlin-jdsl"><img src="https://codecov.io/gh/line/kotlin-jdsl/branch/main/graph/badge.svg"/></a>
<a href="https://codecov.io/gh/line/kotlin-jdsl"><img src="https://codecov.io/gh/line/kotlin-jdsl/branch/develop/graph/badge.svg"/></a>
<a href="https://github.com/line/kotlin-jdsl/pulse"><img src="https://img.shields.io/github/commit-activity/m/line/kotlin-jdsl.svg?label=commits" /></a>
<a href="https://search.maven.org/search?q=g:com.linecorp.kotlin-jdsl"><img src="https://img.shields.io/maven-central/v/com.linecorp.kotlin-jdsl/kotlin-jdsl.svg?label=version" /></a>
<a href="https://github.com/line/kotlin-jdsl/commits"><img src="https://img.shields.io/github/release-date/line/kotlin-jdsl.svg?label=release" /></a>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ allprojects {
apply(plugin = "signing")

group = "com.linecorp.kotlin-jdsl"
version = "3.0.2"
version = "3.1.0-SNAPSHOT"

repositories {
mavenCentral()
Expand Down
12 changes: 6 additions & 6 deletions docs/en/jpql-with-kotlin-jdsl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ Every Kotlin JDSL application requires at least the following dependencies:

```kotlin
dependencies {
implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.0.2")
implementation("com.linecorp.kotlin-jdsl:jpql-render:3.0.2")
implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.1.0-SNAPSHOT")
implementation("com.linecorp.kotlin-jdsl:jpql-render:3.1.0-SNAPSHOT")
}
```

Expand All @@ -110,8 +110,8 @@ dependencies {

```groovy
dependencies {
implementation 'com.linecorp.kotlin-jdsl:jpql-dsl:3.0.2'
implementation 'com.linecorp.kotlin-jdsl:jpql-render:3.0.2'
implementation 'com.linecorp.kotlin-jdsl:jpql-dsl:3.1.0-SNAPSHOT'
implementation 'com.linecorp.kotlin-jdsl:jpql-render:3.1.0-SNAPSHOT'
}
```

Expand All @@ -125,12 +125,12 @@ dependencies {
<dependency>
<groupId>com.linecorp.kotlin-jdsl</groupId>
<artifactId>jpql-dsl</artifactId>
<version>3.0.2</version>
<version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.linecorp.kotlin-jdsl</groupId>
<artifactId>jpql-render</artifactId>
<version>3.0.2</version>
<version>3.1.0-SNAPSHOT</version>
</dependency>
</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 @@ -195,7 +195,7 @@ Kotlin JDSL provides functions to support built-in functions in JPA.
|-----------|--------------|
| CONCAT | not yet |
| SUBSTRING | not yet |
| TRIM | not yet |
| TRIM | support |
| LOWER | support |
| UPPER | support |
| LENGTH | support |
Expand Down
71 changes: 71 additions & 0 deletions docs/en/jpql-with-kotlin-jdsl/paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,77 @@ entity(Book::class, "b").path(Book::isbn).path(Isbn::value)
entity(Book::class, "b")(Book::isbn)(Isbn::value)
```

## Java entity

`path()` and `invoke()` can take `KProperty1` or `KFuction1` as an argument.
`KFunction1` is useful when you use Java entity with private property and public getter.

```java
@Entity
public class Book {
@Id
private Long id;

private String title;

public String getTitle() {
return title;
}
}
```

```kotlin
// compile error
path(Book::title)

// Book.title
path(Book::getTitle)
```

Kotlin JDSL infers the property name from the getter with the following rules:

- If the name starts with `is`, use the name as it is.
- If the name starts with `get`, remove `get` and change the first letter to lowercase.
- Otherwise, use the name as it is.

```kotlin
// Book.isAvailable
path(Book::isAvailable)

// Book.available
path(Book::getAvailable)
```

If you want to use your own rule instead of the above rules, you can implement `JpqlPropertyIntrospector` and provide it to `RenderContext`.
See [Custom DSL](./custom-dsl.md) for more details.
If you are using Spring, see [Spring supports](./spring-supports.md) also.

```kotlin
class MyIntrospector : JpqlPropertyIntrospector() {
override fun introspect(property: KCallable<*>): JpqlPropertyDescription? {
if (property is KFunction1<*, *>) {
// resolve a name with your own rule
val name = ...
return MyProperty(name)
}

return null
}

private data class MyProperty(
override val name: String,
) : JpqlPropertyDescription
}

val myModule = object : JpqlRenderModule {
override fun setupModule(context: JpqlRenderModule.SetupContext) {
context.prependIntrospector(MyIntrospector())
}
}

val myContext = JpqlRenderContext().registerModule(myModule)
```

## Expression

`Path` can be used as [`Expression`](expressions.md), such as in a [select clause](statements.md#select-clause) or [predicate](predicates.md).
Expand Down
4 changes: 2 additions & 2 deletions docs/en/jpql-with-kotlin-jdsl/spring-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Kotlin JDSL supports Spring Boot AutoConfigure.
If you have Spring Boot and `com.linecorp.kotlin-jdsl:spring-data-jpa-support` or `com.linecorp.kotlin-jdsl:spring-batch-support` dependency together, the `JpqlRenderContext` bean is created by AutoConfiguration.

If you declare your `JpqlSerializer` as a bean, it will be included with the `JpqlRenderContext` bean.
If you declare your `JpqlSerializer` or `JpqlIntrospector` as a bean, it will be included with the `JpqlRenderContext` bean.

## Spring Data Repository

Expand Down Expand Up @@ -47,7 +47,7 @@ So if you want to use the features of Kotlin JDSL in `@DataJpaTest`, you need to
## Spring Batch

Spring Batch provides `JpaPagingItemReader` and `JpaCursorItemReader` for querying data with JPQL.
Kotlin JDSL provides `KotlinJdslQueryProvider` so that a JPQL query created in DSL can be executed on it.
Kotlin JDSL provides `KotlinJdslQueryProvider` so that a JPQL query created in DSL can be executed on them.

```kotlin
@Auwoired
Expand Down
12 changes: 6 additions & 6 deletions docs/ko/jpql-with-kotlin-jdsl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ Kotlin JDSL을 실행시키기 위해서는 다음 dependency들이 필수로

```kotlin
dependencies {
implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.0.2")
implementation("com.linecorp.kotlin-jdsl:jpql-render:3.0.2")
implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.1.0-SNAPSHOT")
implementation("com.linecorp.kotlin-jdsl:jpql-render:3.1.0-SNAPSHOT")
}
```

Expand All @@ -111,8 +111,8 @@ dependencies {

```groovy
dependencies {
implementation 'com.linecorp.kotlin-jdsl:jpql-dsl:3.0.2'
implementation 'com.linecorp.kotlin-jdsl:jpql-render:3.0.2'
implementation 'com.linecorp.kotlin-jdsl:jpql-dsl:3.1.0-SNAPSHOT'
implementation 'com.linecorp.kotlin-jdsl:jpql-render:3.1.0-SNAPSHOT'
}
```

Expand All @@ -126,12 +126,12 @@ dependencies {
<dependency>
<groupId>com.linecorp.kotlin-jdsl</groupId>
<artifactId>jpql-dsl</artifactId>
<version>3.0.2</version>
<version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.linecorp.kotlin-jdsl</groupId>
<artifactId>jpql-render</artifactId>
<version>3.0.2</version>
<version>3.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
```
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 @@ -194,7 +194,7 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함
|-----------|--------------|
| CONCAT | not yet |
| SUBSTRING | not yet |
| TRIM | not yet |
| TRIM | support |
| LOWER | support |
| UPPER | support |
| LENGTH | support |
Expand Down
71 changes: 71 additions & 0 deletions docs/ko/jpql-with-kotlin-jdsl/paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,77 @@ entity(Book::class, "b").path(Book::isbn).path(Isbn::value)
entity(Book::class, "b")(Book::isbn)(Isbn::value)
```

## Java entity

`path()``invoke()``KProperty1` 또는 `KFuction1`를 인자로 받습니다.
`KFunction1`의 경우, getter만 public인 Java로 선언한 entity를 사용할 때 유용합니다.

```java
@Entity
public class Book {
@Id
private Long id;

private String title;

public String getTitle() {
return title;
}
}
```

```kotlin
// compile error
path(Book::title)

// Book.title
path(Book::getTitle)
```

Kotlin JDSL은 getter 이름에서 프로퍼티 이름을 추론하기 위해 다음 규칙을 따릅니다.

- `is`로 시작하는 경우 이름 그대로 사용합니다.
- `get`으로 시작하는 경우 `get`을 제거하고 이후 첫 글자를 소문자로 변경합니다.
- 그 외의 경우, 이름 그대로 사용합니다.

```kotlin
// Book.isAvailable
path(Book::isAvailable)

// Book.available
path(Book::getAvailable)
```

위 규칙 대신 나만의 규칙을 사용하고 싶다면, `JpqlPropertyIntrospector`를 구현하고 이를 이를 `RenderContext`에 추가해야 합니다.
더 자세한 내용은 [Custom DSL](./custom-dsl.md)을 참고하세요.
Spring을 사용하고 있다면 [Spring supports](./spring-supports.md)도 참고하세요.

```kotlin
class MyIntrospector : JpqlPropertyIntrospector() {
override fun introspect(property: KCallable<*>): JpqlPropertyDescription? {
if (property is KFunction1<*, *>) {
// 나만의 규칙으로 이름을 추론합니다
val name = ...
return MyProperty(name)
}

return null
}

private data class MyProperty(
override val name: String,
) : JpqlPropertyDescription
}

val myModule = object : JpqlRenderModule {
override fun setupModule(context: JpqlRenderModule.SetupContext) {
context.prependIntrospector(MyIntrospector())
}
}

val myContext = JpqlRenderContext().registerModule(myModule)
```

## Expression

`Path`[select clause](statements.md#select-clause)[predicate](predicates.md) 등에서 [`Expression`](expressions.md)으로 사용될 수 있습니다.
Expand Down
6 changes: 3 additions & 3 deletions docs/ko/jpql-with-kotlin-jdsl/spring-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
## Spring Boot AutoConfigure

Kotlin JDSL은 Spring Boot AutoConfigure를 지원합니다.
만약 프로젝트가 Spring Boot와 `com.linecorp.kotlin-jdsl:spring-data-jpa-support` dependency를 같이 포함하고 있다면, `JpqlRenderContext` bean이 `KotlinJdslAutoConfiguration` 통해 자동 생성 됩니다.
만약 프로젝트가 Spring Boot와 `com.linecorp.kotlin-jdsl:spring-data-jpa-support` dependency를 같이 포함하고 있다면, `JpqlRenderContext` bean이 `KotlinJdslAutoConfiguration` 통해 자동 생성 됩니다.

만약 `JpqlSerializer`를 bean으로 선언했다면, 자동으로 `JpqlRenderContext`에 해당 bean이 포함됩니다.
만약 `JpqlSerializer` 또는 `JpqlIntrospector`를 bean으로 선언했다면, 자동으로 `JpqlRenderContext`에 해당 bean이 포함됩니다.

## Spring Data Repository

Expand Down Expand Up @@ -46,7 +46,7 @@ bookRepository.findPage(pageable) {
## Spring Batch

SpringBatch는 JPQL로 쿼리를 할 수 있도록 `JpaPagingItemReader``JpaCursorItemReader`를 제공합니다.
Kotlin JDSL은 DSL로 생성된 JPQL 쿼리가 JpqReader들에서 실행될 수 있도록 `KotlinJdslQueryProvider` 제공합니다.
Kotlin JDSL은 DSL로 생성된 JPQL 쿼리가 위 ItemReader들에서 실행될 수 있도록 `KotlinJdslQueryProvider` 제공합니다.

```kotlin
@Auwoired
Expand Down
Loading

0 comments on commit df75609

Please sign in to comment.