[tinkerpop] 01/01: TINKERPOP-2420 Added with() support for request options in C#
This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch TINKERPOP-2420 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git commit 637be9253bcf0a5eaf1dda47663eb3e770b4042f Author: Stephen Mallette AuthorDate: Fri Oct 2 16:52:39 2020 -0400 TINKERPOP-2420 Added with() support for request options in C# --- gremlin-dotnet/glv/GraphTraversalSource.template | 24 + gremlin-dotnet/glv/generate.groovy | 1 + .../Driver/Remote/DriverRemoteConnection.cs| 30 ++-- gremlin-dotnet/src/Gremlin.Net/Driver/Tokens.cs| 28 ++- .../Process/Traversal/GraphTraversalSource.cs | 26 +- .../DriverRemoteConnection/GraphTraversalTests.cs | 14 .../apache/tinkerpop/gremlin/driver/Tokens.java| 40 ++ 7 files changed, 137 insertions(+), 26 deletions(-) diff --git a/gremlin-dotnet/glv/GraphTraversalSource.template b/gremlin-dotnet/glv/GraphTraversalSource.template index f3093e5..4ccf77f 100644 --- a/gremlin-dotnet/glv/GraphTraversalSource.template +++ b/gremlin-dotnet/glv/GraphTraversalSource.template @@ -72,6 +72,30 @@ namespace Gremlin.Net.Process.Traversal Bytecode = bytecode; } +public GraphTraversalSource With(string key) +{ +return With(key, true); +} + +public GraphTraversalSource With(string key, object value) +{ +var optionsStrategyInst = Bytecode.SourceInstructions.Find( +inst => inst.OperatorName == "withStrategies" && inst.Arguments[0] is OptionsStrategy); +OptionsStrategy optionsStrategy; + +if (optionsStrategyInst == null) +{ +optionsStrategy = new OptionsStrategy(); +optionsStrategy.Configuration[key] = value; +return WithStrategies(optionsStrategy); +} + +optionsStrategy = optionsStrategyInst.Arguments[0]; +optionsStrategy.Configuration[key] = value; +return new GraphTraversalSource(new List(TraversalStrategies), +new Bytecode(Bytecode)); +} + <% sourceStepMethods.each{ method -> %> public GraphTraversalSource <%= toCSharpMethodName.call(method.methodName) %>(<%= method.parameters %>) { diff --git a/gremlin-dotnet/glv/generate.groovy b/gremlin-dotnet/glv/generate.groovy index 26daa58..a951907 100644 --- a/gremlin-dotnet/glv/generate.groovy +++ b/gremlin-dotnet/glv/generate.groovy @@ -256,6 +256,7 @@ def binding = ["pmethods": P.class.getMethods(). findAll { GraphTraversalSource.class.equals(it.returnType) }. findAll { !it.name.equals("clone") && + !it.name.equals(TraversalSource.Symbols.with) && !it.name.equals(TraversalSource.Symbols.withRemote) && !it.name.equals(TraversalSource.Symbols.withComputer) }. diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs index a52cb87..510a2f4 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs @@ -27,6 +27,7 @@ using System.Threading.Tasks; using Gremlin.Net.Driver.Messages; using Gremlin.Net.Process.Remote; using Gremlin.Net.Process.Traversal; +using Gremlin.Net.Process.Traversal.Strategy.Decoration; namespace Gremlin.Net.Driver.Remote { @@ -37,6 +38,15 @@ namespace Gremlin.Net.Driver.Remote { private readonly IGremlinClient _client; private readonly string _traversalSource; + +/// +/// Filter on these keys provided to OptionsStrategy and apply them to the request. Note that +/// "scriptEvaluationTimeout" was deprecated in 3.3.9 but still supported in server implementations and will +/// be removed in later versions. +/// +private readonly List _allowedKeys = new List +{Tokens.ArgsEvalTimeout, "scriptEvaluationTimeout", Tokens.ArgsBatchSize, + Tokens.RequestId, Tokens.ArgsUserAgent}; /// /// Initializes a new using "g" as the default remote TraversalSource name. @@ -78,9 +88,23 @@ namespace Gremlin.Net.Driver.Remote .Processor(Tokens.ProcessorTraversal) .OverrideRequestId(requestid) .AddArgument(Tokens.ArgsGremlin, bytecode) -.AddArgument(Tokens.ArgsAliases, new Dictionary {{"g", _traversalSource}}) -.Create(); -return await _client.SubmitAsync(requestMsg).ConfigureAwait(false); +
[tinkerpop] 01/01: TINKERPOP-2420 Added with() support for request options in C#
This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch TINKERPOP-2420 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git commit 5ef6bf3e83eaf131355be56a82b3ca7fbc9b3434 Author: Stephen Mallette AuthorDate: Fri Oct 2 16:52:39 2020 -0400 TINKERPOP-2420 Added with() support for request options in C# --- gremlin-dotnet/glv/GraphTraversalSource.template | 24 gremlin-dotnet/glv/generate.groovy | 1 + .../Driver/Remote/DriverRemoteConnection.cs| 23 --- .../Process/Traversal/GraphTraversalSource.cs | 26 ++ .../DriverRemoteConnection/GraphTraversalTests.cs | 13 ++- 5 files changed, 69 insertions(+), 18 deletions(-) diff --git a/gremlin-dotnet/glv/GraphTraversalSource.template b/gremlin-dotnet/glv/GraphTraversalSource.template index f3093e5..4ccf77f 100644 --- a/gremlin-dotnet/glv/GraphTraversalSource.template +++ b/gremlin-dotnet/glv/GraphTraversalSource.template @@ -72,6 +72,30 @@ namespace Gremlin.Net.Process.Traversal Bytecode = bytecode; } +public GraphTraversalSource With(string key) +{ +return With(key, true); +} + +public GraphTraversalSource With(string key, object value) +{ +var optionsStrategyInst = Bytecode.SourceInstructions.Find( +inst => inst.OperatorName == "withStrategies" && inst.Arguments[0] is OptionsStrategy); +OptionsStrategy optionsStrategy; + +if (optionsStrategyInst == null) +{ +optionsStrategy = new OptionsStrategy(); +optionsStrategy.Configuration[key] = value; +return WithStrategies(optionsStrategy); +} + +optionsStrategy = optionsStrategyInst.Arguments[0]; +optionsStrategy.Configuration[key] = value; +return new GraphTraversalSource(new List(TraversalStrategies), +new Bytecode(Bytecode)); +} + <% sourceStepMethods.each{ method -> %> public GraphTraversalSource <%= toCSharpMethodName.call(method.methodName) %>(<%= method.parameters %>) { diff --git a/gremlin-dotnet/glv/generate.groovy b/gremlin-dotnet/glv/generate.groovy index 26daa58..a951907 100644 --- a/gremlin-dotnet/glv/generate.groovy +++ b/gremlin-dotnet/glv/generate.groovy @@ -256,6 +256,7 @@ def binding = ["pmethods": P.class.getMethods(). findAll { GraphTraversalSource.class.equals(it.returnType) }. findAll { !it.name.equals("clone") && + !it.name.equals(TraversalSource.Symbols.with) && !it.name.equals(TraversalSource.Symbols.withRemote) && !it.name.equals(TraversalSource.Symbols.withComputer) }. diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs index a52cb87..a855413 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs @@ -27,6 +27,7 @@ using System.Threading.Tasks; using Gremlin.Net.Driver.Messages; using Gremlin.Net.Process.Remote; using Gremlin.Net.Process.Traversal; +using Gremlin.Net.Process.Traversal.Strategy.Decoration; namespace Gremlin.Net.Driver.Remote { @@ -37,6 +38,8 @@ namespace Gremlin.Net.Driver.Remote { private readonly IGremlinClient _client; private readonly string _traversalSource; +private readonly List _allowedKeys = new List +{"evaluationTimeout", "scriptEvaluationTimeout", "batchSize", "requestId", "userAgent"}; /// /// Initializes a new using "g" as the default remote TraversalSource name. @@ -78,9 +81,23 @@ namespace Gremlin.Net.Driver.Remote .Processor(Tokens.ProcessorTraversal) .OverrideRequestId(requestid) .AddArgument(Tokens.ArgsGremlin, bytecode) -.AddArgument(Tokens.ArgsAliases, new Dictionary {{"g", _traversalSource}}) -.Create(); -return await _client.SubmitAsync(requestMsg).ConfigureAwait(false); +.AddArgument(Tokens.ArgsAliases, new Dictionary {{"g", _traversalSource}}); + +var optionsStrategyInst = bytecode.SourceInstructions.Find( +s => s.OperatorName == "withStrategies" && s.Arguments[0] is OptionsStrategy); +if (optionsStrategyInst != null) +{ +OptionsStrategy optionsStrategy = optionsStrategyInst.Arguments[0]; +foreach (KeyValuePair pair in optionsStrategy.Configuration) +{ +if