Lint
This commit is contained in:
12
.idea/runConfigurations/Publish_To_MavenLocal.xml
generated
12
.idea/runConfigurations/Publish_To_MavenLocal.xml
generated
@@ -1,5 +1,5 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Publish To MavenLocal" type="GradleRunConfiguration" factoryName="Gradle" singleton="false">
|
<configuration default="false" name="Publish To MavenLocal" type="GradleRunConfiguration" factoryName="Gradle" singleton="true">
|
||||||
<ExternalSystemSettings>
|
<ExternalSystemSettings>
|
||||||
<option name="executionName" />
|
<option name="executionName" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
@@ -15,6 +15,16 @@
|
|||||||
</option>
|
</option>
|
||||||
<option name="vmOptions" value="" />
|
<option name="vmOptions" value="" />
|
||||||
</ExternalSystemSettings>
|
</ExternalSystemSettings>
|
||||||
|
<extension name="net.ashald.envfile">
|
||||||
|
<option name="IS_ENABLED" value="false" />
|
||||||
|
<option name="IS_SUBST" value="false" />
|
||||||
|
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
|
||||||
|
<option name="IS_IGNORE_MISSING_FILES" value="false" />
|
||||||
|
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
|
||||||
|
<ENTRIES>
|
||||||
|
<ENTRY IS_ENABLED="true" PARSER="runconfig" />
|
||||||
|
</ENTRIES>
|
||||||
|
</extension>
|
||||||
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled>
|
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled>
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Test and Publish To MavenLocal" type="GradleRunConfiguration" factoryName="Gradle" singleton="false">
|
<configuration default="false" name="Test and Publish To MavenLocal" type="GradleRunConfiguration" factoryName="Gradle" singleton="true">
|
||||||
<ExternalSystemSettings>
|
<ExternalSystemSettings>
|
||||||
<option name="executionName" />
|
<option name="executionName" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
@@ -15,8 +15,19 @@
|
|||||||
</option>
|
</option>
|
||||||
<option name="vmOptions" value="" />
|
<option name="vmOptions" value="" />
|
||||||
</ExternalSystemSettings>
|
</ExternalSystemSettings>
|
||||||
|
<extension name="net.ashald.envfile">
|
||||||
|
<option name="IS_ENABLED" value="false" />
|
||||||
|
<option name="IS_SUBST" value="false" />
|
||||||
|
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
|
||||||
|
<option name="IS_IGNORE_MISSING_FILES" value="false" />
|
||||||
|
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
|
||||||
|
<ENTRIES>
|
||||||
|
<ENTRY IS_ENABLED="true" PARSER="runconfig" />
|
||||||
|
</ENTRIES>
|
||||||
|
</extension>
|
||||||
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled>
|
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled>
|
||||||
<method v="2">
|
<method v="2">
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="ktlint" run_configuration_type="GradleRunConfiguration" />
|
||||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="tests" run_configuration_type="JUnit" />
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="tests" run_configuration_type="JUnit" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
plugins {
|
|
||||||
id("maven-publish")
|
|
||||||
id("org.jetbrains.kotlin.jvm") version "1.3.31"
|
|
||||||
}
|
|
||||||
|
|
||||||
apply(plugin = "kotlin")
|
|
||||||
|
|
||||||
group = "fr.postgresjson"
|
group = "fr.postgresjson"
|
||||||
version = "0.1"
|
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 {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
|||||||
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,5 @@
|
|||||||
#Wed May 29 17:08:27 CEST 2019
|
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class Connection(
|
|||||||
private val password: String,
|
private val password: String,
|
||||||
private val host: String = "localhost",
|
private val host: String = "localhost",
|
||||||
private val port: Int = 5432
|
private val port: Int = 5432
|
||||||
): Executable {
|
) : Executable {
|
||||||
private lateinit var connection: ConnectionPool<PostgreSQLConnection>
|
private lateinit var connection: ConnectionPool<PostgreSQLConnection>
|
||||||
private val serializer = Serializer()
|
private val serializer = Serializer()
|
||||||
private val logger: Logger? by LoggerDelegate()
|
private val logger: Logger? by LoggerDelegate()
|
||||||
@@ -38,7 +38,7 @@ class Connection(
|
|||||||
|
|
||||||
fun <A> inTransaction(f: (Connection) -> CompletableFuture<A>) = connect().inTransaction(f)
|
fun <A> inTransaction(f: (Connection) -> CompletableFuture<A>) = connect().inTransaction(f)
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: List<Any?>,
|
values: List<Any?>,
|
||||||
@@ -62,14 +62,14 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> selectOne(
|
inline fun <reified R : EntityI> selectOne(
|
||||||
sql: String,
|
sql: String,
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
noinline block: SelectOneCallback<R> = {}
|
noinline block: SelectOneCallback<R> = {}
|
||||||
): R? =
|
): R? =
|
||||||
select(sql, object: TypeReference<R>() {}, values, block)
|
select(sql, object : TypeReference<R>() {}, values, block)
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
@@ -80,14 +80,14 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> selectOne(
|
inline fun <reified R : EntityI> selectOne(
|
||||||
sql: String,
|
sql: String,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
noinline block: SelectOneCallback<R> = {}
|
noinline block: SelectOneCallback<R> = {}
|
||||||
): R? =
|
): R? =
|
||||||
select(sql, object: TypeReference<R>() {}, values, block)
|
select(sql, object : TypeReference<R>() {}, values, block)
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: List<Any?>,
|
values: List<Any?>,
|
||||||
@@ -104,14 +104,14 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
noinline block: SelectCallback<R> = {}
|
noinline block: SelectCallback<R> = {}
|
||||||
): List<R> =
|
): List<R> =
|
||||||
select(sql, object: TypeReference<List<R>>() {}, values, block)
|
select(sql, object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
@@ -146,16 +146,16 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
values: Map<String, Any?> = emptyMap(),
|
values: Map<String, Any?> = emptyMap(),
|
||||||
noinline block: SelectPaginatedCallback<R> = {}
|
noinline block: SelectPaginatedCallback<R> = {}
|
||||||
): Paginated<R> =
|
): Paginated<R> =
|
||||||
select(sql, page, limit, object: TypeReference<List<R>>() {}, values, block)
|
select(sql, page, limit, object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
@@ -166,12 +166,12 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
noinline block: SelectCallback<R> = {}
|
noinline block: SelectCallback<R> = {}
|
||||||
): List<R> =
|
): List<R> =
|
||||||
select(sql, object: TypeReference<List<R>>() {}, values, block)
|
select(sql, object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
override fun exec(sql: String, values: List<Any?>): QueryResult {
|
override fun exec(sql: String, values: List<Any?>): QueryResult {
|
||||||
return stopwatchQuery(sql, values) {
|
return stopwatchQuery(sql, values) {
|
||||||
@@ -256,6 +256,5 @@ class Connection(
|
|||||||
logger?.info("Query Error: $sqlForLog, $values", e)
|
logger?.info("Query Error: $sqlForLog, $values", e)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,33 +13,33 @@ interface EmbedExecutable {
|
|||||||
/**
|
/**
|
||||||
* Select One entity with list of parameters
|
* Select One entity with list of parameters
|
||||||
*/
|
*/
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
block: SelectOneCallback<R> = {}
|
block: SelectOneCallback<R> = {}
|
||||||
): R?
|
): R?
|
||||||
|
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
block: SelectOneCallback<R> = {}
|
block: SelectOneCallback<R> = {}
|
||||||
): R?
|
): R?
|
||||||
|
|
||||||
/* Select Miltiples */
|
/* Select Miltiples */
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
block: SelectCallback<R> = {}
|
block: SelectCallback<R> = {}
|
||||||
): List<R>
|
): List<R>
|
||||||
|
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
block: SelectCallback<R> = {}
|
block: SelectCallback<R> = {}
|
||||||
): List<R>
|
): List<R>
|
||||||
|
|
||||||
/* Select Paginated */
|
/* Select Paginated */
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ import fr.postgresjson.entity.EntityI
|
|||||||
interface Executable {
|
interface Executable {
|
||||||
/* Select One */
|
/* Select One */
|
||||||
|
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
block: SelectOneCallback<R> = {}
|
block: SelectOneCallback<R> = {}
|
||||||
): R?
|
): R?
|
||||||
|
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
@@ -23,14 +23,14 @@ interface Executable {
|
|||||||
|
|
||||||
/* Select Miltiples */
|
/* Select Miltiples */
|
||||||
|
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
block: SelectCallback<R> = {}
|
block: SelectCallback<R> = {}
|
||||||
): List<R>
|
): List<R>
|
||||||
|
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
@@ -39,7 +39,7 @@ interface Executable {
|
|||||||
|
|
||||||
/* Select Paginated */
|
/* Select Paginated */
|
||||||
|
|
||||||
fun <R: EntityI> select(
|
fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.github.jasync.sql.db.QueryResult
|
|||||||
import fr.postgresjson.definition.Function
|
import fr.postgresjson.definition.Function
|
||||||
import fr.postgresjson.entity.EntityI
|
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 {
|
override fun toString(): String {
|
||||||
return definition.name
|
return definition.name
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ class Function(val definition: Function, override val connection: Connection): E
|
|||||||
/**
|
/**
|
||||||
* Select One entity with list of parameters
|
* Select One entity with list of parameters
|
||||||
*/
|
*/
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: List<Any?>,
|
values: List<Any?>,
|
||||||
block: (QueryResult, R?) -> Unit
|
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)
|
return connection.select(sql, typeReference, values, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> selectOne(
|
inline fun <reified R : EntityI> selectOne(
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
noinline block: SelectOneCallback<R> = {}
|
noinline block: SelectOneCallback<R> = {}
|
||||||
): R? =
|
): R? =
|
||||||
select(object: TypeReference<R>() {}, values, block)
|
select(object : TypeReference<R>() {}, values, block)
|
||||||
|
|
||||||
inline fun <reified R: EntityI> selectOne(
|
inline fun <reified R : EntityI> selectOne(
|
||||||
value: R,
|
value: R,
|
||||||
noinline block: SelectOneCallback<R> = {}
|
noinline block: SelectOneCallback<R> = {}
|
||||||
): R? =
|
): R? =
|
||||||
select(object: TypeReference<R>() {}, listOf(value), block)
|
select(object : TypeReference<R>() {}, listOf(value), block)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select One entity with named parameters
|
* Select One entity with named parameters
|
||||||
*/
|
*/
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
block: (QueryResult, R?) -> Unit
|
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)
|
return connection.select(sql, typeReference, values, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> selectOne(
|
inline fun <reified R : EntityI> selectOne(
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
noinline block: SelectOneCallback<R> = {}
|
noinline block: SelectOneCallback<R> = {}
|
||||||
): R? =
|
): R? =
|
||||||
select(object: TypeReference<R>() {}, values, block)
|
select(object : TypeReference<R>() {}, values, block)
|
||||||
|
|
||||||
inline fun <reified R: EntityI> selectOne(
|
inline fun <reified R : EntityI> selectOne(
|
||||||
vararg values: Pair<String, Any?>,
|
vararg values: Pair<String, Any?>,
|
||||||
noinline block: SelectOneCallback<R> = {}
|
noinline block: SelectOneCallback<R> = {}
|
||||||
): R? =
|
): R? =
|
||||||
@@ -71,7 +71,7 @@ class Function(val definition: Function, override val connection: Connection): E
|
|||||||
/**
|
/**
|
||||||
* Select list of entities with list of parameters
|
* Select list of entities with list of parameters
|
||||||
*/
|
*/
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: List<Any?>,
|
values: List<Any?>,
|
||||||
block: (QueryResult, List<R>) -> Unit
|
block: (QueryResult, List<R>) -> Unit
|
||||||
@@ -82,16 +82,16 @@ class Function(val definition: Function, override val connection: Connection): E
|
|||||||
return connection.select(sql, typeReference, values, block)
|
return connection.select(sql, typeReference, values, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
noinline block: SelectCallback<R> = {}
|
noinline block: SelectCallback<R> = {}
|
||||||
): List<R> =
|
): List<R> =
|
||||||
select(object: TypeReference<List<R>>() {}, values, block)
|
select(object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select list of entities with named parameters
|
* Select list of entities with named parameters
|
||||||
*/
|
*/
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
block: (QueryResult, List<R>) -> Unit
|
block: (QueryResult, List<R>) -> Unit
|
||||||
@@ -102,13 +102,13 @@ class Function(val definition: Function, override val connection: Connection): E
|
|||||||
return connection.select(sql, typeReference, values, block)
|
return connection.select(sql, typeReference, values, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
noinline block: SelectCallback<R> = {}
|
noinline block: SelectCallback<R> = {}
|
||||||
): List<R> =
|
): List<R> =
|
||||||
select(object: TypeReference<List<R>>() {}, values, block)
|
select(object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
vararg values: Pair<String, Any?>,
|
vararg values: Pair<String, Any?>,
|
||||||
noinline block: SelectCallback<R> = {}
|
noinline block: SelectCallback<R> = {}
|
||||||
): List<R> =
|
): List<R> =
|
||||||
@@ -119,7 +119,7 @@ class Function(val definition: Function, override val connection: Connection): E
|
|||||||
/**
|
/**
|
||||||
* Select Multiple with pagination
|
* Select Multiple with pagination
|
||||||
*/
|
*/
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
@@ -137,21 +137,21 @@ class Function(val definition: Function, override val connection: Connection): E
|
|||||||
return connection.select(sql, page, limit, typeReference, values, block)
|
return connection.select(sql, page, limit, typeReference, values, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
values: Map<String, Any?> = emptyMap(),
|
values: Map<String, Any?> = emptyMap(),
|
||||||
noinline block: SelectPaginatedCallback<R> = {}
|
noinline block: SelectPaginatedCallback<R> = {}
|
||||||
): Paginated<R> =
|
): Paginated<R> =
|
||||||
select(page, limit, object: TypeReference<List<R>>() {}, values, block)
|
select(page, limit, object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
vararg values: Pair<String, Any?>,
|
vararg values: Pair<String, Any?>,
|
||||||
noinline block: SelectPaginatedCallback<R> = {}
|
noinline block: SelectPaginatedCallback<R> = {}
|
||||||
): Paginated<R> =
|
): Paginated<R> =
|
||||||
select(page, limit, object: TypeReference<List<R>>() {}, values.toMap(), block)
|
select(page, limit, object : TypeReference<List<R>>() {}, values.toMap(), block)
|
||||||
|
|
||||||
/* Execute function without traitements */
|
/* Execute function without traitements */
|
||||||
|
|
||||||
@@ -195,11 +195,11 @@ class Function(val definition: Function, override val connection: Connection): E
|
|||||||
val parameters = definition.getParametersIndexedByName()
|
val parameters = definition.getParametersIndexedByName()
|
||||||
val placeholders = values
|
val placeholders = values
|
||||||
.filter { entry ->
|
.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
|
parameter.default === null || entry.value !== null
|
||||||
}
|
}
|
||||||
.map { entry ->
|
.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}"""
|
""""${parameter.name}" := :${parameter.name}::${parameter.type}"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package fr.postgresjson.connexion
|
|||||||
|
|
||||||
import fr.postgresjson.entity.EntityI
|
import fr.postgresjson.entity.EntityI
|
||||||
|
|
||||||
data class Paginated<T: EntityI>(
|
data class Paginated<T : EntityI>(
|
||||||
val result: List<T>,
|
val result: List<T>,
|
||||||
val offset: Int,
|
val offset: Int,
|
||||||
val limit: Int,
|
val limit: Int,
|
||||||
|
|||||||
@@ -4,15 +4,14 @@ import com.fasterxml.jackson.core.type.TypeReference
|
|||||||
import com.github.jasync.sql.db.QueryResult
|
import com.github.jasync.sql.db.QueryResult
|
||||||
import fr.postgresjson.entity.EntityI
|
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 {
|
override fun toString(): String {
|
||||||
return sql
|
return sql
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Select One */
|
/* Select One */
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: List<Any?>,
|
values: List<Any?>,
|
||||||
block: (QueryResult, R?) -> Unit
|
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)
|
return connection.select(this.toString(), typeReference, values, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> selectOne(
|
inline fun <reified R : EntityI> selectOne(
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
noinline block: SelectOneCallback<R> = {}
|
noinline block: SelectOneCallback<R> = {}
|
||||||
): R? =
|
): R? =
|
||||||
select(object: TypeReference<R>() {}, values, block)
|
select(object : TypeReference<R>() {}, values, block)
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
block: (QueryResult, R?) -> Unit
|
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)
|
return connection.select(this.toString(), typeReference, values, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> selectOne(
|
inline fun <reified R : EntityI> selectOne(
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
noinline block: SelectOneCallback<R> = {}
|
noinline block: SelectOneCallback<R> = {}
|
||||||
): R? =
|
): R? =
|
||||||
select(object: TypeReference<R>() {}, values, block)
|
select(object : TypeReference<R>() {}, values, block)
|
||||||
|
|
||||||
/* Select Multiples */
|
/* Select Multiples */
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: List<Any?>,
|
values: List<Any?>,
|
||||||
block: (QueryResult, List<R>) -> Unit
|
block: (QueryResult, List<R>) -> 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)
|
return connection.select(this.toString(), typeReference, values, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
values: List<Any?> = emptyList(),
|
values: List<Any?> = emptyList(),
|
||||||
noinline block: SelectCallback<R> = {}
|
noinline block: SelectCallback<R> = {}
|
||||||
): List<R> =
|
): List<R> =
|
||||||
select(object: TypeReference<List<R>>() {}, values, block)
|
select(object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
block: (QueryResult, List<R>) -> Unit
|
block: (QueryResult, List<R>) -> 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)
|
return connection.select(this.toString(), typeReference, values, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
noinline block: SelectCallback<R> = {}
|
noinline block: SelectCallback<R> = {}
|
||||||
): List<R> =
|
): List<R> =
|
||||||
select(object: TypeReference<List<R>>() {}, values, block)
|
select(object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
override fun <R: EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
@@ -82,13 +81,13 @@ class Query(override val name: String, private val sql: String, override val con
|
|||||||
|
|
||||||
/* Select Paginated */
|
/* Select Paginated */
|
||||||
|
|
||||||
inline fun <reified R: EntityI> select(
|
inline fun <reified R : EntityI> select(
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
values: Map<String, Any?> = emptyMap(),
|
values: Map<String, Any?> = emptyMap(),
|
||||||
noinline block: SelectPaginatedCallback<R> = {}
|
noinline block: SelectPaginatedCallback<R> = {}
|
||||||
): Paginated<R> =
|
): Paginated<R> =
|
||||||
select(page, limit, object: TypeReference<List<R>>() {}, values, block)
|
select(page, limit, object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
/* Execute function without traitements */
|
/* Execute function without traitements */
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class Requester(
|
|||||||
password: String = "dc-project",
|
password: String = "dc-project",
|
||||||
queriesDirectory: File? = null,
|
queriesDirectory: File? = null,
|
||||||
functionsDirectory: File? = null
|
functionsDirectory: File? = null
|
||||||
): this(
|
) : this(
|
||||||
Connection(host = host, port = port, database = database, username = username, password = password),
|
Connection(host = host, port = port, database = database, username = username, password = password),
|
||||||
queriesDirectory,
|
queriesDirectory,
|
||||||
functionsDirectory
|
functionsDirectory
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ package fr.postgresjson.definition
|
|||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
open class Function(
|
open class Function(
|
||||||
override val script: String
|
override val script: String
|
||||||
): Resource, ParametersInterface {
|
) : Resource, ParametersInterface {
|
||||||
val returns: String
|
val returns: String
|
||||||
override val name: String
|
override val name: String
|
||||||
override val parameters: List<Parameter>
|
override val parameters: List<Parameter>
|
||||||
@@ -24,7 +23,7 @@ open class Function(
|
|||||||
if (queryMatch !== null) {
|
if (queryMatch !== null) {
|
||||||
val functionName = queryMatch.groups.get("name")?.value?.trim() ?: error("Function name not found")
|
val functionName = queryMatch.groups.get("name")?.value?.trim() ?: error("Function name not found")
|
||||||
val functionParameters = queryMatch.groups["params"]?.value?.trim()
|
val functionParameters = queryMatch.groups["params"]?.value?.trim()
|
||||||
this.returns = queryMatch.groups["return"]?.value?.trim() ?:""
|
this.returns = queryMatch.groups["return"]?.value?.trim() ?: ""
|
||||||
|
|
||||||
/* Create parameters definition */
|
/* Create parameters definition */
|
||||||
val parameters = if (functionParameters !== null) {
|
val parameters = if (functionParameters !== null) {
|
||||||
@@ -47,8 +46,8 @@ open class Function(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ParseException(message: String, cause: Throwable? = null): Exception(message, cause)
|
abstract class ParseException(message: String, cause: Throwable? = null) : Exception(message, cause)
|
||||||
class FunctionNotFound(cause: Throwable? = null): ParseException("Function not found in script", cause)
|
class FunctionNotFound(cause: Throwable? = null) : ParseException("Function not found in script", cause)
|
||||||
|
|
||||||
fun getDefinition(): String {
|
fun getDefinition(): String {
|
||||||
return parameters
|
return parameters
|
||||||
@@ -56,7 +55,6 @@ open class Function(
|
|||||||
.joinToString(", ") { "${it.name} ${it.type}" }.let {
|
.joinToString(", ") { "${it.name} ${it.type}" }.let {
|
||||||
"$name ($it)"
|
"$name ($it)"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getParametersIndexedByName(): Map<String, Parameter> {
|
fun getParametersIndexedByName(): Map<String, Parameter> {
|
||||||
|
|||||||
@@ -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,
|
name = name,
|
||||||
type = type,
|
type = type,
|
||||||
direction = direction?.let { Direction.valueOf(direction.toUpperCase()) },
|
direction = direction?.let { Direction.valueOf(direction.toUpperCase()) },
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import java.util.*
|
|||||||
/* ID */
|
/* ID */
|
||||||
interface EntityI
|
interface EntityI
|
||||||
|
|
||||||
abstract class Entity<T>(open var id: T? = null): EntityI
|
abstract class Entity<T>(open var id: T? = null) : EntityI
|
||||||
open class UuidEntity(override var id: UUID? = UUID.randomUUID()): Entity<UUID>(id)
|
open class UuidEntity(override var id: UUID? = UUID.randomUUID()) : Entity<UUID>(id)
|
||||||
open class IdEntity(override var id: Int? = null): Entity<Int>(id)
|
open class IdEntity(override var id: Int? = null) : Entity<Int>(id)
|
||||||
|
|
||||||
/* Version */
|
/* Version */
|
||||||
interface EntityVersioning<ID, NUMBER> {
|
interface EntityVersioning<ID, NUMBER> {
|
||||||
@@ -16,7 +16,7 @@ interface EntityVersioning<ID, NUMBER> {
|
|||||||
var versionNumber: NUMBER?
|
var versionNumber: NUMBER?
|
||||||
}
|
}
|
||||||
|
|
||||||
class UuidEntityVersioning: EntityVersioning<UUID, Int> {
|
class UuidEntityVersioning : EntityVersioning<UUID, Int> {
|
||||||
override var versionId: UUID = UUID.randomUUID()
|
override var versionId: UUID = UUID.randomUUID()
|
||||||
override var versionNumber: Int? = null
|
override var versionNumber: Int? = null
|
||||||
}
|
}
|
||||||
@@ -38,77 +38,77 @@ interface EntityDeletedAt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntityCreatedAtImp: EntityCreatedAt {
|
class EntityCreatedAtImp : EntityCreatedAt {
|
||||||
override var createdAt: DateTime? = null
|
override var createdAt: DateTime? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntityUpdatedAtImp: EntityUpdatedAt {
|
class EntityUpdatedAtImp : EntityUpdatedAt {
|
||||||
override var updatedAt: DateTime? = null
|
override var updatedAt: DateTime? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntityDeletedAtImp: EntityDeletedAt {
|
class EntityDeletedAtImp : EntityDeletedAt {
|
||||||
override var deletedAt: DateTime? = null
|
override var deletedAt: DateTime? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Author */
|
/* Author */
|
||||||
interface EntityCreatedBy<T: EntityI> {
|
interface EntityCreatedBy<T : EntityI> {
|
||||||
var createdBy: T?
|
var createdBy: T?
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EntityUpdatedBy<T: EntityI> {
|
interface EntityUpdatedBy<T : EntityI> {
|
||||||
var updatedBy: T?
|
var updatedBy: T?
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EntityDeletedBy<T: EntityI> {
|
interface EntityDeletedBy<T : EntityI> {
|
||||||
var deletedBy: T?
|
var deletedBy: T?
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntityCreatedByImp<UserT: EntityI>(
|
class EntityCreatedByImp<UserT : EntityI>(
|
||||||
override var createdBy: UserT?
|
override var createdBy: UserT?
|
||||||
): EntityCreatedBy<UserT>
|
) : EntityCreatedBy<UserT>
|
||||||
|
|
||||||
class EntityUpdatedByImp<UserT: EntityI>(
|
class EntityUpdatedByImp<UserT : EntityI>(
|
||||||
override var updatedBy: UserT?
|
override var updatedBy: UserT?
|
||||||
): EntityUpdatedBy<UserT>
|
) : EntityUpdatedBy<UserT>
|
||||||
|
|
||||||
class EntityDeletedByImp<UserT: EntityI>(
|
class EntityDeletedByImp<UserT : EntityI>(
|
||||||
override var deletedBy: UserT?
|
override var deletedBy: UserT?
|
||||||
): EntityDeletedBy<UserT>
|
) : EntityDeletedBy<UserT>
|
||||||
|
|
||||||
/* Mixed */
|
/* Mixed */
|
||||||
class EntityDeletedImp<UserT: EntityI>(
|
class EntityDeletedImp<UserT : EntityI>(
|
||||||
override var deletedBy: UserT? = null
|
override var deletedBy: UserT? = null
|
||||||
): EntityDeletedBy<UserT>,
|
) : EntityDeletedBy<UserT>,
|
||||||
EntityDeletedAt by EntityDeletedAtImp()
|
EntityDeletedAt by EntityDeletedAtImp()
|
||||||
|
|
||||||
class EntityUpdatedImp<UserT: EntityI>(
|
class EntityUpdatedImp<UserT : EntityI>(
|
||||||
override var updatedAt: DateTime? = null,
|
override var updatedAt: DateTime? = null,
|
||||||
override var updatedBy: UserT? = null
|
override var updatedBy: UserT? = null
|
||||||
): EntityUpdatedBy<UserT>,
|
) : EntityUpdatedBy<UserT>,
|
||||||
EntityUpdatedAt by EntityUpdatedAtImp()
|
EntityUpdatedAt by EntityUpdatedAtImp()
|
||||||
|
|
||||||
class EntityCreatedImp<UserT: EntityI>(
|
class EntityCreatedImp<UserT : EntityI>(
|
||||||
override var createdAt: DateTime? = null,
|
override var createdAt: DateTime? = null,
|
||||||
override var createdBy: UserT? = null
|
override var createdBy: UserT? = null
|
||||||
): EntityCreatedBy<UserT>,
|
) : EntityCreatedBy<UserT>,
|
||||||
EntityCreatedAt by EntityCreatedAtImp()
|
EntityCreatedAt by EntityCreatedAtImp()
|
||||||
|
|
||||||
/* Published */
|
/* Published */
|
||||||
interface Published<UserT: EntityI> {
|
interface Published<UserT : EntityI> {
|
||||||
var publishedAt: DateTime?
|
var publishedAt: DateTime?
|
||||||
var publishedBy: UserT?
|
var publishedBy: UserT?
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntityPublishedImp<UserT: EntityI>(
|
class EntityPublishedImp<UserT : EntityI>(
|
||||||
override var publishedBy: UserT?
|
override var publishedBy: UserT?
|
||||||
): Published<UserT> {
|
) : Published<UserT> {
|
||||||
override var publishedAt: DateTime? = null
|
override var publishedAt: DateTime? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Implementation */
|
/* Implementation */
|
||||||
abstract class EntityImp<T, UserT: EntityI>(
|
abstract class EntityImp<T, UserT : EntityI>(
|
||||||
updatedBy: UserT?
|
updatedBy: UserT?
|
||||||
): Entity<T>(),
|
) : Entity<T>(),
|
||||||
EntityCreatedAt by EntityCreatedAtImp(),
|
EntityCreatedAt by EntityCreatedAtImp(),
|
||||||
EntityUpdatedAt by EntityUpdatedAtImp(),
|
EntityUpdatedAt by EntityUpdatedAtImp(),
|
||||||
EntityDeletedAt by EntityDeletedAtImp(),
|
EntityDeletedAt by EntityDeletedAtImp(),
|
||||||
@@ -116,10 +116,10 @@ abstract class EntityImp<T, UserT: EntityI>(
|
|||||||
EntityUpdatedBy<UserT> by EntityUpdatedByImp(updatedBy),
|
EntityUpdatedBy<UserT> by EntityUpdatedByImp(updatedBy),
|
||||||
EntityDeletedBy<UserT> by EntityDeletedByImp(updatedBy)
|
EntityDeletedBy<UserT> by EntityDeletedByImp(updatedBy)
|
||||||
|
|
||||||
abstract class UuidEntityExtended<T, UserT: EntityI>(
|
abstract class UuidEntityExtended<T, UserT : EntityI>(
|
||||||
updatedBy: UserT?,
|
updatedBy: UserT?,
|
||||||
publishedBy: UserT?
|
publishedBy: UserT?
|
||||||
):
|
) :
|
||||||
EntityImp<T, UserT>(updatedBy),
|
EntityImp<T, UserT>(updatedBy),
|
||||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
||||||
Published<UserT> by EntityPublishedImp(publishedBy)
|
Published<UserT> by EntityPublishedImp(publishedBy)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ data class Function(
|
|||||||
val down: DefinitionFunction,
|
val down: DefinitionFunction,
|
||||||
private val connection: Connection,
|
private val connection: Connection,
|
||||||
override var executedAt: Date? = null
|
override var executedAt: Date? = null
|
||||||
): Migration {
|
) : Migration {
|
||||||
val name = up.name
|
val name = up.name
|
||||||
override var doExecute: Action? = null
|
override var doExecute: Action? = null
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ data class Function(
|
|||||||
down: String,
|
down: String,
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
executedAt: Date? = null
|
executedAt: Date? = null
|
||||||
): this(
|
) : this(
|
||||||
DefinitionFunction(up),
|
DefinitionFunction(up),
|
||||||
DefinitionFunction(down),
|
DefinitionFunction(down),
|
||||||
connection,
|
connection,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class MigrationEntity(
|
|||||||
val up: String,
|
val up: String,
|
||||||
val down: String,
|
val down: String,
|
||||||
val version: Int
|
val version: Int
|
||||||
): Entity<String?>(filename)
|
) : Entity<String?>(filename)
|
||||||
|
|
||||||
interface Migration {
|
interface Migration {
|
||||||
var executedAt: Date?
|
var executedAt: Date?
|
||||||
@@ -40,9 +40,9 @@ data class Migrations private constructor(
|
|||||||
) {
|
) {
|
||||||
private var directories: List<File> = emptyList()
|
private var directories: List<File> = emptyList()
|
||||||
private val logger: Logger? by LoggerDelegate()
|
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<File>, connection: Connection): this(connection) {
|
constructor(directories: List<File>, connection: Connection) : this(connection) {
|
||||||
initDB()
|
initDB()
|
||||||
this.directories = directories
|
this.directories = directories
|
||||||
reset()
|
reset()
|
||||||
@@ -75,14 +75,14 @@ data class Migrations private constructor(
|
|||||||
*/
|
*/
|
||||||
private fun getMigrationFromDB() {
|
private fun getMigrationFromDB() {
|
||||||
this::class.java.classLoader.getResource("sql/migration/findAllFunction.sql")!!.readText().let {
|
this::class.java.classLoader.getResource("sql/migration/findAllFunction.sql")!!.readText().let {
|
||||||
connection.select<MigrationEntity>(it, object: TypeReference<List<MigrationEntity>>() {})
|
connection.select<MigrationEntity>(it, object : TypeReference<List<MigrationEntity>>() {})
|
||||||
.map { function ->
|
.map { function ->
|
||||||
functions[function.filename] = Function(function.up, function.down, connection, function.executedAt)
|
functions[function.filename] = Function(function.up, function.down, connection, function.executedAt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this::class.java.classLoader.getResource("sql/migration/findAllHistory.sql")!!.readText().let {
|
this::class.java.classLoader.getResource("sql/migration/findAllHistory.sql")!!.readText().let {
|
||||||
connection.select<MigrationEntity>(it, object: TypeReference<List<MigrationEntity>>() {})
|
connection.select<MigrationEntity>(it, object : TypeReference<List<MigrationEntity>>() {})
|
||||||
.map { query ->
|
.map { query ->
|
||||||
queries[query.filename] = Query(query.filename, query.up, query.down, connection, query.executedAt)
|
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()
|
val fileContent = file.readText()
|
||||||
try {
|
try {
|
||||||
addFunction(fileContent)
|
addFunction(fileContent)
|
||||||
} catch(e: FunctionNotFound) {
|
} catch (e: FunctionNotFound) {
|
||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ data class Migrations private constructor(
|
|||||||
|
|
||||||
enum class Direction { UP, DOWN }
|
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)
|
Throwable("The file $path whas not found", cause)
|
||||||
|
|
||||||
fun addFunction(newDefinition: DefinitionFunction, callback: (Function) -> Unit = {}): Migrations {
|
fun addFunction(newDefinition: DefinitionFunction, callback: (Function) -> Unit = {}): Migrations {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ data class Query(
|
|||||||
val down: String,
|
val down: String,
|
||||||
private val connection: Connection,
|
private val connection: Connection,
|
||||||
override var executedAt: Date? = null
|
override var executedAt: Date? = null
|
||||||
): Migration, Entity<String?>(name) {
|
) : Migration, Entity<String?>(name) {
|
||||||
override var doExecute: Action? = null
|
override var doExecute: Action? = null
|
||||||
|
|
||||||
override fun up(): Migration.Status {
|
override fun up(): Migration.Status {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) {
|
|||||||
|
|
||||||
mapper.registerModule(JodaModule())
|
mapper.registerModule(JodaModule())
|
||||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
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 {
|
fun serialize(source: EntityI, pretty: Boolean = false): String {
|
||||||
@@ -27,11 +27,11 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) {
|
|||||||
else mapper.writeValueAsString(source)
|
else mapper.writeValueAsString(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <E: EntityI> deserialize(json: String, valueTypeRef: TypeReference<E>): E {
|
fun <E : EntityI> deserialize(json: String, valueTypeRef: TypeReference<E>): E {
|
||||||
return this.mapper.readValue(json, valueTypeRef)
|
return this.mapper.readValue(json, valueTypeRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified E: EntityI> deserialize(json: String): E? {
|
inline fun <reified E : EntityI> deserialize(json: String): E? {
|
||||||
return this.mapper.readValue(json)
|
return this.mapper.readValue(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,14 +40,14 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified E> deserializeList(json: String): E {
|
inline fun <reified E> deserializeList(json: String): E {
|
||||||
return deserializeList(json, object: TypeReference<E>() {})
|
return deserializeList(json, object : TypeReference<E>() {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <E: EntityI> deserialize(json: String, target: E): E {
|
fun <E : EntityI> deserialize(json: String, target: E): E {
|
||||||
return mapper.readerForUpdating(target).readValue<E>(json)
|
return mapper.readerForUpdating(target).readValue<E>(json)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun EntityI.serialize(pretty: Boolean = false) = Serializer().serialize(this, pretty)
|
fun EntityI.serialize(pretty: Boolean = false) = Serializer().serialize(this, pretty)
|
||||||
inline fun <reified E: EntityI> E.deserialize(json: String) = Serializer().deserialize(json, this)
|
inline fun <reified E : EntityI> E.deserialize(json: String) = Serializer().deserialize(json, this)
|
||||||
inline fun <reified E: EntityI> String.deserialize() = Serializer().deserialize<E>(this)
|
inline fun <reified E : EntityI> String.deserialize() = Serializer().deserialize<E>(this)
|
||||||
@@ -5,6 +5,6 @@ import org.slf4j.LoggerFactory
|
|||||||
import kotlin.properties.ReadOnlyProperty
|
import kotlin.properties.ReadOnlyProperty
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
internal class LoggerDelegate<in R: Any>: ReadOnlyProperty<R, Logger> {
|
internal class LoggerDelegate<in R : Any> : ReadOnlyProperty<R, Logger> {
|
||||||
override fun getValue(thisRef: R, property: KProperty<*>) = LoggerFactory.getLogger(thisRef.javaClass.packageName)
|
override fun getValue(thisRef: R, property: KProperty<*>) = LoggerFactory.getLogger(thisRef.javaClass.packageName)
|
||||||
}
|
}
|
||||||
@@ -8,10 +8,10 @@ import org.junit.jupiter.api.Test
|
|||||||
import org.junit.jupiter.api.TestInstance
|
import org.junit.jupiter.api.TestInstance
|
||||||
|
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class ConnectionTest(): TestAbstract() {
|
class ConnectionTest() : TestAbstract() {
|
||||||
private class ObjTest(var name: String): IdEntity()
|
private class ObjTest(var name: String) : IdEntity()
|
||||||
private class ObjTest2(var title: String, var test: ObjTest?): IdEntity()
|
private class ObjTest2(var title: String, var test: ObjTest?) : IdEntity()
|
||||||
private class ObjTest3(var first: String, var seconde: String, var third: Int): IdEntity()
|
private class ObjTest3(var first: String, var seconde: String, var third: Int) : IdEntity()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getObject() {
|
fun getObject() {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import org.junit.jupiter.api.TestInstance
|
|||||||
|
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class EntityTest() {
|
class EntityTest() {
|
||||||
private class User(id: Int?): Entity<Int?>(id)
|
private class User(id: Int?) : Entity<Int?>(id)
|
||||||
private class ObjTest(var name: String): UuidEntityExtended<Int?, User>(User(1), User(2))
|
private class ObjTest(var name: String) : UuidEntityExtended<Int?, User>(User(1), User(2))
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getObject() {
|
fun getObject() {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import org.junit.jupiter.api.TestInstance
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class MigrationTest(): TestAbstract() {
|
class MigrationTest() : TestAbstract() {
|
||||||
@Test
|
@Test
|
||||||
fun `run up query`() {
|
fun `run up query`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/migrations").toURI())
|
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!!.id, 3)
|
||||||
Assertions.assertEquals(objTest.name, "test")
|
Assertions.assertEquals(objTest.name, "test")
|
||||||
|
|
||||||
|
|
||||||
val resources2 = File(this::class.java.getResource("/sql/function/Test2").toURI())
|
val resources2 = File(this::class.java.getResource("/sql/function/Test2").toURI())
|
||||||
Migrations(resources2, connection).apply {
|
Migrations(resources2, connection).apply {
|
||||||
run().size `should be equal to` 1
|
run().size `should be equal to` 1
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import org.junit.jupiter.api.Assertions.assertEquals
|
|||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class RequesterTest: TestAbstract() {
|
class RequesterTest : TestAbstract() {
|
||||||
class ObjTest(var name:String): IdEntity(1)
|
class ObjTest(var name: String) : IdEntity(1)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `get query from file`() {
|
fun `get query from file`() {
|
||||||
|
|||||||
Reference in New Issue
Block a user