Skip to content

Commit c57c666

Browse files
authored
Merge pull request #215 from zhenlineo/1.4-cpp
Change from optional methods to method overloading
2 parents cfe2905 + f4aabf1 commit c57c666

File tree

12 files changed

+238
-41
lines changed

12 files changed

+238
-41
lines changed

Neo4j.Driver/Neo4j.Driver.Tests/SessionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void ShouldSendOnRun()
5050
var session = NewSession(mockConn.Object);
5151
session.Run("lalalal");
5252

53-
mockConn.Verify(x => x.Run("lalalal", null, It.IsAny<ResultBuilder>(), true), Times.Once);
53+
mockConn.Verify(x => x.Run("lalalal", new Dictionary<string, object>(), It.IsAny<ResultBuilder>(), true), Times.Once);
5454
mockConn.Verify(x => x.Send());
5555
}
5656

Neo4j.Driver/Neo4j.Driver.Tests/StatementRunnerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ internal class MyStatementRunner : StatementRunner
3030
public string Statement { private set; get; }
3131
public IDictionary<string, object> Parameters { private set; get; }
3232

33-
public override IStatementResult Run(string statement, IDictionary<string,object> parameters = null)
33+
public override IStatementResult Run(Statement statement)
3434
{
35-
Statement = statement;
36-
Parameters = parameters;
35+
Statement = statement.Text;
36+
Parameters = statement.Parameters;
3737
return null; // nah, I do not care
3838
}
3939

Neo4j.Driver/Neo4j.Driver.Tests/TransactionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void ShouldRunPullAllSyncRun()
7474

7575
tx.Run("lalala");
7676

77-
mockConn.Verify(x => x.Run("lalala", null, It.IsAny<ResultBuilder>(), true), Times.Once);
77+
mockConn.Verify(x => x.Run("lalala", new Dictionary<string, object>(), It.IsAny<ResultBuilder>(), true), Times.Once);
7878
mockConn.Verify(x => x.Send(), Times.Once);
7979
}
8080

@@ -86,7 +86,7 @@ public void ShouldThrowExceptionIfPreviousTxFailed()
8686

8787
try
8888
{
89-
mockConn.Setup(x => x.Run(It.IsAny<string>(), null, It.IsAny<ResultBuilder>(), true))
89+
mockConn.Setup(x => x.Run(It.IsAny<string>(), new Dictionary<string, object>(), It.IsAny<ResultBuilder>(), true))
9090
.Throws<Neo4jException>();
9191
tx.Run("lalala");
9292
}
@@ -105,7 +105,7 @@ public void ShouldThrowExceptionIfFailedToRunAndFetchResult()
105105
var mockConn = new Mock<IConnection>();
106106
var tx = new Transaction(mockConn.Object);
107107

108-
mockConn.Setup(x => x.Run(It.IsAny<string>(), null, It.IsAny<ResultBuilder>(), true))
108+
mockConn.Setup(x => x.Run(It.IsAny<string>(), new Dictionary<string, object>(), It.IsAny<ResultBuilder>(), true))
109109
.Throws<Neo4jException>();
110110

111111
var error = Xunit.Record.Exception(() => tx.Run("ttt"));

Neo4j.Driver/Neo4j.Driver/Internal/Driver.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ internal class Driver : IDriver
2929
private ILogger _logger;
3030
public Uri Uri { get; }
3131

32+
private const AccessMode DefaultAccessMode = AccessMode.Write;
33+
private const string NullBookmark = null;
34+
3235
internal Driver(Uri uri, IConnectionProvider connectionProvider, IRetryLogic retryLogic, ILogger logger)
3336
{
3437
Throw.ArgumentNullException.IfNull(connectionProvider, nameof(connectionProvider));
@@ -39,7 +42,23 @@ internal Driver(Uri uri, IConnectionProvider connectionProvider, IRetryLogic ret
3942
_retryLogic = retryLogic;
4043
}
4144

42-
public ISession Session(AccessMode defaultMode=AccessMode.Write, string bookmark = null)
45+
public ISession Session()
46+
{
47+
return Session(DefaultAccessMode);
48+
}
49+
50+
public ISession Session(AccessMode defaultMode)
51+
{
52+
return Session(defaultMode, NullBookmark);
53+
}
54+
55+
public ISession Session(string bookmark)
56+
{
57+
return Session(DefaultAccessMode, bookmark);
58+
}
59+
60+
61+
public ISession Session(AccessMode defaultMode, string bookmark)
4362
{
4463
return Session(defaultMode, Bookmark.From(bookmark, _logger));
4564
}

Neo4j.Driver/Neo4j.Driver/Internal/Session.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ public Session(IConnectionProvider provider, ILogger logger, IRetryLogic retryLo
5353
UpdateBookmark(bookmark);
5454
}
5555

56-
public override IStatementResult Run(string statement, IDictionary<string, object> statementParameters = null)
56+
public override IStatementResult Run(Statement statement)
5757
{
5858
return TryExecute(() =>
5959
{
6060
EnsureCanRunMoreStatements();
6161

6262
_connection = _connectionProvider.Acquire(_defaultMode);
63-
var resultBuilder = new ResultBuilder(statement, statementParameters,
63+
var resultBuilder = new ResultBuilder(statement.Text, statement.Parameters,
6464
()=>_connection.ReceiveOne(), _connection.Server, this);
65-
_connection.Run(statement, statementParameters, resultBuilder);
65+
_connection.Run(statement.Text, statement.Parameters, resultBuilder);
6666
_connection.Send();
6767

6868
return resultBuilder.PreBuild();

Neo4j.Driver/Neo4j.Driver/Internal/StatementRunner.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717
using System.Collections.Generic;
18-
using System.Linq;
19-
using System.Reflection;
2018
using Neo4j.Driver.V1;
2119

2220
namespace Neo4j.Driver.Internal
@@ -27,17 +25,22 @@ protected StatementRunner(ILogger logger) : base(logger)
2725
{
2826
}
2927

30-
public abstract IStatementResult Run(string statement, IDictionary<string, object> parameters = null);
28+
public abstract IStatementResult Run(Statement statement);
3129

32-
public IStatementResult Run(Statement statement)
30+
public IStatementResult Run(string statement)
3331
{
34-
return Run(statement.Text, statement.Parameters);
32+
return Run(new Statement(statement));
33+
}
34+
35+
public IStatementResult Run(string statement, IDictionary<string, object> parameters)
36+
{
37+
return Run(new Statement(statement, parameters));
3538
}
3639

3740
public IStatementResult Run(string statement, object parameters)
3841
{
39-
var paramDictionary = parameters.ToDictionary();
40-
return Run(statement, paramDictionary);
42+
var cypherStatement = new Statement(statement, parameters.ToDictionary());
43+
return Run(cypherStatement);
4144
}
4245
}
4346

Neo4j.Driver/Neo4j.Driver/Internal/Transaction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ private void RollBackTx()
123123
_state = State.RolledBack;
124124
}
125125

126-
public override IStatementResult Run(string statement, IDictionary<string, object> parameters=null)
126+
public override IStatementResult Run(Statement statement)
127127
{
128128
return TryExecute(() =>
129129
{
130130
EnsureNotFailed();
131131

132-
var resultBuilder = new ResultBuilder(statement, parameters, () => _connection.ReceiveOne(),
132+
var resultBuilder = new ResultBuilder(statement.Text, statement.Parameters, () => _connection.ReceiveOne(),
133133
_connection.Server);
134-
_connection.Run(statement, parameters, resultBuilder);
134+
_connection.Run(statement.Text, statement.Parameters, resultBuilder);
135135
_connection.Send();
136136
return resultBuilder.PreBuild();
137137
});

Neo4j.Driver/Neo4j.Driver/V1/GraphDatabase.cs

Lines changed: 112 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,58 @@ namespace Neo4j.Driver.V1
2828
public static class GraphDatabase
2929
{
3030
internal const int DefaultBoltPort = 7687;
31+
3132
/// <summary>
3233
/// Returns a driver for a Neo4j instance with default configuration settings.
3334
/// </summary>
3435
/// <param name="uri">
35-
/// The <see cref="Uri" /> to the Neo4j instance. Should be in the form
36-
/// <c>bolt://&lt;server location&gt;:&lt;port&gt;</c>. If <c>port</c> is not supplied the default of <c>7687</c> will
36+
/// The URI to the Neo4j instance. Should be in the form
37+
/// <c>protocol://&lt;server location&gt;:&lt;port&gt;</c>.
38+
/// If <c>port</c> is not supplied the default of <c>7687</c> will
3739
/// be used.
40+
/// The supported protocols in URI could either be <c>bolt</c> or <c>bolt+routing</c>.
41+
/// The protocol <c>bolt</c> should be used when creating a driver connecting to the Neo4j instance directly.
42+
/// The protocol <c>bolt+routing</c> should be used when creating a driver with built-in routing.
43+
/// </param>
44+
/// <returns>A new <see cref="IDriver" /> instance specified by the <paramref name="uri" />.</returns>
45+
/// <remarks>Ensure you provide the protocol for the <paramref name="uri" />.</remarks>
46+
/// <exception cref="ArgumentNullException">Thrown if <paramref name="uri" /> is <c>null</c>.</exception>
47+
public static IDriver Driver(string uri)
48+
{
49+
return Driver(new Uri(uri));
50+
}
51+
52+
/// <summary>
53+
/// Returns a driver for a Neo4j instance with default configuration settings.
54+
/// </summary>
55+
/// <param name="uri">
56+
/// The URI to the Neo4j instance. Should be in the form
57+
/// <c>protocol://&lt;server location&gt;:&lt;port&gt;</c>.
58+
/// If <c>port</c> is not supplied the default of <c>7687</c> will
59+
/// be used.
60+
/// The supported protocols in URI could either be <c>bolt</c> or <c>bolt+routing</c>.
61+
/// The protocol <c>bolt</c> should be used when creating a driver connecting to the Neo4j instance directly.
62+
/// The protocol <c>bolt+routing</c> should be used when creating a driver with built-in routing.
63+
/// </param>
64+
/// <returns>A new <see cref="IDriver" /> instance specified by the <paramref name="uri" />.</returns>
65+
/// <remarks>Ensure you provide the protocol for the <paramref name="uri" />.</remarks>
66+
/// <exception cref="ArgumentNullException">Thrown if <paramref name="uri" /> is <c>null</c>.</exception>
67+
public static IDriver Driver(Uri uri)
68+
{
69+
return Driver(uri, (Config)null);
70+
}
71+
72+
/// <summary>
73+
/// Returns a driver for a Neo4j instance with custom configuration.
74+
/// </summary>
75+
/// <param name="uri">
76+
/// The URI to the Neo4j instance. Should be in the form
77+
/// <c>protocol://&lt;server location&gt;:&lt;port&gt;</c>.
78+
/// If <c>port</c> is not supplied the default of <c>7687</c> will
79+
/// be used.
80+
/// The supported protocols in URI could either be <c>bolt</c> or <c>bolt+routing</c>.
81+
/// The protocol <c>bolt</c> should be used when creating a driver connecting to the Neo4j instance directly.
82+
/// The protocol <c>bolt+routing</c> should be used when creating a driver with built-in routing.
3883
/// </param>
3984
/// <param name="config">
4085
/// Configuration for the driver instance to use, if <c>null</c> <see cref="Config.DefaultConfig" />
@@ -43,18 +88,22 @@ public static class GraphDatabase
4388
/// <returns>A new <see cref="IDriver" /> instance specified by the <paramref name="uri" />.</returns>
4489
/// <remarks>Ensure you provide the protocol for the <paramref name="uri" />.</remarks>
4590
/// <exception cref="ArgumentNullException">Thrown if <paramref name="uri" /> is <c>null</c>.</exception>
46-
public static IDriver Driver(Uri uri, Config config = null)
91+
public static IDriver Driver(string uri, Config config)
4792
{
48-
return Driver(uri, AuthTokens.None, config ?? Config.DefaultConfig);
93+
return Driver(new Uri(uri), config);
4994
}
5095

5196
/// <summary>
52-
/// Returns a driver for a Neo4j instance with default configuration settings.
97+
/// Returns a driver for a Neo4j instance with custom configuration.
5398
/// </summary>
5499
/// <param name="uri">
55100
/// The URI to the Neo4j instance. Should be in the form
56-
/// <c>bolt://&lt;server location&gt;:&lt;port&gt;</c>. If <c>port</c> is not supplied the default of <c>7687</c> will
101+
/// <c>protocol://&lt;server location&gt;:&lt;port&gt;</c>.
102+
/// If <c>port</c> is not supplied the default of <c>7687</c> will
57103
/// be used.
104+
/// The supported protocols in URI could either be <c>bolt</c> or <c>bolt+routing</c>.
105+
/// The protocol <c>bolt</c> should be used when creating a driver connecting to the Neo4j instance directly.
106+
/// The protocol <c>bolt+routing</c> should be used when creating a driver with built-in routing.
58107
/// </param>
59108
/// <param name="config">
60109
/// Configuration for the driver instance to use, if <c>null</c> <see cref="Config.DefaultConfig" />
@@ -63,27 +112,74 @@ public static IDriver Driver(Uri uri, Config config = null)
63112
/// <returns>A new <see cref="IDriver" /> instance specified by the <paramref name="uri" />.</returns>
64113
/// <remarks>Ensure you provide the protocol for the <paramref name="uri" />.</remarks>
65114
/// <exception cref="ArgumentNullException">Thrown if <paramref name="uri" /> is <c>null</c>.</exception>
66-
public static IDriver Driver(string uri, Config config = null)
115+
public static IDriver Driver(Uri uri, Config config)
67116
{
68-
return Driver(new Uri(uri), AuthTokens.None, config ?? Config.DefaultConfig);
117+
return Driver(uri, AuthTokens.None, config);
118+
}
119+
120+
/// <summary>
121+
/// Returns a driver for a Neo4j instance with default configuration settings.
122+
/// </summary>
123+
/// <param name="uri">
124+
/// The URI to the Neo4j instance. Should be in the form
125+
/// <c>protocol://&lt;server location&gt;:&lt;port&gt;</c>.
126+
/// If <c>port</c> is not supplied the default of <c>7687</c> will
127+
/// be used.
128+
/// The supported protocols in URI could either be <c>bolt</c> or <c>bolt+routing</c>.
129+
/// The protocol <c>bolt</c> should be used when creating a driver connecting to the Neo4j instance directly.
130+
/// The protocol <c>bolt+routing</c> should be used when creating a driver with built-in routing.
131+
/// </param>
132+
/// <param name="authToken">Authentication to use, <see cref="AuthTokens" />.</param>
133+
/// <returns>A new <see cref="IDriver" /> instance specified by the <paramref name="uri" />.</returns>
134+
/// <remarks>Ensure you provide the protocol for the <paramref name="uri" />.</remarks>
135+
/// <exception cref="ArgumentNullException">Thrown if <paramref name="uri" /> is <c>null</c>.</exception>
136+
public static IDriver Driver(string uri, IAuthToken authToken)
137+
{
138+
return Driver(new Uri(uri), authToken);
139+
}
140+
141+
/// <summary>
142+
/// Returns a driver for a Neo4j instance with default configuration settings.
143+
/// </summary>
144+
/// <param name="uri">
145+
/// The URI to the Neo4j instance. Should be in the form
146+
/// <c>protocol://&lt;server location&gt;:&lt;port&gt;</c>.
147+
/// If <c>port</c> is not supplied the default of <c>7687</c> will
148+
/// be used.
149+
/// The supported protocols in URI could either be <c>bolt</c> or <c>bolt+routing</c>.
150+
/// The protocol <c>bolt</c> should be used when creating a driver connecting to the Neo4j instance directly.
151+
/// The protocol <c>bolt+routing</c> should be used when creating a driver with built-in routing.
152+
/// </param>
153+
/// <param name="authToken">Authentication to use, <see cref="AuthTokens" />.</param>
154+
/// <returns>A new <see cref="IDriver" /> instance specified by the <paramref name="uri" />.</returns>
155+
/// <remarks>Ensure you provide the protocol for the <paramref name="uri" />.</remarks>
156+
/// <exception cref="ArgumentNullException">Thrown if <paramref name="uri" /> is <c>null</c>.</exception>
157+
public static IDriver Driver(Uri uri, IAuthToken authToken)
158+
{
159+
return Driver(uri, authToken, null);
69160
}
70161

71162
/// <summary>
72163
/// Returns a driver for a Neo4j instance with custom configuration.
73164
/// </summary>
74165
/// <param name="uri">
75-
/// The <see cref="Uri" /> to the Neo4j instance. Should be in the form
76-
/// <c>bolt://&lt;server location&gt;:&lt;port&gt;</c>. If <c>port</c> is not supplied the default of <c>7687</c> will
77-
/// be used.</param>
166+
/// The URI to the Neo4j instance. Should be in the form
167+
/// <c>protocol://&lt;server location&gt;:&lt;port&gt;</c>.
168+
/// If <c>port</c> is not supplied the default of <c>7687</c> will
169+
/// be used.
170+
/// The supported protocols in URI could either be <c>bolt</c> or <c>bolt+routing</c>.
171+
/// The protocol <c>bolt</c> should be used when creating a driver connecting to the Neo4j instance directly.
172+
/// The protocol <c>bolt+routing</c> should be used when creating a driver with built-in routing.
173+
/// </param>
78174
/// <param name="authToken">Authentication to use, <see cref="AuthTokens" />.</param>
79175
/// <param name="config">
80176
/// Configuration for the driver instance to use, if <c>null</c> <see cref="Config.DefaultConfig" />
81177
/// is used.
82178
/// </param>
83179
/// <returns>A new driver to the database instance specified by the <paramref name="uri"/>.</returns>
84-
public static IDriver Driver(string uri, IAuthToken authToken, Config config = null)
180+
public static IDriver Driver(string uri, IAuthToken authToken, Config config)
85181
{
86-
return Driver(new Uri(uri), authToken, config ?? Config.DefaultConfig);
182+
return Driver(new Uri(uri), authToken, config);
87183
}
88184

89185
/// <summary>
@@ -99,8 +195,10 @@ public static IDriver Driver(string uri, IAuthToken authToken, Config config = n
99195
/// is used.
100196
/// </param>
101197
/// <returns>A new driver to the database instance specified by the <paramref name="uri"/>.</returns>
102-
public static IDriver Driver(Uri uri, IAuthToken authToken, Config config = null)
198+
public static IDriver Driver(Uri uri, IAuthToken authToken, Config config)
103199
{
200+
Throw.ArgumentNullException.IfNull(uri, nameof(uri));
201+
Throw.ArgumentNullException.IfNull(authToken, nameof(authToken));
104202
config = config ?? Config.DefaultConfig;
105203

106204
var parsedUri = uri.ParseUri(DefaultBoltPort);

0 commit comments

Comments
 (0)