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 Jun 26, 2024
2 parents 75143df + 025f6c1 commit c8d0f31
Show file tree
Hide file tree
Showing 22 changed files with 113 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.linecorp.kotlinjdsl.example.spring.data.jpa.jpql.entity.author.Author
import com.linecorp.kotlinjdsl.example.spring.data.jpa.jpql.entity.book.Book
import com.linecorp.kotlinjdsl.example.spring.data.jpa.jpql.entity.book.BookAuthor
import com.linecorp.kotlinjdsl.example.spring.data.jpa.jpql.entity.book.BookPrice
import com.linecorp.kotlinjdsl.example.spring.data.jpa.jpql.entity.book.BookPublisher
import com.linecorp.kotlinjdsl.example.spring.data.jpa.jpql.entity.book.Isbn
import com.linecorp.kotlinjdsl.example.spring.data.jpa.jpql.entity.employee.Employee
import com.linecorp.kotlinjdsl.example.spring.data.jpa.jpql.entity.employee.EmployeeDepartment
Expand Down Expand Up @@ -51,6 +52,24 @@ class SelectExample : WithAssertions {
assertThat(actual).isEqualTo(1L)
}

@Test
fun `books reference specific book publisher entity`() {
// when
val actual = bookRepository.findAll {
select(
path(Book::isbn),
).from(
entity(Book::class),
join(entity(BookPublisher::class)).on(path(BookPublisher::book).eq(entity(Book::class))),
).where(
path(BookPublisher::publisherId).eq(3),
)
}

// then
assertThat(actual).isEqualTo(listOf(Isbn("10"), Isbn("11"), Isbn("12")))
}

@Test
fun `authors who haven't written a book`() {
// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ sealed class JpqlRenderClause : AbstractRenderContextElement(Key) {
@SinceJdsl("3.0.0")
open fun isFrom(): Boolean = false

@SinceJdsl("3.5.1")
open fun isJoin(): Boolean = false

@SinceJdsl("3.5.1")
open fun isOn(): Boolean = false

@SinceJdsl("3.0.0")
open fun isWhere(): Boolean = false

Expand Down Expand Up @@ -73,6 +79,20 @@ sealed class JpqlRenderClause : AbstractRenderContextElement(Key) {
override fun toString(): String = "From"
}

@SinceJdsl("3.5.1")
object Join : JpqlRenderClause() {
override fun isJoin(): Boolean = true

override fun toString(): String = "Join"
}

@SinceJdsl("3.5.1")
object On : JpqlRenderClause() {
override fun isOn(): Boolean = true

override fun toString(): String = "On"
}

@SinceJdsl("3.0.0")
object Where : JpqlRenderClause() {
override fun isWhere(): Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class JpqlDerivedEntitySerializer : JpqlSerializer<JpqlDerivedEntity<*>> {

if (
(statement.isSelect() && clause.isFrom()) ||
(statement.isSelect() && clause.isJoin()) ||
(statement.isUpdate() && clause.isUpdate()) ||
(statement.isDelete() && clause.isDeleteFrom())
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class JpqlEntitySerializer : JpqlSerializer<JpqlEntity<*>> {

if (
(statement.isSelect() && clause.isFrom()) ||
(statement.isSelect() && clause.isJoin()) ||
(statement.isUpdate() && clause.isUpdate()) ||
(statement.isDelete() && clause.isDeleteFrom())
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.render.jpql.serializer.impl
import com.linecorp.kotlinjdsl.Internal
import com.linecorp.kotlinjdsl.querymodel.jpql.join.impl.JpqlInnerAssociationFetchJoin
import com.linecorp.kotlinjdsl.render.RenderContext
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderClause
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
Expand All @@ -20,7 +21,8 @@ class JpqlInnerAssociationFetchJoinSerializer : JpqlSerializer<JpqlInnerAssociat
writer.write("INNER JOIN FETCH")
writer.write(" ")

delegate.serialize(part.association, writer, context)
val newJoinContext = context + JpqlRenderClause.Join
delegate.serialize(part.association, writer, newJoinContext)

writer.write(" ")
writer.write("AS")
Expand All @@ -35,7 +37,8 @@ class JpqlInnerAssociationFetchJoinSerializer : JpqlSerializer<JpqlInnerAssociat
writer.write("ON")
writer.write(" ")

delegate.serialize(on, writer, context)
val newOnContext = context + JpqlRenderClause.On
delegate.serialize(on, writer, newOnContext)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.render.jpql.serializer.impl
import com.linecorp.kotlinjdsl.Internal
import com.linecorp.kotlinjdsl.querymodel.jpql.join.impl.JpqlInnerAssociationJoin
import com.linecorp.kotlinjdsl.render.RenderContext
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderClause
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
Expand All @@ -20,7 +21,8 @@ class JpqlInnerAssociationJoinSerializer : JpqlSerializer<JpqlInnerAssociationJo
writer.write("INNER JOIN")
writer.write(" ")

delegate.serialize(part.association, writer, context)
val newJoinContext = context + JpqlRenderClause.Join
delegate.serialize(part.association, writer, newJoinContext)

writer.write(" ")
writer.write("AS")
Expand All @@ -35,7 +37,8 @@ class JpqlInnerAssociationJoinSerializer : JpqlSerializer<JpqlInnerAssociationJo
writer.write("ON")
writer.write(" ")

delegate.serialize(on, writer, context)
val newOnContext = context + JpqlRenderClause.On
delegate.serialize(on, writer, newOnContext)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.render.jpql.serializer.impl
import com.linecorp.kotlinjdsl.Internal
import com.linecorp.kotlinjdsl.querymodel.jpql.join.impl.JpqlInnerFetchJoin
import com.linecorp.kotlinjdsl.render.RenderContext
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderClause
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
Expand All @@ -20,12 +21,14 @@ class JpqlInnerFetchJoinSerializer : JpqlSerializer<JpqlInnerFetchJoin<*>> {
writer.write("INNER JOIN FETCH")
writer.write(" ")

delegate.serialize(part.entity, writer, context)
val newJoinContext = context + JpqlRenderClause.Join
delegate.serialize(part.entity, writer, newJoinContext)

writer.write(" ")
writer.write("ON")
writer.write(" ")

delegate.serialize(part.on, writer, context)
val newOnContext = context + JpqlRenderClause.On
delegate.serialize(part.on, writer, newOnContext)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.render.jpql.serializer.impl
import com.linecorp.kotlinjdsl.Internal
import com.linecorp.kotlinjdsl.querymodel.jpql.join.impl.JpqlInnerJoin
import com.linecorp.kotlinjdsl.render.RenderContext
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderClause
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
Expand All @@ -20,12 +21,14 @@ class JpqlInnerJoinSerializer : JpqlSerializer<JpqlInnerJoin<*>> {
writer.write("INNER JOIN")
writer.write(" ")

delegate.serialize(part.entity, writer, context)
val newJoinContext = context + JpqlRenderClause.Join
delegate.serialize(part.entity, writer, newJoinContext)

writer.write(" ")
writer.write("ON")
writer.write(" ")

delegate.serialize(part.on, writer, context)
val newOnContext = context + JpqlRenderClause.On
delegate.serialize(part.on, writer, newOnContext)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.render.jpql.serializer.impl
import com.linecorp.kotlinjdsl.Internal
import com.linecorp.kotlinjdsl.querymodel.jpql.join.impl.JpqlLeftAssociationFetchJoin
import com.linecorp.kotlinjdsl.render.RenderContext
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderClause
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
Expand All @@ -20,7 +21,8 @@ class JpqlLeftAssociationFetchJoinSerializer : JpqlSerializer<JpqlLeftAssociatio
writer.write("LEFT JOIN FETCH")
writer.write(" ")

delegate.serialize(part.association, writer, context)
val newJoinContext = context + JpqlRenderClause.Join
delegate.serialize(part.association, writer, newJoinContext)

writer.write(" ")
writer.write("AS")
Expand All @@ -35,7 +37,8 @@ class JpqlLeftAssociationFetchJoinSerializer : JpqlSerializer<JpqlLeftAssociatio
writer.write("ON")
writer.write(" ")

delegate.serialize(on, writer, context)
val newOnContext = context + JpqlRenderClause.On
delegate.serialize(on, writer, newOnContext)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.render.jpql.serializer.impl
import com.linecorp.kotlinjdsl.Internal
import com.linecorp.kotlinjdsl.querymodel.jpql.join.impl.JpqlLeftAssociationJoin
import com.linecorp.kotlinjdsl.render.RenderContext
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderClause
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
Expand All @@ -20,7 +21,8 @@ class JpqlLeftAssociationJoinSerializer : JpqlSerializer<JpqlLeftAssociationJoin
writer.write("LEFT JOIN")
writer.write(" ")

delegate.serialize(part.association, writer, context)
val newJoinContext = context + JpqlRenderClause.Join
delegate.serialize(part.association, writer, newJoinContext)

writer.write(" ")
writer.write("AS")
Expand All @@ -35,7 +37,8 @@ class JpqlLeftAssociationJoinSerializer : JpqlSerializer<JpqlLeftAssociationJoin
writer.write("ON")
writer.write(" ")

delegate.serialize(on, writer, context)
val newOnContext = context + JpqlRenderClause.On
delegate.serialize(on, writer, newOnContext)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.render.jpql.serializer.impl
import com.linecorp.kotlinjdsl.Internal
import com.linecorp.kotlinjdsl.querymodel.jpql.join.impl.JpqlLeftFetchJoin
import com.linecorp.kotlinjdsl.render.RenderContext
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderClause
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
Expand All @@ -20,12 +21,14 @@ class JpqlLeftFetchJoinSerializer : JpqlSerializer<JpqlLeftFetchJoin<*>> {
writer.write("LEFT JOIN FETCH")
writer.write(" ")

delegate.serialize(part.entity, writer, context)
val newJoinContext = context + JpqlRenderClause.Join
delegate.serialize(part.entity, writer, newJoinContext)

writer.write(" ")
writer.write("ON")
writer.write(" ")

delegate.serialize(part.on, writer, context)
val newOnContext = context + JpqlRenderClause.On
delegate.serialize(part.on, writer, newOnContext)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.render.jpql.serializer.impl
import com.linecorp.kotlinjdsl.Internal
import com.linecorp.kotlinjdsl.querymodel.jpql.join.impl.JpqlLeftJoin
import com.linecorp.kotlinjdsl.render.RenderContext
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderClause
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
Expand All @@ -16,16 +17,17 @@ class JpqlLeftJoinSerializer : JpqlSerializer<JpqlLeftJoin<*>> {

override fun serialize(part: JpqlLeftJoin<*>, writer: JpqlWriter, context: RenderContext) {
val delegate = context.getValue(JpqlRenderSerializer)

writer.write("LEFT JOIN")
writer.write(" ")

delegate.serialize(part.entity, writer, context)
val newJoinContext = context + JpqlRenderClause.Join
delegate.serialize(part.entity, writer, newJoinContext)

writer.write(" ")
writer.write("ON")
writer.write(" ")

delegate.serialize(part.on, writer, context)
val newOnContext = context + JpqlRenderClause.On
delegate.serialize(part.on, writer, newOnContext)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class JpqlDerivedEntitySerializerTest : WithAssertions {
@StatementClauseSource(
includes = [
StatementClause(JpqlRenderStatement.Select::class, JpqlRenderClause.From::class),
StatementClause(JpqlRenderStatement.Select::class, JpqlRenderClause.Join::class),
StatementClause(JpqlRenderStatement.Update::class, JpqlRenderClause.Update::class),
StatementClause(JpqlRenderStatement.Delete::class, JpqlRenderClause.DeleteFrom::class),
],
Expand Down Expand Up @@ -84,6 +85,7 @@ class JpqlDerivedEntitySerializerTest : WithAssertions {
@StatementClauseSource(
excludes = [
StatementClause(JpqlRenderStatement.Select::class, JpqlRenderClause.From::class),
StatementClause(JpqlRenderStatement.Select::class, JpqlRenderClause.Join::class),
StatementClause(JpqlRenderStatement.Update::class, JpqlRenderClause.Update::class),
StatementClause(JpqlRenderStatement.Delete::class, JpqlRenderClause.DeleteFrom::class),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal class JpqlEntitySerializerTest : WithAssertions {
@StatementClauseSource(
includes = [
StatementClause(JpqlRenderStatement.Select::class, JpqlRenderClause.From::class),
StatementClause(JpqlRenderStatement.Select::class, JpqlRenderClause.Join::class),
StatementClause(JpqlRenderStatement.Update::class, JpqlRenderClause.Update::class),
StatementClause(JpqlRenderStatement.Delete::class, JpqlRenderClause.DeleteFrom::class),
],
Expand Down Expand Up @@ -81,6 +82,7 @@ internal class JpqlEntitySerializerTest : WithAssertions {
@StatementClauseSource(
excludes = [
StatementClause(JpqlRenderStatement.Select::class, JpqlRenderClause.From::class),
StatementClause(JpqlRenderStatement.Select::class, JpqlRenderClause.Join::class),
StatementClause(JpqlRenderStatement.Update::class, JpqlRenderClause.Update::class),
StatementClause(JpqlRenderStatement.Delete::class, JpqlRenderClause.DeleteFrom::class),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths
import com.linecorp.kotlinjdsl.querymodel.jpql.predicate.Predicates
import com.linecorp.kotlinjdsl.render.TestRenderContext
import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderClause
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializerTest
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
Expand Down Expand Up @@ -60,7 +61,7 @@ class JpqlInnerAssociationFetchJoinSerializerTest : WithAssertions {
verifySequence {
writer.write("INNER JOIN FETCH")
writer.write(" ")
serializer.serialize(path1, writer, context)
serializer.serialize(path1, writer, context + JpqlRenderClause.Join)
writer.write(" ")
writer.write("AS")
writer.write(" ")
Expand All @@ -85,15 +86,15 @@ class JpqlInnerAssociationFetchJoinSerializerTest : WithAssertions {
verifySequence {
writer.write("INNER JOIN FETCH")
writer.write(" ")
serializer.serialize(path1, writer, context)
serializer.serialize(path1, writer, context + JpqlRenderClause.Join)
writer.write(" ")
writer.write("AS")
writer.write(" ")
writer.write(entity1.alias)
writer.write(" ")
writer.write("ON")
writer.write(" ")
serializer.serialize(predicate1, writer, context)
serializer.serialize(predicate1, writer, context + JpqlRenderClause.On)
}
}
}
Loading

0 comments on commit c8d0f31

Please sign in to comment.