@@ -9,27 +9,25 @@ package com.datastax.gatling.plugin.model
9
9
import java .nio .ByteBuffer
10
10
11
11
import com .datastax .oss .driver .api .core .cql ._
12
- import com .datastax .oss .driver .api .core .`type` .DataType
13
12
import com .datastax .gatling .plugin .exceptions .DseCqlStatementException
14
13
import com .datastax .gatling .plugin .utils .CqlPreparedStatementUtil
15
14
import io .gatling .commons .validation ._
16
- import io .gatling .core .session .{ Session , _ }
15
+ import io .gatling .core .session ._
17
16
18
17
import scala .collection .JavaConverters ._
19
- import scala .collection .mutable .ArrayBuffer
20
18
import scala .util .{Try , Failure => TryFailure , Success => TrySuccess }
21
19
22
20
23
- trait DseCqlStatement extends DseStatement [Statement ] {
24
- def buildFromSession (session : Session ): Validation [Statement ]
21
+ trait DseCqlStatement [ T ] extends DseStatement [T ] {
22
+ def buildFromSession (session : Session ): Validation [T ]
25
23
}
26
24
27
25
/**
28
26
* Simple CQL Statement from the java driver
29
27
*
30
28
* @param statement the statement to execute
31
29
*/
32
- case class DseCqlSimpleStatement (statement : SimpleStatement ) extends DseCqlStatement {
30
+ case class DseCqlSimpleStatement (statement : SimpleStatement ) extends DseCqlStatement [ SimpleStatement ] {
33
31
def buildFromSession (gatlingSession : Session ): Validation [SimpleStatement ] = {
34
32
statement.success
35
33
}
@@ -41,7 +39,7 @@ case class DseCqlSimpleStatement(statement: SimpleStatement) extends DseCqlState
41
39
* @param preparedStatement the prepared statement on which to bind parameters
42
40
*/
43
41
case class DseCqlBoundStatementNamed (cqlTypes : CqlPreparedStatementUtil , preparedStatement : PreparedStatement )
44
- extends DseCqlStatement {
42
+ extends DseCqlStatement [ BoundStatement ] {
45
43
46
44
def buildFromSession (gatlingSession : Session ): Validation [BoundStatement ] =
47
45
bindParams(
@@ -58,7 +56,7 @@ case class DseCqlBoundStatementNamed(cqlTypes: CqlPreparedStatementUtil, prepare
58
56
* @return
59
57
*/
60
58
protected def bindParams (gatlingSession : Session , boundStatement : BoundStatement ,
61
- queryParams : Map [String , DataType . Name ]): BoundStatement = {
59
+ queryParams : Map [String , Int ]): BoundStatement = {
62
60
queryParams.foreach {
63
61
case (gatlingSessionKey, valType) =>
64
62
cqlTypes.bindParamByName(gatlingSession, boundStatement, valType, gatlingSessionKey)
@@ -75,7 +73,7 @@ case class DseCqlBoundStatementNamed(cqlTypes: CqlPreparedStatementUtil, prepare
75
73
*/
76
74
case class DseCqlBoundStatementWithPassedParams (cqlTypes : CqlPreparedStatementUtil ,
77
75
preparedStatement : PreparedStatement ,
78
- params : Expression [AnyRef ]* ) extends DseCqlStatement {
76
+ params : Expression [AnyRef ]* ) extends DseCqlStatement [ BoundStatement ] {
79
77
80
78
def buildFromSession (gatlingSession : Session ): Validation [BoundStatement ] = {
81
79
val parsedParams : Seq [Validation [AnyRef ]] = params.map(param => param(gatlingSession))
@@ -99,7 +97,7 @@ case class DseCqlBoundStatementWithPassedParams(cqlTypes: CqlPreparedStatementUt
99
97
*/
100
98
case class DseCqlBoundStatementWithParamList (cqlTypes : CqlPreparedStatementUtil ,
101
99
preparedStatement : PreparedStatement ,
102
- sessionKeys : Seq [String ]) extends DseCqlStatement {
100
+ sessionKeys : Seq [String ]) extends DseCqlStatement [ BoundStatement ] {
103
101
104
102
/**
105
103
* Apply the Gatling session params to the Prepared statement
@@ -142,16 +140,16 @@ case class DseCqlBoundStatementWithParamList(cqlTypes: CqlPreparedStatementUtil,
142
140
* @param statements CQL Prepared Statements
143
141
*/
144
142
case class DseCqlBoundBatchStatement (cqlTypes : CqlPreparedStatementUtil , statements : Seq [PreparedStatement ])
145
- extends DseCqlStatement {
143
+ extends DseCqlStatement [ BatchStatement ] {
146
144
147
145
def buildFromSession (gatlingSession : Session ): Validation [BatchStatement ] = {
148
146
149
- val batch = new BatchStatement ( )
147
+ val batch = BatchStatement .builder( DefaultBatchType . LOGGED )
150
148
151
149
statements.foreach(s =>
152
- batch.add (bindParams(gatlingSession, s, cqlTypes.getParamsMap(s))))
150
+ batch.addStatement (bindParams(gatlingSession, s, cqlTypes.getParamsMap(s))))
153
151
154
- batch.success
152
+ batch.build(). success
155
153
}
156
154
157
155
@@ -164,7 +162,7 @@ case class DseCqlBoundBatchStatement(cqlTypes: CqlPreparedStatementUtil, stateme
164
162
* @return
165
163
*/
166
164
protected def bindParams (gatlingSession : Session , statement : PreparedStatement ,
167
- queryParams : Map [String , DataType . Name ]): BoundStatement = {
165
+ queryParams : Map [String , Int ]): BoundStatement = {
168
166
169
167
val boundStatement = statement.bind()
170
168
@@ -185,17 +183,18 @@ case class DseCqlBoundBatchStatement(cqlTypes: CqlPreparedStatementUtil, stateme
185
183
* @param statement SimpleStaten
186
184
* @param payloadRef session variable for custom payload
187
185
*/
188
- case class DseCqlCustomPayloadStatement (statement : SimpleStatement , payloadRef : String ) extends DseCqlStatement {
186
+ case class DseCqlCustomPayloadStatement (statement : SimpleStatement , payloadRef : String )
187
+ extends DseCqlStatement [SimpleStatement ] {
189
188
190
- def buildFromSession (gatlingSession : Session ): Validation [Statement ] = {
189
+ def buildFromSession (gatlingSession : Session ): Validation [SimpleStatement ] = {
191
190
192
191
if (! gatlingSession.contains(payloadRef)) {
193
192
throw new DseCqlStatementException (s " Passed sessionKey: { $payloadRef} does not exist in Session. " )
194
193
}
195
194
196
195
Try {
197
196
val payload = gatlingSession(payloadRef).as[Map [String , ByteBuffer ]].asJava
198
- statement.setOutgoingPayload (payload)
197
+ statement.setCustomPayload (payload)
199
198
} match {
200
199
case TrySuccess (stmt) => stmt.success
201
200
case TryFailure (error) => error.getMessage.failure
@@ -210,7 +209,8 @@ case class DseCqlCustomPayloadStatement(statement: SimpleStatement, payloadRef:
210
209
*
211
210
* @param sessionKey the session key which is associated to a PreparedStatement
212
211
*/
213
- case class DseCqlBoundStatementNamedFromSession (cqlTypes : CqlPreparedStatementUtil , sessionKey : String ) extends DseCqlStatement {
212
+ case class DseCqlBoundStatementNamedFromSession (cqlTypes : CqlPreparedStatementUtil , sessionKey : String )
213
+ extends DseCqlStatement [BoundStatement ] {
214
214
215
215
def buildFromSession (gatlingSession : Session ): Validation [BoundStatement ] = {
216
216
if (! gatlingSession.contains(sessionKey)) {
0 commit comments