-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow accessing the MongoDB ClientSession programmatively
- Loading branch information
1 parent
a26e071
commit 39cc4fc
Showing
5 changed files
with
69 additions
and
2 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
27 changes: 27 additions & 0 deletions
27
...ngodb-panache-kotlin/runtime/src/main/kotlin/io/quarkus/mongodb/panache/kotlin/Panache.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,27 @@ | ||
package io.quarkus.mongodb.panache.kotlin | ||
|
||
import com.mongodb.session.ClientSession | ||
import io.quarkus.mongodb.panache.kotlin.runtime.KotlinMongoOperations | ||
|
||
object Panache { | ||
/** | ||
* Access the current MongoDB ClientSession from the transaction context. Can be used inside a | ||
* method annotated with `@Transactional` to manually access the client session. | ||
* | ||
* @return ClientSession or null if not in the context of a transaction. | ||
*/ | ||
val session: ClientSession | ||
get() = KotlinMongoOperations.INSTANCE.session | ||
|
||
/** | ||
* Access the current MongoDB ClientSession from the transaction context. | ||
* | ||
* @param entityClass the class of the MongoDB entity in case it is configured to use the | ||
* non-default client. | ||
* @return ClientSession or null if not in the context of a transaction. | ||
* @see [session] | ||
*/ | ||
fun getSession(entityClass: Class<*>?): ClientSession { | ||
return KotlinMongoOperations.INSTANCE.getSession(entityClass) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ons/panache/mongodb-panache/runtime/src/main/java/io/quarkus/mongodb/panache/Panache.java
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,30 @@ | ||
package io.quarkus.mongodb.panache; | ||
|
||
import com.mongodb.session.ClientSession; | ||
|
||
import io.quarkus.mongodb.panache.runtime.JavaMongoOperations; | ||
|
||
public class Panache { | ||
|
||
/** | ||
* Access the current MongoDB ClientSession from the transaction context. | ||
* Can be used inside a method annotated with `@Transactional` to manually access the client session. | ||
* | ||
* @return ClientSession or null if not in the context of a transaction. | ||
*/ | ||
public static ClientSession getSession() { | ||
return JavaMongoOperations.INSTANCE.getSession(); | ||
} | ||
|
||
/** | ||
* Access the current MongoDB ClientSession from the transaction context. | ||
* | ||
* @see #getSession() | ||
* | ||
* @param entityClass the class of the MongoDB entity in case it is configured to use the non-default client. | ||
* @return ClientSession or null if not in the context of a transaction. | ||
*/ | ||
public static ClientSession getSession(Class<?> entityClass) { | ||
return JavaMongoOperations.INSTANCE.getSession(entityClass); | ||
} | ||
} |
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