@Override public ClientSession getSession(ClientSessionOptions options) { return getMongoClient().startSession(options); }
/** * Creates a client session with default session options. * * @return the client session * @throws MongoClientException if the MongoDB cluster to which this client is connected does not support sessions * @mongodb.server.release 3.6 * @since 3.8 */ public ClientSession startSession() { return startSession(ClientSessionOptions.builder().build()); }
@Override public ClientSession getSession(ClientSessionOptions options) { return getMongoClient().startSession(options); }
/** * Creates a client session with default session options. * * @return the client session * @throws MongoClientException if the MongoDB cluster to which this client is connected does not support sessions * @mongodb.server.release 3.6 * @since 3.8 */ public ClientSession startSession() { return startSession(ClientSessionOptions.builder().build()); }
ClientSession createClientSession() { ClientSession s = client.startSession(options); synchronized (this) { s.advanceClusterTime(clusterTime); s.advanceOperationTime(operationTime); } return new TrackingClientSession(s); }
ClientSession createClientSession() { ClientSession s = client.startSession(options); synchronized (this) { s.advanceClusterTime(clusterTime); s.advanceOperationTime(operationTime); } return new TrackingClientSession(s); }
MongoCollection<Document> collection = db.getCollection("foo"); try (ClientSession clientSession = client.startSession()) { clientSession.startTransaction(); collection.insertOne(clientSession, new Document("i", 1));
/** * @return {@code true} if client sessions are supported. */ boolean isClientSessionSupported() { if (clientSessionSupported == null) { // must be at least 3.6 if (isVersion(3, 6)) { ClientSessionOptions options = ClientSessionOptions.builder() .causallyConsistent(true).build(); try (ClientSession ignored = client.startSession(options)) { clientSessionSupported = true; } catch (MongoClientException e) { clientSessionSupported = false; } } else { clientSessionSupported = false; } } return clientSessionSupported; }
/** * @return {@code true} if client sessions are supported. */ boolean isClientSessionSupported() { if (clientSessionSupported == null) { // must be at least 3.6 if (isVersion(3, 6)) { ClientSessionOptions options = ClientSessionOptions.builder() .causallyConsistent(true).build(); try (ClientSession ignored = client.startSession(options)) { clientSessionSupported = true; } catch (MongoClientException e) { clientSessionSupported = false; } } else { clientSessionSupported = false; } } return clientSessionSupported; }
@Override public void startTransaction() { if (currentTransaction.get() != null) { throw new IllegalArgumentException("Transaction in progress"); } ClientSessionOptions.Builder b = ClientSessionOptions.builder(); b.causallyConsistent(true); b.defaultTransactionOptions(TransactionOptions.builder().readConcern(ReadConcern.DEFAULT).readPreference(com.mongodb.ReadPreference.primary()).build()); ClientSession ses = mongo.startSession(b.build()); ses.startTransaction(); MongoTransactionContext ctx = new MongoTransactionContext(); ctx.setSession(ses); currentTransaction.set(ctx); }
clientSession = this.client.startSession(); clientSession.startTransaction(); insertEdgeWithId(this.followingMC, edgeId, user, toFollow, clientSession);
clientSession = this.client.startSession(); clientSession.startTransaction(); this.followingMC.deleteOne(clientSession, new Document(makeEdge(user, toRemove).toMap()));
assertTrue(MongoUtils.isCollectionEmpty(nodes, null)); if (status.isClientSessionSupported()) { try (ClientSession s = c.getMongoClient().startSession()) { assertTrue(MongoUtils.isCollectionEmpty(nodes, s)); try (ClientSession s = c.getMongoClient().startSession()) { assertFalse(MongoUtils.isCollectionEmpty(nodes, s)); try (ClientSession s = c.getMongoClient().startSession()) { assertTrue(MongoUtils.isCollectionEmpty(nodes, s));