Big refactoring and implement Function

This commit is contained in:
2019-06-13 15:26:52 +02:00
parent ed87175b3f
commit 2d494d6e3e
4 changed files with 170 additions and 41 deletions

View File

@@ -1,17 +1,22 @@
package fr.postgresjson.repository
import com.github.jasync.sql.db.pool.ConnectionPool
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
import fr.postgresjson.Serializer
import fr.postgresjson.connexion.Connection
import fr.postgresjson.entity.EntityCollection
import fr.postgresjson.entity.EntityI
import kotlin.reflect.KClass
interface RepositoryI<T, E : EntityI<T>>
interface RepositoryI<T, E : EntityI<T?>> {
val entityName: KClass<E>
}
abstract class Repository<T, E : EntityI<T>> : RepositoryI<T, E> {
abstract var connection: ConnectionPool<PostgreSQLConnection>
abstract class Repository<T, E : EntityI<T?>>(override val entityName: KClass<E>) : RepositoryI<T, E> {
abstract var connection: Connection
abstract fun getClassName(): String
fun <T> findById(id: T): EntityI<T?>? {
val sql = this.connection.getQuery(entityName.toString())
return when (val e = EntityCollection().get(id)) {
null -> {
// TODO create Request
@@ -20,4 +25,4 @@ abstract class Repository<T, E : EntityI<T>> : RepositoryI<T, E> {
else -> e
}
}
}
}