com.mongodb.ClientSessionOptions Java Examples
The following examples show how to use
com.mongodb.ClientSessionOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoClientImpl.java From mongo-java-driver-reactivestreams with Apache License 2.0 | 6 votes |
@Override public Publisher<ClientSession> startSession(final ClientSessionOptions options) { return new ObservableToPublisher<ClientSession>(com.mongodb.async.client.Observables.observe( new Block<com.mongodb.async.SingleResultCallback<ClientSession>>() { @Override public void apply(final com.mongodb.async.SingleResultCallback<ClientSession> clientSessionSingleResultCallback) { wrapped.startSession(options, new com.mongodb.async.SingleResultCallback<com.mongodb.async.client.ClientSession>() { @Override public void onResult(final com.mongodb.async.client.ClientSession result, final Throwable t) { if (t != null) { clientSessionSingleResultCallback.onResult(null, t); } else { clientSessionSingleResultCallback.onResult(new ClientSessionImpl(result, this), null); } } }); } })); }
Example #2
Source File: MongoDB.java From aion with MIT License | 5 votes |
@Override public boolean open() { if (isOpen()) { return true; } LOG.info("Initializing MongoDB at {}", mongoClientUri); // Get the client and create a session for this instance MongoClient mongoClient = MongoConnectionManager.inst().getMongoClientInstance(this.mongoClientUri); ClientSessionOptions sessionOptions = ClientSessionOptions.builder() .causallyConsistent(true) .defaultTransactionOptions( TransactionOptions.builder() .readConcern(ReadConcern.DEFAULT) .writeConcern(WriteConcern.MAJORITY) .readPreference(ReadPreference.nearest()) .build()) .build(); this.clientSession = mongoClient.startSession(sessionOptions); // Get the database and our collection. Mongo takes care of creating these if they don't // exist MongoDatabase mongoDb = mongoClient.getDatabase(MongoConstants.AION_DB_NAME); // Gets the collection where we will be saving our values. Mongo creates it if it doesn't // yet exist this.collection = mongoDb.getCollection(this.name, BsonDocument.class); LOG.info("Finished opening the Mongo connection"); return isOpen(); }
Example #3
Source File: ListDatabaseTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testSessionCreation() { // Session requires replicas ClientSession session = client.startSession(ClientSessionOptions.builder().causallyConsistent(true).build()) .await().indefinitely(); assertThat(session).isNotNull(); session.close(); }
Example #4
Source File: BeihuMongoDataAutoConfiguration.java From beihu-boot with Apache License 2.0 | 4 votes |
@Override public ClientSession getSession(ClientSessionOptions options) { return this.mongoDbFactory.getSession(options); }
Example #5
Source File: ReactiveMongoClientImpl.java From quarkus with Apache License 2.0 | 4 votes |
@Override public Uni<ClientSession> startSession(ClientSessionOptions options) { return Wrappers.toUni(client.startSession(options)); }
Example #6
Source File: MongoClientWrapper.java From ditto with Eclipse Public License 2.0 | 4 votes |
@Override public Publisher<ClientSession> startSession(final ClientSessionOptions options) { return mongoClient.startSession(options); }
Example #7
Source File: ClientSessionImpl.java From mongo-java-driver-reactivestreams with Apache License 2.0 | 4 votes |
@Override public ClientSessionOptions getOptions() { return wrapped.getOptions(); }
Example #8
Source File: MongoClientImpl.java From mongo-java-driver-reactivestreams with Apache License 2.0 | 4 votes |
@Override public Publisher<ClientSession> startSession() { return startSession(ClientSessionOptions.builder().build()); }
Example #9
Source File: MongoFactoryBean.java From mongodb-orm with Apache License 2.0 | 4 votes |
@Override public ClientSession getSession(ClientSessionOptions options) { return dataSource.getClient().startSession(); }
Example #10
Source File: BaseMorphiaSession.java From morphia with Apache License 2.0 | 4 votes |
@Override public ClientSessionOptions getOptions() { return session.getOptions(); }
Example #11
Source File: DatastoreImpl.java From morphia with Apache License 2.0 | 4 votes |
@Override public MorphiaSession startSession(final ClientSessionOptions options) { return new MorphiaSessionImpl(mongoClient.startSession(options), mongoClient, database, mapper, queryFactory); }
Example #12
Source File: DatastoreImpl.java From morphia with Apache License 2.0 | 4 votes |
@Override public <T> T withTransaction(final ClientSessionOptions options, final MorphiaTransaction<T> transaction) { return doTransaction(startSession(options), transaction); }
Example #13
Source File: ReactiveMongoClient.java From quarkus with Apache License 2.0 | 2 votes |
/** * Creates a client session. * * @param options the options for the client session * @return a {@link Uni} completed when the session is ready to be used. */ Uni<ClientSession> startSession(ClientSessionOptions options);
Example #14
Source File: MongoClient.java From mongo-java-driver-reactivestreams with Apache License 2.0 | 2 votes |
/** * Creates a client session. * * @param options the options for the client session * @return a publisher for the client session. * @mongodb.server.release 3.6 * @since 1.7 */ Publisher<ClientSession> startSession(ClientSessionOptions options);
Example #15
Source File: Datastore.java From morphia with Apache License 2.0 | 2 votes |
/** * Starts a new session on the server. * * @param options the options to apply * @return the new session reference * @morphia.experimental * @since 2.0 */ MorphiaSession startSession(ClientSessionOptions options);
Example #16
Source File: Datastore.java From morphia with Apache License 2.0 | 2 votes |
/** * @param <T> the return type * @param options the session options to apply * @param transaction the transaction wrapper * @return the return value * @morphia.experimental * @since 2.0 */ <T> T withTransaction(ClientSessionOptions options, MorphiaTransaction<T> transaction);