-
Notifications
You must be signed in to change notification settings - Fork 90
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 #451 from SeongYunKim/feature/eclipselink-support
support module for eclipselink (jakarta, javax)
- Loading branch information
Showing
38 changed files
with
2,213 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
plugins { | ||
alias(libs.plugins.kotlin.noarg) | ||
alias(libs.plugins.kotlin.allopen) | ||
alias(libs.plugins.kotlin.jpa) | ||
} | ||
|
||
dependencies { | ||
@Suppress("VulnerableLibrariesLocal", "RedundantSuppression") | ||
implementation(projects.example) | ||
implementation(projects.jpqlDsl) | ||
implementation(projects.jpqlRender) | ||
implementation(projects.eclipselinkSupport) | ||
|
||
implementation(libs.logback) | ||
implementation(libs.eclipselink.v4) | ||
|
||
runtimeOnly(libs.test.h2) | ||
|
||
testFixturesImplementation(libs.eclipselink.v4) | ||
testFixturesImplementation(projects.jpqlRender) | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(17) | ||
} | ||
|
||
noArg { | ||
annotation("com.linecorp.kotlinjdsl.example.eclipselink.annotation.CompositeId") | ||
} | ||
|
||
allOpen { | ||
annotation("com.linecorp.kotlinjdsl.example.eclipselink.annotation.CompositeId") | ||
annotation("jakarta.persistence.Entity") | ||
annotation("jakarta.persistence.Embeddable") | ||
} | ||
|
||
tasks.withType<PublishToMavenRepository>().configureEach { enabled = false } | ||
tasks.withType<PublishToMavenLocal>().configureEach { enabled = false } |
3 changes: 3 additions & 0 deletions
3
...ink/src/main/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/annotation/CompositeId.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,3 @@ | ||
package com.linecorp.kotlinjdsl.example.eclipselink.annotation | ||
|
||
annotation class CompositeId |
25 changes: 25 additions & 0 deletions
25
...elink/src/main/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/author/Author.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,25 @@ | ||
@file:Suppress("JpaDataSourceORMInspection") | ||
|
||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.author | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "author") | ||
class Author( | ||
@Id | ||
@Column(name = "author_id") | ||
val authorId: Long, | ||
|
||
@Column(name = "name") | ||
var name: String, | ||
) { | ||
override fun equals(other: Any?): Boolean = Objects.equals(authorId, (other as? Author)?.authorId) | ||
override fun hashCode(): Int = Objects.hashCode(authorId) | ||
|
||
override fun toString(): String = "Author(authorId=$authorId)" | ||
} |
56 changes: 56 additions & 0 deletions
56
...lipselink/src/main/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/book/Book.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,56 @@ | ||
@file:Suppress("LeakingThis", "unused", "JpaDataSourceORMInspection") | ||
|
||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.book | ||
|
||
import jakarta.persistence.AttributeOverride | ||
import jakarta.persistence.CascadeType | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Embedded | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.OneToMany | ||
import jakarta.persistence.OneToOne | ||
import jakarta.persistence.Table | ||
import java.time.OffsetDateTime | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "book") | ||
class Book( | ||
@Id | ||
@Column(name = "isbn") | ||
val isbn: String, | ||
|
||
@Column(name = "title") | ||
var title: String, | ||
|
||
@Column(name = "image_url") | ||
var imageUrl: String, | ||
|
||
@Embedded | ||
@AttributeOverride(name = "value", column = Column(name = "price")) | ||
var price: BookPrice, | ||
|
||
@Embedded | ||
@AttributeOverride(name = "value", column = Column(name = "sale_price")) | ||
var salePrice: BookPrice, | ||
|
||
@Column(name = "publish_date") | ||
var publishDate: OffsetDateTime, | ||
|
||
@OneToMany(mappedBy = "book", cascade = [CascadeType.ALL], orphanRemoval = true) | ||
val authors: MutableSet<BookAuthor>, | ||
|
||
@OneToOne(mappedBy = "book", cascade = [CascadeType.ALL], orphanRemoval = true) | ||
val publisher: BookPublisher, | ||
) { | ||
init { | ||
authors.forEach { it.book = this } | ||
publisher.book = this | ||
} | ||
|
||
override fun equals(other: Any?): Boolean = Objects.equals(isbn, (other as? Book)?.isbn) | ||
override fun hashCode(): Int = Objects.hashCode(isbn) | ||
|
||
override fun toString(): String = "Book(isbn=$isbn)" | ||
} |
45 changes: 45 additions & 0 deletions
45
...ink/src/main/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/book/BookAuthor.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,45 @@ | ||
@file:Suppress("JpaDataSourceORMInspection") | ||
|
||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.book | ||
|
||
import com.linecorp.kotlinjdsl.example.eclipselink.annotation.CompositeId | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.IdClass | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.ManyToOne | ||
import jakarta.persistence.Table | ||
import java.io.Serializable | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "book_author") | ||
@IdClass(BookAuthor.BookAuthorId::class) | ||
class BookAuthor( | ||
@Id | ||
@Column(name = "author_id") | ||
val authorId: Long, | ||
) { | ||
@Id | ||
@ManyToOne | ||
@JoinColumn(name = "isbn") | ||
lateinit var book: Book | ||
|
||
private val bookAuthorId get() = BookAuthorId(book.isbn, authorId) | ||
|
||
override fun equals(other: Any?): Boolean = | ||
Objects.equals(bookAuthorId, (other as? BookAuthor)?.bookAuthorId) | ||
|
||
override fun hashCode(): Int = | ||
Objects.hashCode(bookAuthorId) | ||
|
||
override fun toString(): String = | ||
"BookAuthor(bookAuthorId=$bookAuthorId)" | ||
|
||
@CompositeId | ||
data class BookAuthorId( | ||
val book: String, | ||
val authorId: Long, | ||
) : Serializable | ||
} |
21 changes: 21 additions & 0 deletions
21
...link/src/main/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/book/BookPrice.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,21 @@ | ||
@file:Suppress("unused") | ||
|
||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.book | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Embeddable | ||
import java.math.BigDecimal | ||
|
||
@Embeddable | ||
data class BookPrice( | ||
@Column(name = "price", scale = 2) | ||
val value: BigDecimal, | ||
) | ||
|
||
fun BookPrice(int: Int): BookPrice { | ||
return BookPrice(BigDecimal.valueOf(int.toLong()).setScale(2)) | ||
} | ||
|
||
fun BookPrice(double: Double): BookPrice { | ||
return BookPrice(BigDecimal.valueOf(double).setScale(2)) | ||
} |
45 changes: 45 additions & 0 deletions
45
.../src/main/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/book/BookPublisher.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,45 @@ | ||
@file:Suppress("JpaDataSourceORMInspection") | ||
|
||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.book | ||
|
||
import com.linecorp.kotlinjdsl.example.eclipselink.annotation.CompositeId | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.IdClass | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.OneToOne | ||
import jakarta.persistence.Table | ||
import java.io.Serializable | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "book_publisher") | ||
@IdClass(BookPublisher.BookPublisherId::class) | ||
class BookPublisher( | ||
@Id | ||
@Column(name = "publisher_id") | ||
val publisherId: Long, | ||
) { | ||
@Id | ||
@OneToOne | ||
@JoinColumn(name = "isbn") | ||
lateinit var book: Book | ||
|
||
private val bookPublisherId get() = BookPublisherId(book.isbn, publisherId) | ||
|
||
override fun equals(other: Any?): Boolean = | ||
Objects.equals(bookPublisherId, (other as? BookPublisher)?.bookPublisherId) | ||
|
||
override fun hashCode(): Int = | ||
Objects.hashCode(bookPublisherId) | ||
|
||
override fun toString(): String = | ||
"BookPublisher(bookPublisherId=$bookPublisherId)" | ||
|
||
@CompositeId | ||
data class BookPublisherId( | ||
val book: String, | ||
val publisherId: Long, | ||
) : Serializable | ||
} |
14 changes: 14 additions & 0 deletions
14
...lipselink/src/main/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/book/Isbn.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,14 @@ | ||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.book | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Embeddable | ||
import java.io.Serializable | ||
|
||
/** | ||
* International Standard Book Number | ||
*/ | ||
@Embeddable | ||
data class Isbn( | ||
@Column(name = "isbn") | ||
val value: String, | ||
) : Serializable |
25 changes: 25 additions & 0 deletions
25
...c/main/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/department/Department.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,25 @@ | ||
@file:Suppress("JpaDataSourceORMInspection") | ||
|
||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.department | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "department") | ||
class Department( | ||
@Id | ||
@Column(name = "department_id") | ||
val departmentId: Long, | ||
|
||
@Column(name = "name") | ||
val name: String, | ||
) { | ||
override fun equals(other: Any?): Boolean = Objects.equals(departmentId, (other as? Department)?.departmentId) | ||
override fun hashCode(): Int = Objects.hashCode(departmentId) | ||
|
||
override fun toString(): String = "Department(departmentId=$departmentId)" | ||
} |
48 changes: 48 additions & 0 deletions
48
...k/src/main/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/employee/Employee.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,48 @@ | ||
@file:Suppress("LeakingThis", "unused", "JpaDataSourceORMInspection") | ||
|
||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.employee | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.DiscriminatorColumn | ||
import jakarta.persistence.Embedded | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Inheritance | ||
import jakarta.persistence.InheritanceType | ||
import jakarta.persistence.OneToMany | ||
import jakarta.persistence.Table | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "employee") | ||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) | ||
@DiscriminatorColumn(name = "employee_type") | ||
class Employee( | ||
@Id | ||
@Column(name = "employee_id") | ||
val employeeId: Long, | ||
|
||
@Column(name = "name") | ||
var name: String, | ||
|
||
@Column(name = "nickname") | ||
var nickname: String?, | ||
|
||
@Column(name = "phone") | ||
var phone: String, | ||
|
||
@Embedded | ||
val address: EmployeeAddress, | ||
|
||
@OneToMany(mappedBy = "employee") | ||
val departments: MutableSet<EmployeeDepartment>, | ||
) { | ||
init { | ||
departments.forEach { it.employee = this } | ||
} | ||
|
||
override fun equals(other: Any?): Boolean = Objects.equals(employeeId, (other as? Employee)?.employeeId) | ||
override fun hashCode(): Int = Objects.hashCode(employeeId) | ||
|
||
override fun toString(): String = "Employee(employeeId=$employeeId)" | ||
} |
22 changes: 22 additions & 0 deletions
22
...ain/kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/employee/EmployeeAddress.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,22 @@ | ||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.employee | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Embeddable | ||
|
||
@Embeddable | ||
data class EmployeeAddress( | ||
@Column(name = "zip_code") | ||
val zipCode: String, | ||
|
||
@Column(name = "street_address_1") | ||
val streetAddress1: String, | ||
|
||
@Column(name = "street_address_2") | ||
val streetAddress2: String?, | ||
|
||
@Column(name = "city") | ||
val city: String, | ||
|
||
@Column(name = "province") | ||
val province: String, | ||
) |
45 changes: 45 additions & 0 deletions
45
.../kotlin/com/linecorp/kotlinjdsl/example/eclipselink/entity/employee/EmployeeDepartment.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,45 @@ | ||
@file:Suppress("JpaDataSourceORMInspection") | ||
|
||
package com.linecorp.kotlinjdsl.example.eclipselink.entity.employee | ||
|
||
import com.linecorp.kotlinjdsl.example.eclipselink.annotation.CompositeId | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.IdClass | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.ManyToOne | ||
import jakarta.persistence.Table | ||
import java.io.Serializable | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "employee_department") | ||
@IdClass(EmployeeDepartment.EmployeeDepartmentId::class) | ||
class EmployeeDepartment( | ||
@Id | ||
@Column(name = "department_id") | ||
val departmentId: Long, | ||
) { | ||
@Id | ||
@ManyToOne | ||
@JoinColumn(name = "employee_id") | ||
lateinit var employee: Employee | ||
|
||
private val employeeDepartmentId get() = EmployeeDepartmentId(employee.employeeId, departmentId) | ||
|
||
override fun equals(other: Any?): Boolean = | ||
Objects.equals(employeeDepartmentId, (other as? EmployeeDepartment)?.employeeDepartmentId) | ||
|
||
override fun hashCode(): Int = | ||
Objects.hashCode(employeeDepartmentId) | ||
|
||
override fun toString(): String = | ||
"EmployeeDepartment(employeeDepartmentId=$employeeDepartmentId)" | ||
|
||
@CompositeId | ||
data class EmployeeDepartmentId( | ||
val employee: Long, | ||
val departmentId: Long, | ||
) : Serializable | ||
} |
Oops, something went wrong.