Skip to content

Commit

Permalink
chore: Fix more detekt issues (#1772)
Browse files Browse the repository at this point in the history
* chore: remove detekt SpacingAroundColon issues

* chore: remove detekt ParameterListWrapping issues

* chore: remove detekt SpacingAroundComma issues

* chore: remove detekt Wrapping issues

* chore: remove detekt NoConsecutiveBlankLines issues

* chore: remove detekt NoUnusedImports issues

* chore: remove detekt SpacingAroundOperators issues

* chore: remove detekt MultiLineIfElse issues
  • Loading branch information
joc-a committed Jun 27, 2023
1 parent 57c66af commit 22b4002
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ open class JsonColumnType<T : Any>(
val serialize: (T) -> String,
/** Returns the function that decodes a JSON String to an object of type [T]. */
val deserialize: (String) -> T
): ColumnType() {
) : ColumnType() {
override fun sqlType(): String = currentDialect.dataTypeProvider.jsonType()

override fun valueFromDB(value: Any): Any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ open class InsertStatement<Key : Any>(val table: Table, val isIgnore: Boolean =
}
}

assert(isIgnore || autoGeneratedKeys.isEmpty() ||
autoGeneratedKeys.size == inserted || currentDialect.supportsTernaryAffectedRowValues) {
assert(
isIgnore || autoGeneratedKeys.isEmpty() || autoGeneratedKeys.size == inserted ||
currentDialect.supportsTernaryAffectedRowValues
) {
"Number of autoincs (${autoGeneratedKeys.size}) doesn't match number of batch entries ($inserted)"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.jetbrains.exposed.sql.statements.api.PreparedStatementApi

interface StatementInterceptor {
fun beforeExecution(transaction: Transaction, context: StatementContext) {}
fun afterStatementPrepared(transaction : Transaction, preparedStatement: PreparedStatementApi) {}
fun afterStatementPrepared(transaction: Transaction, preparedStatement: PreparedStatementApi) {}
fun afterExecution(transaction: Transaction, contexts: List<StatementContext>, executedStatement: PreparedStatementApi) {}

fun beforeCommit(transaction: Transaction) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ fun <T> inTopLevelTransaction(
val delay = when {
minRepetitionDelay < maxRepetitionDelay -> {
intermediateDelay += retryInterval * repetitions
ThreadLocalRandom.current().nextLong(intermediateDelay , intermediateDelay + retryInterval)
ThreadLocalRandom.current().nextLong(intermediateDelay, intermediateDelay + retryInterval)
}
minRepetitionDelay == maxRepetitionDelay -> minRepetitionDelay
else -> 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ object Algorithms {
{ base64Encoder.encodeToString(encrypt(it.toByteArray())) },
{ String(decrypt(base64Decoder.decode(it))) },
{ inputLen ->
base64EncodedLength(AES_256_GCM_BLOCK_LENGTH + inputLen + AES_256_GCM_TAG_LENGTH) }
base64EncodedLength(AES_256_GCM_BLOCK_LENGTH + inputLen + AES_256_GCM_TAG_LENGTH)
}
)
}
}
Expand All @@ -49,7 +50,8 @@ object Algorithms {
{ String(decrypt(base64Decoder.decode(it))) },
{ inputLen ->
val paddingSize = (AES_256_CBC_BLOCK_LENGTH - inputLen % AES_256_CBC_BLOCK_LENGTH)
base64EncodedLength(AES_256_CBC_BLOCK_LENGTH + inputLen + paddingSize) }
base64EncodedLength(AES_256_CBC_BLOCK_LENGTH + inputLen + paddingSize)
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ val Transaction.entityCache: EntityCache by transactionScope { EntityCache(this)
class EntityCache(private val transaction: Transaction) {
private var flushingEntities = false
private var initializingEntities: LinkedIdentityHashSet<Entity<*>> = LinkedIdentityHashSet()
internal val pendingInitializationLambdas = IdentityHashMap<Entity<*>, MutableList<(Entity<*>)->Unit>>()
internal val pendingInitializationLambdas = IdentityHashMap<Entity<*>, MutableList<(Entity<*>) -> Unit>>()
val data = LinkedHashMap<IdTable<*>, MutableMap<Any, Entity<*>>>()
internal val inserts = LinkedHashMap<IdTable<*>, MutableSet<Entity<*>>>()
private val updates = LinkedHashMap<IdTable<*>, MutableSet<Entity<*>>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,14 @@ abstract class EntityClass<ID : Comparable<ID>, out T : Entity<ID>>(
else -> findQuery
}.toList()

internal fun <SID: Comparable<SID>> warmUpLinkedReferences(
references: List<EntityID<SID>>, sourceRefColumn: Column<EntityID<SID>>, targetRefColumn: Column<EntityID<ID>>, linkTable: Table,
forUpdate: Boolean? = null, optimizedLoad: Boolean = false
) : List<T> {
internal fun <SID : Comparable<SID>> warmUpLinkedReferences(
references: List<EntityID<SID>>,
sourceRefColumn: Column<EntityID<SID>>,
targetRefColumn: Column<EntityID<ID>>,
linkTable: Table,
forUpdate: Boolean? = null,
optimizedLoad: Boolean = false
): List<T> {
if (references.isEmpty()) return emptyList()
val distinctRefIds = references.distinct()
val transaction = TransactionManager.current()
Expand Down Expand Up @@ -475,7 +479,7 @@ abstract class EntityClass<ID : Comparable<ID>, out T : Entity<ID>>(
* Can be useful when references target the same entities. That will prevent from loading them multiple times (per each reference row) and will require
* less memory/bandwidth for "heavy" entities (with a lot of columns or columns with huge data in it)
*/
fun <SID: Comparable<SID>> warmUpLinkedReferences(references: List<EntityID<SID>>, linkTable: Table, forUpdate: Boolean? = null, optimizedLoad: Boolean = false): List<T> {
fun <SID : Comparable<SID>> warmUpLinkedReferences(references: List<EntityID<SID>>, linkTable: Table, forUpdate: Boolean? = null, optimizedLoad: Boolean = false): List<T> {
if (references.isEmpty()) return emptyList()

val sourceRefColumn = linkTable.columns.singleOrNull { it.referee == references.first().table.id } as? Column<EntityID<SID>>
Expand All @@ -489,8 +493,6 @@ abstract class EntityClass<ID : Comparable<ID>, out T : Entity<ID>>(
fun <ID : Comparable<ID>, T : Entity<ID>> isAssignableTo(entityClass: EntityClass<ID, T>) = entityClass.klass.isAssignableFrom(klass)
}



abstract class ImmutableEntityClass<ID : Comparable<ID>, out T : Entity<ID>>(
table: IdTable<ID>,
entityType: Class<T>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ fun Transaction.registerChange(entityClass: EntityClass<*, Entity<*>>, entityId:
}
}


private var isProcessingEventsLaunched by transactionScope { false }
fun Transaction.alertSubscribers() {
if (isProcessingEventsLaunched) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ class EntityLifecycleInterceptor : GlobalStatementInterceptor {
}

override fun afterExecution(transaction: Transaction, contexts: List<StatementContext>, executedStatement: PreparedStatementApi) {
if (!isExecutedWithinEntityLifecycle || contexts.first().statement !is InsertStatement<*>)
if (!isExecutedWithinEntityLifecycle || contexts.first().statement !is InsertStatement<*>) {
transaction.alertSubscribers()
}
}

override fun beforeCommit(transaction: Transaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private fun <ID : Comparable<ID>> List<Entity<ID>>.preloadRelations(
}
}

fun <SRCID : Comparable<SRCID>, SRC : Entity<SRCID>, REF : Entity<*>, L: Iterable<SRC>> L.with(vararg relations: KProperty1<out REF, Any?>): L {
fun <SRCID : Comparable<SRCID>, SRC : Entity<SRCID>, REF : Entity<*>, L : Iterable<SRC>> L.with(vararg relations: KProperty1<out REF, Any?>): L {
toList().apply {
if (any { it.isNewEntity() }) {
TransactionManager.current().flushCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.jetbrains.exposed.sql.vendors.OracleDialect
import org.jetbrains.exposed.sql.vendors.SQLServerDialect
import org.jetbrains.exposed.sql.vendors.h2Mode
import org.junit.Test
import org.junit.runners.model.MultipleFailureException
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
Expand Down

0 comments on commit 22b4002

Please sign in to comment.