From 15027d4da1d8bd278c99e6627792637803db6d00 Mon Sep 17 00:00:00 2001 From: "andrey.tarashevskiy" Date: Sat, 16 Jun 2018 17:38:19 +0300 Subject: [PATCH] After merge fixes --- src/main/kotlin/org/jetbrains/exposed/sql/DateApi.kt | 9 +++------ src/main/kotlin/org/jetbrains/exposed/sql/Op.kt | 2 +- .../kotlin/org/jetbrains/exposed/sql/vendors/H2.kt | 11 +++++++---- .../org/jetbrains/exposed/sql/vendors/PostgreSQL.kt | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/org/jetbrains/exposed/sql/DateApi.kt b/src/main/kotlin/org/jetbrains/exposed/sql/DateApi.kt index 3596e22e54..b06e725c8a 100644 --- a/src/main/kotlin/org/jetbrains/exposed/sql/DateApi.kt +++ b/src/main/kotlin/org/jetbrains/exposed/sql/DateApi.kt @@ -15,20 +15,17 @@ abstract class DateColumnType(val type: DateType): ColumnType() { } abstract class DateApi { - inner class Date(val expr: Expression) : Function() { + inner class Date(val expr: Expression) : Function(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() { + inner class CurrentDateTime : Function(columnType(DateType.DATETIME)) { override fun toSQL(queryBuilder: QueryBuilder) = "CURRENT_TIMESTAMP" - override val columnType: IColumnType = columnType(DateType.DATETIME) } - inner class Month(val expr: Expression) : Function() { + inner class Month(val expr: Expression) : Function(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 diff --git a/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt b/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt index 9e590faa3b..7e441bda23 100644 --- a/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt +++ b/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt @@ -2,7 +2,7 @@ package org.jetbrains.exposed.sql import org.jetbrains.exposed.dao.EntityID -abstract class Op : Expression() { +abstract class Op : Expression() { object TRUE : Op() { override fun toSQL(queryBuilder: QueryBuilder): String = "TRUE" } diff --git a/src/main/kotlin/org/jetbrains/exposed/sql/vendors/H2.kt b/src/main/kotlin/org/jetbrains/exposed/sql/vendors/H2.kt index 1feacfc8b0..06abd8e1d8 100644 --- a/src/main/kotlin/org/jetbrains/exposed/sql/vendors/H2.kt +++ b/src/main/kotlin/org/jetbrains/exposed/sql/vendors/H2.kt @@ -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" @@ -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, Any?>>, transaction: Transaction): String { @@ -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)})" } } diff --git a/src/main/kotlin/org/jetbrains/exposed/sql/vendors/PostgreSQL.kt b/src/main/kotlin/org/jetbrains/exposed/sql/vendors/PostgreSQL.kt index 6d96114a81..164ba0b861 100644 --- a/src/main/kotlin/org/jetbrains/exposed/sql/vendors/PostgreSQL.kt +++ b/src/main/kotlin/org/jetbrains/exposed/sql/vendors/PostgreSQL.kt @@ -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"