diff --git a/.idea/runConfigurations/Publish_To_MavenLocal.xml b/.idea/runConfigurations/Publish_To_MavenLocal.xml index 3586d59..c5d7a78 100644 --- a/.idea/runConfigurations/Publish_To_MavenLocal.xml +++ b/.idea/runConfigurations/Publish_To_MavenLocal.xml @@ -1,5 +1,5 @@ - + + + true diff --git a/.idea/runConfigurations/Test_and_Publish_To_MavenLocal.xml b/.idea/runConfigurations/Test_and_Publish_To_MavenLocal.xml index d46eeca..a72bf1e 100644 --- a/.idea/runConfigurations/Test_and_Publish_To_MavenLocal.xml +++ b/.idea/runConfigurations/Test_and_Publish_To_MavenLocal.xml @@ -1,5 +1,5 @@ - + + + true + diff --git a/build.gradle.kts b/build.gradle.kts index 6f37a7e..6c8474f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,16 @@ -plugins { - id("maven-publish") - id("org.jetbrains.kotlin.jvm") version "1.3.31" -} - -apply(plugin = "kotlin") - group = "fr.postgresjson" version = "0.1" +plugins { + jacoco + + id("maven-publish") + id("org.jetbrains.kotlin.jvm") version "1.3.50" + + id("org.jlleitschuh.gradle.ktlint") version "8.2.0" + id("org.owasp.dependencycheck") version "5.1.0" +} + repositories { mavenCentral() jcenter() diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5554267..7c4388a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed May 29 17:08:27 CEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip diff --git a/src/main/kotlin/fr/postgresjson/connexion/Connection.kt b/src/main/kotlin/fr/postgresjson/connexion/Connection.kt index 768fa8f..b585075 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Connection.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Connection.kt @@ -22,7 +22,7 @@ class Connection( private val password: String, private val host: String = "localhost", private val port: Int = 5432 -): Executable { +) : Executable { private lateinit var connection: ConnectionPool private val serializer = Serializer() private val logger: Logger? by LoggerDelegate() @@ -38,7 +38,7 @@ class Connection( fun inTransaction(f: (Connection) -> CompletableFuture) = connect().inTransaction(f) - override fun select( + override fun select( sql: String, typeReference: TypeReference, values: List, @@ -62,14 +62,14 @@ class Connection( } } - inline fun selectOne( + inline fun selectOne( sql: String, values: List = emptyList(), noinline block: SelectOneCallback = {} ): R? = - select(sql, object: TypeReference() {}, values, block) + select(sql, object : TypeReference() {}, values, block) - override fun select( + override fun select( sql: String, typeReference: TypeReference, values: Map, @@ -80,14 +80,14 @@ class Connection( } } - inline fun selectOne( + inline fun selectOne( sql: String, values: Map, noinline block: SelectOneCallback = {} ): R? = - select(sql, object: TypeReference() {}, values, block) + select(sql, object : TypeReference() {}, values, block) - override fun select( + override fun select( sql: String, typeReference: TypeReference>, values: List, @@ -104,14 +104,14 @@ class Connection( } } - inline fun select( + inline fun select( sql: String, values: List = emptyList(), noinline block: SelectCallback = {} ): List = - select(sql, object: TypeReference>() {}, values, block) + select(sql, object : TypeReference>() {}, values, block) - override fun select( + override fun select( sql: String, page: Int, limit: Int, @@ -146,16 +146,16 @@ class Connection( } } - inline fun select( + inline fun select( sql: String, page: Int, limit: Int, values: Map = emptyMap(), noinline block: SelectPaginatedCallback = {} ): Paginated = - select(sql, page, limit, object: TypeReference>() {}, values, block) + select(sql, page, limit, object : TypeReference>() {}, values, block) - override fun select( + override fun select( sql: String, typeReference: TypeReference>, values: Map, @@ -166,12 +166,12 @@ class Connection( } } - inline fun select( + inline fun select( sql: String, values: Map, noinline block: SelectCallback = {} ): List = - select(sql, object: TypeReference>() {}, values, block) + select(sql, object : TypeReference>() {}, values, block) override fun exec(sql: String, values: List): QueryResult { return stopwatchQuery(sql, values) { @@ -256,6 +256,5 @@ class Connection( logger?.info("Query Error: $sqlForLog, $values", e) throw e } - } } diff --git a/src/main/kotlin/fr/postgresjson/connexion/EmbedExecutable.kt b/src/main/kotlin/fr/postgresjson/connexion/EmbedExecutable.kt index 8ff9ea7..43bbc2c 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/EmbedExecutable.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/EmbedExecutable.kt @@ -13,33 +13,33 @@ interface EmbedExecutable { /** * Select One entity with list of parameters */ - fun select( + fun select( typeReference: TypeReference, values: List = emptyList(), block: SelectOneCallback = {} ): R? - fun select( + fun select( typeReference: TypeReference, values: Map, block: SelectOneCallback = {} ): R? /* Select Miltiples */ - fun select( + fun select( typeReference: TypeReference>, values: List = emptyList(), block: SelectCallback = {} ): List - fun select( + fun select( typeReference: TypeReference>, values: Map, block: SelectCallback = {} ): List /* Select Paginated */ - fun select( + fun select( page: Int, limit: Int, typeReference: TypeReference>, diff --git a/src/main/kotlin/fr/postgresjson/connexion/Executable.kt b/src/main/kotlin/fr/postgresjson/connexion/Executable.kt index 7fb265e..4c8ead7 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Executable.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Executable.kt @@ -7,14 +7,14 @@ import fr.postgresjson.entity.EntityI interface Executable { /* Select One */ - fun select( + fun select( sql: String, typeReference: TypeReference, values: List = emptyList(), block: SelectOneCallback = {} ): R? - fun select( + fun select( sql: String, typeReference: TypeReference, values: Map, @@ -23,14 +23,14 @@ interface Executable { /* Select Miltiples */ - fun select( + fun select( sql: String, typeReference: TypeReference>, values: List = emptyList(), block: SelectCallback = {} ): List - fun select( + fun select( sql: String, typeReference: TypeReference>, values: Map, @@ -39,7 +39,7 @@ interface Executable { /* Select Paginated */ - fun select( + fun select( sql: String, page: Int, limit: Int, diff --git a/src/main/kotlin/fr/postgresjson/connexion/Function.kt b/src/main/kotlin/fr/postgresjson/connexion/Function.kt index d5cd5c3..0dfdde5 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Function.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Function.kt @@ -5,7 +5,7 @@ import com.github.jasync.sql.db.QueryResult import fr.postgresjson.definition.Function import fr.postgresjson.entity.EntityI -class Function(val definition: Function, override val connection: Connection): EmbedExecutable { +class Function(val definition: Function, override val connection: Connection) : EmbedExecutable { override fun toString(): String { return definition.name } @@ -17,7 +17,7 @@ class Function(val definition: Function, override val connection: Connection): E /** * Select One entity with list of parameters */ - override fun select( + override fun select( typeReference: TypeReference, values: List, block: (QueryResult, R?) -> Unit @@ -28,22 +28,22 @@ class Function(val definition: Function, override val connection: Connection): E return connection.select(sql, typeReference, values, block) } - inline fun selectOne( + inline fun selectOne( values: List = emptyList(), noinline block: SelectOneCallback = {} ): R? = - select(object: TypeReference() {}, values, block) + select(object : TypeReference() {}, values, block) - inline fun selectOne( + inline fun selectOne( value: R, noinline block: SelectOneCallback = {} ): R? = - select(object: TypeReference() {}, listOf(value), block) + select(object : TypeReference() {}, listOf(value), block) /** * Select One entity with named parameters */ - override fun select( + override fun select( typeReference: TypeReference, values: Map, block: (QueryResult, R?) -> Unit @@ -54,13 +54,13 @@ class Function(val definition: Function, override val connection: Connection): E return connection.select(sql, typeReference, values, block) } - inline fun selectOne( + inline fun selectOne( values: Map, noinline block: SelectOneCallback = {} ): R? = - select(object: TypeReference() {}, values, block) + select(object : TypeReference() {}, values, block) - inline fun selectOne( + inline fun selectOne( vararg values: Pair, noinline block: SelectOneCallback = {} ): R? = @@ -71,7 +71,7 @@ class Function(val definition: Function, override val connection: Connection): E /** * Select list of entities with list of parameters */ - override fun select( + override fun select( typeReference: TypeReference>, values: List, block: (QueryResult, List) -> Unit @@ -82,16 +82,16 @@ class Function(val definition: Function, override val connection: Connection): E return connection.select(sql, typeReference, values, block) } - inline fun select( + inline fun select( values: List = emptyList(), noinline block: SelectCallback = {} ): List = - select(object: TypeReference>() {}, values, block) + select(object : TypeReference>() {}, values, block) /** * Select list of entities with named parameters */ - override fun select( + override fun select( typeReference: TypeReference>, values: Map, block: (QueryResult, List) -> Unit @@ -102,13 +102,13 @@ class Function(val definition: Function, override val connection: Connection): E return connection.select(sql, typeReference, values, block) } - inline fun select( + inline fun select( values: Map, noinline block: SelectCallback = {} ): List = - select(object: TypeReference>() {}, values, block) + select(object : TypeReference>() {}, values, block) - inline fun select( + inline fun select( vararg values: Pair, noinline block: SelectCallback = {} ): List = @@ -119,7 +119,7 @@ class Function(val definition: Function, override val connection: Connection): E /** * Select Multiple with pagination */ - override fun select( + override fun select( page: Int, limit: Int, typeReference: TypeReference>, @@ -137,21 +137,21 @@ class Function(val definition: Function, override val connection: Connection): E return connection.select(sql, page, limit, typeReference, values, block) } - inline fun select( + inline fun select( page: Int, limit: Int, values: Map = emptyMap(), noinline block: SelectPaginatedCallback = {} ): Paginated = - select(page, limit, object: TypeReference>() {}, values, block) + select(page, limit, object : TypeReference>() {}, values, block) - inline fun select( + inline fun select( page: Int, limit: Int, vararg values: Pair, noinline block: SelectPaginatedCallback = {} ): Paginated = - select(page, limit, object: TypeReference>() {}, values.toMap(), block) + select(page, limit, object : TypeReference>() {}, values.toMap(), block) /* Execute function without traitements */ @@ -195,11 +195,11 @@ class Function(val definition: Function, override val connection: Connection): E val parameters = definition.getParametersIndexedByName() val placeholders = values .filter { entry -> - val parameter = parameters[entry.key] ?: parameters["_"+entry.key] ?: error("Parameter ${entry.key} of function ${definition.name} not exist") + val parameter = parameters[entry.key] ?: parameters["_" + entry.key] ?: error("Parameter ${entry.key} of function ${definition.name} not exist") parameter.default === null || entry.value !== null } .map { entry -> - val parameter = parameters[entry.key] ?: parameters["_"+entry.key] ?: error("Parameter ${entry.key} of function ${definition.name} not exist") + val parameter = parameters[entry.key] ?: parameters["_" + entry.key] ?: error("Parameter ${entry.key} of function ${definition.name} not exist") """"${parameter.name}" := :${parameter.name}::${parameter.type}""" } diff --git a/src/main/kotlin/fr/postgresjson/connexion/Paginated.kt b/src/main/kotlin/fr/postgresjson/connexion/Paginated.kt index 1ad55a9..6768597 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Paginated.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Paginated.kt @@ -2,7 +2,7 @@ package fr.postgresjson.connexion import fr.postgresjson.entity.EntityI -data class Paginated( +data class Paginated( val result: List, val offset: Int, val limit: Int, diff --git a/src/main/kotlin/fr/postgresjson/connexion/Query.kt b/src/main/kotlin/fr/postgresjson/connexion/Query.kt index d95a856..5b519eb 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Query.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Query.kt @@ -4,15 +4,14 @@ import com.fasterxml.jackson.core.type.TypeReference import com.github.jasync.sql.db.QueryResult import fr.postgresjson.entity.EntityI - -class Query(override val name: String, private val sql: String, override val connection: Connection): EmbedExecutable { +class Query(override val name: String, private val sql: String, override val connection: Connection) : EmbedExecutable { override fun toString(): String { return sql } /* Select One */ - override fun select( + override fun select( typeReference: TypeReference, values: List, block: (QueryResult, R?) -> Unit @@ -20,13 +19,13 @@ class Query(override val name: String, private val sql: String, override val con return connection.select(this.toString(), typeReference, values, block) } - inline fun selectOne( + inline fun selectOne( values: List = emptyList(), noinline block: SelectOneCallback = {} ): R? = - select(object: TypeReference() {}, values, block) + select(object : TypeReference() {}, values, block) - override fun select( + override fun select( typeReference: TypeReference, values: Map, block: (QueryResult, R?) -> Unit @@ -34,15 +33,15 @@ class Query(override val name: String, private val sql: String, override val con return connection.select(this.toString(), typeReference, values, block) } - inline fun selectOne( + inline fun selectOne( values: Map, noinline block: SelectOneCallback = {} ): R? = - select(object: TypeReference() {}, values, block) + select(object : TypeReference() {}, values, block) /* Select Multiples */ - override fun select( + override fun select( typeReference: TypeReference>, values: List, block: (QueryResult, List) -> Unit @@ -50,13 +49,13 @@ class Query(override val name: String, private val sql: String, override val con return connection.select(this.toString(), typeReference, values, block) } - inline fun select( + inline fun select( values: List = emptyList(), noinline block: SelectCallback = {} ): List = - select(object: TypeReference>() {}, values, block) + select(object : TypeReference>() {}, values, block) - override fun select( + override fun select( typeReference: TypeReference>, values: Map, block: (QueryResult, List) -> Unit @@ -64,13 +63,13 @@ class Query(override val name: String, private val sql: String, override val con return connection.select(this.toString(), typeReference, values, block) } - inline fun select( + inline fun select( values: Map, noinline block: SelectCallback = {} ): List = - select(object: TypeReference>() {}, values, block) + select(object : TypeReference>() {}, values, block) - override fun select( + override fun select( page: Int, limit: Int, typeReference: TypeReference>, @@ -82,13 +81,13 @@ class Query(override val name: String, private val sql: String, override val con /* Select Paginated */ - inline fun select( + inline fun select( page: Int, limit: Int, values: Map = emptyMap(), noinline block: SelectPaginatedCallback = {} ): Paginated = - select(page, limit, object: TypeReference>() {}, values, block) + select(page, limit, object : TypeReference>() {}, values, block) /* Execute function without traitements */ diff --git a/src/main/kotlin/fr/postgresjson/connexion/Requester.kt b/src/main/kotlin/fr/postgresjson/connexion/Requester.kt index 96588d3..3d44790 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Requester.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Requester.kt @@ -80,7 +80,7 @@ class Requester( password: String = "dc-project", queriesDirectory: File? = null, functionsDirectory: File? = null - ): this( + ) : this( Connection(host = host, port = port, database = database, username = username, password = password), queriesDirectory, functionsDirectory diff --git a/src/main/kotlin/fr/postgresjson/definition/Function.kt b/src/main/kotlin/fr/postgresjson/definition/Function.kt index 8dce564..a1ab399 100644 --- a/src/main/kotlin/fr/postgresjson/definition/Function.kt +++ b/src/main/kotlin/fr/postgresjson/definition/Function.kt @@ -2,10 +2,9 @@ package fr.postgresjson.definition import java.io.File - open class Function( override val script: String -): Resource, ParametersInterface { +) : Resource, ParametersInterface { val returns: String override val name: String override val parameters: List @@ -24,7 +23,7 @@ open class Function( if (queryMatch !== null) { val functionName = queryMatch.groups.get("name")?.value?.trim() ?: error("Function name not found") val functionParameters = queryMatch.groups["params"]?.value?.trim() - this.returns = queryMatch.groups["return"]?.value?.trim() ?:"" + this.returns = queryMatch.groups["return"]?.value?.trim() ?: "" /* Create parameters definition */ val parameters = if (functionParameters !== null) { @@ -47,8 +46,8 @@ open class Function( } } - abstract class ParseException(message: String, cause: Throwable? = null): Exception(message, cause) - class FunctionNotFound(cause: Throwable? = null): ParseException("Function not found in script", cause) + abstract class ParseException(message: String, cause: Throwable? = null) : Exception(message, cause) + class FunctionNotFound(cause: Throwable? = null) : ParseException("Function not found in script", cause) fun getDefinition(): String { return parameters @@ -56,7 +55,6 @@ open class Function( .joinToString(", ") { "${it.name} ${it.type}" }.let { "$name ($it)" } - } fun getParametersIndexedByName(): Map { diff --git a/src/main/kotlin/fr/postgresjson/definition/Parameter.kt b/src/main/kotlin/fr/postgresjson/definition/Parameter.kt index 4a7d97c..976f657 100644 --- a/src/main/kotlin/fr/postgresjson/definition/Parameter.kt +++ b/src/main/kotlin/fr/postgresjson/definition/Parameter.kt @@ -18,7 +18,7 @@ class Parameter(val name: String, val type: String, direction: Direction? = Dire } } - constructor(name: String, type: String, direction: String? = "IN", default: Any? = null): this( + constructor(name: String, type: String, direction: String? = "IN", default: Any? = null) : this( name = name, type = type, direction = direction?.let { Direction.valueOf(direction.toUpperCase()) }, diff --git a/src/main/kotlin/fr/postgresjson/entity/Entity.kt b/src/main/kotlin/fr/postgresjson/entity/Entity.kt index 8aaa066..ded2ccc 100644 --- a/src/main/kotlin/fr/postgresjson/entity/Entity.kt +++ b/src/main/kotlin/fr/postgresjson/entity/Entity.kt @@ -6,9 +6,9 @@ import java.util.* /* ID */ interface EntityI -abstract class Entity(open var id: T? = null): EntityI -open class UuidEntity(override var id: UUID? = UUID.randomUUID()): Entity(id) -open class IdEntity(override var id: Int? = null): Entity(id) +abstract class Entity(open var id: T? = null) : EntityI +open class UuidEntity(override var id: UUID? = UUID.randomUUID()) : Entity(id) +open class IdEntity(override var id: Int? = null) : Entity(id) /* Version */ interface EntityVersioning { @@ -16,7 +16,7 @@ interface EntityVersioning { var versionNumber: NUMBER? } -class UuidEntityVersioning: EntityVersioning { +class UuidEntityVersioning : EntityVersioning { override var versionId: UUID = UUID.randomUUID() override var versionNumber: Int? = null } @@ -38,77 +38,77 @@ interface EntityDeletedAt { } } -class EntityCreatedAtImp: EntityCreatedAt { +class EntityCreatedAtImp : EntityCreatedAt { override var createdAt: DateTime? = null } -class EntityUpdatedAtImp: EntityUpdatedAt { +class EntityUpdatedAtImp : EntityUpdatedAt { override var updatedAt: DateTime? = null } -class EntityDeletedAtImp: EntityDeletedAt { +class EntityDeletedAtImp : EntityDeletedAt { override var deletedAt: DateTime? = null } /* Author */ -interface EntityCreatedBy { +interface EntityCreatedBy { var createdBy: T? } -interface EntityUpdatedBy { +interface EntityUpdatedBy { var updatedBy: T? } -interface EntityDeletedBy { +interface EntityDeletedBy { var deletedBy: T? } -class EntityCreatedByImp( +class EntityCreatedByImp( override var createdBy: UserT? -): EntityCreatedBy +) : EntityCreatedBy -class EntityUpdatedByImp( +class EntityUpdatedByImp( override var updatedBy: UserT? -): EntityUpdatedBy +) : EntityUpdatedBy -class EntityDeletedByImp( +class EntityDeletedByImp( override var deletedBy: UserT? -): EntityDeletedBy +) : EntityDeletedBy /* Mixed */ -class EntityDeletedImp( +class EntityDeletedImp( override var deletedBy: UserT? = null -): EntityDeletedBy, - EntityDeletedAt by EntityDeletedAtImp() +) : EntityDeletedBy, + EntityDeletedAt by EntityDeletedAtImp() -class EntityUpdatedImp( +class EntityUpdatedImp( override var updatedAt: DateTime? = null, override var updatedBy: UserT? = null -): EntityUpdatedBy, - EntityUpdatedAt by EntityUpdatedAtImp() +) : EntityUpdatedBy, + EntityUpdatedAt by EntityUpdatedAtImp() -class EntityCreatedImp( +class EntityCreatedImp( override var createdAt: DateTime? = null, override var createdBy: UserT? = null -): EntityCreatedBy, - EntityCreatedAt by EntityCreatedAtImp() +) : EntityCreatedBy, + EntityCreatedAt by EntityCreatedAtImp() /* Published */ -interface Published { +interface Published { var publishedAt: DateTime? var publishedBy: UserT? } -class EntityPublishedImp( +class EntityPublishedImp( override var publishedBy: UserT? -): Published { +) : Published { override var publishedAt: DateTime? = null } /* Implementation */ -abstract class EntityImp( +abstract class EntityImp( updatedBy: UserT? -): Entity(), +) : Entity(), EntityCreatedAt by EntityCreatedAtImp(), EntityUpdatedAt by EntityUpdatedAtImp(), EntityDeletedAt by EntityDeletedAtImp(), @@ -116,10 +116,10 @@ abstract class EntityImp( EntityUpdatedBy by EntityUpdatedByImp(updatedBy), EntityDeletedBy by EntityDeletedByImp(updatedBy) -abstract class UuidEntityExtended( +abstract class UuidEntityExtended( updatedBy: UserT?, publishedBy: UserT? -): +) : EntityImp(updatedBy), EntityVersioning by UuidEntityVersioning(), Published by EntityPublishedImp(publishedBy) diff --git a/src/main/kotlin/fr/postgresjson/migration/Function.kt b/src/main/kotlin/fr/postgresjson/migration/Function.kt index b3ce805..24b828e 100644 --- a/src/main/kotlin/fr/postgresjson/migration/Function.kt +++ b/src/main/kotlin/fr/postgresjson/migration/Function.kt @@ -13,7 +13,7 @@ data class Function( val down: DefinitionFunction, private val connection: Connection, override var executedAt: Date? = null -): Migration { +) : Migration { val name = up.name override var doExecute: Action? = null @@ -28,7 +28,7 @@ data class Function( down: String, connection: Connection, executedAt: Date? = null - ): this( + ) : this( DefinitionFunction(up), DefinitionFunction(down), connection, diff --git a/src/main/kotlin/fr/postgresjson/migration/Migrations.kt b/src/main/kotlin/fr/postgresjson/migration/Migrations.kt index 75ea6b8..1d13d62 100644 --- a/src/main/kotlin/fr/postgresjson/migration/Migrations.kt +++ b/src/main/kotlin/fr/postgresjson/migration/Migrations.kt @@ -19,7 +19,7 @@ class MigrationEntity( val up: String, val down: String, val version: Int -): Entity(filename) +) : Entity(filename) interface Migration { var executedAt: Date? @@ -40,9 +40,9 @@ data class Migrations private constructor( ) { private var directories: List = emptyList() private val logger: Logger? by LoggerDelegate() - constructor(directory: File, connection: Connection): this(listOf(directory), connection) + constructor(directory: File, connection: Connection) : this(listOf(directory), connection) - constructor(directories: List, connection: Connection): this(connection) { + constructor(directories: List, connection: Connection) : this(connection) { initDB() this.directories = directories reset() @@ -75,14 +75,14 @@ data class Migrations private constructor( */ private fun getMigrationFromDB() { this::class.java.classLoader.getResource("sql/migration/findAllFunction.sql")!!.readText().let { - connection.select(it, object: TypeReference>() {}) + connection.select(it, object : TypeReference>() {}) .map { function -> functions[function.filename] = Function(function.up, function.down, connection, function.executedAt) } } this::class.java.classLoader.getResource("sql/migration/findAllHistory.sql")!!.readText().let { - connection.select(it, object: TypeReference>() {}) + connection.select(it, object : TypeReference>() {}) .map { query -> queries[query.filename] = Query(query.filename, query.up, query.down, connection, query.executedAt) } @@ -122,7 +122,7 @@ data class Migrations private constructor( val fileContent = file.readText() try { addFunction(fileContent) - } catch(e: FunctionNotFound) { + } catch (e: FunctionNotFound) { // Nothing } } @@ -131,7 +131,7 @@ data class Migrations private constructor( enum class Direction { UP, DOWN } - internal class DownMigrationNotDefined(path: String, cause: FileNotFoundException): + internal class DownMigrationNotDefined(path: String, cause: FileNotFoundException) : Throwable("The file $path whas not found", cause) fun addFunction(newDefinition: DefinitionFunction, callback: (Function) -> Unit = {}): Migrations { diff --git a/src/main/kotlin/fr/postgresjson/migration/Query.kt b/src/main/kotlin/fr/postgresjson/migration/Query.kt index 673d994..700a86a 100644 --- a/src/main/kotlin/fr/postgresjson/migration/Query.kt +++ b/src/main/kotlin/fr/postgresjson/migration/Query.kt @@ -11,7 +11,7 @@ data class Query( val down: String, private val connection: Connection, override var executedAt: Date? = null -): Migration, Entity(name) { +) : Migration, Entity(name) { override var doExecute: Action? = null override fun up(): Migration.Status { diff --git a/src/main/kotlin/fr/postgresjson/repository/Repository.kt b/src/main/kotlin/fr/postgresjson/repository/RepositoryI.kt similarity index 100% rename from src/main/kotlin/fr/postgresjson/repository/Repository.kt rename to src/main/kotlin/fr/postgresjson/repository/RepositoryI.kt diff --git a/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt b/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt index 2509ca4..7ff6209 100644 --- a/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt +++ b/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt @@ -19,7 +19,7 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) { mapper.registerModule(JodaModule()) mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) } fun serialize(source: EntityI, pretty: Boolean = false): String { @@ -27,11 +27,11 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) { else mapper.writeValueAsString(source) } - fun deserialize(json: String, valueTypeRef: TypeReference): E { + fun deserialize(json: String, valueTypeRef: TypeReference): E { return this.mapper.readValue(json, valueTypeRef) } - inline fun deserialize(json: String): E? { + inline fun deserialize(json: String): E? { return this.mapper.readValue(json) } @@ -40,14 +40,14 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) { } inline fun deserializeList(json: String): E { - return deserializeList(json, object: TypeReference() {}) + return deserializeList(json, object : TypeReference() {}) } - fun deserialize(json: String, target: E): E { + fun deserialize(json: String, target: E): E { return mapper.readerForUpdating(target).readValue(json) } } fun EntityI.serialize(pretty: Boolean = false) = Serializer().serialize(this, pretty) -inline fun E.deserialize(json: String) = Serializer().deserialize(json, this) -inline fun String.deserialize() = Serializer().deserialize(this) \ No newline at end of file +inline fun E.deserialize(json: String) = Serializer().deserialize(json, this) +inline fun String.deserialize() = Serializer().deserialize(this) \ No newline at end of file diff --git a/src/main/kotlin/fr/postgresjson/utils/LoggerDelegate.kt b/src/main/kotlin/fr/postgresjson/utils/LoggerDelegate.kt index 87083b7..c3685cd 100644 --- a/src/main/kotlin/fr/postgresjson/utils/LoggerDelegate.kt +++ b/src/main/kotlin/fr/postgresjson/utils/LoggerDelegate.kt @@ -5,6 +5,6 @@ import org.slf4j.LoggerFactory import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty -internal class LoggerDelegate: ReadOnlyProperty { +internal class LoggerDelegate : ReadOnlyProperty { override fun getValue(thisRef: R, property: KProperty<*>) = LoggerFactory.getLogger(thisRef.javaClass.packageName) } \ No newline at end of file diff --git a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt index c615245..18df595 100644 --- a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt +++ b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt @@ -8,10 +8,10 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class ConnectionTest(): TestAbstract() { - private class ObjTest(var name: String): IdEntity() - private class ObjTest2(var title: String, var test: ObjTest?): IdEntity() - private class ObjTest3(var first: String, var seconde: String, var third: Int): IdEntity() +class ConnectionTest() : TestAbstract() { + private class ObjTest(var name: String) : IdEntity() + private class ObjTest2(var title: String, var test: ObjTest?) : IdEntity() + private class ObjTest3(var first: String, var seconde: String, var third: Int) : IdEntity() @Test fun getObject() { diff --git a/src/test/kotlin/fr/postgresjson/EntityTest.kt b/src/test/kotlin/fr/postgresjson/EntityTest.kt index b732d23..03cfc95 100644 --- a/src/test/kotlin/fr/postgresjson/EntityTest.kt +++ b/src/test/kotlin/fr/postgresjson/EntityTest.kt @@ -7,8 +7,8 @@ import org.junit.jupiter.api.TestInstance @TestInstance(TestInstance.Lifecycle.PER_CLASS) class EntityTest() { - private class User(id: Int?): Entity(id) - private class ObjTest(var name: String): UuidEntityExtended(User(1), User(2)) + private class User(id: Int?) : Entity(id) + private class ObjTest(var name: String) : UuidEntityExtended(User(1), User(2)) @Test fun getObject() { diff --git a/src/test/kotlin/fr/postgresjson/MigrationTest.kt b/src/test/kotlin/fr/postgresjson/MigrationTest.kt index e161af5..a531a63 100644 --- a/src/test/kotlin/fr/postgresjson/MigrationTest.kt +++ b/src/test/kotlin/fr/postgresjson/MigrationTest.kt @@ -13,7 +13,7 @@ import org.junit.jupiter.api.TestInstance import java.io.File @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class MigrationTest(): TestAbstract() { +class MigrationTest() : TestAbstract() { @Test fun `run up query`() { val resources = File(this::class.java.getResource("/sql/migrations").toURI()) @@ -123,7 +123,6 @@ class MigrationTest(): TestAbstract() { Assertions.assertEquals(objTest!!.id, 3) Assertions.assertEquals(objTest.name, "test") - val resources2 = File(this::class.java.getResource("/sql/function/Test2").toURI()) Migrations(resources2, connection).apply { run().size `should be equal to` 1 diff --git a/src/test/kotlin/fr/postgresjson/RequesterTest.kt b/src/test/kotlin/fr/postgresjson/RequesterTest.kt index ae0f4ef..2e3c3aa 100644 --- a/src/test/kotlin/fr/postgresjson/RequesterTest.kt +++ b/src/test/kotlin/fr/postgresjson/RequesterTest.kt @@ -8,8 +8,8 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.io.File -class RequesterTest: TestAbstract() { - class ObjTest(var name:String): IdEntity(1) +class RequesterTest : TestAbstract() { + class ObjTest(var name: String) : IdEntity(1) @Test fun `get query from file`() {