mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
commit
2a04b9057b
@ -155,6 +155,7 @@ public class CqlActivity extends SimpleActivity implements Activity, ActivityDef
|
||||
|
||||
ParsedStmt parsed = stmtDef.getParsed().orError();
|
||||
boolean prepared = Boolean.valueOf(stmtDef.getParams().getOrDefault("prepared", "true"));
|
||||
boolean parametrized = Boolean.valueOf(stmtDef.getParams().getOrDefault("parametrized", "false"));
|
||||
long ratio = Long.valueOf(stmtDef.getParams().getOrDefault("ratio", "1"));
|
||||
|
||||
Optional<ConsistencyLevel> cl = Optional.ofNullable(
|
||||
@ -218,7 +219,7 @@ public class CqlActivity extends SimpleActivity implements Activity, ActivityDef
|
||||
psummary.append(" idempotent=>").append(i);
|
||||
simpleStatement.setIdempotent(i);
|
||||
});
|
||||
template = new ReadyCQLStatementTemplate(getSession(), simpleStatement, ratio, parsed.getName());
|
||||
template = new ReadyCQLStatementTemplate(getSession(), simpleStatement, ratio, parsed.getName(), parametrized);
|
||||
}
|
||||
|
||||
Optional.ofNullable(stmtDef.getParams().getOrDefault("save", null))
|
||||
|
@ -1,19 +1,55 @@
|
||||
package io.nosqlbench.activitytype.cql.statements.binders;
|
||||
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.SimpleStatement;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import io.nosqlbench.virtdata.core.bindings.ValuesArrayBinder;
|
||||
|
||||
/**
|
||||
* This binder is not meant to be used with anything but DDL or statements
|
||||
* which should not be trying to parameterize values in general. If this changes,
|
||||
* support will be added for parameterized values here.
|
||||
* which should not be trying to parameterize values in general.
|
||||
* Parametrized values are still possible through parametrized constructor parameter.
|
||||
* This binder should be avoided in favor of binders returning PreparedStatement
|
||||
*/
|
||||
public class SimpleStatementValuesBinder
|
||||
implements ValuesArrayBinder<SimpleStatement, Statement> {
|
||||
|
||||
private final boolean parametrized;
|
||||
|
||||
public SimpleStatementValuesBinder(boolean parametrized){
|
||||
this.parametrized = parametrized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement bindValues(SimpleStatement context, Object[] values) {
|
||||
return new SimpleStatement(context.getQueryString(), values);
|
||||
String query = context.getQueryString();
|
||||
if(parametrized) {
|
||||
String[] splits = query.split("\\?");
|
||||
assert splits.length == values.length+1;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(splits[0]);
|
||||
for(int i = 1; i < splits.length; i++) {
|
||||
sb.append(values[i - 1]);
|
||||
sb.append(splits[i]);
|
||||
}
|
||||
query = sb.toString();
|
||||
System.out.println(query);
|
||||
|
||||
}
|
||||
SimpleStatement simpleStatement = new SimpleStatement(query);
|
||||
ConsistencyLevel cl = context.getConsistencyLevel();
|
||||
if(cl != null){
|
||||
simpleStatement.setConsistencyLevel(context.getConsistencyLevel());
|
||||
}
|
||||
//Does it really makes senses?
|
||||
ConsistencyLevel serial_cl = context.getSerialConsistencyLevel();
|
||||
if(serial_cl != null){
|
||||
simpleStatement.setSerialConsistencyLevel(context.getSerialConsistencyLevel());
|
||||
}
|
||||
Boolean idempotent = context.isIdempotent();
|
||||
if(idempotent != null){
|
||||
simpleStatement.setIdempotent(idempotent);
|
||||
}
|
||||
return simpleStatement;
|
||||
}
|
||||
}
|
||||
|
@ -50,13 +50,13 @@ public class ReadyCQLStatementTemplate {
|
||||
this.ratio = ratio;
|
||||
}
|
||||
|
||||
public ReadyCQLStatementTemplate(Session session, SimpleStatement simpleStatement, long ratio, String name) {
|
||||
public ReadyCQLStatementTemplate(Session session, SimpleStatement simpleStatement, long ratio, String name, boolean parametrized) {
|
||||
this.session = session;
|
||||
this.name = name;
|
||||
template = new ContextualBindingsArrayTemplate<>(
|
||||
simpleStatement,
|
||||
new BindingsTemplate(),
|
||||
new SimpleStatementValuesBinder()
|
||||
new SimpleStatementValuesBinder(parametrized)
|
||||
);
|
||||
this.ratio = ratio;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user