Skip to content

Commit

Permalink
After merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapac committed Jun 16, 2018
1 parent 778cb05 commit 15027d4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/main/kotlin/org/jetbrains/exposed/sql/DateApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ abstract class DateColumnType(val type: DateType): ColumnType() {
}

abstract class DateApi<T:Any> {
inner class Date(val expr: Expression<T?>) : Function<T>() {
inner class Date(val expr: Expression<out T?>) : Function<T>(columnType(DateType.DATE)) {
override fun toSQL(queryBuilder: QueryBuilder): String
= currentDialect.functionProvider.cast(expr, columnType, queryBuilder)
override val columnType: IColumnType = columnType(DateType.DATE)
}

inner class CurrentDateTime : Function<T>() {
inner class CurrentDateTime : Function<T>(columnType(DateType.DATETIME)) {
override fun toSQL(queryBuilder: QueryBuilder) = "CURRENT_TIMESTAMP"
override val columnType: IColumnType = columnType(DateType.DATETIME)
}

inner class Month(val expr: Expression<T?>) : Function<T>() {
inner class Month(val expr: Expression<out T?>) : Function<T>(columnType(DateType.DATE)) {
override fun toSQL(queryBuilder: QueryBuilder): String = "MONTH(${expr.toSQL(queryBuilder)})"
override val columnType: IColumnType = columnType(DateType.DATE)
}

protected abstract fun columnType(type: DateType) : DateColumnType
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/jetbrains/exposed/sql/Op.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.jetbrains.exposed.sql

import org.jetbrains.exposed.dao.EntityID

abstract class Op<out T> : Expression<T>() {
abstract class Op<T> : Expression<T>() {
object TRUE : Op<Boolean>() {
override fun toSQL(queryBuilder: QueryBuilder): String = "TRUE"
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/org/jetbrains/exposed/sql/vendors/H2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import org.h2.jdbc.JdbcConnection
import org.jetbrains.exposed.exceptions.throwUnsupportedException
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.joda.time.DateTime
import java.sql.Wrapper
import java.text.DateFormat
import java.util.*

internal object H2DataTypeProvider : DataTypeProvider() {
override fun uuidType(): String = "UUID"
Expand All @@ -19,9 +20,11 @@ internal object H2FunctionProvider : FunctionProvider() {

private val isMySQLMode: Boolean get() = currentMode() == "MySQL"

private fun dbReleaseDate(transaction: Transaction) : DateTime {
private val RELEASE_DATE_1_4_197 = DateFormat.getDateInstance().parse("2018-03-18")

private fun dbReleaseDate(transaction: Transaction) : Date {
val releaseDate = transaction.db.metadata.databaseProductVersion.substringAfterLast('(').substringBeforeLast(')')
return DateTime.parse(releaseDate)
return DateFormat.getDateInstance().parse(releaseDate)
}

override fun replace(table: Table, data: List<Pair<Column<*>, Any?>>, transaction: Transaction): String {
Expand All @@ -41,7 +44,7 @@ internal object H2FunctionProvider : FunctionProvider() {
val uniqueCols = columns.filter { it.indexInPK != null || it in uniqueIdxCols}
return when {
// INSERT IGNORE support added in H2 version 1.4.197 (2018-03-18)
ignore && uniqueCols.isNotEmpty() && isMySQLMode && dbReleaseDate(transaction).isBefore(DateTime.parse("2018-03-18")) -> {
ignore && uniqueCols.isNotEmpty() && isMySQLMode && dbReleaseDate(transaction) < RELEASE_DATE_1_4_197 -> {
val def = super.insert(false, table, columns, expr, transaction)
def + " ON DUPLICATE KEY UPDATE " + uniqueCols.joinToString { "${transaction.identity(it)}=VALUES(${transaction.identity(it)})" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal object PostgreSQLDataTypeProvider : DataTypeProvider() {

override fun longAutoincType(): String = "BIGSERIAL"

override fun dateTimeType(): String = "TIMESTAMP"
override fun dateTimeType(type: DateType): String = "TIMESTAMP"

override fun uuidType(): String = "uuid"

Expand Down

0 comments on commit 15027d4

Please sign in to comment.