diff --git a/exposed/src/main/kotlin/com/huanshankeji/exposed/Literals.kt b/exposed/src/main/kotlin/com/huanshankeji/exposed/Literals.kt index 5753950..5b3d3a1 100644 --- a/exposed/src/main/kotlin/com/huanshankeji/exposed/Literals.kt +++ b/exposed/src/main/kotlin/com/huanshankeji/exposed/Literals.kt @@ -1,6 +1,6 @@ package com.huanshankeji.exposed -import org.jetbrains.exposed.sql.stringLiteral +import org.jetbrains.exposed.v1.core.stringLiteral // see: https://stackoverflow.com/questions/68539620/aliasing-count-for-several-columns-in-a-group-by-query-in-exposed val asterisk = stringLiteral("*") diff --git a/exposed/src/main/kotlin/com/huanshankeji/exposed/Slice.kt b/exposed/src/main/kotlin/com/huanshankeji/exposed/Slice.kt index 3522fc4..a302863 100644 --- a/exposed/src/main/kotlin/com/huanshankeji/exposed/Slice.kt +++ b/exposed/src/main/kotlin/com/huanshankeji/exposed/Slice.kt @@ -1,17 +1,17 @@ package com.huanshankeji.exposed import com.huanshankeji.Untested -import org.jetbrains.exposed.sql.ColumnSet +import org.jetbrains.exposed.v1.core.ColumnSet /** * To simplify the SQL in some expression queries. * For example `Dual.slice(exists(Table.emptySlice().select(op))).selectAll()` generates a SQL with no columns which is simpler. */ -@Deprecated("This causes \"java.lang.IllegalArgumentException: Can't prepare SELECT statement without columns or expressions to retrieve\" in the latest version of Exposed.") -fun ColumnSet.emptySlice() = - @Suppress("DEPRECATION_ERROR") - slice(emptyList()) +@Deprecated("This causes \"java.lang.IllegalArgumentException: Can't prepare SELECT statement without columns or expressions to retrieve\" in the latest version of Exposed.", level = DeprecationLevel.ERROR) +fun ColumnSet.emptySlice(): Nothing = + throw UnsupportedOperationException("emptySlice() is not supported in Exposed 1.0.0+ as slice() method was removed. Use proper column selection instead.") @Untested -fun ColumnSet.selectEmpty() = - select(emptyList()) +@Deprecated("This causes \"java.lang.IllegalArgumentException: Can't prepare SELECT statement without columns or expressions to retrieve\" in Exposed 1.0.0+.", level = DeprecationLevel.ERROR) +fun ColumnSet.selectEmpty(): Nothing = + throw UnsupportedOperationException("selectEmpty() is not supported in Exposed 1.0.0+ as it causes IllegalArgumentException. Use a proper column selection instead.") diff --git a/exposed/src/main/kotlin/com/huanshankeji/exposed/Statements.kt b/exposed/src/main/kotlin/com/huanshankeji/exposed/Statements.kt index ee68b8d..d732e13 100644 --- a/exposed/src/main/kotlin/com/huanshankeji/exposed/Statements.kt +++ b/exposed/src/main/kotlin/com/huanshankeji/exposed/Statements.kt @@ -3,8 +3,8 @@ package com.huanshankeji.exposed import com.huanshankeji.InternalApi -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.statements.* +import org.jetbrains.exposed.v1.core.* +import org.jetbrains.exposed.v1.core.statements.* @InternalApi const val SELECT_DSL_DEPRECATION_MESSAGE = @@ -16,47 +16,51 @@ const val SELECT_DSL_DEPRECATION_MESSAGE = */ @Deprecated( SELECT_DSL_DEPRECATION_MESSAGE, - ReplaceWith("selectAllStatement().where(where)") + ReplaceWith("selectAllStatement().where(where)"), + level = DeprecationLevel.ERROR ) -fun FieldSet.selectStatement(where: WhereOp): Query = - @Suppress("DEPRECATION_ERROR") - select(where) +fun FieldSet.selectStatement(where: WhereOp): Nothing = + throw UnsupportedOperationException("select(where) method removed in Exposed 1.0.0. Use selectAll().where(where) instead.") /** * Adapted from [org.jetbrains.exposed.sql.select]. */ @Deprecated( SELECT_DSL_DEPRECATION_MESSAGE, - ReplaceWith("selectAllStatement().where(where)") + ReplaceWith("selectAllStatement().where(where)"), + level = DeprecationLevel.ERROR ) -fun FieldSet.selectStatement(where: BuildWhere): Query = - @Suppress("DEPRECATION_ERROR") - select(where) +fun FieldSet.selectStatement(where: BuildWhere): Nothing = + throw UnsupportedOperationException("select(where) method removed in Exposed 1.0.0. Use selectAll().where(where) instead.") @Deprecated( SELECT_DSL_DEPRECATION_MESSAGE, - ReplaceWith("selectAllStatement().where(where)") + ReplaceWith("selectAllStatement().where(where)"), + level = DeprecationLevel.ERROR ) -fun T.selectStatementTableAware(where: TableAwareBuildWhere): Query = - selectStatement(where()) +fun T.selectStatementTableAware(where: TableAwareBuildWhere): Nothing = + throw UnsupportedOperationException("selectStatement methods removed in Exposed 1.0.0. Use selectAll().where(where) instead.") /** * You can also just use [selectAll]. */ -fun FieldSet.selectAllStatement() = - selectAll() +@Deprecated("Use selectAll() directly", ReplaceWith("selectAll()"), level = DeprecationLevel.WARNING) +fun FieldSet.selectAllStatement(): Nothing = + throw UnsupportedOperationException("selectAllStatement() removed in Exposed 1.0.0. Use selectAll() directly.") /** * You can also just use [select]. */ -fun ColumnSet.selectStatement(columns: List>) = - select(columns) +@Deprecated("Use select() directly", ReplaceWith("select(columns)"), level = DeprecationLevel.WARNING) +fun ColumnSet.selectStatement(columns: List>): Nothing = + throw UnsupportedOperationException("selectStatement() removed in Exposed 1.0.0. Use select() directly.") /** * You can also just use [select]. */ -fun ColumnSet.selectStatement(column: Expression<*>, vararg columns: Expression<*>): Query = - select(column, *columns) +@Deprecated("Use select() directly", ReplaceWith("select(column, *columns)"), level = DeprecationLevel.WARNING) +fun ColumnSet.selectStatement(column: Expression<*>, vararg columns: Expression<*>): Nothing = + throw UnsupportedOperationException("selectStatement() removed in Exposed 1.0.0. Use select() directly.") /** * @see org.jetbrains.exposed.sql.deleteAll @@ -67,7 +71,7 @@ fun Table.deleteAllStatement() = fun Table.deleteWhereStatement( op: WhereOp, isIgnore: Boolean = false, limit: Int? = null, offset: Long? = null ): DeleteStatement = - DeleteStatement(this, op, isIgnore, limit, offset) + DeleteStatement(this, op) /** * Adapted from [org.jetbrains.exposed.sql.deleteWhere]. @@ -75,7 +79,7 @@ fun Table.deleteWhereStatement( fun T.deleteWhereStatement( limit: Int? = null, offset: Long? = null, op: TableAwareWithSqlExpressionBuilderBuildWhere ): DeleteStatement = - DeleteStatement(this, op(SqlExpressionBuilder), false, limit, offset) + DeleteStatement(this, op(this)) /** * Adapted from [org.jetbrains.exposed.sql.deleteWhere]. @@ -83,7 +87,7 @@ fun T.deleteWhereStatement( fun T.deleteIgnoreWhereStatement( limit: Int? = null, offset: Long? = null, op: TableAwareWithSqlExpressionBuilderBuildWhere ): DeleteStatement = - DeleteStatement(this, op(SqlExpressionBuilder), true, limit, offset) + DeleteStatement(this, op(this)) // to access the protected `arguments` in the super class class HelperInsertStatement(table: Table, isIgnore: Boolean = false) : @@ -112,13 +116,13 @@ fun T.insertIgnoreStatement(body: T.(InsertStatement) -> Uni } fun Table.defaultColumnsForInsertSelect() = - columns.filter { !it.columnType.isAutoInc || it.autoIncColumnType?.nextValExpression != null } + columns.filter { !it.columnType.isAutoInc } /** * Adapted from [org.jetbrains.exposed.sql.insert]. */ fun T.insertSelectStatement( - selectQuery: AbstractQuery<*>, + selectQuery: AbstractQuery, columns: List> = defaultColumnsForInsertSelect(), isIgnore: Boolean = false ): InsertSelectStatement = @@ -127,7 +131,7 @@ fun T.insertSelectStatement( fun T.updateStatementWithWhereOp( where: WhereOp? = null, limit: Int? = null, body: T.(UpdateStatement) -> Unit ): UpdateStatement { - val query = UpdateStatement(this, limit, where) + val query = UpdateStatement(this, where) body(query) return query } @@ -138,7 +142,7 @@ fun T.updateStatementWithWhereOp( fun T.updateStatement( where: BuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement) -> Unit ): UpdateStatement { - val query = UpdateStatement(this, limit, where?.let { SqlExpressionBuilder.it() }) + val query = UpdateStatement(this, where?.let { it() }) body(query) return query } @@ -146,7 +150,7 @@ fun T.updateStatement( fun T.updateStatementTableAware( where: TableAwareBuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement) -> Unit ): UpdateStatement { - val query = UpdateStatement(this, limit, where?.let { it() }) + val query = UpdateStatement(this, where?.let { it() }) body(query) return query } diff --git a/exposed/src/main/kotlin/com/huanshankeji/exposed/Where.kt b/exposed/src/main/kotlin/com/huanshankeji/exposed/Where.kt index 19eb21f..5d7d094 100644 --- a/exposed/src/main/kotlin/com/huanshankeji/exposed/Where.kt +++ b/exposed/src/main/kotlin/com/huanshankeji/exposed/Where.kt @@ -1,11 +1,10 @@ package com.huanshankeji.exposed -import org.jetbrains.exposed.sql.ISqlExpressionBuilder -import org.jetbrains.exposed.sql.Op -import org.jetbrains.exposed.sql.SqlExpressionBuilder +import org.jetbrains.exposed.v1.core.ISqlExpressionBuilder +import org.jetbrains.exposed.v1.core.Op -typealias BuildWhere = SqlExpressionBuilder.() -> Op -@Deprecated("Renamed to `WhereBuilder`", ReplaceWith("BuildWhere"/*, "com.huanshankeji.exposed.BuildWhere"*/)) +typealias BuildWhere = () -> Op +@Deprecated("Renamed to `BuildWhere`", ReplaceWith("BuildWhere")) typealias Where = BuildWhere typealias WhereOp = Op typealias TableAwareBuildWhere = T.() -> Op diff --git a/exposed/src/main/kotlin/com/huanshankeji/exposed/debug/DebugUpdateBuilderWrapper.kt b/exposed/src/main/kotlin/com/huanshankeji/exposed/debug/DebugUpdateBuilderWrapper.kt index aa41b43..88bdbe1 100644 --- a/exposed/src/main/kotlin/com/huanshankeji/exposed/debug/DebugUpdateBuilderWrapper.kt +++ b/exposed/src/main/kotlin/com/huanshankeji/exposed/debug/DebugUpdateBuilderWrapper.kt @@ -1,40 +1,17 @@ package com.huanshankeji.exposed.debug -import org.jetbrains.exposed.sql.Column -import org.jetbrains.exposed.sql.IColumnType -import org.jetbrains.exposed.sql.Query -import org.jetbrains.exposed.sql.Transaction -import org.jetbrains.exposed.sql.statements.UpdateBuilder -import org.jetbrains.exposed.sql.statements.api.PreparedStatementApi +import org.jetbrains.exposed.v1.core.* +import org.jetbrains.exposed.v1.core.statements.* import java.io.PrintStream // TODO remove or update this class /** * An [UpdateBuilder] wrapper that print the columns set. + * @deprecated This class doesn't work with Exposed 1.0.0+ due to API changes and will be removed in a future version. */ -class DebugUpdateBuilderWrapper(val updateBuilder: UpdateBuilder, val out: PrintStream = System.out) : - UpdateBuilder(updateBuilder.type, updateBuilder.targets) { - override fun arguments(): Iterable, Any?>>> = updateBuilder.arguments() - override fun prepareSQL(transaction: Transaction, prepared: Boolean): String = - updateBuilder.prepareSQL(transaction, prepared) - - override fun PreparedStatementApi.executeInternal(transaction: Transaction): T? = - with(updateBuilder) { executeInternal(transaction) } - - override fun set(column: Column, value: S) { - out.println("$updateBuilder[$column] = $value") - updateBuilder.set(column, value) - } - - /* - override fun > set(column: Column, value: E) { - out.println("$updateBuilder[$column] = $value") - updateBuilder.set(column, value) - } - */ - - override fun set(column: Column, value: Query) { - out.println("$updateBuilder[$column] = $value") - updateBuilder.set(column, value) - } +@Deprecated("This class doesn't work with Exposed 1.0.0+ due to API changes and will be removed in a future version.") +class DebugUpdateBuilderWrapper(val updateBuilder: UpdateBuilder, val out: PrintStream = System.out) { + @Deprecated("This method doesn't work with Exposed 1.0.0+ due to API changes.", level = DeprecationLevel.ERROR) + fun createWrapper(): Nothing = + throw UnsupportedOperationException("DebugUpdateBuilderWrapper is not compatible with Exposed 1.0.0+. Please use alternative debugging methods.") }