Skip to content

Commit

Permalink
trial
Browse files Browse the repository at this point in the history
  • Loading branch information
joc-a committed Mar 6, 2024
1 parent b547376 commit 85d77f5
Show file tree
Hide file tree
Showing 42 changed files with 581 additions and 759 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ open class EntityID<T : Comparable<T>> protected constructor(val table: IdTable<
var _value: Any? = id

/** The identity value of type [T] wrapped by this [EntityID] instance. */
val value: T get() {
if (_value == null) {
invokeOnNoValue()
check(_value != null) { "Entity must be inserted" }
val value: T
get() {
if (_value == null) {
invokeOnNoValue()
check(_value != null) { "Entity must be inserted" }
}

@Suppress("UNCHECKED_CAST")
return _value!! as T
}

@Suppress("UNCHECKED_CAST")
return _value!! as T
}

/** Performs steps when the internal [_value] is accessed without first being initialized. */
protected open fun invokeOnNoValue() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Alias<out T : Table>(val delegate: T, val alias: String) : Table() {
/** The table name along with its [alias]. */
val tableNameWithAlias: String = "${delegate.tableName} $alias"

private fun <T : Any?> Column<T>.clone() = Column<T>(this@Alias, name, columnType)
private fun <T> Column<T>.clone() = Column<T>(this@Alias, name, columnType)

/**
* Returns the original column from the [delegate] table, or `null` if the [column] is not associated
Expand Down Expand Up @@ -111,7 +111,7 @@ class QueryAlias(val query: AbstractQuery<*>, val alias: String) : ColumnSet() {

override infix fun crossJoin(otherTable: ColumnSet): Join = Join(this, otherTable, JoinType.CROSS)

private fun <T : Any?> Column<T>.clone() = Column<T>(table.alias(alias), name, columnType)
private fun <T> Column<T>.clone() = Column<T>(table.alias(alias), name, columnType)
}

/**
Expand Down
17 changes: 9 additions & 8 deletions exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Column.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Column<T>(
/** Name of the column. */
val name: String,
/** Data type of the column. */
override val columnType: IColumnType
override val columnType: IColumnType<out T>
) : ExpressionWithColumnType<T>(), DdlAware, Comparable<Column<*>> {
/** The foreign key constraint on this column, or `null` if the column is not referencing. */
var foreignKey: ForeignKeyConstraint? = null
Expand Down Expand Up @@ -63,12 +63,13 @@ class Column<T>(
private val isLastColumnInPK: Boolean
get() = this == table.primaryKey?.columns?.last()

internal val isPrimaryConstraintWillBeDefined: Boolean get() = when {
currentDialect is SQLiteDialect && columnType.isAutoInc -> false
table.isCustomPKNameDefined() -> isLastColumnInPK
isOneColumnPK() -> false
else -> isLastColumnInPK
}
internal val isPrimaryConstraintWillBeDefined: Boolean
get() = when {
currentDialect is SQLiteDialect && columnType.isAutoInc -> false
table.isCustomPKNameDefined() -> isLastColumnInPK
isOneColumnPK() -> false
else -> isLastColumnInPK
}

override fun createStatement(): List<String> {
val alterTablePrefix = "ALTER TABLE ${TransactionManager.current().identity(table)} ADD"
Expand Down Expand Up @@ -154,7 +155,7 @@ class Column<T>(
/**
* Returns a copy of this column, but with the given column type.
*/
fun withColumnType(columnType: IColumnType) = Column<T>(
fun withColumnType(columnType: IColumnType<T>) = Column<T>(
table = this.table,
name = this.name,
columnType = columnType
Expand Down
Loading

0 comments on commit 85d77f5

Please sign in to comment.