com.dbobjekts.metadata.column.NullableColumn.kt Maven / Gradle / Ivy
package com.dbobjekts.metadata.column
import com.dbobjekts.metadata.DefaultTable
import com.dbobjekts.api.AnyTable
import com.dbobjekts.metadata.ColumnFactory
import java.sql.PreparedStatement
import java.sql.ResultSet
abstract class NullableColumn(
table: AnyTable = DefaultTable,
name: String = "dummy",
internal val sqlType: Int,
valueClass: Class<*>,
aggregateType: AggregateType?
) : Column(table,name, valueClass, aggregateType) {
override fun create(value: I?): ColumnAndValue = NullableColumnAndValue(this, value)
@Suppress("UNCHECKED_CAST")
open fun distinct(): NullableColumn = ColumnFactory.distinctClone(this) as NullableColumn
internal fun setNull(): ColumnAndValue = NullableColumnAndValue(this, null)
override fun retrieveValue(position: Int, rs: ResultSet): I? {
val value = getValue(position, rs)
return if (rs.wasNull())
null else value
}
abstract fun getValue(position: Int, resultSet: ResultSet): I?
abstract fun setValue(position: Int, statement: PreparedStatement, value: I)
override fun putValue(position: Int, statement: PreparedStatement, value: I?) {
if (value == null)
statement.setNull(position, sqlType)
else
setValue(position, statement, value)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy