Skip to content

Commit

Permalink
fix: EXPOSED-669 Review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
obabichevjb committed Jan 27, 2025
1 parent 2cc9830 commit bc5e53b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion exposed-core/api/exposed-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,6 @@ public final class org/jetbrains/exposed/sql/ResultRow {
public final class org/jetbrains/exposed/sql/ResultRow$Companion {
public final fun create (Ljava/sql/ResultSet;Ljava/util/Map;)Lorg/jetbrains/exposed/sql/ResultRow;
public final fun createAndFillDefaults (Ljava/util/List;)Lorg/jetbrains/exposed/sql/ResultRow;
public final fun createAndFillFromWrappedValues (Ljava/util/Map;)Lorg/jetbrains/exposed/sql/ResultRow;
public final fun createAndFillValues (Ljava/util/Map;)Lorg/jetbrains/exposed/sql/ResultRow;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ class ResultRow(
return ResultRow(fieldIndex, values)
}

/** Creates a [ResultRow] using the expressions and values provided by [data].
* If the value associated with [ColumnWithTransform] column it will be unwrapped.
* [ResultRow] supposed to store unwrapped values. */
fun createAndFillFromWrappedValues(data: Map<Expression<*>, Any?>): ResultRow {
return createAndFillValues(unwrapColumnValues(data))
}

/** Creates a [ResultRow] storing [columns] with their default or nullable values. */
fun createAndFillDefaults(columns: List<Column<*>>): ResultRow =
ResultRow(columns.withIndex().associate { it.value to it.index }).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ abstract class EntityClass<ID : Any, out T : Entity<ID>>(
}
}.toMap()

return wrapRow(ResultRow.createAndFillFromWrappedValues(newFieldsMapping))
return wrapRow(ResultRow.createAndFillValues(unwrapColumnValues(newFieldsMapping)))
}

/**
Expand Down Expand Up @@ -267,7 +267,7 @@ abstract class EntityClass<ID : Any, out T : Entity<ID>>(
}
}.toMap()

return wrapRow(ResultRow.createAndFillFromWrappedValues(newFieldsMapping))
return wrapRow(ResultRow.createAndFillValues(unwrapColumnValues(newFieldsMapping)))
}

/**
Expand Down Expand Up @@ -1172,3 +1172,9 @@ abstract class ImmutableCachedEntityClass<ID : Any, out T : Entity<ID>>(
expireCache()
}
}

internal fun <T : Expression<*>> unwrapColumnValues(values: Map<T, Any?>): Map<T, Any?> = values.mapValues { (col, value) ->
if (col !is ExpressionWithColumnType<*>) return@mapValues value

value?.let { (col.columnType as? ColumnWithTransform<Any, Any>)?.unwrapRecursive(it) } ?: value
}

0 comments on commit bc5e53b

Please sign in to comment.