open fun new()

in exposed-dao/src/main/kotlin/org/jetbrains/exposed/v1/dao/EntityClass.kt [372:401]


    open fun new(id: ID?, init: T.() -> Unit): T {
        val entityId = if (id == null && table.id.defaultValueFun != null) {
            table.id.defaultValueFun!!()
        } else {
            DaoEntityID(id, table)
        }
        val entityCache = warmCache()
        val prototype: T = createInstance(entityId, null)
        prototype.klass = this
        prototype.db = TransactionManager.current().db
        prototype._readValues = ResultRow.createAndFillDefaults(dependsOnColumns)
        if (entityId._value != null) {
            prototype.writeIdColumnValue(table, entityId)
        }
        try {
            entityCache.addNotInitializedEntityToQueue(prototype)
            prototype.init()
        } finally {
            entityCache.finishEntityInitialization(prototype)
        }
        val readValues = prototype._readValues!!
        val writeValues = prototype.writeValues
        table.columns.filter { col ->
            col.defaultValueFun != null && col !in writeValues && readValues.hasValue(col)
        }.forEach { col ->
            writeValues[col as Column<Any?>] = readValues[col]
        }
        entityCache.scheduleInsert(this, prototype)
        return prototype
    }