Improve gradle tasks
This commit is contained in:
@@ -12,7 +12,7 @@ import fr.postgresjson.entity.Serializable
|
||||
import fr.postgresjson.serializer.Serializer
|
||||
import fr.postgresjson.utils.LoggerDelegate
|
||||
import org.slf4j.Logger
|
||||
import java.util.concurrent.*
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
typealias SelectOneCallback<T> = QueryResult.(T?) -> Unit
|
||||
typealias SelectCallback<T> = QueryResult.(List<T>) -> Unit
|
||||
@@ -280,11 +280,14 @@ class Connection(
|
||||
logger?.debug("Query executed in $duration ms \n{}", args)
|
||||
return result
|
||||
} catch (e: Throwable) {
|
||||
logger?.info("""
|
||||
logger?.info(
|
||||
"""
|
||||
Query Error:
|
||||
${sql.prependIndent()},
|
||||
${values.joinToString(", ").prependIndent()}
|
||||
""".trimIndent(), e)
|
||||
""".trimIndent(),
|
||||
e
|
||||
)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +59,4 @@ interface EmbedExecutable {
|
||||
fun sendQuery(values: Map<String, Any?>): Int
|
||||
fun sendQuery(vararg values: Pair<String, Any?>): Int =
|
||||
sendQuery(values.toMap())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,4 +52,4 @@ interface Executable {
|
||||
fun exec(sql: String, values: Map<String, Any?>): QueryResult
|
||||
fun sendQuery(sql: String, values: List<Any?> = emptyList()): Int
|
||||
fun sendQuery(sql: String, values: Map<String, Any?>): Int
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,4 +205,4 @@ class Function(val definition: Function, override val connection: Connection) :
|
||||
|
||||
return placeholders.joinToString(separator = ", ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,4 @@ data class Paginated<T : EntityI>(
|
||||
fun isLastPage(): Boolean = currentPage >= totalPages
|
||||
|
||||
private fun Double.ceil(): Int = ceil(this).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,4 +106,4 @@ class Query(override val name: String, private val sql: String, override val con
|
||||
override fun sendQuery(values: Map<String, Any?>): Int {
|
||||
return connection.sendQuery(sql, values)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package fr.postgresjson.connexion
|
||||
import fr.postgresjson.utils.searchSqlFiles
|
||||
import java.net.URI
|
||||
import fr.postgresjson.definition.Function as DefinitionFunction
|
||||
import fr.postgresjson.definition.Function as FunctionDefinition
|
||||
import fr.postgresjson.definition.Query as QueryDefinition
|
||||
|
||||
class Requester(
|
||||
@@ -52,7 +51,7 @@ class Requester(
|
||||
fun addFunction(functionsDirectory: URI): Requester {
|
||||
functionsDirectory.searchSqlFiles()
|
||||
.forEach {
|
||||
if (it is FunctionDefinition) {
|
||||
if (it is DefinitionFunction) {
|
||||
addFunction(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,4 +87,4 @@ class Function(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,4 @@ class Migration(
|
||||
|
||||
class MigrationNotFound(cause: Throwable? = null) : Resource.ParseException("Migration not found in script", cause)
|
||||
enum class Direction { UP, DOWN }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,4 @@ class Parameter(val name: String, val type: String, direction: Direction? = Dire
|
||||
|
||||
interface ParametersInterface {
|
||||
val parameters: List<Parameter>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@ class Query(
|
||||
"""-- *name ?: ?(?<name>[^ \n]+)"""
|
||||
.toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE))
|
||||
.find(script)?.let {
|
||||
it.groups["name"]?.value?.trim()
|
||||
}
|
||||
it.groups["name"]?.value?.trim()
|
||||
}
|
||||
|
||||
/** Try to get name from the filename */
|
||||
private fun getNameFromFile(source: Path): String = source
|
||||
.fileName.toString()
|
||||
.substringAfterLast("/")
|
||||
.substringBeforeLast(".sql")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,4 @@ interface Resource {
|
||||
|
||||
interface ResourceCollection {
|
||||
val parameters: List<Parameter>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package fr.postgresjson.entity
|
||||
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
import java.util.UUID
|
||||
|
||||
interface EntityRefI<T> : EntityI {
|
||||
val id: T
|
||||
@@ -123,4 +123,4 @@ abstract class UuidEntityExtended<T, UserT : EntityI>(
|
||||
) :
|
||||
EntityImp<T, UserT>(updatedBy),
|
||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(0),
|
||||
Published<UserT> by EntityPublishedImp(publishedBy)
|
||||
Published<UserT> by EntityPublishedImp(publishedBy)
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.github.jasync.sql.db.postgresql.exceptions.GenericDatabaseException
|
||||
import fr.postgresjson.connexion.Connection
|
||||
import fr.postgresjson.migration.Migration.Action
|
||||
import fr.postgresjson.migration.Migration.Status
|
||||
import java.util.*
|
||||
import java.util.concurrent.*
|
||||
import java.util.Date
|
||||
import java.util.concurrent.CompletionException
|
||||
import fr.postgresjson.definition.Function as DefinitionFunction
|
||||
|
||||
data class Function(
|
||||
@@ -93,4 +93,4 @@ data class Function(
|
||||
infix fun `is different from`(other: DefinitionFunction): Boolean {
|
||||
return other.script != this.up.script
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package fr.postgresjson.migration
|
||||
import fr.postgresjson.connexion.Connection
|
||||
import fr.postgresjson.entity.Entity
|
||||
import fr.postgresjson.migration.Migration.Action
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
|
||||
data class MigrationScript(
|
||||
val name: String,
|
||||
@@ -62,4 +62,4 @@ data class MigrationScript(
|
||||
it.doExecute = this.doExecute
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package fr.postgresjson.migration
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference
|
||||
import fr.postgresjson.connexion.Connection
|
||||
import fr.postgresjson.definition.Migration as DefinitionMigration
|
||||
import fr.postgresjson.entity.Entity
|
||||
import fr.postgresjson.migration.Migration.Action
|
||||
import fr.postgresjson.migration.Migration.Status
|
||||
@@ -11,8 +10,9 @@ import fr.postgresjson.utils.searchSqlFiles
|
||||
import org.slf4j.Logger
|
||||
import java.io.FileNotFoundException
|
||||
import java.net.URI
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
import fr.postgresjson.definition.Function as DefinitionFunction
|
||||
import fr.postgresjson.definition.Migration as DefinitionMigration
|
||||
|
||||
class MigrationEntity(
|
||||
val filename: String,
|
||||
@@ -313,4 +313,4 @@ data class Migrations private constructor(
|
||||
fun status(): Map<String, Int> {
|
||||
TODO("not implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +51,4 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) {
|
||||
fun Serializable.serialize(pretty: Boolean = false) = Serializer().serialize(this, pretty)
|
||||
fun List<Serializable>.serialize(pretty: Boolean = false) = Serializer().serialize(this, pretty)
|
||||
inline fun <reified E : Serializable> E.deserialize(json: String) = Serializer().deserialize(json, this)
|
||||
inline fun <reified E : Serializable> String.deserialize() = Serializer().deserialize<E>(this)
|
||||
inline fun <reified E : Serializable> String.deserialize() = Serializer().deserialize<E>(this)
|
||||
|
||||
@@ -7,4 +7,4 @@ import kotlin.reflect.KProperty
|
||||
|
||||
internal class LoggerDelegate<in R : Any> : ReadOnlyProperty<R, Logger> {
|
||||
override fun getValue(thisRef: R, property: KProperty<*>) = LoggerFactory.getLogger(thisRef.javaClass.packageName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,4 @@ fun URI.searchSqlFiles() = sequence<Resource> {
|
||||
}
|
||||
|
||||
private fun Path.walk(maxDepth: Int = 2147483647, vararg options: FileVisitOption) = Files.walk(this, maxDepth, *options)
|
||||
private fun URI.walk(maxDepth: Int = 2147483647, vararg options: FileVisitOption) = Files.walk(Path.of(this), maxDepth, *options)
|
||||
private fun URI.walk(maxDepth: Int = 2147483647, vararg options: FileVisitOption) = Files.walk(Path.of(this), maxDepth, *options)
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package fr.postgresjson
|
||||
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.Parameter
|
||||
import org.junit.Assert.*
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import java.util.*
|
||||
import java.util.UUID
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class ConnectionTest() : TestAbstract() {
|
||||
@@ -26,17 +28,18 @@ class ConnectionTest() : TestAbstract() {
|
||||
|
||||
@Test
|
||||
fun getExistingObject() {
|
||||
val objs: List<ObjTest2> = connection.select("""
|
||||
select
|
||||
json_agg(j)
|
||||
FROM (
|
||||
SELECT
|
||||
t.id, t.title,
|
||||
t2 as test
|
||||
from test2 t
|
||||
JOIN test t2 ON t.test_id = t2.id
|
||||
) j;
|
||||
""".trimIndent()
|
||||
val objs: List<ObjTest2> = connection.select(
|
||||
"""
|
||||
select
|
||||
json_agg(j)
|
||||
FROM (
|
||||
SELECT
|
||||
t.id, t.title,
|
||||
t2 as test
|
||||
from test2 t
|
||||
JOIN test t2 ON t.test_id = t2.id
|
||||
) j;
|
||||
""".trimIndent()
|
||||
)
|
||||
assertNotNull(objs)
|
||||
assertEquals(objs.size, 2)
|
||||
@@ -179,4 +182,4 @@ class ConnectionTest() : TestAbstract() {
|
||||
assertEquals("sec", result.seconde)
|
||||
assertEquals(123, result.third)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package fr.postgresjson
|
||||
|
||||
import fr.postgresjson.entity.*
|
||||
import fr.postgresjson.entity.Entity
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.EntityUpdatedBy
|
||||
import fr.postgresjson.entity.Published
|
||||
import fr.postgresjson.entity.UuidEntityExtended
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import java.util.*
|
||||
import java.util.UUID
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class EntityTest() {
|
||||
@@ -24,4 +31,4 @@ class EntityTest() {
|
||||
assertTrue(obj is EntityCreatedAt)
|
||||
assertTrue(obj is EntityUpdatedAt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.amshove.kluent.shouldThrow
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import java.util.*
|
||||
import java.util.UUID
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class MigrationTest() : TestAbstract() {
|
||||
@@ -128,4 +128,4 @@ class MigrationTest() : TestAbstract() {
|
||||
run().size `should be equal to` 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import fr.postgresjson.entity.UuidEntity
|
||||
import org.junit.Assert
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.*
|
||||
import java.util.UUID
|
||||
|
||||
class RequesterTest : TestAbstract() {
|
||||
class ObjTest(var name: String, id: UUID = UUID.fromString("5623d902-3067-42f3-bfd9-095dbb12c29f")) : UuidEntity(id)
|
||||
@@ -166,4 +166,4 @@ class RequesterTest : TestAbstract() {
|
||||
|
||||
assertEquals("myName", obj.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import java.util.*
|
||||
import java.util.UUID
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
internal class SerializerTest {
|
||||
@@ -85,4 +85,4 @@ internal class SerializerTest {
|
||||
assertEquals("update", objDeserialized.val1)
|
||||
assertEquals(123, objDeserialized.val2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,4 @@ abstract class TestAbstract {
|
||||
sendQuery(downSQL.readText()).join()
|
||||
}.disconnect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user