All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dbobjekts.metadata.column.DateTimeColumns.kt Maven / Gradle / Ivy

There is a newer version: 0.6.0-RC2
Show newest version
package com.dbobjekts.metadata.column

import com.dbobjekts.api.AnyTable
import com.dbobjekts.util.DateUtil
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.Types
import java.time.LocalDateTime

class DateTimeColumn(table: AnyTable, name: String, aggregateType: AggregateType?) :
    NonNullableColumn(table,name, LocalDateTime::class.java, aggregateType) {
    constructor(table: AnyTable, name: String) : this(table, name, null)

    override fun getValue(position: Int, resultSet: ResultSet): LocalDateTime? =
        resultSet.getTimestamp(position)?.let { DateUtil.toLocalDateTime(it) }

    override fun setValue(position: Int, statement: PreparedStatement, value: LocalDateTime) =
        statement.setTimestamp(position, DateUtil.toSqlTimeStamp(value))
}

class NullableDateTimeColumn(table: AnyTable, name: String, aggregateType: AggregateType?) :
    NullableColumn(table,name, Types.TIMESTAMP, LocalDateTime::class.java, aggregateType) {
    constructor(table: AnyTable, name: String) : this(table, name, null)

    override fun getValue(position: Int, resultSet: ResultSet): LocalDateTime? =
        resultSet.getTimestamp(position)?.let { DateUtil.toLocalDateTime(it) }

    override fun setValue(position: Int, statement: PreparedStatement, value: LocalDateTime?) =
        statement.setTimestamp(position, DateUtil.toSqlTimeStamp(value!!))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy