Skip to content

Commit

Permalink
Remove explicit date format for H2_Oracle. 1) it works without it, 2)…
Browse files Browse the repository at this point in the history
… H2 converts TO_TIMESTEMP(...) to STATEMENT '...', it breaks logic of addMissingColumnsStatements(), it always finds difference in column defaults.
  • Loading branch information
obabichevjb committed Apr 26, 2024
1 parent 20f9371 commit c484fe3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ internal object OracleDataTypeProvider : DataTypeProvider() {

override fun jsonType(): String = "VARCHAR2(4000)"

override fun processForDefaultValue(e: Expression<*>): String = when {
e is LiteralOp<*> && (e.columnType as? IDateColumnType)?.hasTimePart == true -> "TIMESTAMP ${super.processForDefaultValue(e)}"
else -> super.processForDefaultValue(e)
}

override fun hexToDb(hexString: String): String = "HEXTORAW('$hexString')"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,8 @@ class JavaLocalDateTimeColumnType : ColumnType<LocalDateTime>(), IDateColumnType
val dialect = currentDialect
return when {
dialect is SQLiteDialect -> "'${SQLITE_AND_ORACLE_DATE_TIME_STRING_FORMATTER.format(instant)}'"
dialect is OracleDialect || dialect.h2Mode == H2Dialect.H2CompatibilityMode.Oracle ->
dialect is OracleDialect ->
"TO_TIMESTAMP('${SQLITE_AND_ORACLE_DATE_TIME_STRING_FORMATTER.format(instant)}', 'YYYY-MM-DD HH24:MI:SS.FF3')"

dialect is MysqlDialect -> {
val formatter = if (dialect.isFractionDateTimeSupported()) MYSQL_FRACTION_DATE_TIME_STRING_FORMATTER else MYSQL_DATE_TIME_STRING_FORMATTER
"'${formatter.format(instant)}'"
Expand Down Expand Up @@ -250,9 +249,12 @@ class JavaLocalTimeColumnType : ColumnType<LocalTime>(), IDateColumnType {
override fun sqlType(): String = currentDialect.dataTypeProvider.timeType()

override fun nonNullValueToString(value: LocalTime): String {
if (currentDialect is OracleDialect || currentDialect.h2Mode == H2Dialect.H2CompatibilityMode.Oracle) {
if (currentDialect is OracleDialect) {
return "TO_TIMESTAMP('${ORACLE_TIME_STRING_FORMATTER.format(value)}', 'YYYY-MM-DD HH24:MI:SS')"
}
if (currentDialect.h2Mode == H2Dialect.H2CompatibilityMode.Oracle) {
return "'${ORACLE_TIME_STRING_FORMATTER.format(value)}'"
}

return "'${DEFAULT_TIME_STRING_FORMATTER.format(value)}'"
}
Expand Down Expand Up @@ -302,10 +304,12 @@ class JavaInstantColumnType : ColumnType<Instant>(), IDateColumnType {
override fun nonNullValueToString(value: Instant): String {
val dialect = currentDialect
return when {
dialect is SQLiteDialect -> "'${SQLITE_AND_ORACLE_DATE_TIME_STRING_FORMATTER.format(value)}'"
dialect is OracleDialect || dialect.h2Mode == H2Dialect.H2CompatibilityMode.Oracle ->
dialect is OracleDialect ->
"TO_TIMESTAMP('${SQLITE_AND_ORACLE_DATE_TIME_STRING_FORMATTER.format(value)}', 'YYYY-MM-DD HH24:MI:SS.FF3')"

dialect is SQLiteDialect ->
"'${SQLITE_AND_ORACLE_DATE_TIME_STRING_FORMATTER.format(value)}'"

dialect is MysqlDialect -> {
val formatter = if (dialect.isFractionDateTimeSupported()) MYSQL_FRACTION_DATE_TIME_STRING_FORMATTER else MYSQL_DATE_TIME_STRING_FORMATTER
"'${formatter.format(value)}'"
Expand Down Expand Up @@ -359,7 +363,7 @@ class JavaOffsetDateTimeColumnType : ColumnType<OffsetDateTime>(), IDateColumnTy
override fun nonNullValueToString(value: OffsetDateTime): String = when (currentDialect) {
is SQLiteDialect -> "'${value.format(SQLITE_OFFSET_DATE_TIME_FORMATTER)}'"
is MysqlDialect -> "'${value.format(MYSQL_OFFSET_DATE_TIME_FORMATTER)}'"
is OracleDialect -> "'${value.format(ORACLE_OFFSET_DATE_TIME_FORMATTER)}'"
is OracleDialect -> "TO_TIMESTAMP_TZ('${value.format(ORACLE_OFFSET_DATE_TIME_FORMATTER)}', 'YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM')"
else -> "'${value.format(DEFAULT_OFFSET_DATE_TIME_FORMATTER)}'"
}

Expand Down

0 comments on commit c484fe3

Please sign in to comment.