Add Helper Entity
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package fr.postgresjson.serializer
|
package fr.postgresjson
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser
|
import com.fasterxml.jackson.core.JsonParser
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException
|
import com.fasterxml.jackson.core.JsonProcessingException
|
||||||
@@ -3,8 +3,8 @@ package fr.postgresjson.connexion
|
|||||||
import com.github.jasync.sql.db.pool.ConnectionPool
|
import com.github.jasync.sql.db.pool.ConnectionPool
|
||||||
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
|
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
|
||||||
import com.github.jasync.sql.db.postgresql.PostgreSQLConnectionBuilder
|
import com.github.jasync.sql.db.postgresql.PostgreSQLConnectionBuilder
|
||||||
|
import fr.postgresjson.Serializer
|
||||||
import fr.postgresjson.entity.EntityI
|
import fr.postgresjson.entity.EntityI
|
||||||
import fr.postgresjson.serializer.Serializer
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,90 @@
|
|||||||
package fr.postgresjson.entity
|
package fr.postgresjson.entity
|
||||||
|
|
||||||
|
import org.joda.time.DateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
/* ID */
|
||||||
interface EntityI<T> {
|
interface EntityI<T> {
|
||||||
var id: T?
|
var id: T?
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Entity<T>(override var id: T? = null) : EntityI<T?>
|
abstract class Entity<T>(override var id: T? = null) : EntityI<T?>
|
||||||
abstract class UuidEntity(override var id: UUID? = UUID.randomUUID()) : Entity<UUID?>(id)
|
abstract class UuidEntity(override var id: UUID? = UUID.randomUUID()) : Entity<UUID?>(id)
|
||||||
abstract class IdEntity(override var id: Int? = null) : Entity<Int?>(id)
|
abstract class IdEntity(override var id: Int? = null) : Entity<Int?>(id)
|
||||||
|
|
||||||
|
/* Version */
|
||||||
interface EntityVersioning<T> {
|
interface EntityVersioning<T> {
|
||||||
var version: T
|
var version: T
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EntityVersioningIncrement : EntityVersioning<Int>
|
interface EntityVersioningIncrement : EntityVersioning<Int?>
|
||||||
|
class EntityVersioningIncrementImp() : EntityVersioningIncrement {
|
||||||
|
override var version: Int? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EntityVersioningDate : EntityVersioning<DateTime?>
|
||||||
|
class EntityVersioningDateImp() : EntityVersioningDate {
|
||||||
|
override var version: DateTime? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dates */
|
||||||
|
interface EntityCreatedAt {
|
||||||
|
var createdAt: DateTime?
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EntityUpdatedAt {
|
||||||
|
var updatedAt: DateTime?
|
||||||
|
}
|
||||||
|
|
||||||
|
class EntityCreatedAtImp : EntityCreatedAt {
|
||||||
|
override var createdAt: DateTime? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
class EntityUpdatedAtImp : EntityUpdatedAt {
|
||||||
|
override var updatedAt: DateTime? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
interface User<T> : EntityI<T> {
|
||||||
|
fun isValid(): Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Author */
|
||||||
|
interface CreatedBy<T> {
|
||||||
|
var createdBy: User<T>?
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UpdatedBy<T> {
|
||||||
|
var updatedBy: User<T>?
|
||||||
|
}
|
||||||
|
|
||||||
|
class EntityCreatedByImp<T> : CreatedBy<T> {
|
||||||
|
override var createdBy: User<T>? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
class EntityUpdatedByImp<T> : UpdatedBy<T> {
|
||||||
|
override var updatedBy: User<T>? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Published */
|
||||||
|
interface Published<UserT> {
|
||||||
|
var publishedAt: DateTime?
|
||||||
|
var publishedBy: User<UserT>?
|
||||||
|
}
|
||||||
|
|
||||||
|
class EntityPublishedImp<UserT> : Published<UserT> {
|
||||||
|
override var publishedAt: DateTime? = null
|
||||||
|
override var publishedBy: User<UserT>? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Implementation */
|
||||||
|
abstract class EntityImp<T, UserT> : Entity<T>(),
|
||||||
|
EntityCreatedAt by EntityCreatedAtImp(),
|
||||||
|
EntityUpdatedAt by EntityUpdatedAtImp(),
|
||||||
|
CreatedBy<UserT> by EntityCreatedByImp(),
|
||||||
|
UpdatedBy<UserT> by EntityUpdatedByImp()
|
||||||
|
|
||||||
|
abstract class EntityExtended<T, UserT> :
|
||||||
|
EntityImp<T, UserT>(),
|
||||||
|
EntityVersioningIncrement by EntityVersioningIncrementImp(),
|
||||||
|
Published<UserT> by EntityPublishedImp()
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package fr.postgresjson.repository
|
|||||||
|
|
||||||
import com.github.jasync.sql.db.pool.ConnectionPool
|
import com.github.jasync.sql.db.pool.ConnectionPool
|
||||||
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
|
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
|
||||||
|
import fr.postgresjson.Serializer
|
||||||
import fr.postgresjson.entity.EntityCollection
|
import fr.postgresjson.entity.EntityCollection
|
||||||
import fr.postgresjson.entity.EntityI
|
import fr.postgresjson.entity.EntityI
|
||||||
import fr.postgresjson.serializer.Serializer
|
|
||||||
|
|
||||||
interface RepositoryI<T, E : EntityI<T>>
|
interface RepositoryI<T, E : EntityI<T>>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package fr.postgresjson.serializer
|
package fr.postgresjson
|
||||||
|
|
||||||
import fr.postgresjson.connexion.Connection
|
import fr.postgresjson.connexion.Connection
|
||||||
import fr.postgresjson.entity.IdEntity
|
import fr.postgresjson.entity.IdEntity
|
||||||
25
src/test/kotlin/fr/postgresjson/EntityTest.kt
Normal file
25
src/test/kotlin/fr/postgresjson/EntityTest.kt
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package fr.postgresjson
|
||||||
|
|
||||||
|
import fr.postgresjson.entity.*
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.TestInstance
|
||||||
|
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
|
class EntityTest() {
|
||||||
|
private class ObjTest(var name: String): EntityExtended<Int?, Int?>()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getObject() {
|
||||||
|
val obj: ObjTest? = ObjTest("plop")
|
||||||
|
assertTrue(obj is ObjTest)
|
||||||
|
assertTrue(obj is EntityExtended<Int?, Int?>)
|
||||||
|
assertTrue(obj is EntityI<Int?>)
|
||||||
|
assertTrue(obj is Entity<Int?>)
|
||||||
|
assertTrue(obj is Published<Int?>)
|
||||||
|
assertTrue(obj is CreatedBy<Int?>)
|
||||||
|
assertTrue(obj is UpdatedBy<Int?>)
|
||||||
|
assertTrue(obj is EntityCreatedAt)
|
||||||
|
assertTrue(obj is EntityUpdatedAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package fr.postgresjson.serializer
|
package fr.postgresjson
|
||||||
|
|
||||||
import fr.postgresjson.connexion.Connection
|
import fr.postgresjson.connexion.Connection
|
||||||
import fr.postgresjson.entity.IdEntity
|
import fr.postgresjson.entity.IdEntity
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package fr.postgresjson.serializer
|
package fr.postgresjson
|
||||||
|
|
||||||
import fr.postgresjson.entity.IdEntity
|
import fr.postgresjson.entity.IdEntity
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
Reference in New Issue
Block a user