Skip to content

Commit

Permalink
add afterStatementPrepared method to StatementInterceptor (JetBrains#…
Browse files Browse the repository at this point in the history
…1622)

* add after query prepared interceptor

* add apiDump results

---------

Co-authored-by: Aleksandr Shubert <alex.shubert@gmail.com>
  • Loading branch information
2 people authored and saral committed Oct 3, 2023
1 parent 9129f6d commit 6e8d23b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exposed-core/api/exposed-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ public final class org/jetbrains/exposed/sql/CompositeSqlLogger : org/jetbrains/
public fun afterExecution (Lorg/jetbrains/exposed/sql/Transaction;Ljava/util/List;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public fun afterRollback ()V
public fun afterRollback (Lorg/jetbrains/exposed/sql/Transaction;)V
public fun afterStatementPrepared (Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public fun beforeCommit (Lorg/jetbrains/exposed/sql/Transaction;)V
public fun beforeExecution (Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/StatementContext;)V
public fun beforeRollback (Lorg/jetbrains/exposed/sql/Transaction;)V
Expand Down Expand Up @@ -2494,6 +2495,7 @@ public final class org/jetbrains/exposed/sql/statements/GlobalStatementIntercept
public static fun afterExecution (Lorg/jetbrains/exposed/sql/statements/GlobalStatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;Ljava/util/List;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public static fun afterRollback (Lorg/jetbrains/exposed/sql/statements/GlobalStatementInterceptor;)V
public static fun afterRollback (Lorg/jetbrains/exposed/sql/statements/GlobalStatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;)V
public static fun afterStatementPrepared (Lorg/jetbrains/exposed/sql/statements/GlobalStatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public static fun beforeCommit (Lorg/jetbrains/exposed/sql/statements/GlobalStatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;)V
public static fun beforeExecution (Lorg/jetbrains/exposed/sql/statements/GlobalStatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/StatementContext;)V
public static fun beforeRollback (Lorg/jetbrains/exposed/sql/statements/GlobalStatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;)V
Expand Down Expand Up @@ -2586,6 +2588,7 @@ public abstract interface class org/jetbrains/exposed/sql/statements/StatementIn
public abstract fun afterExecution (Lorg/jetbrains/exposed/sql/Transaction;Ljava/util/List;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public abstract fun afterRollback ()V
public abstract fun afterRollback (Lorg/jetbrains/exposed/sql/Transaction;)V
public abstract fun afterStatementPrepared (Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public abstract fun beforeCommit (Lorg/jetbrains/exposed/sql/Transaction;)V
public abstract fun beforeExecution (Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/StatementContext;)V
public abstract fun beforeRollback (Lorg/jetbrains/exposed/sql/Transaction;)V
Expand All @@ -2598,6 +2601,7 @@ public final class org/jetbrains/exposed/sql/statements/StatementInterceptor$Def
public static fun afterExecution (Lorg/jetbrains/exposed/sql/statements/StatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;Ljava/util/List;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public static fun afterRollback (Lorg/jetbrains/exposed/sql/statements/StatementInterceptor;)V
public static fun afterRollback (Lorg/jetbrains/exposed/sql/statements/StatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;)V
public static fun afterStatementPrepared (Lorg/jetbrains/exposed/sql/statements/StatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public static fun beforeCommit (Lorg/jetbrains/exposed/sql/statements/StatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;)V
public static fun beforeExecution (Lorg/jetbrains/exposed/sql/statements/StatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/StatementContext;)V
public static fun beforeRollback (Lorg/jetbrains/exposed/sql/statements/StatementInterceptor;Lorg/jetbrains/exposed/sql/Transaction;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ abstract class Statement<out T>(val type: StatementType, val targets: List<Table
}

transaction.currentStatement = statement
transaction.interceptors.forEach { it.afterStatementPrepared(transaction, statement) }
val result = try {
statement.executeInternal(transaction)
} catch (e: SQLException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ import org.jetbrains.exposed.sql.Key
import org.jetbrains.exposed.sql.Transaction
import org.jetbrains.exposed.sql.statements.api.PreparedStatementApi

/**
* In general, statement execution flow works in a following way :
* 1) beforeExecution
* 2) PreparedStatement is created
* 3) afterStatementPrepared with prepared statement, which was created at phase 2
* 4) Execute SQL query
* 5) afterExecution
*/

interface StatementInterceptor {
fun beforeExecution(transaction: Transaction, context: StatementContext) {}
fun afterStatementPrepared(transaction : Transaction, preparedStatement: PreparedStatementApi) {}
fun afterExecution(transaction: Transaction, contexts: List<StatementContext>, executedStatement: PreparedStatementApi) {}

fun beforeCommit(transaction: Transaction) {}
Expand Down
1 change: 1 addition & 0 deletions exposed-dao/api/exposed-dao.api
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public final class org/jetbrains/exposed/dao/EntityLifecycleInterceptor : org/je
public fun afterExecution (Lorg/jetbrains/exposed/sql/Transaction;Ljava/util/List;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public fun afterRollback ()V
public fun afterRollback (Lorg/jetbrains/exposed/sql/Transaction;)V
public fun afterStatementPrepared (Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;)V
public fun beforeCommit (Lorg/jetbrains/exposed/sql/Transaction;)V
public fun beforeExecution (Lorg/jetbrains/exposed/sql/Transaction;Lorg/jetbrains/exposed/sql/statements/StatementContext;)V
public fun beforeRollback (Lorg/jetbrains/exposed/sql/Transaction;)V
Expand Down

0 comments on commit 6e8d23b

Please sign in to comment.