-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,204 additions
and
1,031 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/Versions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/ColumnMetadata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.jetbrains.exposed.sql.vendors | ||
|
||
/** | ||
* Represents metadata information about a specific column. | ||
*/ | ||
data class ColumnMetadata( | ||
/** Name of the column. */ | ||
val name: String, | ||
/** | ||
* Type of the column. | ||
* | ||
* @see java.sql.Types | ||
*/ | ||
val type: Int, | ||
/** Whether the column if nullable or not. */ | ||
val nullable: Boolean, | ||
/** Optional size of the column. */ | ||
val size: Int?, | ||
/** Is the column auto increment */ | ||
val autoIncrement: Boolean, | ||
/** Default value */ | ||
val defaultDbValue: String?, | ||
) |
153 changes: 153 additions & 0 deletions
153
exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/DataTypeProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package org.jetbrains.exposed.sql.vendors | ||
|
||
import org.jetbrains.exposed.exceptions.UnsupportedByDialectException | ||
import org.jetbrains.exposed.sql.* | ||
import org.jetbrains.exposed.sql.Function | ||
import java.nio.ByteBuffer | ||
import java.util.* | ||
|
||
/** | ||
* Provides definitions for all the supported SQL data types. | ||
* By default, definitions from the SQL standard are provided but if a vendor doesn't support a specific type, or it is | ||
* implemented differently, the corresponding function should be overridden. | ||
*/ | ||
abstract class DataTypeProvider { | ||
// Numeric types | ||
|
||
/** Numeric type for storing 1-byte integers. */ | ||
open fun byteType(): String = "TINYINT" | ||
|
||
/** Numeric type for storing 1-byte unsigned integers. | ||
* | ||
* **Note:** If the database being used is not MySQL, MariaDB, or SQL Server, this will represent the 2-byte | ||
* integer type. | ||
*/ | ||
open fun ubyteType(): String = "SMALLINT" | ||
|
||
/** Numeric type for storing 2-byte integers. */ | ||
open fun shortType(): String = "SMALLINT" | ||
|
||
/** Numeric type for storing 2-byte unsigned integers. | ||
* | ||
* **Note:** If the database being used is not MySQL or MariaDB, this will represent the 4-byte integer type. | ||
*/ | ||
open fun ushortType(): String = "INT" | ||
|
||
/** Numeric type for storing 4-byte integers. */ | ||
open fun integerType(): String = "INT" | ||
|
||
/** Numeric type for storing 4-byte unsigned integers. | ||
* | ||
* **Note:** If the database being used is not MySQL or MariaDB, this will represent the 8-byte integer type. | ||
*/ | ||
open fun uintegerType(): String = "BIGINT" | ||
|
||
/** Numeric type for storing 4-byte integers, marked as auto-increment. */ | ||
open fun integerAutoincType(): String = "INT AUTO_INCREMENT" | ||
|
||
/** Numeric type for storing 8-byte integers. */ | ||
open fun longType(): String = "BIGINT" | ||
|
||
/** Numeric type for storing 8-byte unsigned integers. */ | ||
open fun ulongType(): String = "BIGINT" | ||
|
||
/** Numeric type for storing 8-byte integers, and marked as auto-increment. */ | ||
open fun longAutoincType(): String = "BIGINT AUTO_INCREMENT" | ||
|
||
/** Numeric type for storing 4-byte (single precision) floating-point numbers. */ | ||
open fun floatType(): String = "FLOAT" | ||
|
||
/** Numeric type for storing 8-byte (double precision) floating-point numbers. */ | ||
open fun doubleType(): String = "DOUBLE PRECISION" | ||
|
||
// Character types | ||
|
||
/** Character type for storing strings of variable length up to a maximum. */ | ||
open fun varcharType(colLength: Int): String = "VARCHAR($colLength)" | ||
|
||
/** Character type for storing strings of variable length. | ||
* Some database (postgresql) use the same data type name to provide virtually _unlimited_ length. */ | ||
open fun textType(): String = "TEXT" | ||
|
||
/** Character type for storing strings of _medium_ length. */ | ||
open fun mediumTextType(): String = "TEXT" | ||
|
||
/** Character type for storing strings of variable and _large_ length. */ | ||
open fun largeTextType(): String = "TEXT" | ||
|
||
// Binary data types | ||
|
||
/** Binary type for storing binary strings of variable and _unlimited_ length. */ | ||
abstract fun binaryType(): String | ||
|
||
/** Binary type for storing binary strings of a specific [length]. */ | ||
open fun binaryType(length: Int): String = if (length == Int.MAX_VALUE) "VARBINARY(MAX)" else "VARBINARY($length)" | ||
|
||
/** Binary type for storing BLOBs. */ | ||
open fun blobType(): String = "BLOB" | ||
|
||
/** Binary type for storing [UUID]. */ | ||
open fun uuidType(): String = "BINARY(16)" | ||
|
||
@Suppress("MagicNumber") | ||
open fun uuidToDB(value: UUID): Any = | ||
ByteBuffer.allocate(16).putLong(value.mostSignificantBits).putLong(value.leastSignificantBits).array() | ||
|
||
// Date/Time types | ||
|
||
/** Data type for storing both date and time without a time zone. */ | ||
open fun dateTimeType(): String = "DATETIME" | ||
|
||
/** Data type for storing both date and time with a time zone. */ | ||
open fun timestampWithTimeZoneType(): String = "TIMESTAMP WITH TIME ZONE" | ||
|
||
/** Time type for storing time without a time zone. */ | ||
open fun timeType(): String = "TIME" | ||
|
||
/** Data type for storing date without time or a time zone. */ | ||
open fun dateType(): String = "DATE" | ||
|
||
// Boolean type | ||
|
||
/** Data type for storing boolean values. */ | ||
open fun booleanType(): String = "BOOLEAN" | ||
|
||
/** Returns the SQL representation of the specified [bool] value. */ | ||
open fun booleanToStatementString(bool: Boolean): String = bool.toString().uppercase() | ||
|
||
/** Returns the boolean value of the specified SQL [value]. */ | ||
open fun booleanFromStringToBoolean(value: String): Boolean = value.toBoolean() | ||
|
||
// JSON types | ||
|
||
/** Data type for storing JSON in a non-binary text format. */ | ||
open fun jsonType(): String = "JSON" | ||
|
||
/** Data type for storing JSON in a decomposed binary format. */ | ||
open fun jsonBType(): String = | ||
throw UnsupportedByDialectException("This vendor does not support binary JSON data type", currentDialect) | ||
|
||
// Misc. | ||
|
||
/** Returns the SQL representation of the specified expression, for it to be used as a column default value. */ | ||
open fun processForDefaultValue(e: Expression<*>): String = when { | ||
e is LiteralOp<*> && e.columnType is JsonColumnMarker -> if (currentDialect is H2Dialect) { | ||
"$e".substringAfter("JSON ") | ||
} else { | ||
"'$e'" | ||
} | ||
|
||
e is LiteralOp<*> -> "$e" | ||
e is Function<*> -> "$e" | ||
currentDialect is MysqlDialect -> "$e" | ||
currentDialect is SQLServerDialect -> "$e" | ||
else -> "($e)" | ||
} | ||
|
||
open fun precessOrderByClause(queryBuilder: QueryBuilder, expression: Expression<*>, sortOrder: SortOrder) { | ||
queryBuilder.append((expression as? ExpressionAlias<*>)?.alias ?: expression, " ", sortOrder.code) | ||
} | ||
|
||
/** Returns the hex-encoded value to be inserted into the database. */ | ||
abstract fun hexToDb(hexString: String): String | ||
} |
Oops, something went wrong.