use of com.datastax.dse.protocol.internal.request.RawBytesQuery in project java-driver by datastax.
the class GraphConversions method createContinuousMessageFromGraphStatement.
public static Message createContinuousMessageFromGraphStatement(GraphStatement<?> statement, GraphProtocol subProtocol, DriverExecutionProfile config, InternalDriverContext context, GraphBinaryModule graphBinaryModule) {
final List<ByteBuffer> encodedQueryParams;
if (!(statement instanceof ScriptGraphStatement) || ((ScriptGraphStatement) statement).getQueryParams().isEmpty()) {
encodedQueryParams = Collections.emptyList();
} else {
try {
Map<String, Object> queryParams = ((ScriptGraphStatement) statement).getQueryParams();
if (subProtocol.isGraphBinary()) {
Buffer graphBinaryParams = graphBinaryModule.serialize(queryParams);
encodedQueryParams = Collections.singletonList(graphBinaryParams.nioBuffer());
graphBinaryParams.release();
} else {
encodedQueryParams = Collections.singletonList(GraphSONUtils.serializeToByteBuffer(queryParams, subProtocol));
}
} catch (IOException e) {
throw new UncheckedIOException("Couldn't serialize parameters for GraphStatement: " + statement, e);
}
}
int consistencyLevel = DefaultConsistencyLevel.valueOf(config.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).getProtocolCode();
long timestamp = statement.getTimestamp();
if (timestamp == Statement.NO_DEFAULT_TIMESTAMP) {
timestamp = context.getTimestampGenerator().next();
}
int pageSize = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_PAGE_SIZE);
int maxPages = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES);
int maxPagesPerSecond = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND);
int maxEnqueuedPages = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES);
ContinuousPagingOptions options = new ContinuousPagingOptions(maxPages, maxPagesPerSecond, maxEnqueuedPages);
DseQueryOptions queryOptions = new DseQueryOptions(consistencyLevel, encodedQueryParams, // ignored by the DSE Graph server
Collections.emptyMap(), // also ignored
true, pageSize, null, // also ignored
ProtocolConstants.ConsistencyLevel.LOCAL_SERIAL, timestamp, // also ignored
null, // graph CP does not support sizeInBytes
false, options);
if (statement instanceof ScriptGraphStatement) {
return new Query(((ScriptGraphStatement) statement).getScript(), queryOptions);
} else {
return new RawBytesQuery(getQueryBytes(statement, subProtocol), queryOptions);
}
}
use of com.datastax.dse.protocol.internal.request.RawBytesQuery in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_query_message_from_batch_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_batch_statement(GraphProtocol graphProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
@SuppressWarnings("rawtypes") List<GraphTraversal> traversalsTest = ImmutableList.of(// GraphDataTypesTest
DseGraph.g.addV("person").property("p1", 2.3f).property("p2", LocalDateTime.now(ZoneOffset.UTC)), DseGraph.g.addV("software").property("p3", new BigInteger("123456789123456789123456789123456789")).property("p4", ImmutableList.of(Point.fromCoordinates(30.4, 25.63746284))));
GraphStatement<?> graphStatement = BatchGraphStatement.builder().addTraversals(traversalsTest).build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
Map<String, ByteBuffer> createdCustomPayload = GraphConversions.createCustomPayload(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
// checks
assertThat(m).isInstanceOf(RawBytesQuery.class);
testQueryRequestAndPayloadContents(((RawBytesQuery) m), createdCustomPayload, GraphConversions.bytecodeToSerialize(graphStatement), graphProtocol, module);
}
use of com.datastax.dse.protocol.internal.request.RawBytesQuery in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_query_message_from_fluent_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_fluent_statement(GraphProtocol graphProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
GraphTraversal<?, ?> traversalTest = DseGraph.g.V().has("person", "name", "marko").has("p1", 1L).has("p2", Uuids.random());
GraphStatement<?> graphStatement = FluentGraphStatement.newInstance(traversalTest);
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
Map<String, ByteBuffer> createdCustomPayload = GraphConversions.createCustomPayload(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
// checks
assertThat(m).isInstanceOf(RawBytesQuery.class);
testQueryRequestAndPayloadContents(((RawBytesQuery) m), createdCustomPayload, GraphConversions.bytecodeToSerialize(graphStatement), graphProtocol, module);
}
use of com.datastax.dse.protocol.internal.request.RawBytesQuery in project java-driver by datastax.
the class GraphConversions method createMessageFromGraphStatement.
static Message createMessageFromGraphStatement(GraphStatement<?> statement, GraphProtocol subProtocol, DriverExecutionProfile config, InternalDriverContext context, GraphBinaryModule graphBinaryModule) {
final List<ByteBuffer> encodedQueryParams;
if (!(statement instanceof ScriptGraphStatement) || ((ScriptGraphStatement) statement).getQueryParams().isEmpty()) {
encodedQueryParams = Collections.emptyList();
} else {
try {
Map<String, Object> queryParams = ((ScriptGraphStatement) statement).getQueryParams();
if (subProtocol.isGraphBinary()) {
Buffer graphBinaryParams = graphBinaryModule.serialize(queryParams);
encodedQueryParams = Collections.singletonList(graphBinaryParams.nioBuffer());
graphBinaryParams.release();
} else {
encodedQueryParams = Collections.singletonList(GraphSONUtils.serializeToByteBuffer(queryParams, subProtocol));
}
} catch (IOException e) {
throw new UncheckedIOException("Couldn't serialize parameters for GraphStatement: " + statement, e);
}
}
ConsistencyLevel consistency = statement.getConsistencyLevel();
int consistencyLevel = (consistency == null) ? context.getConsistencyLevelRegistry().nameToCode(config.getString(DefaultDriverOption.REQUEST_CONSISTENCY)) : consistency.getProtocolCode();
long timestamp = statement.getTimestamp();
if (timestamp == Statement.NO_DEFAULT_TIMESTAMP) {
timestamp = context.getTimestampGenerator().next();
}
DseQueryOptions queryOptions = new DseQueryOptions(consistencyLevel, encodedQueryParams, // ignored by the DSE Graph server
Collections.emptyMap(), // also ignored
true, // also ignored
50, // also ignored
null, // also ignored
ProtocolConstants.ConsistencyLevel.LOCAL_SERIAL, timestamp, // also ignored
null, // also ignored
false, // also ignored
null);
if (statement instanceof ScriptGraphStatement) {
return new Query(((ScriptGraphStatement) statement).getScript(), queryOptions);
} else {
return new RawBytesQuery(getQueryBytes(statement, subProtocol), queryOptions);
}
}
Aggregations