derive session from space directly

This commit is contained in:
Jonathan Shook 2024-10-30 13:09:15 -05:00
parent 919a741fa8
commit a13b433b23
10 changed files with 15 additions and 38 deletions

View File

@ -40,13 +40,12 @@ public class CqlD4BatchStmtDispenser extends Cqld4CqlBaseOpDispenser<Cqld4CqlBat
public CqlD4BatchStmtDispenser( public CqlD4BatchStmtDispenser(
Cqld4DriverAdapter adapter, Cqld4DriverAdapter adapter,
LongFunction<CqlSession> sessionFunc,
ParsedOp op, ParsedOp op,
int repeat, int repeat,
ParsedOp subop, ParsedOp subop,
OpDispenser<? extends Cqld4CqlOp> subopDispenser OpDispenser<? extends Cqld4CqlOp> subopDispenser
) { ) {
super(adapter, sessionFunc, op); super(adapter, op);
this.repeat = repeat; this.repeat = repeat;
this.subop = subop; this.subop = subop;
this.opfunc = createStmtFunc(op, subopDispenser); this.opfunc = createStmtFunc(op, subopDispenser);
@ -90,7 +89,7 @@ public class CqlD4BatchStmtDispenser extends Cqld4CqlBaseOpDispenser<Cqld4CqlBat
public Cqld4CqlBatchStatement getOp(long value) { public Cqld4CqlBatchStatement getOp(long value) {
Statement bstmt = opfunc.apply(value); Statement bstmt = opfunc.apply(value);
return new Cqld4CqlBatchStatement( return new Cqld4CqlBatchStatement(
getSessionFunc().apply(value), sessionF.apply(value),
(BatchStatement) bstmt, (BatchStatement) bstmt,
getMaxPages(), getMaxPages(),
getMaxLwtRetries(), getMaxLwtRetries(),

View File

@ -55,7 +55,6 @@ public abstract class Cqld4BaseOpDispenser<T extends Cqld4BaseOp> extends BaseOp
protected final LongFunction<CqlSession> sessionF; protected final LongFunction<CqlSession> sessionF;
public Cqld4BaseOpDispenser(Cqld4DriverAdapter adapter, public Cqld4BaseOpDispenser(Cqld4DriverAdapter adapter,
LongFunction<CqlSession> sessionFunc,
ParsedOp op) { ParsedOp op) {
super((DriverAdapter<? extends T, ? extends Cqld4Space>) adapter, op); super((DriverAdapter<? extends T, ? extends Cqld4Space>) adapter, op);
this.sessionF = l -> adapter.getSpaceCache().get(l).getSession(); this.sessionF = l -> adapter.getSpaceCache().get(l).getSession();
@ -94,11 +93,6 @@ public abstract class Cqld4BaseOpDispenser<T extends Cqld4BaseOp> extends BaseOp
return maxLwtRetries; return maxLwtRetries;
} }
public LongFunction<CqlSession> getSessionFunc() {
return sessionFunc;
}
/** /**
* All implementations of a CQL Statement Dispenser should be using the method * All implementations of a CQL Statement Dispenser should be using the method
* provided by this function. This ensures that {@link Statement}-level attributes * provided by this function. This ensures that {@link Statement}-level attributes

View File

@ -38,22 +38,18 @@ import java.util.function.Supplier;
public class Cqld4FluentGraphOpDispenser extends Cqld4BaseOpDispenser<Cqld4BaseOp> { public class Cqld4FluentGraphOpDispenser extends Cqld4BaseOpDispenser<Cqld4BaseOp> {
private final LongFunction<? extends String> graphnameFunc; private final LongFunction<? extends String> graphnameFunc;
private final LongFunction<CqlSession> sessionFunc;
private final Bindings virtdataBindings; private final Bindings virtdataBindings;
private final ThreadLocal<Script> tlScript; private final ThreadLocal<Script> tlScript;
public Cqld4FluentGraphOpDispenser( public Cqld4FluentGraphOpDispenser(
Cqld4DriverAdapter adapter, Cqld4DriverAdapter adapter,
LongFunction<CqlSession> sessionFunc,
ParsedOp op, ParsedOp op,
LongFunction<? extends String> graphnameFunc, LongFunction<? extends String> graphnameFunc,
LongFunction<CqlSession> sessionFunc1,
Bindings virtdataBindings, Bindings virtdataBindings,
Supplier<Script> scriptSupplier Supplier<Script> scriptSupplier
) { ) {
super(adapter, op); super(adapter, op);
this.graphnameFunc = graphnameFunc; this.graphnameFunc = graphnameFunc;
this.sessionFunc = sessionFunc1;
this.virtdataBindings = virtdataBindings; this.virtdataBindings = virtdataBindings;
this.tlScript = ThreadLocal.withInitial(scriptSupplier); this.tlScript = ThreadLocal.withInitial(scriptSupplier);
} }
@ -66,7 +62,7 @@ public class Cqld4FluentGraphOpDispenser extends Cqld4BaseOpDispenser<Cqld4BaseO
allMap.forEach((k,v) -> script.getBinding().setVariable(k,v)); allMap.forEach((k,v) -> script.getBinding().setVariable(k,v));
GraphTraversal<Vertex,Vertex> v = (GraphTraversal<Vertex, Vertex>) script.run(); GraphTraversal<Vertex,Vertex> v = (GraphTraversal<Vertex, Vertex>) script.run();
FluentGraphStatement fgs = new FluentGraphStatementBuilder(v).setGraphName(graphname).build(); FluentGraphStatement fgs = new FluentGraphStatementBuilder(v).setGraphName(graphname).build();
return new Cqld4FluentGraphOp(sessionFunc.apply(value),fgs); return new Cqld4FluentGraphOp(sessionF.apply(value),fgs);
} }

View File

@ -48,16 +48,11 @@ public class Cqld4PreparedStmtDispenser extends Cqld4BaseOpDispenser {
public Cqld4PreparedStmtDispenser( public Cqld4PreparedStmtDispenser(
Cqld4DriverAdapter adapter, Cqld4DriverAdapter adapter,
LongFunction<CqlSession> sessionFunc, ParsedOp op,
ParsedOp op, ParsedTemplateString stmtTpl,
ParsedTemplateString stmtTpl, RSProcessors processors
RSProcessors processors
) { ) {
super(adapter, sessionFunc, op); super(adapter, op);
if (op.isDynamic("space")) {
throw new RuntimeException("Prepared statements and dynamic space values are not yet supported" +
" but are being implemented");
}
this.processors = processors; this.processors = processors;
this.stmtTpl = stmtTpl; this.stmtTpl = stmtTpl;
this.fieldsF = getFieldsFunction(op); this.fieldsF = getFieldsFunction(op);
@ -71,10 +66,6 @@ public class Cqld4PreparedStmtDispenser extends Cqld4BaseOpDispenser {
return varbinder; return varbinder;
} }
@Override
public LongFunction<CqlSession> getSessionFunc() {
return super.getSessionFunc();
}
protected LongFunction<Statement> createStmtFunc(LongFunction<Object[]> fieldsF, ParsedOp op) { protected LongFunction<Statement> createStmtFunc(LongFunction<Object[]> fieldsF, ParsedOp op) {

View File

@ -35,7 +35,6 @@ public class Cqld4RawStmtDispenser extends Cqld4BaseOpDispenser<Cqld4CqlOp> {
private final LongFunction<String> targetFunction; private final LongFunction<String> targetFunction;
public Cqld4RawStmtDispenser(Cqld4DriverAdapter adapter, public Cqld4RawStmtDispenser(Cqld4DriverAdapter adapter,
LongFunction<CqlSession> sessionFunc,
LongFunction<String> targetFunction, ParsedOp cmd) { LongFunction<String> targetFunction, ParsedOp cmd) {
super(adapter, cmd); super(adapter, cmd);
this.targetFunction=targetFunction; this.targetFunction=targetFunction;
@ -50,7 +49,7 @@ public class Cqld4RawStmtDispenser extends Cqld4BaseOpDispenser<Cqld4CqlOp> {
@Override @Override
public Cqld4CqlSimpleStatement getOp(long value) { public Cqld4CqlSimpleStatement getOp(long value) {
return new Cqld4CqlSimpleStatement( return new Cqld4CqlSimpleStatement(
getSessionFunc().apply(value), sessionF.apply(value),
(SimpleStatement) stmtFunc.apply(value), (SimpleStatement) stmtFunc.apply(value),
getMaxPages(), getMaxPages(),
isRetryReplace(), isRetryReplace(),

View File

@ -33,8 +33,8 @@ public class Cqld4SimpleCqlStmtDispenser<T extends Cqld4CqlOp> extends Cqld4Base
private final LongFunction<Statement> stmtFunc; private final LongFunction<Statement> stmtFunc;
private final LongFunction<String> targetFunction; private final LongFunction<String> targetFunction;
public Cqld4SimpleCqlStmtDispenser(Cqld4DriverAdapter adapter, LongFunction<CqlSession> sessionFunc, LongFunction<String> targetFunction, ParsedOp cmd) { public Cqld4SimpleCqlStmtDispenser(Cqld4DriverAdapter adapter, LongFunction<String> targetFunction, ParsedOp cmd) {
super(adapter, sessionFunc,cmd); super(adapter, cmd);
this.targetFunction=targetFunction; this.targetFunction=targetFunction;
this.stmtFunc =createStmtFunc(cmd); this.stmtFunc =createStmtFunc(cmd);
} }
@ -46,7 +46,7 @@ public class Cqld4SimpleCqlStmtDispenser<T extends Cqld4CqlOp> extends Cqld4Base
@Override @Override
public Cqld4CqlSimpleStatement getOp(long value) { public Cqld4CqlSimpleStatement getOp(long value) {
return new Cqld4CqlSimpleStatement( return new Cqld4CqlSimpleStatement(
sessionFunc.apply(value), this.sessionF.apply(value),
(SimpleStatement) stmtFunc.apply(value), (SimpleStatement) stmtFunc.apply(value),
getMaxPages(), getMaxPages(),
isRetryReplace(), isRetryReplace(),

View File

@ -29,8 +29,8 @@ public class Cqld4SsTableDispenser extends Cqld4BaseOpDispenser {
// private final LongFunction<Statement> stmtFunc; // private final LongFunction<Statement> stmtFunc;
// private final LongFunction<String> targetFunction; // private final LongFunction<String> targetFunction;
public Cqld4SsTableDispenser(Cqld4DriverAdapter adapter, LongFunction<CqlSession> sessionFunc, LongFunction<String> targetFunction, ParsedOp cmd) { public Cqld4SsTableDispenser(Cqld4DriverAdapter adapter, LongFunction<String> targetFunction, ParsedOp cmd) {
super(adapter,sessionFunc,cmd); super(adapter,cmd);
// this.targetFunction=targetFunction; // this.targetFunction=targetFunction;
// this.tableFunc =createTableFunc(cmd); // this.tableFunc =createTableFunc(cmd);
} }

View File

@ -38,7 +38,7 @@ public class CqlD4BatchStmtMapper extends Cqld4BaseOpMapper<Cqld4BaseOp> {
} }
@Override @Override
public OpDispenser<Cqld4BaseOp> apply(ParsedOp op, LongFunction<Cqld4Space> spaceInitF) { public OpDispenser<Cqld4CqlBatchStatement> apply(ParsedOp op, LongFunction<Cqld4Space> spaceInitF) {
ParsedOp subop = op.getAsSubOp("op_template", ParsedOp.SubOpNaming.ParentAndSubKey); ParsedOp subop = op.getAsSubOp("op_template", ParsedOp.SubOpNaming.ParentAndSubKey);
int repeat = op.getStaticValue("repeat"); int repeat = op.getStaticValue("repeat");
OpDispenser<? extends Cqld4BaseOp> od = new Cqld4CqlOpMapper(adapter).apply(op, spaceInitF); OpDispenser<? extends Cqld4BaseOp> od = new Cqld4CqlOpMapper(adapter).apply(op, spaceInitF);

View File

@ -69,7 +69,7 @@ public class CqlD4PreparedStmtMapper extends Cqld4BaseOpMapper<Cqld4BaseOp> {
}); });
}); });
return new Cqld4PreparedStmtDispenser(adapter, sessionFunc, op, stmtTpl, processors); return new Cqld4PreparedStmtDispenser(adapter, op, stmtTpl, processors);
} }
} }

View File

@ -95,10 +95,8 @@ public class Cqld4FluentGraphOpMapper<CO extends Cqld4FluentGraphOp> extends Cql
return new Cqld4FluentGraphOpDispenser( return new Cqld4FluentGraphOpDispenser(
adapter, adapter,
sessionFunc,
op, op,
graphnameFunc, graphnameFunc,
sessionFunc,
virtdataBindings, virtdataBindings,
supplier supplier
); );