1// Copyright (C) MongoDB, Inc. 2019-present. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); you may 4// not use this file except in compliance with the License. You may obtain 5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 6 7// Code generated by operationgen. DO NOT EDIT. 8 9package operation 10 11import ( 12 "context" 13 "errors" 14 15 "go.mongodb.org/mongo-driver/event" 16 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore" 17 "go.mongodb.org/mongo-driver/x/mongo/driver" 18 "go.mongodb.org/mongo-driver/x/mongo/driver/description" 19 "go.mongodb.org/mongo-driver/x/mongo/driver/session" 20) 21 22// EndSessions performs an endSessions operation. 23type EndSessions struct { 24 sessionIDs bsoncore.Document 25 session *session.Client 26 clock *session.ClusterClock 27 monitor *event.CommandMonitor 28 crypt *driver.Crypt 29 database string 30 deployment driver.Deployment 31 selector description.ServerSelector 32} 33 34// NewEndSessions constructs and returns a new EndSessions. 35func NewEndSessions(sessionIDs bsoncore.Document) *EndSessions { 36 return &EndSessions{ 37 sessionIDs: sessionIDs, 38 } 39} 40 41func (es *EndSessions) processResponse(response bsoncore.Document, srvr driver.Server, desc description.Server) error { 42 var err error 43 return err 44} 45 46// Execute runs this operations and returns an error if the operaiton did not execute successfully. 47func (es *EndSessions) Execute(ctx context.Context) error { 48 if es.deployment == nil { 49 return errors.New("the EndSessions operation must have a Deployment set before Execute can be called") 50 } 51 52 return driver.Operation{ 53 CommandFn: es.command, 54 ProcessResponseFn: es.processResponse, 55 Client: es.session, 56 Clock: es.clock, 57 CommandMonitor: es.monitor, 58 Crypt: es.crypt, 59 Database: es.database, 60 Deployment: es.deployment, 61 Selector: es.selector, 62 }.Execute(ctx, nil) 63 64} 65 66func (es *EndSessions) command(dst []byte, desc description.SelectedServer) ([]byte, error) { 67 if es.sessionIDs != nil { 68 dst = bsoncore.AppendArrayElement(dst, "endSessions", es.sessionIDs) 69 } 70 return dst, nil 71} 72 73// sessionIDs specify the sessions to be expired. 74func (es *EndSessions) SessionIDs(sessionIDs bsoncore.Document) *EndSessions { 75 if es == nil { 76 es = new(EndSessions) 77 } 78 79 es.sessionIDs = sessionIDs 80 return es 81} 82 83// Session sets the session for this operation. 84func (es *EndSessions) Session(session *session.Client) *EndSessions { 85 if es == nil { 86 es = new(EndSessions) 87 } 88 89 es.session = session 90 return es 91} 92 93// ClusterClock sets the cluster clock for this operation. 94func (es *EndSessions) ClusterClock(clock *session.ClusterClock) *EndSessions { 95 if es == nil { 96 es = new(EndSessions) 97 } 98 99 es.clock = clock 100 return es 101} 102 103// CommandMonitor sets the monitor to use for APM events. 104func (es *EndSessions) CommandMonitor(monitor *event.CommandMonitor) *EndSessions { 105 if es == nil { 106 es = new(EndSessions) 107 } 108 109 es.monitor = monitor 110 return es 111} 112 113// Crypt sets the Crypt object to use for automatic encryption and decryption. 114func (es *EndSessions) Crypt(crypt *driver.Crypt) *EndSessions { 115 if es == nil { 116 es = new(EndSessions) 117 } 118 119 es.crypt = crypt 120 return es 121} 122 123// Database sets the database to run this operation against. 124func (es *EndSessions) Database(database string) *EndSessions { 125 if es == nil { 126 es = new(EndSessions) 127 } 128 129 es.database = database 130 return es 131} 132 133// Deployment sets the deployment to use for this operation. 134func (es *EndSessions) Deployment(deployment driver.Deployment) *EndSessions { 135 if es == nil { 136 es = new(EndSessions) 137 } 138 139 es.deployment = deployment 140 return es 141} 142 143// ServerSelector sets the selector used to retrieve a server. 144func (es *EndSessions) ServerSelector(selector description.ServerSelector) *EndSessions { 145 if es == nil { 146 es = new(EndSessions) 147 } 148 149 es.selector = selector 150 return es 151} 152