Skip to content

Commit bbc90c1

Browse files
author
Roman Janusz
committed
scaladocs and cosmetics
1 parent 239d37f commit bbc90c1

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

commons-mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedClientSession.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import org.bson.{BsonDocument, BsonTimestamp}
1010

1111
import java.io.Closeable
1212

13+
/**
14+
* Better typed wrapper over [[ClientSession]].
15+
*/
1316
class TypedClientSession(val nativeSession: ClientSession)
1417
extends Closeable with TypedMongoUtils {
1518

@@ -30,6 +33,11 @@ class TypedClientSession(val nativeSession: ClientSession)
3033
def abortTransaction: Task[Unit] =
3134
empty(nativeSession.abortTransaction())
3235

36+
/**
37+
* Executes a MongoDB transaction - whose contents are expressed as Monix [[Task]].
38+
* If the task succeeds, the transaction is committed. If the task fails, the transaction is aborted and the
39+
* error is propagated. The transaction is also aborted upon cancellation.
40+
*/
3341
def inTransaction[T](
3442
transactionOptions: TransactionOptions = TransactionOptions.builder().build()
3543
)(

commons-mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoClient.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,29 @@ class TypedMongoClient(
7070
): Task[TypedClientSession] =
7171
single(nativeClient.startSession(options)).map(new TypedClientSession(_))
7272

73+
/**
74+
* Executes some code in context of a MongoDB client session. The session is closed afterwards.
75+
*
76+
* Note: in order for actual MongoDB operations to be associated with the session, you need to use
77+
* `withSession` on [[TypedMongoClient]], [[TypedMongoDatabase]] or [[TypedMongoCollection]] and use the
78+
* returned copy of these objects.
79+
*/
7380
def inSession[T](
7481
options: ClientSessionOptions = ClientSessionOptions.builder().build()
7582
)(
7683
task: TypedClientSession => Task[T]
7784
): Task[T] =
7885
startSession(options).bracket(task)(s => Task(s.close()))
7986

87+
/**
88+
* Executes some code in context of a MongoDB client session, within a transaction.
89+
* After the [[Task]] finishes, fails or is cancelled, the transaction is either committed or aborted depending
90+
* on the outcome and the session is closed.
91+
*
92+
* Note: in order for actual MongoDB operations to be associated with the session and the transaction,
93+
* you need to use `withSession` on [[TypedMongoClient]], [[TypedMongoDatabase]] or [[TypedMongoCollection]]
94+
* and use the returned copy of these objects.
95+
*/
8096
def inTransaction[T](
8197
sessionOptions: ClientSessionOptions = ClientSessionOptions.builder().build(),
8298
transactionOptions: TransactionOptions = TransactionOptions.builder().build(),

commons-mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class TypedMongoCollection[E <: BaseMongoEntity] private(
1919
val nativeCollection: MongoCollection[E],
2020
docCollection: MongoCollection[BsonDocument],
2121
val clientSession: Opt[TypedClientSession],
22-
)(
23-
implicit meta: MongoEntityMeta[E]
22+
)(implicit
23+
meta: MongoEntityMeta[E]
2424
) extends DataTypeDsl[E] with TypedMongoUtils {
2525

2626
def this(

commons-mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoDatabase.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import monix.eval.Task
1010
import monix.reactive.Observable
1111
import org.bson.Document
1212

13+
/**
14+
* Better typed wrapper over [[MongoDatabase]].
15+
*/
1316
class TypedMongoDatabase(
1417
val nativeDatabase: MongoDatabase,
1518
val clientSession: OptArg[TypedClientSession] = OptArg.Empty,

commons-mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoUtils.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,12 @@ trait TypedMongoUtils {
2020
protected final def multi[T](publisher: Publisher[T]): Observable[T] =
2121
Observable.fromReactivePublisher(publisher)
2222

23+
/**
24+
* Transforms an expression `method(nullableArg, moreArgs)` into
25+
* `if(nullableArg ne null) method(nullableArg, moreArgs) else method(moreArgs)`.
26+
*
27+
* Reduces boilerplate associated with calling overloaded methods from Mongo ReactiveStreams driver that
28+
* may or may not take `ClientSession` as its first argument (non-nullable).
29+
*/
2330
protected def optionalizeFirstArg[T](expr: T): T = macro MiscMacros.optionalizeFirstArg
2431
}

0 commit comments

Comments
 (0)