mirror of
https://github.com/gotson/komga.git
synced 2025-12-06 08:32:25 +01:00
exhaustive JPA names for tables and columns
This commit is contained in:
parent
d900318b42
commit
4bf32fe332
6 changed files with 41 additions and 6 deletions
|
|
@ -5,32 +5,45 @@ import java.nio.file.Path
|
|||
import java.nio.file.Paths
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.CascadeType
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.FetchType
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.Id
|
||||
import javax.persistence.JoinColumn
|
||||
import javax.persistence.ManyToOne
|
||||
import javax.persistence.OneToOne
|
||||
import javax.persistence.PrimaryKeyJoinColumn
|
||||
import javax.persistence.Table
|
||||
import javax.validation.constraints.NotBlank
|
||||
import javax.validation.constraints.NotNull
|
||||
|
||||
@Entity
|
||||
@Table(name = "book")
|
||||
class Book(
|
||||
@NotBlank
|
||||
@Column(name = "name", nullable = false)
|
||||
val name: String,
|
||||
|
||||
@Column(name = "url", nullable = false)
|
||||
val url: URL,
|
||||
|
||||
@Column(name = "updated", nullable = false)
|
||||
val updated: LocalDateTime
|
||||
) {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id", nullable = false, unique = true)
|
||||
@PrimaryKeyJoinColumn
|
||||
var id: Long = 0
|
||||
|
||||
@NotNull
|
||||
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||
@JoinColumn(name = "serie_id", nullable = false)
|
||||
lateinit var serie: Serie
|
||||
|
||||
@OneToOne(optional = false, orphanRemoval = true, cascade = [CascadeType.ALL], fetch = FetchType.LAZY, mappedBy = "book")
|
||||
@OneToOne(optional = false, orphanRemoval = true, cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "book_metadata_id", nullable = false)
|
||||
var metadata: BookMetadata = BookMetadata().also { it.book = this }
|
||||
set(value) {
|
||||
value.book = this
|
||||
|
|
|
|||
|
|
@ -9,24 +9,32 @@ import javax.persistence.Enumerated
|
|||
import javax.persistence.FetchType
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.Id
|
||||
import javax.persistence.JoinColumn
|
||||
import javax.persistence.OneToOne
|
||||
import javax.persistence.Table
|
||||
|
||||
@Entity
|
||||
@Table(name = "book_metadata")
|
||||
class BookMetadata(
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "status", nullable = false)
|
||||
val status: Status = Status.UNKNOWN,
|
||||
|
||||
@Column(name = "media_type")
|
||||
val mediaType: String? = null,
|
||||
|
||||
pages: List<BookPage> = emptyList()
|
||||
) {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id", nullable = false, unique = true)
|
||||
val id: Long = 0
|
||||
|
||||
@OneToOne(optional = false, fetch = FetchType.LAZY)
|
||||
@OneToOne(optional = false, fetch = FetchType.LAZY, mappedBy = "metadata")
|
||||
lateinit var book: Book
|
||||
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(name = "book_metadata_pages")
|
||||
@CollectionTable(name = "book_metadata_pages", joinColumns = [JoinColumn(name = "book_metadata_id")])
|
||||
@Column(name = "pages")
|
||||
private val _pages: MutableList<BookPage> = mutableListOf()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
package org.gotson.komga.domain.model
|
||||
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Embeddable
|
||||
|
||||
@Embeddable
|
||||
class BookPage(
|
||||
@Column(name = "file_name", nullable = false)
|
||||
val fileName: String,
|
||||
|
||||
@Column(name = "media_type", nullable = false)
|
||||
val mediaType: String
|
||||
)
|
||||
|
|
@ -3,23 +3,31 @@ package org.gotson.komga.domain.model
|
|||
import java.net.URL
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.CascadeType
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.FetchType
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.Id
|
||||
import javax.persistence.OneToMany
|
||||
import javax.persistence.Table
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Entity
|
||||
@Table(name = "serie")
|
||||
class Serie(
|
||||
@NotBlank
|
||||
@Column(name = "name", nullable = false)
|
||||
val name: String,
|
||||
|
||||
@Column(name = "url", nullable = false)
|
||||
val url: URL,
|
||||
|
||||
@Column(name = "updated", nullable = false)
|
||||
val updated: LocalDateTime
|
||||
) {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id", nullable = false, unique = true)
|
||||
var id: Long = 0
|
||||
|
||||
@OneToMany(cascade = [CascadeType.ALL], fetch = FetchType.LAZY, mappedBy = "serie", orphanRemoval = true)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class PersistenceTest(
|
|||
@Test
|
||||
fun `given serie with book when saving then metadata is also saved`() {
|
||||
// given
|
||||
val serie = makeSerie(name = "serie", books = mutableListOf(makeBook("book1")))
|
||||
val serie = makeSerie(name = "serie", books = listOf(makeBook("book1")))
|
||||
|
||||
// when
|
||||
serieRepository.save(serie)
|
||||
|
|
@ -47,7 +47,7 @@ class PersistenceTest(
|
|||
@Test
|
||||
fun `given existing book when updating metadata then new metadata is saved`() {
|
||||
// given
|
||||
val serie = makeSerie(name = "serie", books = mutableListOf(makeBook("book1")))
|
||||
val serie = makeSerie(name = "serie", books = listOf(makeBook("book1")))
|
||||
serieRepository.save(serie)
|
||||
|
||||
// when
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ application.version: TESTING
|
|||
|
||||
spring:
|
||||
jpa:
|
||||
show-sql: true
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
logging.level.org.hibernate:
|
||||
SQL: DEBUG
|
||||
type.descriptor.sql.BasicBinder: TRACE
|
||||
Loading…
Reference in a new issue